Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Parse options for the GNU linker. |
b3adc24a | 2 | Copyright (C) 1991-2020 Free Software Foundation, Inc. |
252b5132 | 3 | |
f96b4a7b | 4 | This file is part of the GNU Binutils. |
252b5132 | 5 | |
f96b4a7b | 6 | This program is free software; you can redistribute it and/or modify |
53b2a62f | 7 | it under the terms of the GNU General Public License as published by |
f96b4a7b NC |
8 | the Free Software Foundation; either version 3 of the License, or |
9 | (at your option) any later version. | |
252b5132 | 10 | |
f96b4a7b | 11 | This program is distributed in the hope that it will be useful, |
53b2a62f NC |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
252b5132 | 15 | |
53b2a62f | 16 | You should have received a copy of the GNU General Public License |
f96b4a7b NC |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
19 | MA 02110-1301, USA. */ | |
252b5132 | 20 | |
3db64b00 | 21 | #include "sysdep.h" |
252b5132 | 22 | #include "bfd.h" |
c428fa83 | 23 | #include "bfdver.h" |
252b5132 RH |
24 | #include "libiberty.h" |
25 | #include <stdio.h> | |
26 | #include <string.h> | |
3882b010 | 27 | #include "safe-ctype.h" |
252b5132 RH |
28 | #include "getopt.h" |
29 | #include "bfdlink.h" | |
1ff6de03 | 30 | #include "ctf-api.h" |
252b5132 RH |
31 | #include "ld.h" |
32 | #include "ldmain.h" | |
33 | #include "ldmisc.h" | |
34 | #include "ldexp.h" | |
35 | #include "ldlang.h" | |
df2a7313 | 36 | #include <ldgram.h> |
252b5132 RH |
37 | #include "ldlex.h" |
38 | #include "ldfile.h" | |
39 | #include "ldver.h" | |
40 | #include "ldemul.h" | |
28c309a2 | 41 | #include "demangle.h" |
0381901e | 42 | #if BFD_SUPPORTS_PLUGINS |
5d3236ee | 43 | #include "plugin.h" |
0381901e | 44 | #endif /* BFD_SUPPORTS_PLUGINS */ |
252b5132 RH |
45 | |
46 | #ifndef PATH_SEPARATOR | |
47 | #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__)) | |
48 | #define PATH_SEPARATOR ';' | |
49 | #else | |
50 | #define PATH_SEPARATOR ':' | |
51 | #endif | |
52 | #endif | |
53 | ||
5cc18311 | 54 | /* Somewhere above, sys/stat.h got included . . . . */ |
252b5132 RH |
55 | #if !defined(S_ISDIR) && defined(S_IFDIR) |
56 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
57 | #endif | |
58 | ||
1579bae1 AM |
59 | static void set_default_dirlist (char *); |
60 | static void set_section_start (char *, char *); | |
ba916c8a | 61 | static void set_segment_start (const char *, char *); |
1579bae1 | 62 | static void help (void); |
252b5132 | 63 | |
252b5132 RH |
64 | /* The long options. This structure is used for both the option |
65 | parsing and the help text. */ | |
66 | ||
1e9cc1c2 NC |
67 | enum control_enum { |
68 | /* Use one dash before long option name. */ | |
f82aa165 | 69 | ONE_DASH = 1, |
1e9cc1c2 | 70 | /* Use two dashes before long option name. */ |
f82aa165 | 71 | TWO_DASHES = 2, |
1e9cc1c2 NC |
72 | /* Only accept two dashes before the long option name. |
73 | This is an overloading of the use of this enum, since originally it | |
74 | was only intended to tell the --help display function how to display | |
75 | the long option name. This feature was added in order to resolve | |
76 | the confusion about the -omagic command line switch. Is it setting | |
77 | the output file name to "magic" or is it setting the NMAGIC flag on | |
78 | the output ? It has been decided that it is setting the output file | |
79 | name, and that if you want to set the NMAGIC flag you should use -N | |
80 | or --omagic. */ | |
81 | EXACTLY_TWO_DASHES, | |
82 | /* Don't mention this option in --help output. */ | |
83 | NO_HELP | |
84 | }; | |
85 | ||
b79e8c78 NC |
86 | struct ld_option |
87 | { | |
252b5132 RH |
88 | /* The long option information. */ |
89 | struct option opt; | |
90 | /* The short option with the same meaning ('\0' if none). */ | |
91 | char shortopt; | |
92 | /* The name of the argument (NULL if none). */ | |
93 | const char *arg; | |
94 | /* The documentation string. If this is NULL, this is a synonym for | |
95 | the previous option. */ | |
96 | const char *doc; | |
1e9cc1c2 | 97 | enum control_enum control; |
252b5132 RH |
98 | }; |
99 | ||
b79e8c78 NC |
100 | static const struct ld_option ld_options[] = |
101 | { | |
252b5132 | 102 | { {NULL, required_argument, NULL, '\0'}, |
6feb9908 AM |
103 | 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"), |
104 | ONE_DASH }, | |
252b5132 | 105 | { {"architecture", required_argument, NULL, 'A'}, |
6feb9908 | 106 | 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES }, |
252b5132 | 107 | { {"format", required_argument, NULL, 'b'}, |
6feb9908 AM |
108 | 'b', N_("TARGET"), N_("Specify target for following input files"), |
109 | TWO_DASHES }, | |
252b5132 | 110 | { {"mri-script", required_argument, NULL, 'c'}, |
6feb9908 | 111 | 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES }, |
252b5132 | 112 | { {"dc", no_argument, NULL, 'd'}, |
6feb9908 | 113 | 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH }, |
252b5132 | 114 | { {"dp", no_argument, NULL, 'd'}, |
6feb9908 | 115 | '\0', NULL, NULL, ONE_DASH }, |
7bdf4127 AB |
116 | { {"force-group-allocation", no_argument, NULL, |
117 | OPTION_FORCE_GROUP_ALLOCATION}, | |
118 | '\0', NULL, N_("Force group members out of groups"), TWO_DASHES }, | |
252b5132 | 119 | { {"entry", required_argument, NULL, 'e'}, |
6feb9908 | 120 | 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES }, |
252b5132 | 121 | { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC}, |
6feb9908 | 122 | 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES }, |
267e2722 CD |
123 | { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC}, |
124 | '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES }, | |
abf874aa CL |
125 | { {"enable-non-contiguous-regions", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS}, |
126 | '\0', NULL, N_("Enable support of non-contiguous memory regions"), TWO_DASHES }, | |
127 | { {"enable-non-contiguous-regions-warnings", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS}, | |
128 | '\0', NULL, N_("Enable warnings when --enable-non-contiguous-regions may cause unexpected behaviour"), TWO_DASHES }, | |
252b5132 | 129 | { {"EB", no_argument, NULL, OPTION_EB}, |
6feb9908 | 130 | '\0', NULL, N_("Link big-endian objects"), ONE_DASH }, |
252b5132 | 131 | { {"EL", no_argument, NULL, OPTION_EL}, |
6feb9908 | 132 | '\0', NULL, N_("Link little-endian objects"), ONE_DASH }, |
252b5132 | 133 | { {"auxiliary", required_argument, NULL, 'f'}, |
6feb9908 AM |
134 | 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"), |
135 | TWO_DASHES }, | |
252b5132 | 136 | { {"filter", required_argument, NULL, 'F'}, |
6feb9908 AM |
137 | 'F', N_("SHLIB"), N_("Filter for shared object symbol table"), |
138 | TWO_DASHES }, | |
252b5132 | 139 | { {NULL, no_argument, NULL, '\0'}, |
6feb9908 | 140 | 'g', NULL, N_("Ignored"), ONE_DASH }, |
252b5132 | 141 | { {"gpsize", required_argument, NULL, 'G'}, |
6feb9908 AM |
142 | 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"), |
143 | TWO_DASHES }, | |
252b5132 | 144 | { {"soname", required_argument, NULL, OPTION_SONAME}, |
6feb9908 | 145 | 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH }, |
506eee22 | 146 | { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER}, |
6feb9908 AM |
147 | 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"), |
148 | TWO_DASHES }, | |
9b8b325a RF |
149 | { {"no-dynamic-linker", no_argument, NULL, OPTION_NO_DYNAMIC_LINKER}, |
150 | '\0', NULL, N_("Produce an executable with no program interpreter header"), | |
151 | TWO_DASHES }, | |
252b5132 | 152 | { {"library", required_argument, NULL, 'l'}, |
6feb9908 | 153 | 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES }, |
252b5132 | 154 | { {"library-path", required_argument, NULL, 'L'}, |
6feb9908 AM |
155 | 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), |
156 | TWO_DASHES }, | |
e2243057 RS |
157 | { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT}, |
158 | '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES }, | |
252b5132 | 159 | { {NULL, required_argument, NULL, '\0'}, |
6feb9908 | 160 | 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH }, |
252b5132 | 161 | { {"print-map", no_argument, NULL, 'M'}, |
6feb9908 | 162 | 'M', NULL, N_("Print map file on standard output"), TWO_DASHES }, |
252b5132 | 163 | { {"nmagic", no_argument, NULL, 'n'}, |
6feb9908 | 164 | 'n', NULL, N_("Do not page align data"), TWO_DASHES }, |
252b5132 | 165 | { {"omagic", no_argument, NULL, 'N'}, |
6feb9908 AM |
166 | 'N', NULL, N_("Do not page align data, do not make text readonly"), |
167 | EXACTLY_TWO_DASHES }, | |
63fd3b82 | 168 | { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC}, |
6feb9908 AM |
169 | '\0', NULL, N_("Page align data, make text readonly"), |
170 | EXACTLY_TWO_DASHES }, | |
252b5132 | 171 | { {"output", required_argument, NULL, 'o'}, |
6feb9908 | 172 | 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES }, |
252b5132 | 173 | { {NULL, required_argument, NULL, '\0'}, |
6feb9908 | 174 | 'O', NULL, N_("Optimize output file"), ONE_DASH }, |
76359541 TP |
175 | { {"out-implib", required_argument, NULL, OPTION_OUT_IMPLIB}, |
176 | '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES }, | |
0381901e | 177 | #if BFD_SUPPORTS_PLUGINS |
5d3236ee DK |
178 | { {"plugin", required_argument, NULL, OPTION_PLUGIN}, |
179 | '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH }, | |
180 | { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT}, | |
181 | '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH }, | |
94bf3a11 L |
182 | { {"flto", optional_argument, NULL, OPTION_IGNORE}, |
183 | '\0', NULL, N_("Ignored for GCC LTO option compatibility"), | |
184 | ONE_DASH }, | |
185 | { {"flto-partition=", required_argument, NULL, OPTION_IGNORE}, | |
186 | '\0', NULL, N_("Ignored for GCC LTO option compatibility"), | |
187 | ONE_DASH }, | |
070558eb AM |
188 | #else |
189 | { {"plugin", required_argument, NULL, OPTION_IGNORE}, | |
190 | '\0', N_("PLUGIN"), N_("Load named plugin (ignored)"), ONE_DASH }, | |
191 | { {"plugin-opt", required_argument, NULL, OPTION_IGNORE}, | |
192 | '\0', N_("ARG"), N_("Send arg to last-loaded plugin (ignored)"), ONE_DASH }, | |
0381901e | 193 | #endif /* BFD_SUPPORTS_PLUGINS */ |
add24320 L |
194 | { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE}, |
195 | '\0', NULL, N_("Ignored for GCC linker option compatibility"), | |
196 | ONE_DASH }, | |
88b9e2eb L |
197 | { {"map-whole-files", optional_argument, NULL, OPTION_IGNORE}, |
198 | '\0', NULL, N_("Ignored for gold option compatibility"), | |
199 | TWO_DASHES }, | |
200 | { {"no-map-whole-files", optional_argument, NULL, OPTION_IGNORE}, | |
201 | '\0', NULL, N_("Ignored for gold option compatibility"), | |
202 | TWO_DASHES }, | |
252b5132 | 203 | { {"Qy", no_argument, NULL, OPTION_IGNORE}, |
6feb9908 | 204 | '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH }, |
a712da20 | 205 | { {"emit-relocs", no_argument, NULL, 'q'}, |
6feb9908 | 206 | 'q', NULL, "Generate relocations in final output", TWO_DASHES }, |
1049f94e | 207 | { {"relocatable", no_argument, NULL, 'r'}, |
6feb9908 | 208 | 'r', NULL, N_("Generate relocatable output"), TWO_DASHES }, |
252b5132 | 209 | { {NULL, no_argument, NULL, '\0'}, |
6feb9908 | 210 | 'i', NULL, NULL, ONE_DASH }, |
252b5132 | 211 | { {"just-symbols", required_argument, NULL, 'R'}, |
6feb9908 AM |
212 | 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"), |
213 | TWO_DASHES }, | |
252b5132 | 214 | { {"strip-all", no_argument, NULL, 's'}, |
6feb9908 | 215 | 's', NULL, N_("Strip all symbols"), TWO_DASHES }, |
252b5132 | 216 | { {"strip-debug", no_argument, NULL, 'S'}, |
6feb9908 | 217 | 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES }, |
d5cd3933 | 218 | { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED}, |
6feb9908 | 219 | '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES }, |
d5cd3933 | 220 | { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED}, |
6feb9908 | 221 | '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES }, |
252b5132 | 222 | { {"trace", no_argument, NULL, 't'}, |
6feb9908 | 223 | 't', NULL, N_("Trace file opens"), TWO_DASHES }, |
252b5132 | 224 | { {"script", required_argument, NULL, 'T'}, |
6feb9908 | 225 | 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES }, |
14be8564 L |
226 | { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT}, |
227 | '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES }, | |
228 | { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT}, | |
229 | '\0', NULL, NULL, ONE_DASH }, | |
252b5132 | 230 | { {"undefined", required_argument, NULL, 'u'}, |
6feb9908 AM |
231 | 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), |
232 | TWO_DASHES }, | |
0a618243 AB |
233 | { {"require-defined", required_argument, NULL, OPTION_REQUIRE_DEFINED_SYMBOL}, |
234 | '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"), | |
235 | TWO_DASHES }, | |
577a0623 | 236 | { {"unique", optional_argument, NULL, OPTION_UNIQUE}, |
6feb9908 AM |
237 | '\0', N_("[=SECTION]"), |
238 | N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES }, | |
252b5132 | 239 | { {"Ur", no_argument, NULL, OPTION_UR}, |
6feb9908 | 240 | '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH }, |
252b5132 | 241 | { {"version", no_argument, NULL, OPTION_VERSION}, |
6feb9908 | 242 | 'v', NULL, N_("Print version information"), TWO_DASHES }, |
252b5132 | 243 | { {NULL, no_argument, NULL, '\0'}, |
6feb9908 | 244 | 'V', NULL, N_("Print version and emulation information"), ONE_DASH }, |
252b5132 | 245 | { {"discard-all", no_argument, NULL, 'x'}, |
6feb9908 | 246 | 'x', NULL, N_("Discard all local symbols"), TWO_DASHES }, |
252b5132 | 247 | { {"discard-locals", no_argument, NULL, 'X'}, |
6feb9908 | 248 | 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES }, |
f5fa8ca2 | 249 | { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE}, |
6feb9908 | 250 | '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES }, |
252b5132 | 251 | { {"trace-symbol", required_argument, NULL, 'y'}, |
6feb9908 | 252 | 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES }, |
252b5132 | 253 | { {NULL, required_argument, NULL, '\0'}, |
6feb9908 AM |
254 | 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), |
255 | ONE_DASH }, | |
252b5132 | 256 | { {"start-group", no_argument, NULL, '('}, |
6feb9908 | 257 | '(', NULL, N_("Start a group"), TWO_DASHES }, |
252b5132 | 258 | { {"end-group", no_argument, NULL, ')'}, |
6feb9908 AM |
259 | ')', NULL, N_("End a group"), TWO_DASHES }, |
260 | { {"accept-unknown-input-arch", no_argument, NULL, | |
261 | OPTION_ACCEPT_UNKNOWN_INPUT_ARCH}, | |
262 | '\0', NULL, | |
263 | N_("Accept input files whose architecture cannot be determined"), | |
264 | TWO_DASHES }, | |
265 | { {"no-accept-unknown-input-arch", no_argument, NULL, | |
266 | OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH}, | |
267 | '\0', NULL, N_("Reject input files whose architecture is unknown"), | |
268 | TWO_DASHES }, | |
ddbb8a31 NC |
269 | |
270 | /* The next two options are deprecated because of their similarity to | |
271 | --as-needed and --no-as-needed. They have been replaced by | |
99bca8f9 | 272 | --copy-dt-needed-entries and --no-copy-dt-needed-entries. */ |
ddbb8a31 NC |
273 | { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC}, |
274 | '\0', NULL, NULL, NO_HELP }, | |
275 | { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC}, | |
276 | '\0', NULL, NULL, NO_HELP }, | |
277 | ||
278 | { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR}, | |
8fdd7217 NC |
279 | '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"), |
280 | TWO_DASHES }, | |
ddbb8a31 NC |
281 | { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR}, |
282 | '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n" | |
283 | " the command line"), | |
8fdd7217 | 284 | TWO_DASHES }, |
252b5132 | 285 | { {"assert", required_argument, NULL, OPTION_ASSERT}, |
6feb9908 | 286 | '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH }, |
252b5132 | 287 | { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED}, |
6feb9908 | 288 | '\0', NULL, N_("Link against shared libraries"), ONE_DASH }, |
252b5132 | 289 | { {"dy", no_argument, NULL, OPTION_CALL_SHARED}, |
6feb9908 | 290 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 291 | { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, |
6feb9908 | 292 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 293 | { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED}, |
6feb9908 | 294 | '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH }, |
252b5132 | 295 | { {"dn", no_argument, NULL, OPTION_NON_SHARED}, |
6feb9908 | 296 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 297 | { {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, |
6feb9908 | 298 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 299 | { {"static", no_argument, NULL, OPTION_NON_SHARED}, |
6feb9908 | 300 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 301 | { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC}, |
6feb9908 | 302 | '\0', NULL, N_("Bind global references locally"), ONE_DASH }, |
d8cf8b51 | 303 | { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS}, |
40b36307 | 304 | '\0', NULL, N_("Bind global function references locally"), ONE_DASH }, |
252b5132 | 305 | { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS}, |
6feb9908 AM |
306 | '\0', NULL, N_("Check section addresses for overlaps (default)"), |
307 | TWO_DASHES }, | |
252b5132 | 308 | { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS}, |
6feb9908 AM |
309 | '\0', NULL, N_("Do not check section addresses for overlaps"), |
310 | TWO_DASHES }, | |
ddbb8a31 NC |
311 | { {"copy-dt-needed-entries", no_argument, NULL, |
312 | OPTION_ADD_DT_NEEDED_FOR_DYNAMIC}, | |
313 | '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"), | |
314 | TWO_DASHES }, | |
315 | { {"no-copy-dt-needed-entries", no_argument, NULL, | |
316 | OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC}, | |
317 | '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"), | |
318 | TWO_DASHES }, | |
319 | ||
252b5132 | 320 | { {"cref", no_argument, NULL, OPTION_CREF}, |
6feb9908 | 321 | '\0', NULL, N_("Output cross reference table"), TWO_DASHES }, |
252b5132 | 322 | { {"defsym", required_argument, NULL, OPTION_DEFSYM}, |
6feb9908 | 323 | '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES }, |
28c309a2 | 324 | { {"demangle", optional_argument, NULL, OPTION_DEMANGLE}, |
6feb9908 AM |
325 | '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"), |
326 | TWO_DASHES }, | |
3f0a5f17 ME |
327 | { {"disable-multiple-abs-defs", no_argument, NULL, |
328 | OPTION_DISABLE_MULTIPLE_DEFS_ABS}, | |
329 | '\0', NULL, N_("Do not allow multiple definitions with symbols included\n" | |
330 | " in filename invoked by -R or --just-symbols"), | |
331 | TWO_DASHES}, | |
252b5132 | 332 | { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS}, |
6feb9908 | 333 | '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES}, |
8fdd7217 NC |
334 | { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}, |
335 | '\0', NULL, N_("Treat warnings as errors"), | |
336 | TWO_DASHES }, | |
0fe58ccd NC |
337 | { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL}, |
338 | '\0', NULL, N_("Do not treat warnings as errors (default)"), | |
339 | TWO_DASHES }, | |
3dbf70a2 | 340 | { {"fini", required_argument, NULL, OPTION_FINI}, |
6feb9908 | 341 | '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH }, |
252b5132 | 342 | { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX}, |
6feb9908 | 343 | '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES}, |
252b5132 | 344 | { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS}, |
6feb9908 AM |
345 | '\0', NULL, N_("Remove unused sections (on some targets)"), |
346 | TWO_DASHES }, | |
252b5132 | 347 | { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS}, |
6feb9908 AM |
348 | '\0', NULL, N_("Don't remove unused sections (default)"), |
349 | TWO_DASHES }, | |
c17d87de NC |
350 | { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS}, |
351 | '\0', NULL, N_("List removed unused sections on stderr"), | |
352 | TWO_DASHES }, | |
353 | { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS}, | |
354 | '\0', NULL, N_("Do not list removed unused sections"), | |
355 | TWO_DASHES }, | |
22185505 | 356 | { {"gc-keep-exported", no_argument, NULL, OPTION_GC_KEEP_EXPORTED}, |
357 | '\0', NULL, N_("Keep exported symbols when removing unused sections"), | |
358 | TWO_DASHES }, | |
2d643429 | 359 | { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE}, |
6feb9908 AM |
360 | '\0', NULL, N_("Set default hash table size close to <NUMBER>"), |
361 | TWO_DASHES }, | |
252b5132 | 362 | { {"help", no_argument, NULL, OPTION_HELP}, |
6feb9908 | 363 | '\0', NULL, N_("Print option help"), TWO_DASHES }, |
3dbf70a2 | 364 | { {"init", required_argument, NULL, OPTION_INIT}, |
6feb9908 | 365 | '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH }, |
252b5132 | 366 | { {"Map", required_argument, NULL, OPTION_MAP}, |
72a3b182 | 367 | '\0', N_("FILE/DIR"), N_("Write a linker map to FILE or DIR/<outputname>.map"), ONE_DASH }, |
4818e05f | 368 | { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON}, |
6feb9908 | 369 | '\0', NULL, N_("Do not define Common storage"), TWO_DASHES }, |
252b5132 | 370 | { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE }, |
6feb9908 | 371 | '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES }, |
252b5132 | 372 | { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY}, |
6feb9908 | 373 | '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES }, |
252b5132 | 374 | { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED}, |
6feb9908 AM |
375 | '\0', NULL, N_("Do not allow unresolved references in object files"), |
376 | TWO_DASHES }, | |
b79e8c78 | 377 | { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED}, |
cc643b88 | 378 | '\0', NULL, N_("Allow unresolved references in shared libraries"), |
6feb9908 AM |
379 | TWO_DASHES }, |
380 | { {"no-allow-shlib-undefined", no_argument, NULL, | |
381 | OPTION_NO_ALLOW_SHLIB_UNDEFINED}, | |
382 | '\0', NULL, N_("Do not allow unresolved references in shared libs"), | |
383 | TWO_DASHES }, | |
384 | { {"allow-multiple-definition", no_argument, NULL, | |
385 | OPTION_ALLOW_MULTIPLE_DEFINITION}, | |
386 | '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES }, | |
31941635 | 387 | { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION}, |
6feb9908 | 388 | '\0', NULL, N_("Disallow undefined version"), TWO_DASHES }, |
3e3b46e5 PB |
389 | { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER}, |
390 | '\0', NULL, N_("Create default symbol version"), TWO_DASHES }, | |
fc0e6df6 PB |
391 | { {"default-imported-symver", no_argument, NULL, |
392 | OPTION_DEFAULT_IMPORTED_SYMVER}, | |
393 | '\0', NULL, N_("Create default symbol version for imported symbols"), | |
394 | TWO_DASHES }, | |
252b5132 | 395 | { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH}, |
6feb9908 | 396 | '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES}, |
fe7929ce AM |
397 | { {"no-warn-search-mismatch", no_argument, NULL, |
398 | OPTION_NO_WARN_SEARCH_MISMATCH}, | |
399 | '\0', NULL, N_("Don't warn on finding an incompatible library"), | |
400 | TWO_DASHES}, | |
252b5132 | 401 | { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE}, |
6feb9908 | 402 | '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES }, |
252b5132 | 403 | { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, |
6feb9908 AM |
404 | '\0', NULL, N_("Create an output file even if errors occur"), |
405 | TWO_DASHES }, | |
252b5132 | 406 | { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, |
6feb9908 | 407 | '\0', NULL, NULL, NO_HELP }, |
361b220e | 408 | { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB}, |
6feb9908 | 409 | '\0', NULL, N_("Only use library directories specified on\n" |
c58dea77 AM |
410 | " the command line"), |
411 | ONE_DASH }, | |
252b5132 | 412 | { {"oformat", required_argument, NULL, OPTION_OFORMAT}, |
6feb9908 AM |
413 | '\0', N_("TARGET"), N_("Specify target of output file"), |
414 | EXACTLY_TWO_DASHES }, | |
30824704 RM |
415 | { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT}, |
416 | '\0', NULL, N_("Print default output format"), TWO_DASHES }, | |
cb9322a8 HPN |
417 | { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT}, |
418 | '\0', NULL, N_("Print current sysroot"), TWO_DASHES }, | |
252b5132 | 419 | { {"qmagic", no_argument, NULL, OPTION_IGNORE}, |
6feb9908 AM |
420 | '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH }, |
421 | { {"reduce-memory-overheads", no_argument, NULL, | |
422 | OPTION_REDUCE_MEMORY_OVERHEADS}, | |
423 | '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"), | |
424 | TWO_DASHES }, | |
252b5132 | 425 | { {"relax", no_argument, NULL, OPTION_RELAX}, |
28d5f677 NC |
426 | '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES }, |
427 | { {"no-relax", no_argument, NULL, OPTION_NO_RELAX}, | |
428 | '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES }, | |
252b5132 | 429 | { {"retain-symbols-file", required_argument, NULL, |
6feb9908 AM |
430 | OPTION_RETAIN_SYMBOLS_FILE}, |
431 | '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES }, | |
252b5132 | 432 | { {"rpath", required_argument, NULL, OPTION_RPATH}, |
6feb9908 | 433 | '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH }, |
252b5132 | 434 | { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK}, |
6feb9908 AM |
435 | '\0', N_("PATH"), N_("Set link time shared library search path"), |
436 | ONE_DASH }, | |
252b5132 | 437 | { {"shared", no_argument, NULL, OPTION_SHARED}, |
6feb9908 | 438 | '\0', NULL, N_("Create a shared library"), ONE_DASH }, |
252b5132 | 439 | { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */ |
6feb9908 | 440 | '\0', NULL, NULL, ONE_DASH }, |
36af4a4e | 441 | { {"pie", no_argument, NULL, OPTION_PIE}, |
6feb9908 | 442 | '\0', NULL, N_("Create a position independent executable"), ONE_DASH }, |
36af4a4e | 443 | { {"pic-executable", no_argument, NULL, OPTION_PIE}, |
6feb9908 | 444 | '\0', NULL, NULL, TWO_DASHES }, |
de7dd2bd | 445 | { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON}, |
9d5777a3 RM |
446 | '\0', N_("[=ascending|descending]"), |
447 | N_("Sort common symbols by alignment [in specified order]"), | |
de7dd2bd | 448 | TWO_DASHES }, |
252b5132 | 449 | { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, |
6feb9908 | 450 | '\0', NULL, NULL, NO_HELP }, |
bcaa7b3e | 451 | { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION}, |
9d5777a3 | 452 | '\0', N_("name|alignment"), |
bcaa7b3e | 453 | N_("Sort sections by name or maximum alignment"), TWO_DASHES }, |
db6751f2 | 454 | { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS}, |
6feb9908 AM |
455 | '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"), |
456 | TWO_DASHES }, | |
a854a4a7 | 457 | { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE}, |
6feb9908 AM |
458 | '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"), |
459 | TWO_DASHES }, | |
a854a4a7 | 460 | { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC}, |
6feb9908 AM |
461 | '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"), |
462 | TWO_DASHES }, | |
252b5132 | 463 | { {"stats", no_argument, NULL, OPTION_STATS}, |
6feb9908 | 464 | '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES }, |
ea20a7da | 465 | { {"target-help", no_argument, NULL, OPTION_TARGET_HELP}, |
6feb9908 | 466 | '\0', NULL, N_("Display target specific options"), TWO_DASHES }, |
252b5132 | 467 | { {"task-link", required_argument, NULL, OPTION_TASK_LINK}, |
6feb9908 | 468 | '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES }, |
252b5132 | 469 | { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}, |
6feb9908 | 470 | '\0', NULL, N_("Use same format as native linker"), TWO_DASHES }, |
176355da | 471 | { {"section-start", required_argument, NULL, OPTION_SECTION_START}, |
6feb9908 AM |
472 | '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"), |
473 | TWO_DASHES }, | |
252b5132 | 474 | { {"Tbss", required_argument, NULL, OPTION_TBSS}, |
6feb9908 | 475 | '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH }, |
252b5132 | 476 | { {"Tdata", required_argument, NULL, OPTION_TDATA}, |
6feb9908 | 477 | '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH }, |
252b5132 | 478 | { {"Ttext", required_argument, NULL, OPTION_TTEXT}, |
6feb9908 | 479 | '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH }, |
258795f5 L |
480 | { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT}, |
481 | '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH }, | |
9d5777a3 RM |
482 | { {"Trodata-segment", required_argument, NULL, OPTION_TRODATA_SEGMENT}, |
483 | '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH }, | |
0d705e9f AM |
484 | { {"Tldata-segment", required_argument, NULL, OPTION_TLDATA_SEGMENT}, |
485 | '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH }, | |
6feb9908 AM |
486 | { {"unresolved-symbols=<method>", required_argument, NULL, |
487 | OPTION_UNRESOLVED_SYMBOLS}, | |
488 | '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n" | |
c58dea77 AM |
489 | " ignore-all, report-all, ignore-in-object-files,\n" |
490 | " ignore-in-shared-libs"), | |
491 | TWO_DASHES }, | |
1715a13c L |
492 | { {"verbose", optional_argument, NULL, OPTION_VERBOSE}, |
493 | '\0', N_("[=NUMBER]"), | |
494 | N_("Output lots of information during link"), TWO_DASHES }, | |
252b5132 | 495 | { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */ |
6feb9908 | 496 | '\0', NULL, NULL, NO_HELP }, |
252b5132 | 497 | { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT }, |
6feb9908 | 498 | '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES }, |
252b5132 RH |
499 | { {"version-exports-section", required_argument, NULL, |
500 | OPTION_VERSION_EXPORTS_SECTION }, | |
6feb9908 | 501 | '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n" |
c58dea77 AM |
502 | " SYMBOL as the version."), |
503 | TWO_DASHES }, | |
40b36307 L |
504 | { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA}, |
505 | '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES }, | |
506 | { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW}, | |
507 | '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES }, | |
55255dae L |
508 | { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO}, |
509 | '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES }, | |
510 | { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST}, | |
511 | '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES }, | |
37a141bf FS |
512 | { {"export-dynamic-symbol", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL}, |
513 | '\0', N_("SYMBOL"), N_("Export the specified symbol"), EXACTLY_TWO_DASHES }, | |
514 | { {"export-dynamic-symbol-list", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL_LIST}, | |
515 | '\0', N_("FILE"), N_("Read export dynamic symbol list"), EXACTLY_TWO_DASHES }, | |
252b5132 | 516 | { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON}, |
6feb9908 | 517 | '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES }, |
252b5132 | 518 | { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS}, |
6feb9908 AM |
519 | '\0', NULL, N_("Warn if global constructors/destructors are seen"), |
520 | TWO_DASHES }, | |
252b5132 | 521 | { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP}, |
6feb9908 | 522 | '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES }, |
252b5132 | 523 | { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE}, |
6feb9908 | 524 | '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES }, |
252b5132 | 525 | { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN}, |
6feb9908 AM |
526 | '\0', NULL, N_("Warn if start of section changes due to alignment"), |
527 | TWO_DASHES }, | |
a6dbf402 | 528 | { {"warn-textrel", no_argument, NULL, OPTION_WARN_TEXTREL}, |
b32632c4 L |
529 | '\0', NULL, |
530 | #if DEFAULT_LD_TEXTREL_CHECK_WARNING | |
531 | N_("Warn if outpout has DT_TEXTREL (default)"), | |
532 | #else | |
533 | N_("Warn if outpout has DT_TEXTREL"), | |
534 | #endif | |
8fdd7217 | 535 | TWO_DASHES }, |
a6dbf402 L |
536 | { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_TEXTREL}, |
537 | '\0', NULL, NULL, NO_HELP }, | |
a0c402a5 L |
538 | { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM}, |
539 | '\0', NULL, N_("Warn if an object has alternate ELF machine code"), | |
540 | TWO_DASHES }, | |
6feb9908 AM |
541 | { {"warn-unresolved-symbols", no_argument, NULL, |
542 | OPTION_WARN_UNRESOLVED_SYMBOLS}, | |
560e09e9 | 543 | '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES }, |
6feb9908 AM |
544 | { {"error-unresolved-symbols", no_argument, NULL, |
545 | OPTION_ERROR_UNRESOLVED_SYMBOLS}, | |
560e09e9 | 546 | '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES }, |
252b5132 | 547 | { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE}, |
6feb9908 AM |
548 | '\0', NULL, N_("Include all objects from following archives"), |
549 | TWO_DASHES }, | |
252b5132 | 550 | { {"wrap", required_argument, NULL, OPTION_WRAP}, |
6feb9908 | 551 | '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES }, |
0e86e20e AM |
552 | { {"ignore-unresolved-symbol", required_argument, NULL, |
553 | OPTION_IGNORE_UNRESOLVED_SYMBOL}, | |
554 | '\0', N_("SYMBOL"), | |
555 | N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES }, | |
26278bb8 UD |
556 | { {"push-state", no_argument, NULL, OPTION_PUSH_STATE}, |
557 | '\0', NULL, N_("Push state of flags governing input file handling"), | |
558 | TWO_DASHES }, | |
559 | { {"pop-state", no_argument, NULL, OPTION_POP_STATE}, | |
560 | '\0', NULL, N_("Pop state of flags governing input file handling"), | |
561 | TWO_DASHES }, | |
3604cb1f TG |
562 | { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE}, |
563 | '\0', NULL, N_("Report target memory usage"), TWO_DASHES }, | |
c005eb9e AB |
564 | { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING}, |
565 | '\0', N_("=MODE"), N_("Control how orphan sections are handled."), | |
566 | TWO_DASHES }, | |
035801ce FS |
567 | { {"print-map-discarded", no_argument, NULL, OPTION_PRINT_MAP_DISCARDED}, |
568 | '\0', NULL, N_("Show discarded sections in map file output (default)"), | |
569 | TWO_DASHES }, | |
570 | { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISCARDED}, | |
571 | '\0', NULL, N_("Do not show discarded sections in map file output"), | |
572 | TWO_DASHES }, | |
252b5132 RH |
573 | }; |
574 | ||
e4897a32 | 575 | #define OPTION_COUNT ARRAY_SIZE (ld_options) |
252b5132 | 576 | |
252b5132 | 577 | void |
1579bae1 | 578 | parse_args (unsigned argc, char **argv) |
252b5132 | 579 | { |
e4897a32 NC |
580 | unsigned i; |
581 | int is, il, irl; | |
252b5132 RH |
582 | int ingroup = 0; |
583 | char *default_dirlist = NULL; | |
3bcf5557 AM |
584 | char *shortopts; |
585 | struct option *longopts; | |
586 | struct option *really_longopts; | |
252b5132 | 587 | int last_optind; |
1914e264 AM |
588 | enum symbolic_enum |
589 | { | |
590 | symbolic_unset = 0, | |
591 | symbolic, | |
592 | symbolic_functions, | |
593 | } opt_symbolic = symbolic_unset; | |
594 | enum dynamic_list_enum | |
595 | { | |
596 | dynamic_list_unset = 0, | |
597 | dynamic_list_data, | |
598 | dynamic_list | |
599 | } opt_dynamic_list = dynamic_list_unset; | |
37a141bf | 600 | struct bfd_elf_dynamic_list *export_list = NULL; |
252b5132 | 601 | |
1e9cc1c2 NC |
602 | shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2); |
603 | longopts = (struct option *) | |
604 | xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1)); | |
605 | really_longopts = (struct option *) | |
606 | malloc (sizeof (*really_longopts) * (OPTION_COUNT + 1)); | |
3bcf5557 | 607 | |
252b5132 RH |
608 | /* Starting the short option string with '-' is for programs that |
609 | expect options and other ARGV-elements in any order and that care about | |
610 | the ordering of the two. We describe each non-option ARGV-element | |
611 | as if it were the argument of an option with character code 1. */ | |
612 | shortopts[0] = '-'; | |
613 | is = 1; | |
614 | il = 0; | |
e4897a32 | 615 | irl = 0; |
252b5132 RH |
616 | for (i = 0; i < OPTION_COUNT; i++) |
617 | { | |
618 | if (ld_options[i].shortopt != '\0') | |
619 | { | |
620 | shortopts[is] = ld_options[i].shortopt; | |
621 | ++is; | |
622 | if (ld_options[i].opt.has_arg == required_argument | |
623 | || ld_options[i].opt.has_arg == optional_argument) | |
624 | { | |
625 | shortopts[is] = ':'; | |
626 | ++is; | |
627 | if (ld_options[i].opt.has_arg == optional_argument) | |
628 | { | |
629 | shortopts[is] = ':'; | |
630 | ++is; | |
631 | } | |
632 | } | |
633 | } | |
634 | if (ld_options[i].opt.name != NULL) | |
635 | { | |
e4897a32 NC |
636 | if (ld_options[i].control == EXACTLY_TWO_DASHES) |
637 | { | |
638 | really_longopts[irl] = ld_options[i].opt; | |
639 | ++irl; | |
640 | } | |
641 | else | |
642 | { | |
643 | longopts[il] = ld_options[i].opt; | |
644 | ++il; | |
645 | } | |
252b5132 RH |
646 | } |
647 | } | |
648 | shortopts[is] = '\0'; | |
649 | longopts[il].name = NULL; | |
e4897a32 | 650 | really_longopts[irl].name = NULL; |
252b5132 | 651 | |
3bcf5557 AM |
652 | ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts); |
653 | ||
252b5132 RH |
654 | /* The -G option is ambiguous on different platforms. Sometimes it |
655 | specifies the largest data size to put into the small data | |
656 | section. Sometimes it is equivalent to --shared. Unfortunately, | |
657 | the first form takes an argument, while the second does not. | |
658 | ||
659 | We need to permit the --shared form because on some platforms, | |
660 | such as Solaris, gcc -shared will pass -G to the linker. | |
661 | ||
662 | To permit either usage, we look through the argument list. If we | |
663 | find -G not followed by a number, we change it into --shared. | |
664 | This will work for most normal cases. */ | |
665 | for (i = 1; i < argc; i++) | |
666 | if (strcmp (argv[i], "-G") == 0 | |
667 | && (i + 1 >= argc | |
3882b010 | 668 | || ! ISDIGIT (argv[i + 1][0]))) |
252b5132 RH |
669 | argv[i] = (char *) "--shared"; |
670 | ||
671 | /* Because we permit long options to start with a single dash, and | |
672 | we have a --library option, and the -l option is conventionally | |
673 | used with an immediately following argument, we can have bad | |
674 | results if somebody tries to use -l with a library whose name | |
675 | happens to start with "ibrary", as in -li. We avoid problems by | |
676 | simply turning -l into --library. This means that users will | |
677 | have to use two dashes in order to use --library, which is OK | |
678 | since that's how it is documented. | |
679 | ||
680 | FIXME: It's possible that this problem can arise for other short | |
681 | options as well, although the user does always have the recourse | |
682 | of adding a space between the option and the argument. */ | |
683 | for (i = 1; i < argc; i++) | |
684 | { | |
685 | if (argv[i][0] == '-' | |
686 | && argv[i][1] == 'l' | |
687 | && argv[i][2] != '\0') | |
688 | { | |
689 | char *n; | |
690 | ||
1e9cc1c2 | 691 | n = (char *) xmalloc (strlen (argv[i]) + 20); |
252b5132 RH |
692 | sprintf (n, "--library=%s", argv[i] + 2); |
693 | argv[i] = n; | |
694 | } | |
695 | } | |
696 | ||
697 | last_optind = -1; | |
698 | while (1) | |
699 | { | |
89894c62 | 700 | int longind; |
252b5132 | 701 | int optc; |
dab69f68 | 702 | static unsigned int defsym_count; |
252b5132 RH |
703 | |
704 | /* Using last_optind lets us avoid calling ldemul_parse_args | |
705 | multiple times on a single option, which would lead to | |
706 | confusion in the internal static variables maintained by | |
707 | getopt. This could otherwise happen for an argument like | |
708 | -nx, in which the -n is parsed as a single option, and we | |
709 | loop around to pick up the -x. */ | |
710 | if (optind != last_optind) | |
89894c62 AM |
711 | if (ldemul_parse_args (argc, argv)) |
712 | continue; | |
252b5132 RH |
713 | |
714 | /* getopt_long_only is like getopt_long, but '-' as well as '--' | |
715 | can indicate a long option. */ | |
0fc3347a | 716 | opterr = 0; |
89894c62 | 717 | last_optind = optind; |
252b5132 | 718 | optc = getopt_long_only (argc, argv, shortopts, longopts, &longind); |
0fc3347a NC |
719 | if (optc == '?') |
720 | { | |
89894c62 AM |
721 | optind = last_optind; |
722 | optc = getopt_long (argc, argv, "-", really_longopts, &longind); | |
0fc3347a | 723 | } |
b7ed8fad | 724 | |
3bcf5557 AM |
725 | if (ldemul_handle_option (optc)) |
726 | continue; | |
727 | ||
252b5132 RH |
728 | if (optc == -1) |
729 | break; | |
0fc3347a | 730 | |
252b5132 RH |
731 | switch (optc) |
732 | { | |
0fc3347a | 733 | case '?': |
f82aa165 NC |
734 | { |
735 | /* If the last word on the command line is an option that | |
736 | requires an argument, getopt will refuse to recognise it. | |
737 | Try to catch such options here and issue a more helpful | |
738 | error message than just "unrecognized option". */ | |
739 | int opt; | |
740 | ||
741 | for (opt = ARRAY_SIZE (ld_options); opt--;) | |
742 | if (ld_options[opt].opt.has_arg == required_argument | |
743 | /* FIXME: There are a few short options that do not | |
744 | have long equivalents, but which require arguments. | |
745 | We should handle them too. */ | |
746 | && ld_options[opt].opt.name != NULL | |
747 | && strcmp (argv[last_optind] + ld_options[opt].control, ld_options[opt].opt.name) == 0) | |
748 | { | |
749 | einfo (_("%P: %s: missing argument\n"), argv[last_optind]); | |
750 | break; | |
751 | } | |
752 | ||
753 | if (opt == -1) | |
754 | einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]); | |
755 | } | |
058a363d BE |
756 | /* Fall through. */ |
757 | ||
252b5132 | 758 | default: |
df5f2391 | 759 | einfo (_("%F%P: use the --help option for usage information\n")); |
80bb3407 | 760 | break; |
210a7bd1 | 761 | |
252b5132 | 762 | case 1: /* File name. */ |
1579bae1 | 763 | lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL); |
252b5132 RH |
764 | break; |
765 | ||
766 | case OPTION_IGNORE: | |
767 | break; | |
768 | case 'a': | |
769 | /* For HP/UX compatibility. Actually -a shared should mean | |
1579bae1 AM |
770 | ``use only shared libraries'' but, then, we don't |
771 | currently support shared libraries on HP/UX anyhow. */ | |
252b5132 | 772 | if (strcmp (optarg, "archive") == 0) |
66be1055 | 773 | input_flags.dynamic = FALSE; |
252b5132 RH |
774 | else if (strcmp (optarg, "shared") == 0 |
775 | || strcmp (optarg, "default") == 0) | |
66be1055 | 776 | input_flags.dynamic = TRUE; |
252b5132 | 777 | else |
df5f2391 | 778 | einfo (_("%F%P: unrecognized -a option `%s'\n"), optarg); |
252b5132 RH |
779 | break; |
780 | case OPTION_ASSERT: | |
781 | /* FIXME: We just ignore these, but we should handle them. */ | |
782 | if (strcmp (optarg, "definitions") == 0) | |
783 | ; | |
784 | else if (strcmp (optarg, "nodefinitions") == 0) | |
785 | ; | |
786 | else if (strcmp (optarg, "nosymbolic") == 0) | |
787 | ; | |
788 | else if (strcmp (optarg, "pure-text") == 0) | |
789 | ; | |
790 | else | |
df5f2391 | 791 | einfo (_("%F%P: unrecognized -assert option `%s'\n"), optarg); |
252b5132 RH |
792 | break; |
793 | case 'A': | |
794 | ldfile_add_arch (optarg); | |
795 | break; | |
796 | case 'b': | |
797 | lang_add_target (optarg); | |
798 | break; | |
799 | case 'c': | |
800 | ldfile_open_command_file (optarg); | |
801 | parser_input = input_mri_script; | |
802 | yyparse (); | |
803 | break; | |
804 | case OPTION_CALL_SHARED: | |
66be1055 | 805 | input_flags.dynamic = TRUE; |
252b5132 RH |
806 | break; |
807 | case OPTION_NON_SHARED: | |
66be1055 | 808 | input_flags.dynamic = FALSE; |
252b5132 RH |
809 | break; |
810 | case OPTION_CREF: | |
b34976b6 AM |
811 | command_line.cref = TRUE; |
812 | link_info.notice_all = TRUE; | |
252b5132 RH |
813 | break; |
814 | case 'd': | |
b34976b6 | 815 | command_line.force_common_definition = TRUE; |
252b5132 | 816 | break; |
6c19b93b AM |
817 | case OPTION_FORCE_GROUP_ALLOCATION: |
818 | command_line.force_group_allocation = TRUE; | |
819 | break; | |
252b5132 RH |
820 | case OPTION_DEFSYM: |
821 | lex_string = optarg; | |
dab69f68 | 822 | lex_redirect (optarg, "--defsym", ++defsym_count); |
252b5132 | 823 | parser_input = input_defsym; |
252b5132 | 824 | yyparse (); |
252b5132 RH |
825 | lex_string = NULL; |
826 | break; | |
827 | case OPTION_DEMANGLE: | |
b34976b6 | 828 | demangling = TRUE; |
28c309a2 NC |
829 | if (optarg != NULL) |
830 | { | |
831 | enum demangling_styles style; | |
5cc18311 | 832 | |
28c309a2 | 833 | style = cplus_demangle_name_to_style (optarg); |
5cc18311 | 834 | if (style == unknown_demangling) |
1d6d1a2c | 835 | einfo (_("%F%P: unknown demangling style `%s'\n"), |
28c309a2 | 836 | optarg); |
5cc18311 | 837 | |
28c309a2 | 838 | cplus_demangle_set_style (style); |
e47d05ad | 839 | } |
252b5132 | 840 | break; |
506eee22 | 841 | case 'I': /* Used on Solaris. */ |
252b5132 RH |
842 | case OPTION_DYNAMIC_LINKER: |
843 | command_line.interpreter = optarg; | |
9b8b325a RF |
844 | link_info.nointerp = 0; |
845 | break; | |
846 | case OPTION_NO_DYNAMIC_LINKER: | |
847 | link_info.nointerp = 1; | |
252b5132 | 848 | break; |
e2243057 RS |
849 | case OPTION_SYSROOT: |
850 | /* Already handled in ldmain.c. */ | |
851 | break; | |
252b5132 RH |
852 | case OPTION_EB: |
853 | command_line.endian = ENDIAN_BIG; | |
854 | break; | |
855 | case OPTION_EL: | |
856 | command_line.endian = ENDIAN_LITTLE; | |
857 | break; | |
858 | case OPTION_EMBEDDED_RELOCS: | |
b34976b6 | 859 | command_line.embedded_relocs = TRUE; |
252b5132 RH |
860 | break; |
861 | case OPTION_EXPORT_DYNAMIC: | |
862 | case 'E': /* HP/UX compatibility. */ | |
b34976b6 | 863 | link_info.export_dynamic = TRUE; |
252b5132 | 864 | break; |
267e2722 CD |
865 | case OPTION_NO_EXPORT_DYNAMIC: |
866 | link_info.export_dynamic = FALSE; | |
867 | break; | |
abf874aa CL |
868 | case OPTION_NON_CONTIGUOUS_REGIONS: |
869 | link_info.non_contiguous_regions = TRUE; | |
870 | break; | |
871 | case OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS: | |
872 | link_info.non_contiguous_regions_warnings = TRUE; | |
873 | break; | |
252b5132 | 874 | case 'e': |
b34976b6 | 875 | lang_add_entry (optarg, TRUE); |
252b5132 RH |
876 | break; |
877 | case 'f': | |
878 | if (command_line.auxiliary_filters == NULL) | |
879 | { | |
1e9cc1c2 | 880 | command_line.auxiliary_filters = (char **) |
6c19b93b | 881 | xmalloc (2 * sizeof (char *)); |
252b5132 RH |
882 | command_line.auxiliary_filters[0] = optarg; |
883 | command_line.auxiliary_filters[1] = NULL; | |
884 | } | |
885 | else | |
886 | { | |
887 | int c; | |
888 | char **p; | |
889 | ||
890 | c = 0; | |
891 | for (p = command_line.auxiliary_filters; *p != NULL; p++) | |
892 | ++c; | |
1e9cc1c2 | 893 | command_line.auxiliary_filters = (char **) |
6c19b93b AM |
894 | xrealloc (command_line.auxiliary_filters, |
895 | (c + 2) * sizeof (char *)); | |
252b5132 RH |
896 | command_line.auxiliary_filters[c] = optarg; |
897 | command_line.auxiliary_filters[c + 1] = NULL; | |
898 | } | |
899 | break; | |
900 | case 'F': | |
901 | command_line.filter_shlib = optarg; | |
902 | break; | |
903 | case OPTION_FORCE_EXE_SUFFIX: | |
b34976b6 | 904 | command_line.force_exe_suffix = TRUE; |
252b5132 RH |
905 | break; |
906 | case 'G': | |
907 | { | |
908 | char *end; | |
909 | g_switch_value = strtoul (optarg, &end, 0); | |
910 | if (*end) | |
df5f2391 | 911 | einfo (_("%F%P: invalid number `%s'\n"), optarg); |
252b5132 RH |
912 | } |
913 | break; | |
914 | case 'g': | |
915 | /* Ignore. */ | |
916 | break; | |
917 | case OPTION_GC_SECTIONS: | |
57316bff | 918 | link_info.gc_sections = TRUE; |
252b5132 | 919 | break; |
c17d87de NC |
920 | case OPTION_PRINT_GC_SECTIONS: |
921 | link_info.print_gc_sections = TRUE; | |
922 | break; | |
22185505 | 923 | case OPTION_GC_KEEP_EXPORTED: |
924 | link_info.gc_keep_exported = TRUE; | |
925 | break; | |
252b5132 RH |
926 | case OPTION_HELP: |
927 | help (); | |
928 | xexit (0); | |
929 | break; | |
930 | case 'L': | |
b34976b6 | 931 | ldfile_add_library_path (optarg, TRUE); |
252b5132 RH |
932 | break; |
933 | case 'l': | |
1579bae1 | 934 | lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL); |
252b5132 RH |
935 | break; |
936 | case 'M': | |
937 | config.map_filename = "-"; | |
938 | break; | |
939 | case 'm': | |
940 | /* Ignore. Was handled in a pre-parse. */ | |
941 | break; | |
942 | case OPTION_MAP: | |
943 | config.map_filename = optarg; | |
944 | break; | |
945 | case 'N': | |
b34976b6 AM |
946 | config.text_read_only = FALSE; |
947 | config.magic_demand_paged = FALSE; | |
66be1055 | 948 | input_flags.dynamic = FALSE; |
252b5132 | 949 | break; |
63fd3b82 | 950 | case OPTION_NO_OMAGIC: |
b34976b6 AM |
951 | config.text_read_only = TRUE; |
952 | config.magic_demand_paged = TRUE; | |
66be1055 | 953 | /* NB/ Does not set input_flags.dynamic to TRUE. |
63fd3b82 NC |
954 | Use --call-shared or -Bdynamic for this. */ |
955 | break; | |
252b5132 | 956 | case 'n': |
fa1477dc | 957 | config.text_read_only = TRUE; |
b34976b6 | 958 | config.magic_demand_paged = FALSE; |
66be1055 | 959 | input_flags.dynamic = FALSE; |
252b5132 | 960 | break; |
4818e05f | 961 | case OPTION_NO_DEFINE_COMMON: |
a4819f54 | 962 | link_info.inhibit_common_definition = TRUE; |
4818e05f | 963 | break; |
252b5132 | 964 | case OPTION_NO_DEMANGLE: |
b34976b6 | 965 | demangling = FALSE; |
252b5132 RH |
966 | break; |
967 | case OPTION_NO_GC_SECTIONS: | |
57316bff | 968 | link_info.gc_sections = FALSE; |
252b5132 | 969 | break; |
c17d87de NC |
970 | case OPTION_NO_PRINT_GC_SECTIONS: |
971 | link_info.print_gc_sections = FALSE; | |
972 | break; | |
252b5132 | 973 | case OPTION_NO_KEEP_MEMORY: |
b34976b6 | 974 | link_info.keep_memory = FALSE; |
252b5132 RH |
975 | break; |
976 | case OPTION_NO_UNDEFINED: | |
95a51568 | 977 | link_info.unresolved_syms_in_objects = RM_DIAGNOSE; |
252b5132 | 978 | break; |
b79e8c78 | 979 | case OPTION_ALLOW_SHLIB_UNDEFINED: |
560e09e9 | 980 | link_info.unresolved_syms_in_shared_libs = RM_IGNORE; |
b79e8c78 | 981 | break; |
ae9a127f | 982 | case OPTION_NO_ALLOW_SHLIB_UNDEFINED: |
95a51568 | 983 | link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE; |
ae9a127f | 984 | break; |
560e09e9 NC |
985 | case OPTION_UNRESOLVED_SYMBOLS: |
986 | if (strcmp (optarg, "ignore-all") == 0) | |
987 | { | |
988 | link_info.unresolved_syms_in_objects = RM_IGNORE; | |
989 | link_info.unresolved_syms_in_shared_libs = RM_IGNORE; | |
990 | } | |
991 | else if (strcmp (optarg, "report-all") == 0) | |
992 | { | |
95a51568 FS |
993 | link_info.unresolved_syms_in_objects = RM_DIAGNOSE; |
994 | link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE; | |
560e09e9 NC |
995 | } |
996 | else if (strcmp (optarg, "ignore-in-object-files") == 0) | |
997 | { | |
998 | link_info.unresolved_syms_in_objects = RM_IGNORE; | |
95a51568 | 999 | link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE; |
560e09e9 | 1000 | } |
6c19b93b | 1001 | else if (strcmp (optarg, "ignore-in-shared-libs") == 0) |
560e09e9 | 1002 | { |
95a51568 | 1003 | link_info.unresolved_syms_in_objects = RM_DIAGNOSE; |
560e09e9 NC |
1004 | link_info.unresolved_syms_in_shared_libs = RM_IGNORE; |
1005 | } | |
1006 | else | |
df5f2391 | 1007 | einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg); |
560e09e9 NC |
1008 | break; |
1009 | case OPTION_WARN_UNRESOLVED_SYMBOLS: | |
95a51568 | 1010 | link_info.warn_unresolved_syms = TRUE; |
560e09e9 | 1011 | break; |
560e09e9 | 1012 | case OPTION_ERROR_UNRESOLVED_SYMBOLS: |
95a51568 | 1013 | link_info.warn_unresolved_syms = FALSE; |
6feb9908 | 1014 | break; |
aa713662 | 1015 | case OPTION_ALLOW_MULTIPLE_DEFINITION: |
b34976b6 | 1016 | link_info.allow_multiple_definition = TRUE; |
aa713662 | 1017 | break; |
31941635 | 1018 | case OPTION_NO_UNDEFINED_VERSION: |
b34976b6 | 1019 | link_info.allow_undefined_version = FALSE; |
31941635 | 1020 | break; |
3e3b46e5 PB |
1021 | case OPTION_DEFAULT_SYMVER: |
1022 | link_info.create_default_symver = TRUE; | |
1023 | break; | |
fc0e6df6 PB |
1024 | case OPTION_DEFAULT_IMPORTED_SYMVER: |
1025 | link_info.default_imported_symver = TRUE; | |
1026 | break; | |
252b5132 | 1027 | case OPTION_NO_WARN_MISMATCH: |
b34976b6 | 1028 | command_line.warn_mismatch = FALSE; |
252b5132 | 1029 | break; |
fe7929ce AM |
1030 | case OPTION_NO_WARN_SEARCH_MISMATCH: |
1031 | command_line.warn_search_mismatch = FALSE; | |
1032 | break; | |
252b5132 | 1033 | case OPTION_NOINHIBIT_EXEC: |
b34976b6 | 1034 | force_make_executable = TRUE; |
252b5132 | 1035 | break; |
361b220e | 1036 | case OPTION_NOSTDLIB: |
b34976b6 | 1037 | config.only_cmd_line_lib_dirs = TRUE; |
361b220e | 1038 | break; |
252b5132 | 1039 | case OPTION_NO_WHOLE_ARCHIVE: |
66be1055 | 1040 | input_flags.whole_archive = FALSE; |
252b5132 RH |
1041 | break; |
1042 | case 'O': | |
1043 | /* FIXME "-O<non-digits> <value>" used to set the address of | |
1044 | section <non-digits>. Was this for compatibility with | |
1045 | something, or can we create a new option to do that | |
1046 | (with a syntax similar to -defsym)? | |
1047 | getopt can't handle two args to an option without kludges. */ | |
1048 | ||
1049 | /* Enable optimizations of output files. */ | |
b34976b6 | 1050 | link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE; |
252b5132 RH |
1051 | break; |
1052 | case 'o': | |
5cc18311 | 1053 | lang_add_output (optarg, 0); |
252b5132 RH |
1054 | break; |
1055 | case OPTION_OFORMAT: | |
1579bae1 | 1056 | lang_add_output_format (optarg, NULL, NULL, 0); |
252b5132 | 1057 | break; |
76359541 TP |
1058 | case OPTION_OUT_IMPLIB: |
1059 | command_line.out_implib_filename = xstrdup (optarg); | |
1060 | break; | |
cb9322a8 HPN |
1061 | case OPTION_PRINT_SYSROOT: |
1062 | if (*ld_sysroot) | |
1063 | puts (ld_sysroot); | |
1064 | xexit (0); | |
1065 | break; | |
30824704 RM |
1066 | case OPTION_PRINT_OUTPUT_FORMAT: |
1067 | command_line.print_output_format = TRUE; | |
1068 | break; | |
0381901e | 1069 | #if BFD_SUPPORTS_PLUGINS |
5d3236ee | 1070 | case OPTION_PLUGIN: |
d82184d7 | 1071 | plugin_opt_plugin (optarg); |
5d3236ee DK |
1072 | break; |
1073 | case OPTION_PLUGIN_OPT: | |
1074 | if (plugin_opt_plugin_arg (optarg)) | |
df5f2391 | 1075 | einfo (_("%F%P: bad -plugin-opt option\n")); |
5d3236ee | 1076 | break; |
0381901e | 1077 | #endif /* BFD_SUPPORTS_PLUGINS */ |
a712da20 | 1078 | case 'q': |
b34976b6 | 1079 | link_info.emitrelocations = TRUE; |
a712da20 | 1080 | break; |
8c5ff972 | 1081 | case 'i': |
252b5132 | 1082 | case 'r': |
210a7bd1 NC |
1083 | if (optind == last_optind) |
1084 | /* This can happen if the user put "-rpath,a" on the command | |
1085 | line. (Or something similar. The comma is important). | |
1086 | Getopt becomes confused and thinks that this is a -r option | |
1087 | but it cannot parse the text after the -r so it refuses to | |
1088 | increment the optind counter. Detect this case and issue | |
1089 | an error message here. We cannot just make this a warning, | |
1090 | increment optind, and continue because getopt is too confused | |
1091 | and will seg-fault the next time around. */ | |
df5f2391 | 1092 | einfo(_("%F%P: unrecognised option: %s\n"), argv[optind]); |
b7a26f91 | 1093 | |
0e1862bb | 1094 | if (bfd_link_pic (&link_info)) |
df5f2391 | 1095 | einfo (_("%F%P: -r and %s may not be used together\n"), |
0e1862bb L |
1096 | bfd_link_dll (&link_info) ? "-shared" : "-pie"); |
1097 | ||
1098 | link_info.type = type_relocatable; | |
b34976b6 AM |
1099 | config.build_constructors = FALSE; |
1100 | config.magic_demand_paged = FALSE; | |
1101 | config.text_read_only = FALSE; | |
66be1055 | 1102 | input_flags.dynamic = FALSE; |
252b5132 RH |
1103 | break; |
1104 | case 'R': | |
1105 | /* The GNU linker traditionally uses -R to mean to include | |
1106 | only the symbols from a file. The Solaris linker uses -R | |
1107 | to set the path used by the runtime linker to find | |
1108 | libraries. This is the GNU linker -rpath argument. We | |
1109 | try to support both simultaneously by checking the file | |
1110 | named. If it is a directory, rather than a regular file, | |
1111 | we assume -rpath was meant. */ | |
1112 | { | |
1113 | struct stat s; | |
1114 | ||
1115 | if (stat (optarg, &s) >= 0 | |
1116 | && ! S_ISDIR (s.st_mode)) | |
1117 | { | |
1118 | lang_add_input_file (optarg, | |
1119 | lang_input_file_is_symbols_only_enum, | |
1579bae1 | 1120 | NULL); |
252b5132 RH |
1121 | break; |
1122 | } | |
1123 | } | |
1124 | /* Fall through. */ | |
1125 | case OPTION_RPATH: | |
1126 | if (command_line.rpath == NULL) | |
d1b2b2dc | 1127 | command_line.rpath = xstrdup (optarg); |
252b5132 RH |
1128 | else |
1129 | { | |
1130 | size_t rpath_len = strlen (command_line.rpath); | |
1131 | size_t optarg_len = strlen (optarg); | |
1132 | char *buf; | |
1133 | char *cp = command_line.rpath; | |
1134 | ||
1135 | /* First see whether OPTARG is already in the path. */ | |
1136 | do | |
1137 | { | |
c76308d2 RS |
1138 | if (strncmp (optarg, cp, optarg_len) == 0 |
1139 | && (cp[optarg_len] == 0 | |
1140 | || cp[optarg_len] == config.rpath_separator)) | |
252b5132 RH |
1141 | /* We found it. */ |
1142 | break; | |
1143 | ||
1144 | /* Not yet found. */ | |
c76308d2 | 1145 | cp = strchr (cp, config.rpath_separator); |
252b5132 RH |
1146 | if (cp != NULL) |
1147 | ++cp; | |
1148 | } | |
1149 | while (cp != NULL); | |
1150 | ||
1151 | if (cp == NULL) | |
1152 | { | |
1e9cc1c2 | 1153 | buf = (char *) xmalloc (rpath_len + optarg_len + 2); |
c76308d2 RS |
1154 | sprintf (buf, "%s%c%s", command_line.rpath, |
1155 | config.rpath_separator, optarg); | |
252b5132 RH |
1156 | free (command_line.rpath); |
1157 | command_line.rpath = buf; | |
1158 | } | |
1159 | } | |
1160 | break; | |
1161 | case OPTION_RPATH_LINK: | |
1162 | if (command_line.rpath_link == NULL) | |
d1b2b2dc | 1163 | command_line.rpath_link = xstrdup (optarg); |
252b5132 RH |
1164 | else |
1165 | { | |
1166 | char *buf; | |
1167 | ||
1e9cc1c2 | 1168 | buf = (char *) xmalloc (strlen (command_line.rpath_link) |
6c19b93b AM |
1169 | + strlen (optarg) |
1170 | + 2); | |
c76308d2 RS |
1171 | sprintf (buf, "%s%c%s", command_line.rpath_link, |
1172 | config.rpath_separator, optarg); | |
252b5132 RH |
1173 | free (command_line.rpath_link); |
1174 | command_line.rpath_link = buf; | |
1175 | } | |
1176 | break; | |
28d5f677 NC |
1177 | case OPTION_NO_RELAX: |
1178 | DISABLE_RELAXATION; | |
1179 | break; | |
252b5132 | 1180 | case OPTION_RELAX: |
28d5f677 | 1181 | ENABLE_RELAXATION; |
252b5132 RH |
1182 | break; |
1183 | case OPTION_RETAIN_SYMBOLS_FILE: | |
1184 | add_keepsyms_file (optarg); | |
1185 | break; | |
1186 | case 'S': | |
1187 | link_info.strip = strip_debugger; | |
1188 | break; | |
1189 | case 's': | |
1190 | link_info.strip = strip_all; | |
1191 | break; | |
d5cd3933 AM |
1192 | case OPTION_STRIP_DISCARDED: |
1193 | link_info.strip_discarded = TRUE; | |
1194 | break; | |
1195 | case OPTION_NO_STRIP_DISCARDED: | |
1196 | link_info.strip_discarded = FALSE; | |
1197 | break; | |
3f0a5f17 ME |
1198 | case OPTION_DISABLE_MULTIPLE_DEFS_ABS: |
1199 | link_info.prohibit_multiple_definition_absolute = TRUE; | |
1200 | break; | |
252b5132 RH |
1201 | case OPTION_SHARED: |
1202 | if (config.has_shared) | |
560e09e9 | 1203 | { |
0e1862bb | 1204 | if (bfd_link_relocatable (&link_info)) |
df5f2391 AM |
1205 | einfo (_("%F%P: -r and %s may not be used together\n"), |
1206 | "-shared"); | |
0e1862bb L |
1207 | |
1208 | link_info.type = type_dll; | |
560e09e9 NC |
1209 | /* When creating a shared library, the default |
1210 | behaviour is to ignore any unresolved references. */ | |
1211 | if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) | |
1212 | link_info.unresolved_syms_in_objects = RM_IGNORE; | |
1213 | if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) | |
1214 | link_info.unresolved_syms_in_shared_libs = RM_IGNORE; | |
1215 | } | |
252b5132 | 1216 | else |
df5f2391 | 1217 | einfo (_("%F%P: -shared not supported\n")); |
252b5132 | 1218 | break; |
36af4a4e JJ |
1219 | case OPTION_PIE: |
1220 | if (config.has_shared) | |
1221 | { | |
0e1862bb | 1222 | if (bfd_link_relocatable (&link_info)) |
df5f2391 | 1223 | einfo (_("%F%P: -r and %s may not be used together\n"), "-pie"); |
0e1862bb | 1224 | |
64d94ba0 | 1225 | link_info.type = type_pie; |
36af4a4e JJ |
1226 | } |
1227 | else | |
df5f2391 | 1228 | einfo (_("%F%P: -pie not supported\n")); |
36af4a4e | 1229 | break; |
252b5132 RH |
1230 | case 'h': /* Used on Solaris. */ |
1231 | case OPTION_SONAME: | |
b0054819 UD |
1232 | if (optarg[0] == '\0' && command_line.soname |
1233 | && command_line.soname[0]) | |
1234 | einfo (_("%P: SONAME must not be empty string; keeping previous one\n")); | |
1235 | else | |
1236 | command_line.soname = optarg; | |
252b5132 RH |
1237 | break; |
1238 | case OPTION_SORT_COMMON: | |
de7dd2bd NC |
1239 | if (optarg == NULL |
1240 | || strcmp (optarg, N_("descending")) == 0) | |
6c19b93b AM |
1241 | config.sort_common = sort_descending; |
1242 | else if (strcmp (optarg, N_("ascending")) == 0) | |
de7dd2bd NC |
1243 | config.sort_common = sort_ascending; |
1244 | else | |
df5f2391 | 1245 | einfo (_("%F%P: invalid common section sorting option: %s\n"), |
de7dd2bd | 1246 | optarg); |
252b5132 | 1247 | break; |
bcaa7b3e L |
1248 | case OPTION_SORT_SECTION: |
1249 | if (strcmp (optarg, N_("name")) == 0) | |
1250 | sort_section = by_name; | |
1251 | else if (strcmp (optarg, N_("alignment")) == 0) | |
1252 | sort_section = by_alignment; | |
1253 | else | |
df5f2391 | 1254 | einfo (_("%F%P: invalid section sorting option: %s\n"), |
bcaa7b3e L |
1255 | optarg); |
1256 | break; | |
252b5132 | 1257 | case OPTION_STATS: |
b34976b6 | 1258 | config.stats = TRUE; |
252b5132 RH |
1259 | break; |
1260 | case OPTION_SYMBOLIC: | |
1914e264 | 1261 | opt_symbolic = symbolic; |
d8cf8b51 L |
1262 | break; |
1263 | case OPTION_SYMBOLIC_FUNCTIONS: | |
1914e264 | 1264 | opt_symbolic = symbolic_functions; |
252b5132 RH |
1265 | break; |
1266 | case 't': | |
727a29ba | 1267 | ++trace_files; |
252b5132 RH |
1268 | break; |
1269 | case 'T': | |
53d25da6 | 1270 | previous_script_handle = saved_script_handle; |
6ec6968b | 1271 | ldfile_open_script_file (optarg); |
252b5132 RH |
1272 | parser_input = input_script; |
1273 | yyparse (); | |
53d25da6 | 1274 | previous_script_handle = NULL; |
252b5132 | 1275 | break; |
14be8564 L |
1276 | case OPTION_DEFAULT_SCRIPT: |
1277 | command_line.default_script = optarg; | |
1278 | break; | |
176355da NC |
1279 | case OPTION_SECTION_START: |
1280 | { | |
1281 | char *optarg2; | |
227aeb07 AM |
1282 | char *sec_name; |
1283 | int len; | |
176355da NC |
1284 | |
1285 | /* Check for <something>=<somthing>... */ | |
1286 | optarg2 = strchr (optarg, '='); | |
1287 | if (optarg2 == NULL) | |
df5f2391 | 1288 | einfo (_("%F%P: invalid argument to option" |
6feb9908 | 1289 | " \"--section-start\"\n")); |
176355da | 1290 | |
e47d05ad | 1291 | optarg2++; |
5cc18311 | 1292 | |
176355da NC |
1293 | /* So far so good. Are all the args present? */ |
1294 | if ((*optarg == '\0') || (*optarg2 == '\0')) | |
df5f2391 | 1295 | einfo (_("%F%P: missing argument(s) to option" |
6feb9908 | 1296 | " \"--section-start\"\n")); |
176355da | 1297 | |
227aeb07 AM |
1298 | /* We must copy the section name as set_section_start |
1299 | doesn't do it for us. */ | |
1300 | len = optarg2 - optarg; | |
1e9cc1c2 | 1301 | sec_name = (char *) xmalloc (len); |
227aeb07 AM |
1302 | memcpy (sec_name, optarg, len - 1); |
1303 | sec_name[len - 1] = 0; | |
176355da NC |
1304 | |
1305 | /* Then set it... */ | |
227aeb07 | 1306 | set_section_start (sec_name, optarg2); |
176355da NC |
1307 | } |
1308 | break; | |
ea20a7da CC |
1309 | case OPTION_TARGET_HELP: |
1310 | /* Mention any target specific options. */ | |
b7a26f91 KH |
1311 | ldemul_list_emulation_options (stdout); |
1312 | exit (0); | |
252b5132 | 1313 | case OPTION_TBSS: |
ba916c8a | 1314 | set_segment_start (".bss", optarg); |
252b5132 RH |
1315 | break; |
1316 | case OPTION_TDATA: | |
ba916c8a | 1317 | set_segment_start (".data", optarg); |
252b5132 RH |
1318 | break; |
1319 | case OPTION_TTEXT: | |
ba916c8a | 1320 | set_segment_start (".text", optarg); |
252b5132 | 1321 | break; |
258795f5 L |
1322 | case OPTION_TTEXT_SEGMENT: |
1323 | set_segment_start (".text-segment", optarg); | |
1324 | break; | |
9d5777a3 RM |
1325 | case OPTION_TRODATA_SEGMENT: |
1326 | set_segment_start (".rodata-segment", optarg); | |
1327 | break; | |
0d705e9f AM |
1328 | case OPTION_TLDATA_SEGMENT: |
1329 | set_segment_start (".ldata-segment", optarg); | |
1330 | break; | |
252b5132 | 1331 | case OPTION_TRADITIONAL_FORMAT: |
b34976b6 | 1332 | link_info.traditional_format = TRUE; |
252b5132 RH |
1333 | break; |
1334 | case OPTION_TASK_LINK: | |
b34976b6 | 1335 | link_info.task_link = TRUE; |
1a0670f3 | 1336 | /* Fall through. */ |
252b5132 | 1337 | case OPTION_UR: |
0e1862bb | 1338 | if (bfd_link_pic (&link_info)) |
df5f2391 | 1339 | einfo (_("%F%P: -r and %s may not be used together\n"), |
0e1862bb L |
1340 | bfd_link_dll (&link_info) ? "-shared" : "-pie"); |
1341 | ||
1342 | link_info.type = type_relocatable; | |
b34976b6 AM |
1343 | config.build_constructors = TRUE; |
1344 | config.magic_demand_paged = FALSE; | |
1345 | config.text_read_only = FALSE; | |
66be1055 | 1346 | input_flags.dynamic = FALSE; |
252b5132 RH |
1347 | break; |
1348 | case 'u': | |
24898b70 | 1349 | ldlang_add_undef (optarg, TRUE); |
252b5132 | 1350 | break; |
6c19b93b AM |
1351 | case OPTION_REQUIRE_DEFINED_SYMBOL: |
1352 | ldlang_add_require_defined (optarg); | |
0a618243 | 1353 | break; |
a854a4a7 | 1354 | case OPTION_UNIQUE: |
577a0623 AM |
1355 | if (optarg != NULL) |
1356 | lang_add_unique (optarg); | |
1357 | else | |
b34976b6 | 1358 | config.unique_orphan_sections = TRUE; |
a854a4a7 | 1359 | break; |
252b5132 RH |
1360 | case OPTION_VERBOSE: |
1361 | ldversion (1); | |
b34976b6 | 1362 | version_printed = TRUE; |
cd6f1cf3 | 1363 | verbose = TRUE; |
8aae64e6 | 1364 | overflow_cutoff_limit = -2; |
1715a13c L |
1365 | if (optarg != NULL) |
1366 | { | |
1367 | char *end; | |
d436a15e | 1368 | int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0); |
1715a13c | 1369 | if (*end) |
df5f2391 | 1370 | einfo (_("%F%P: invalid number `%s'\n"), optarg); |
0381901e | 1371 | #if BFD_SUPPORTS_PLUGINS |
1715a13c | 1372 | report_plugin_symbols = level > 1; |
0381901e | 1373 | #endif /* BFD_SUPPORTS_PLUGINS */ |
1715a13c | 1374 | } |
252b5132 RH |
1375 | break; |
1376 | case 'v': | |
1377 | ldversion (0); | |
b34976b6 | 1378 | version_printed = TRUE; |
252b5132 RH |
1379 | break; |
1380 | case 'V': | |
1381 | ldversion (1); | |
b34976b6 | 1382 | version_printed = TRUE; |
252b5132 RH |
1383 | break; |
1384 | case OPTION_VERSION: | |
d32820f2 | 1385 | ldversion (2); |
252b5132 RH |
1386 | xexit (0); |
1387 | break; | |
1388 | case OPTION_VERSION_SCRIPT: | |
1389 | /* This option indicates a small script that only specifies | |
1579bae1 AM |
1390 | version information. Read it, but don't assume that |
1391 | we've seen a linker script. */ | |
252b5132 | 1392 | { |
b7a26f91 | 1393 | FILE *hold_script_handle; |
252b5132 | 1394 | |
b9a8de1e | 1395 | hold_script_handle = saved_script_handle; |
252b5132 | 1396 | ldfile_open_command_file (optarg); |
b9a8de1e | 1397 | saved_script_handle = hold_script_handle; |
252b5132 RH |
1398 | parser_input = input_version_script; |
1399 | yyparse (); | |
1400 | } | |
1401 | break; | |
1402 | case OPTION_VERSION_EXPORTS_SECTION: | |
1403 | /* This option records a version symbol to be applied to the | |
1404 | symbols listed for export to be found in the object files | |
1405 | .exports sections. */ | |
1406 | command_line.version_exports_section = optarg; | |
1407 | break; | |
40b36307 | 1408 | case OPTION_DYNAMIC_LIST_DATA: |
1914e264 | 1409 | opt_dynamic_list = dynamic_list_data; |
40b36307 | 1410 | break; |
55255dae L |
1411 | case OPTION_DYNAMIC_LIST_CPP_TYPEINFO: |
1412 | lang_append_dynamic_list_cpp_typeinfo (); | |
1914e264 AM |
1413 | if (opt_dynamic_list != dynamic_list_data) |
1414 | opt_dynamic_list = dynamic_list; | |
40b36307 L |
1415 | break; |
1416 | case OPTION_DYNAMIC_LIST_CPP_NEW: | |
1417 | lang_append_dynamic_list_cpp_new (); | |
1914e264 AM |
1418 | if (opt_dynamic_list != dynamic_list_data) |
1419 | opt_dynamic_list = dynamic_list; | |
55255dae L |
1420 | break; |
1421 | case OPTION_DYNAMIC_LIST: | |
1422 | /* This option indicates a small script that only specifies | |
1423 | a dynamic list. Read it, but don't assume that we've | |
1424 | seen a linker script. */ | |
1425 | { | |
1426 | FILE *hold_script_handle; | |
1427 | ||
1428 | hold_script_handle = saved_script_handle; | |
1429 | ldfile_open_command_file (optarg); | |
1430 | saved_script_handle = hold_script_handle; | |
1431 | parser_input = input_dynamic_list; | |
37a141bf | 1432 | current_dynamic_list_p = &link_info.dynamic_list; |
55255dae L |
1433 | yyparse (); |
1434 | } | |
1914e264 AM |
1435 | if (opt_dynamic_list != dynamic_list_data) |
1436 | opt_dynamic_list = dynamic_list; | |
55255dae | 1437 | break; |
37a141bf FS |
1438 | case OPTION_EXPORT_DYNAMIC_SYMBOL: |
1439 | { | |
1440 | struct bfd_elf_version_expr *expr | |
1441 | = lang_new_vers_pattern (NULL, xstrdup (optarg), NULL, | |
1442 | FALSE); | |
1443 | lang_append_dynamic_list (&export_list, expr); | |
1444 | } | |
1445 | break; | |
1446 | case OPTION_EXPORT_DYNAMIC_SYMBOL_LIST: | |
1447 | /* This option indicates a small script that only specifies | |
1448 | an export list. Read it, but don't assume that we've | |
1449 | seen a linker script. */ | |
1450 | { | |
1451 | FILE *hold_script_handle; | |
1452 | ||
1453 | hold_script_handle = saved_script_handle; | |
1454 | ldfile_open_command_file (optarg); | |
1455 | saved_script_handle = hold_script_handle; | |
1456 | parser_input = input_dynamic_list; | |
1457 | current_dynamic_list_p = &export_list; | |
1458 | yyparse (); | |
1459 | } | |
1460 | break; | |
252b5132 | 1461 | case OPTION_WARN_COMMON: |
b34976b6 | 1462 | config.warn_common = TRUE; |
252b5132 RH |
1463 | break; |
1464 | case OPTION_WARN_CONSTRUCTORS: | |
b34976b6 | 1465 | config.warn_constructors = TRUE; |
252b5132 | 1466 | break; |
7ce691ae | 1467 | case OPTION_WARN_FATAL: |
b34976b6 | 1468 | config.fatal_warnings = TRUE; |
7ce691ae | 1469 | break; |
0fe58ccd NC |
1470 | case OPTION_NO_WARN_FATAL: |
1471 | config.fatal_warnings = FALSE; | |
1472 | break; | |
252b5132 | 1473 | case OPTION_WARN_MULTIPLE_GP: |
b34976b6 | 1474 | config.warn_multiple_gp = TRUE; |
252b5132 RH |
1475 | break; |
1476 | case OPTION_WARN_ONCE: | |
b34976b6 | 1477 | config.warn_once = TRUE; |
252b5132 RH |
1478 | break; |
1479 | case OPTION_WARN_SECTION_ALIGN: | |
b34976b6 | 1480 | config.warn_section_align = TRUE; |
252b5132 | 1481 | break; |
a6dbf402 L |
1482 | case OPTION_WARN_TEXTREL: |
1483 | link_info.textrel_check = textrel_check_warning; | |
8fdd7217 | 1484 | break; |
a0c402a5 L |
1485 | case OPTION_WARN_ALTERNATE_EM: |
1486 | link_info.warn_alternate_em = TRUE; | |
1487 | break; | |
252b5132 | 1488 | case OPTION_WHOLE_ARCHIVE: |
66be1055 | 1489 | input_flags.whole_archive = TRUE; |
252b5132 | 1490 | break; |
ddbb8a31 | 1491 | case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC: |
66be1055 | 1492 | input_flags.add_DT_NEEDED_for_dynamic = TRUE; |
e56f61be | 1493 | break; |
ddbb8a31 | 1494 | case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC: |
66be1055 | 1495 | input_flags.add_DT_NEEDED_for_dynamic = FALSE; |
e56f61be | 1496 | break; |
ddbb8a31 | 1497 | case OPTION_ADD_DT_NEEDED_FOR_REGULAR: |
66be1055 | 1498 | input_flags.add_DT_NEEDED_for_regular = TRUE; |
4a43e768 | 1499 | break; |
ddbb8a31 | 1500 | case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR: |
66be1055 | 1501 | input_flags.add_DT_NEEDED_for_regular = FALSE; |
4a43e768 | 1502 | break; |
252b5132 RH |
1503 | case OPTION_WRAP: |
1504 | add_wrap (optarg); | |
1505 | break; | |
0e86e20e AM |
1506 | case OPTION_IGNORE_UNRESOLVED_SYMBOL: |
1507 | add_ignoresym (&link_info, optarg); | |
1508 | break; | |
f5fa8ca2 JJ |
1509 | case OPTION_DISCARD_NONE: |
1510 | link_info.discard = discard_none; | |
1511 | break; | |
252b5132 RH |
1512 | case 'X': |
1513 | link_info.discard = discard_l; | |
1514 | break; | |
1515 | case 'x': | |
1516 | link_info.discard = discard_all; | |
1517 | break; | |
1518 | case 'Y': | |
0112cd26 | 1519 | if (CONST_STRNEQ (optarg, "P,")) |
252b5132 | 1520 | optarg += 2; |
5e2ab612 | 1521 | free (default_dirlist); |
252b5132 RH |
1522 | default_dirlist = xstrdup (optarg); |
1523 | break; | |
1524 | case 'y': | |
1525 | add_ysym (optarg); | |
1526 | break; | |
db6751f2 JJ |
1527 | case OPTION_SPARE_DYNAMIC_TAGS: |
1528 | link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0); | |
1529 | break; | |
252b5132 | 1530 | case OPTION_SPLIT_BY_RELOC: |
a854a4a7 AM |
1531 | if (optarg != NULL) |
1532 | config.split_by_reloc = strtoul (optarg, NULL, 0); | |
1533 | else | |
1534 | config.split_by_reloc = 32768; | |
5cc18311 | 1535 | break; |
252b5132 | 1536 | case OPTION_SPLIT_BY_FILE: |
a854a4a7 AM |
1537 | if (optarg != NULL) |
1538 | config.split_by_file = bfd_scan_vma (optarg, NULL, 0); | |
1539 | else | |
1540 | config.split_by_file = 1; | |
5cc18311 | 1541 | break; |
252b5132 | 1542 | case OPTION_CHECK_SECTIONS: |
02b0b1aa | 1543 | command_line.check_section_addresses = 1; |
252b5132 RH |
1544 | break; |
1545 | case OPTION_NO_CHECK_SECTIONS: | |
02b0b1aa | 1546 | command_line.check_section_addresses = 0; |
252b5132 | 1547 | break; |
312b768e NC |
1548 | case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH: |
1549 | command_line.accept_unknown_input_arch = TRUE; | |
1550 | break; | |
1551 | case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH: | |
1552 | command_line.accept_unknown_input_arch = FALSE; | |
1553 | break; | |
252b5132 | 1554 | case '(': |
252b5132 | 1555 | lang_enter_group (); |
20f3d0d6 | 1556 | ingroup++; |
252b5132 RH |
1557 | break; |
1558 | case ')': | |
1559 | if (! ingroup) | |
df5f2391 | 1560 | einfo (_("%F%P: group ended before it began (--help for usage)\n")); |
210a7bd1 | 1561 | |
252b5132 | 1562 | lang_leave_group (); |
20f3d0d6 | 1563 | ingroup--; |
252b5132 | 1564 | break; |
3dbf70a2 MM |
1565 | |
1566 | case OPTION_INIT: | |
1567 | link_info.init_function = optarg; | |
1568 | break; | |
5cc18311 | 1569 | |
3dbf70a2 MM |
1570 | case OPTION_FINI: |
1571 | link_info.fini_function = optarg; | |
1572 | break; | |
2d643429 | 1573 | |
35835446 | 1574 | case OPTION_REDUCE_MEMORY_OVERHEADS: |
c0f00686 | 1575 | link_info.reduce_memory_overheads = TRUE; |
2d643429 NC |
1576 | if (config.hash_table_size == 0) |
1577 | config.hash_table_size = 1021; | |
35835446 | 1578 | break; |
2d643429 | 1579 | |
6c19b93b | 1580 | case OPTION_HASH_SIZE: |
2d643429 NC |
1581 | { |
1582 | bfd_size_type new_size; | |
1583 | ||
6c19b93b AM |
1584 | new_size = strtoul (optarg, NULL, 0); |
1585 | if (new_size) | |
1586 | config.hash_table_size = new_size; | |
1587 | else | |
df5f2391 | 1588 | einfo (_("%X%P: --hash-size needs a numeric argument\n")); |
6c19b93b AM |
1589 | } |
1590 | break; | |
26278bb8 UD |
1591 | |
1592 | case OPTION_PUSH_STATE: | |
1593 | input_flags.pushed = xmemdup (&input_flags, | |
1594 | sizeof (input_flags), | |
1595 | sizeof (input_flags)); | |
1596 | break; | |
1597 | ||
1598 | case OPTION_POP_STATE: | |
1599 | if (input_flags.pushed == NULL) | |
df5f2391 | 1600 | einfo (_("%F%P: no state pushed before popping\n")); |
26278bb8 UD |
1601 | else |
1602 | { | |
1603 | struct lang_input_statement_flags *oldp = input_flags.pushed; | |
1604 | memcpy (&input_flags, oldp, sizeof (input_flags)); | |
1605 | free (oldp); | |
1606 | } | |
1607 | break; | |
3604cb1f TG |
1608 | |
1609 | case OPTION_PRINT_MEMORY_USAGE: | |
1610 | command_line.print_memory_usage = TRUE; | |
1611 | break; | |
c005eb9e AB |
1612 | |
1613 | case OPTION_ORPHAN_HANDLING: | |
1614 | if (strcasecmp (optarg, "place") == 0) | |
1615 | config.orphan_handling = orphan_handling_place; | |
1616 | else if (strcasecmp (optarg, "warn") == 0) | |
1617 | config.orphan_handling = orphan_handling_warn; | |
1618 | else if (strcasecmp (optarg, "error") == 0) | |
1619 | config.orphan_handling = orphan_handling_error; | |
1620 | else if (strcasecmp (optarg, "discard") == 0) | |
1621 | config.orphan_handling = orphan_handling_discard; | |
1622 | else | |
df5f2391 | 1623 | einfo (_("%F%P: invalid argument to option" |
c005eb9e AB |
1624 | " \"--orphan-handling\"\n")); |
1625 | break; | |
035801ce FS |
1626 | |
1627 | case OPTION_NO_PRINT_MAP_DISCARDED: | |
1628 | config.print_map_discarded = FALSE; | |
1629 | break; | |
1630 | ||
1631 | case OPTION_PRINT_MAP_DISCARDED: | |
1632 | config.print_map_discarded = TRUE; | |
1633 | break; | |
252b5132 RH |
1634 | } |
1635 | } | |
1636 | ||
198204a7 NC |
1637 | /* Run a couple of checks on the map filename. */ |
1638 | if (config.map_filename) | |
1639 | { | |
198204a7 NC |
1640 | if (config.map_filename[0] == 0) |
1641 | { | |
72a3b182 NC |
1642 | einfo (_("%P: no file/directory name provided for map output; ignored\n")); |
1643 | config.map_filename = NULL; | |
198204a7 NC |
1644 | } |
1645 | else | |
1646 | { | |
1647 | struct stat s; | |
1648 | ||
1649 | /* If the map filename is actually a directory then create | |
72a3b182 | 1650 | a file inside it, based upon the output filename. */ |
198204a7 NC |
1651 | if (stat (config.map_filename, &s) >= 0 |
1652 | && S_ISDIR (s.st_mode)) | |
1653 | { | |
1654 | char * new_name; | |
1655 | ||
72a3b182 | 1656 | /* FIXME: This is a (trivial) memory leak. */ |
198204a7 NC |
1657 | if (asprintf (&new_name, "%s/%s.map", |
1658 | config.map_filename, output_filename) < 0) | |
72a3b182 NC |
1659 | { |
1660 | /* If this alloc fails then something is probably very | |
1661 | wrong. Better to halt now rather than continue on | |
1662 | into more problems. */ | |
1663 | einfo (_("%P%F: cannot create name for linker map file: %E\n")); | |
1664 | new_name = NULL; | |
1665 | } | |
1666 | ||
198204a7 NC |
1667 | config.map_filename = new_name; |
1668 | } | |
1669 | } | |
1670 | } | |
1671 | ||
b0054819 UD |
1672 | if (command_line.soname && command_line.soname[0] == '\0') |
1673 | { | |
1674 | einfo (_("%P: SONAME must not be empty string; ignored\n")); | |
1675 | command_line.soname = NULL; | |
1676 | } | |
1677 | ||
20f3d0d6 AM |
1678 | while (ingroup) |
1679 | { | |
776ab89f | 1680 | einfo (_("%P: missing --end-group; added as last command line option\n")); |
20f3d0d6 AM |
1681 | lang_leave_group (); |
1682 | ingroup--; | |
1683 | } | |
252b5132 RH |
1684 | |
1685 | if (default_dirlist != NULL) | |
5ed6aba4 NC |
1686 | { |
1687 | set_default_dirlist (default_dirlist); | |
1688 | free (default_dirlist); | |
1689 | } | |
560e09e9 NC |
1690 | |
1691 | if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) | |
1692 | /* FIXME: Should we allow emulations a chance to set this ? */ | |
95a51568 | 1693 | link_info.unresolved_syms_in_objects = RM_DIAGNOSE; |
6feb9908 | 1694 | |
560e09e9 NC |
1695 | if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) |
1696 | /* FIXME: Should we allow emulations a chance to set this ? */ | |
95a51568 | 1697 | link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE; |
5d3236ee | 1698 | |
0e1862bb L |
1699 | if (bfd_link_relocatable (&link_info) |
1700 | && command_line.check_section_addresses < 0) | |
1701 | command_line.check_section_addresses = 0; | |
9bbc1a67 | 1702 | |
37a141bf FS |
1703 | if (export_list) |
1704 | { | |
1705 | struct bfd_elf_version_expr *head = export_list->head.list; | |
1706 | struct bfd_elf_version_expr *next; | |
1707 | ||
1708 | /* For --export-dynamic-symbol[-list]: | |
1709 | 1. When building executable, treat like --dynamic-list. | |
1710 | 2. When building shared object: | |
1711 | a. If -Bsymbolic or --dynamic-list are used, treat like | |
1712 | --dynamic-list. | |
1713 | b. Otherwise, ignored. | |
1714 | */ | |
1715 | if (!bfd_link_relocatable (&link_info) | |
1716 | && (bfd_link_executable (&link_info) | |
1717 | || opt_symbolic != symbolic_unset | |
1718 | || opt_dynamic_list != dynamic_list_unset)) | |
1719 | { | |
1720 | /* Append the export list to link_info.dynamic_list. */ | |
1721 | if (link_info.dynamic_list) | |
1722 | { | |
1723 | for (next = head; next->next != NULL; next = next->next) | |
1724 | ; | |
1725 | next->next = link_info.dynamic_list->head.list; | |
1726 | link_info.dynamic_list->head.list = head; | |
1727 | } | |
1728 | else | |
1729 | link_info.dynamic_list = export_list; | |
1730 | ||
1731 | if (opt_dynamic_list != dynamic_list_data) | |
1732 | opt_dynamic_list = dynamic_list; | |
1733 | } | |
1734 | else | |
1735 | { | |
1736 | /* Free the export list. */ | |
1737 | for (; head->next != NULL; head = next) | |
1738 | { | |
1739 | next = head->next; | |
1740 | free (head); | |
1741 | } | |
1742 | free (export_list); | |
1743 | } | |
1744 | } | |
1745 | ||
bb68f22c FS |
1746 | switch (opt_dynamic_list) |
1747 | { | |
1748 | case dynamic_list_unset: | |
1749 | break; | |
1750 | case dynamic_list_data: | |
1751 | link_info.dynamic_data = TRUE; | |
1752 | /* Fall through. */ | |
1753 | case dynamic_list: | |
1754 | link_info.dynamic = TRUE; | |
1755 | opt_symbolic = symbolic_unset; | |
1756 | break; | |
1757 | } | |
1758 | ||
1914e264 AM |
1759 | /* -Bsymbolic and -Bsymbols-functions are for shared library output. */ |
1760 | if (bfd_link_dll (&link_info)) | |
1761 | switch (opt_symbolic) | |
1762 | { | |
1763 | case symbolic_unset: | |
1764 | break; | |
1765 | case symbolic: | |
1766 | link_info.symbolic = TRUE; | |
1767 | if (link_info.dynamic_list) | |
1768 | { | |
1769 | struct bfd_elf_version_expr *ent, *next; | |
1770 | for (ent = link_info.dynamic_list->head.list; ent; ent = next) | |
1771 | { | |
1772 | next = ent->next; | |
1773 | free (ent); | |
1774 | } | |
1775 | free (link_info.dynamic_list); | |
1776 | link_info.dynamic_list = NULL; | |
1777 | } | |
1914e264 AM |
1778 | break; |
1779 | case symbolic_functions: | |
bb68f22c FS |
1780 | link_info.dynamic = TRUE; |
1781 | link_info.dynamic_data = TRUE; | |
1914e264 AM |
1782 | break; |
1783 | } | |
9bbc1a67 | 1784 | |
0e1862bb | 1785 | if (!bfd_link_dll (&link_info)) |
9bbc1a67 AM |
1786 | { |
1787 | if (command_line.filter_shlib) | |
df5f2391 | 1788 | einfo (_("%F%P: -F may not be used without -shared\n")); |
9bbc1a67 | 1789 | if (command_line.auxiliary_filters) |
df5f2391 | 1790 | einfo (_("%F%P: -f may not be used without -shared\n")); |
9bbc1a67 AM |
1791 | } |
1792 | ||
9bbc1a67 AM |
1793 | /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I |
1794 | don't see how else this can be handled, since in this case we | |
1795 | must preserve all externally visible symbols. */ | |
0e1862bb | 1796 | if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all) |
9bbc1a67 AM |
1797 | { |
1798 | link_info.strip = strip_debugger; | |
1799 | if (link_info.discard == discard_sec_merge) | |
1800 | link_info.discard = discard_all; | |
1801 | } | |
252b5132 RH |
1802 | } |
1803 | ||
1804 | /* Add the (colon-separated) elements of DIRLIST_PTR to the | |
1805 | library search path. */ | |
1806 | ||
1807 | static void | |
1579bae1 | 1808 | set_default_dirlist (char *dirlist_ptr) |
252b5132 RH |
1809 | { |
1810 | char *p; | |
1811 | ||
1812 | while (1) | |
1813 | { | |
1814 | p = strchr (dirlist_ptr, PATH_SEPARATOR); | |
1815 | if (p != NULL) | |
1816 | *p = '\0'; | |
1817 | if (*dirlist_ptr != '\0') | |
b34976b6 | 1818 | ldfile_add_library_path (dirlist_ptr, TRUE); |
252b5132 RH |
1819 | if (p == NULL) |
1820 | break; | |
1821 | dirlist_ptr = p + 1; | |
1822 | } | |
1823 | } | |
1824 | ||
1825 | static void | |
1579bae1 | 1826 | set_section_start (char *sect, char *valstr) |
252b5132 | 1827 | { |
93697284 AM |
1828 | const char *end; |
1829 | bfd_vma val = bfd_scan_vma (valstr, &end, 16); | |
252b5132 | 1830 | if (*end) |
df5f2391 | 1831 | einfo (_("%F%P: invalid hex number `%s'\n"), valstr); |
ba916c8a | 1832 | lang_section_start (sect, exp_intop (val), NULL); |
252b5132 | 1833 | } |
ba916c8a MM |
1834 | |
1835 | static void | |
1836 | set_segment_start (const char *section, char *valstr) | |
1837 | { | |
1838 | const char *name; | |
1839 | const char *end; | |
1840 | segment_type *seg; | |
1841 | ||
1842 | bfd_vma val = bfd_scan_vma (valstr, &end, 16); | |
1843 | if (*end) | |
df5f2391 | 1844 | einfo (_("%F%P: invalid hex number `%s'\n"), valstr); |
ba916c8a MM |
1845 | /* If we already have an entry for this segment, update the existing |
1846 | value. */ | |
1847 | name = section + 1; | |
1848 | for (seg = segments; seg; seg = seg->next) | |
1849 | if (strcmp (seg->name, name) == 0) | |
1850 | { | |
1851 | seg->value = val; | |
42b7a39b | 1852 | lang_section_start (section, exp_intop (val), seg); |
ba916c8a MM |
1853 | return; |
1854 | } | |
1855 | /* There was no existing value so we must create a new segment | |
1856 | entry. */ | |
988de25b | 1857 | seg = stat_alloc (sizeof (*seg)); |
ba916c8a MM |
1858 | seg->name = name; |
1859 | seg->value = val; | |
1860 | seg->used = FALSE; | |
1861 | /* Add it to the linked list of segments. */ | |
1862 | seg->next = segments; | |
1863 | segments = seg; | |
1864 | /* Historically, -Ttext and friends set the base address of a | |
1865 | particular section. For backwards compatibility, we still do | |
1866 | that. If a SEGMENT_START directive is seen, the section address | |
1867 | assignment will be disabled. */ | |
1868 | lang_section_start (section, exp_intop (val), seg); | |
1869 | } | |
1870 | ||
c58212ea L |
1871 | static void |
1872 | elf_shlib_list_options (FILE *file) | |
1873 | { | |
1874 | fprintf (file, _("\ | |
1875 | --audit=AUDITLIB Specify a library to use for auditing\n")); | |
1876 | fprintf (file, _("\ | |
1877 | -Bgroup Selects group name lookup rules for DSO\n")); | |
1878 | fprintf (file, _("\ | |
1879 | --disable-new-dtags Disable new dynamic tags\n")); | |
1880 | fprintf (file, _("\ | |
1881 | --enable-new-dtags Enable new dynamic tags\n")); | |
1882 | fprintf (file, _("\ | |
1883 | --eh-frame-hdr Create .eh_frame_hdr section\n")); | |
29063f8b NC |
1884 | fprintf (file, _("\ |
1885 | --no-eh-frame-hdr Do not create .eh_frame_hdr section\n")); | |
c58212ea L |
1886 | fprintf (file, _("\ |
1887 | --exclude-libs=LIBS Make all symbols in LIBS hidden\n")); | |
1888 | fprintf (file, _("\ | |
ba311c5b NC |
1889 | --hash-style=STYLE Set hash style to sysv/gnu/both. Default: ")); |
1890 | if (DEFAULT_EMIT_SYSV_HASH) | |
1891 | { | |
1892 | /* Note - these strings are not translated as | |
1893 | they are keywords not descriptive text. */ | |
1894 | if (DEFAULT_EMIT_GNU_HASH) | |
1895 | fprintf (file, "both\n"); | |
1896 | else | |
1897 | fprintf (file, "sysv\n"); | |
1898 | } | |
1899 | else | |
1900 | { | |
1901 | if (DEFAULT_EMIT_GNU_HASH) | |
1902 | fprintf (file, "gnu\n"); | |
1903 | else | |
1904 | /* FIXME: Can this happen ? */ | |
1905 | fprintf (file, "none\n"); | |
1906 | } | |
c58212ea L |
1907 | fprintf (file, _("\ |
1908 | -P AUDITLIB, --depaudit=AUDITLIB\n" "\ | |
df5f2391 | 1909 | Specify a library to use for auditing dependencies\n")); |
c58212ea L |
1910 | fprintf (file, _("\ |
1911 | -z combreloc Merge dynamic relocs into one section and sort\n")); | |
1912 | fprintf (file, _("\ | |
1913 | -z nocombreloc Don't merge dynamic relocs into one section\n")); | |
1914 | fprintf (file, _("\ | |
1915 | -z global Make symbols in DSO available for subsequently\n\ | |
df5f2391 | 1916 | loaded objects\n")); |
c58212ea L |
1917 | fprintf (file, _("\ |
1918 | -z initfirst Mark DSO to be initialized first at runtime\n")); | |
1919 | fprintf (file, _("\ | |
1920 | -z interpose Mark object to interpose all DSOs but executable\n")); | |
1921 | fprintf (file, _("\ | |
1922 | -z lazy Mark object lazy runtime binding (default)\n")); | |
1923 | fprintf (file, _("\ | |
1924 | -z loadfltr Mark object requiring immediate process\n")); | |
1925 | fprintf (file, _("\ | |
1926 | -z nocopyreloc Don't create copy relocs\n")); | |
1927 | fprintf (file, _("\ | |
1928 | -z nodefaultlib Mark object not to use default search paths\n")); | |
1929 | fprintf (file, _("\ | |
1930 | -z nodelete Mark DSO non-deletable at runtime\n")); | |
1931 | fprintf (file, _("\ | |
1932 | -z nodlopen Mark DSO not available to dlopen\n")); | |
1933 | fprintf (file, _("\ | |
1934 | -z nodump Mark DSO not available to dldump\n")); | |
1935 | fprintf (file, _("\ | |
1936 | -z now Mark object non-lazy runtime binding\n")); | |
1937 | fprintf (file, _("\ | |
1938 | -z origin Mark object requiring immediate $ORIGIN\n\ | |
df5f2391 | 1939 | processing at runtime\n")); |
da4463c7 | 1940 | #if DEFAULT_LD_Z_RELRO |
c58212ea | 1941 | fprintf (file, _("\ |
da4463c7 | 1942 | -z relro Create RELRO program header (default)\n")); |
c58212ea L |
1943 | fprintf (file, _("\ |
1944 | -z norelro Don't create RELRO program header\n")); | |
da4463c7 L |
1945 | #else |
1946 | fprintf (file, _("\ | |
1947 | -z relro Create RELRO program header\n")); | |
1948 | fprintf (file, _("\ | |
1949 | -z norelro Don't create RELRO program header (default)\n")); | |
1950 | #endif | |
b14b7ff1 L |
1951 | #if DEFAULT_LD_Z_SEPARATE_CODE |
1952 | fprintf (file, _("\ | |
1953 | -z separate-code Create separate code program header (default)\n")); | |
1954 | fprintf (file, _("\ | |
1955 | -z noseparate-code Don't create separate code program header\n")); | |
1956 | #else | |
47acac12 L |
1957 | fprintf (file, _("\ |
1958 | -z separate-code Create separate code program header\n")); | |
1959 | fprintf (file, _("\ | |
1960 | -z noseparate-code Don't create separate code program header (default)\n")); | |
b14b7ff1 | 1961 | #endif |
c58212ea | 1962 | fprintf (file, _("\ |
b8871f35 L |
1963 | -z common Generate common symbols with STT_COMMON type\n")); |
1964 | fprintf (file, _("\ | |
1965 | -z nocommon Generate common symbols with STT_OBJECT type\n")); | |
1966 | fprintf (file, _("\ | |
75e06f97 | 1967 | -z stack-size=SIZE Set size of stack segment\n")); |
a6dbf402 L |
1968 | if (link_info.textrel_check == textrel_check_error) |
1969 | fprintf (file, _("\ | |
1970 | -z text Treat DT_TEXTREL in output as error (default)\n")); | |
1971 | else | |
1972 | fprintf (file, _("\ | |
1973 | -z text Treat DT_TEXTREL in output as error\n")); | |
1974 | if (link_info.textrel_check == textrel_check_none) | |
1975 | { | |
1976 | fprintf (file, _("\ | |
1977 | -z notext Don't treat DT_TEXTREL in output as error (default)\n")); | |
1978 | fprintf (file, _("\ | |
1979 | -z textoff Don't treat DT_TEXTREL in output as error (default)\n")); | |
1980 | } | |
1981 | else | |
1982 | { | |
1983 | fprintf (file, _("\ | |
1984 | -z notext Don't treat DT_TEXTREL in output as error\n")); | |
1985 | fprintf (file, _("\ | |
1986 | -z textoff Don't treat DT_TEXTREL in output as error\n")); | |
1987 | } | |
c58212ea L |
1988 | } |
1989 | ||
1990 | static void | |
1991 | elf_static_list_options (FILE *file) | |
1992 | { | |
1993 | fprintf (file, _("\ | |
1994 | --build-id[=STYLE] Generate build ID note\n")); | |
1995 | fprintf (file, _("\ | |
0ce398f1 L |
1996 | --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\ |
1997 | Compress DWARF debug sections using zlib\n")); | |
6c3bc0f8 NC |
1998 | #ifdef DEFAULT_FLAG_COMPRESS_DEBUG |
1999 | fprintf (file, _("\ | |
2000 | Default: zlib-gabi\n")); | |
2001 | #else | |
2002 | fprintf (file, _("\ | |
2003 | Default: none\n")); | |
2004 | #endif | |
0ce398f1 | 2005 | fprintf (file, _("\ |
c58212ea L |
2006 | -z common-page-size=SIZE Set common page size to SIZE\n")); |
2007 | fprintf (file, _("\ | |
2008 | -z max-page-size=SIZE Set maximum page size to SIZE\n")); | |
2009 | fprintf (file, _("\ | |
df5f2391 | 2010 | -z defs Report unresolved symbols in object files\n")); |
c58212ea L |
2011 | fprintf (file, _("\ |
2012 | -z muldefs Allow multiple definitions\n")); | |
2013 | fprintf (file, _("\ | |
2014 | -z execstack Mark executable as requiring executable stack\n")); | |
2015 | fprintf (file, _("\ | |
2016 | -z noexecstack Mark executable as not requiring executable stack\n")); | |
93ab9c0d NC |
2017 | fprintf (file, _("\ |
2018 | -z globalaudit Mark executable requiring global auditing\n")); | |
c58212ea L |
2019 | } |
2020 | ||
2021 | static void | |
2022 | elf_plt_unwind_list_options (FILE *file) | |
2023 | { | |
2024 | fprintf (file, _("\ | |
df5f2391 AM |
2025 | --ld-generated-unwind-info Generate exception handling info for PLT\n")); |
2026 | fprintf (file, _("\ | |
c58212ea L |
2027 | --no-ld-generated-unwind-info\n\ |
2028 | Don't generate exception handling info for PLT\n")); | |
2029 | } | |
2030 | ||
2031 | static void | |
2032 | ld_list_options (FILE *file, bfd_boolean elf, bfd_boolean shlib, | |
2033 | bfd_boolean plt_unwind) | |
2034 | { | |
2035 | if (!elf) | |
2036 | return; | |
2037 | printf (_("ELF emulations:\n")); | |
2038 | if (plt_unwind) | |
2039 | elf_plt_unwind_list_options (file); | |
2040 | elf_static_list_options (file); | |
2041 | if (shlib) | |
2042 | elf_shlib_list_options (file); | |
2043 | } | |
2044 | ||
252b5132 RH |
2045 | \f |
2046 | /* Print help messages for the options. */ | |
2047 | ||
2048 | static void | |
1579bae1 | 2049 | help (void) |
252b5132 | 2050 | { |
e4897a32 | 2051 | unsigned i; |
252b5132 | 2052 | const char **targets, **pp; |
a55ff675 | 2053 | int len; |
252b5132 RH |
2054 | |
2055 | printf (_("Usage: %s [options] file...\n"), program_name); | |
2056 | ||
2057 | printf (_("Options:\n")); | |
2058 | for (i = 0; i < OPTION_COUNT; i++) | |
2059 | { | |
2060 | if (ld_options[i].doc != NULL) | |
2061 | { | |
b34976b6 | 2062 | bfd_boolean comma; |
e4897a32 | 2063 | unsigned j; |
252b5132 RH |
2064 | |
2065 | printf (" "); | |
2066 | ||
b34976b6 | 2067 | comma = FALSE; |
252b5132 RH |
2068 | len = 2; |
2069 | ||
2070 | j = i; | |
2071 | do | |
2072 | { | |
2073 | if (ld_options[j].shortopt != '\0' | |
2074 | && ld_options[j].control != NO_HELP) | |
2075 | { | |
2076 | printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt); | |
2077 | len += (comma ? 2 : 0) + 2; | |
2078 | if (ld_options[j].arg != NULL) | |
2079 | { | |
2080 | if (ld_options[j].opt.has_arg != optional_argument) | |
2081 | { | |
2082 | printf (" "); | |
2083 | ++len; | |
2084 | } | |
2085 | printf ("%s", _(ld_options[j].arg)); | |
2086 | len += strlen (_(ld_options[j].arg)); | |
2087 | } | |
b34976b6 | 2088 | comma = TRUE; |
252b5132 RH |
2089 | } |
2090 | ++j; | |
2091 | } | |
2092 | while (j < OPTION_COUNT && ld_options[j].doc == NULL); | |
2093 | ||
2094 | j = i; | |
2095 | do | |
2096 | { | |
2097 | if (ld_options[j].opt.name != NULL | |
2098 | && ld_options[j].control != NO_HELP) | |
2099 | { | |
e4897a32 NC |
2100 | int two_dashes = |
2101 | (ld_options[j].control == TWO_DASHES | |
2102 | || ld_options[j].control == EXACTLY_TWO_DASHES); | |
b7a26f91 | 2103 | |
252b5132 RH |
2104 | printf ("%s-%s%s", |
2105 | comma ? ", " : "", | |
e4897a32 | 2106 | two_dashes ? "-" : "", |
252b5132 RH |
2107 | ld_options[j].opt.name); |
2108 | len += ((comma ? 2 : 0) | |
2109 | + 1 | |
e4897a32 | 2110 | + (two_dashes ? 1 : 0) |
252b5132 RH |
2111 | + strlen (ld_options[j].opt.name)); |
2112 | if (ld_options[j].arg != NULL) | |
2113 | { | |
2114 | printf (" %s", _(ld_options[j].arg)); | |
2115 | len += 1 + strlen (_(ld_options[j].arg)); | |
2116 | } | |
b34976b6 | 2117 | comma = TRUE; |
252b5132 RH |
2118 | } |
2119 | ++j; | |
2120 | } | |
2121 | while (j < OPTION_COUNT && ld_options[j].doc == NULL); | |
2122 | ||
2123 | if (len >= 30) | |
2124 | { | |
2125 | printf ("\n"); | |
2126 | len = 0; | |
2127 | } | |
2128 | ||
2129 | for (; len < 30; len++) | |
2130 | putchar (' '); | |
2131 | ||
2132 | printf ("%s\n", _(ld_options[i].doc)); | |
2133 | } | |
2134 | } | |
a55ff675 MM |
2135 | printf (_(" @FILE")); |
2136 | for (len = strlen (" @FILE"); len < 30; len++) | |
2137 | putchar (' '); | |
2138 | printf (_("Read options from FILE\n")); | |
252b5132 | 2139 | |
f75692fe NC |
2140 | /* Note: Various tools (such as libtool) depend upon the |
2141 | format of the listings below - do not change them. */ | |
252b5132 | 2142 | /* xgettext:c-format */ |
f75692fe | 2143 | printf (_("%s: supported targets:"), program_name); |
252b5132 RH |
2144 | targets = bfd_target_list (); |
2145 | for (pp = targets; *pp != NULL; pp++) | |
2146 | printf (" %s", *pp); | |
2147 | free (targets); | |
2148 | printf ("\n"); | |
2149 | ||
2150 | /* xgettext:c-format */ | |
f75692fe | 2151 | printf (_("%s: supported emulations: "), program_name); |
252b5132 RH |
2152 | ldemul_list_emulations (stdout); |
2153 | printf ("\n"); | |
2154 | ||
2155 | /* xgettext:c-format */ | |
2156 | printf (_("%s: emulation specific options:\n"), program_name); | |
c58212ea L |
2157 | ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS, |
2158 | ELF_PLT_UNWIND_LIST_OPTIONS); | |
252b5132 RH |
2159 | ldemul_list_emulation_options (stdout); |
2160 | printf ("\n"); | |
c20f4f8c | 2161 | |
92f01d61 JM |
2162 | if (REPORT_BUGS_TO[0]) |
2163 | printf (_("Report bugs to %s\n"), REPORT_BUGS_TO); | |
252b5132 | 2164 | } |