RISC-V: Support SiFive extensions: xsfvqmaccdod, xsfvqmaccqoq and xsfvfnrclipxfqf
[binutils-gdb.git] / ld / lexsup.c
blob533535c2b89ba1450757da108afb1d62350a4ca2
1 /* Parse options for the GNU linker.
2 Copyright (C) 1991-2024 Free Software Foundation, Inc.
4 This file is part of the GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
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.
16 You should have received a copy of the GNU General Public License
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. */
21 #include "sysdep.h"
22 #include "bfd.h"
23 #include "bfdver.h"
24 #include "libiberty.h"
25 #include "filenames.h"
26 #include <stdio.h>
27 #include <string.h>
28 #include <errno.h>
29 #include "safe-ctype.h"
30 #include "getopt.h"
31 #include "bfdlink.h"
32 #include "ctf-api.h"
33 #include "ld.h"
34 #include "ldmain.h"
35 #include "ldmisc.h"
36 #include "ldexp.h"
37 #include "ldlang.h"
38 #include <ldgram.h>
39 #include "ldlex.h"
40 #include "ldfile.h"
41 #include "ldver.h"
42 #include "ldemul.h"
43 #include "demangle.h"
44 #if BFD_SUPPORTS_PLUGINS
45 #include "plugin.h"
46 #endif /* BFD_SUPPORTS_PLUGINS */
48 #ifndef PATH_SEPARATOR
49 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
50 #define PATH_SEPARATOR ';'
51 #else
52 #define PATH_SEPARATOR ':'
53 #endif
54 #endif
56 /* Somewhere above, sys/stat.h got included . . . . */
57 #if !defined(S_ISDIR) && defined(S_IFDIR)
58 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
59 #endif
61 static void set_default_dirlist (char *);
62 static void set_section_start (char *, char *);
63 static void set_segment_start (const char *, char *);
64 static void help (void);
66 /* The long options. This structure is used for both the option
67 parsing and the help text. */
69 enum control_enum {
70 /* Use one dash before long option name. */
71 ONE_DASH = 1,
72 /* Use two dashes before long option name. */
73 TWO_DASHES = 2,
74 /* Only accept two dashes before the long option name.
75 This is an overloading of the use of this enum, since originally it
76 was only intended to tell the --help display function how to display
77 the long option name. This feature was added in order to resolve
78 the confusion about the -omagic command line switch. Is it setting
79 the output file name to "magic" or is it setting the NMAGIC flag on
80 the output ? It has been decided that it is setting the output file
81 name, and that if you want to set the NMAGIC flag you should use -N
82 or --omagic. */
83 EXACTLY_TWO_DASHES,
84 /* Don't mention this option in --help output. */
85 NO_HELP
88 struct ld_option
90 /* The long option information. */
91 struct option opt;
92 /* The short option with the same meaning ('\0' if none). */
93 char shortopt;
94 /* The name of the argument (NULL if none). */
95 const char *arg;
96 /* The documentation string. If this is NULL, this is a synonym for
97 the previous option. */
98 const char *doc;
99 enum control_enum control;
102 static const struct ld_option ld_options[] =
104 { {NULL, required_argument, NULL, '\0'},
105 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
106 ONE_DASH },
107 { {"architecture", required_argument, NULL, 'A'},
108 'A', N_("ARCH"), N_("Set architecture") , EXACTLY_TWO_DASHES },
109 { {"format", required_argument, NULL, 'b'},
110 'b', N_("TARGET"), N_("Specify target for following input files"),
111 EXACTLY_TWO_DASHES },
112 { {"mri-script", required_argument, NULL, 'c'},
113 'c', N_("FILE"), N_("Read MRI format linker script"), EXACTLY_TWO_DASHES },
114 { {"dc", no_argument, NULL, 'd'},
115 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
116 { {"dp", no_argument, NULL, 'd'},
117 '\0', NULL, NULL, ONE_DASH },
118 { {"dependency-file", required_argument, NULL, OPTION_DEPENDENCY_FILE},
119 '\0', N_("FILE"), N_("Write dependency file"), TWO_DASHES },
120 { {"force-group-allocation", no_argument, NULL,
121 OPTION_FORCE_GROUP_ALLOCATION},
122 '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
123 { {"entry", required_argument, NULL, 'e'},
124 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
125 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
126 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
127 { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC},
128 '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES },
129 { {"enable-non-contiguous-regions", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS},
130 '\0', NULL, N_("Enable support of non-contiguous memory regions"), TWO_DASHES },
131 { {"enable-non-contiguous-regions-warnings", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS},
132 '\0', NULL, N_("Enable warnings when --enable-non-contiguous-regions may cause unexpected behaviour"), TWO_DASHES },
133 { {"disable-linker-version", no_argument, NULL, OPTION_DISABLE_LINKER_VERSION},
134 '\0', NULL, N_("Disable the LINKER_VERSION linker script directive"), TWO_DASHES },
135 { {"enable-linker-version", no_argument, NULL, OPTION_ENABLE_LINKER_VERSION},
136 '\0', NULL, N_("Enable the LINKER_VERSION linker script directive"), TWO_DASHES },
137 { {"EB", no_argument, NULL, OPTION_EB},
138 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
139 { {"EL", no_argument, NULL, OPTION_EL},
140 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
141 { {"auxiliary", required_argument, NULL, 'f'},
142 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
143 TWO_DASHES },
144 { {"filter", required_argument, NULL, 'F'},
145 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
146 TWO_DASHES },
147 { {NULL, no_argument, NULL, '\0'},
148 'g', NULL, N_("Ignored"), ONE_DASH },
149 { {"gpsize", required_argument, NULL, 'G'},
150 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
151 TWO_DASHES },
152 { {"soname", required_argument, NULL, OPTION_SONAME},
153 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
154 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
155 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
156 TWO_DASHES },
157 { {"no-dynamic-linker", no_argument, NULL, OPTION_NO_DYNAMIC_LINKER},
158 '\0', NULL, N_("Produce an executable with no program interpreter header"),
159 TWO_DASHES },
160 { {"library", required_argument, NULL, 'l'},
161 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
162 { {"library-path", required_argument, NULL, 'L'},
163 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
164 TWO_DASHES },
165 { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
166 '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
167 { {NULL, required_argument, NULL, '\0'},
168 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
169 { {"print-map", no_argument, NULL, 'M'},
170 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
171 { {"nmagic", no_argument, NULL, 'n'},
172 'n', NULL, N_("Do not page align data"), TWO_DASHES },
173 { {"omagic", no_argument, NULL, 'N'},
174 'N', NULL, N_("Do not page align data, do not make text readonly"),
175 EXACTLY_TWO_DASHES },
176 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
177 '\0', NULL, N_("Page align data, make text readonly"),
178 EXACTLY_TWO_DASHES },
179 { {"output", required_argument, NULL, 'o'},
180 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
181 { {NULL, required_argument, NULL, '\0'},
182 'O', NULL, N_("Optimize output file"), ONE_DASH },
183 { {"out-implib", required_argument, NULL, OPTION_OUT_IMPLIB},
184 '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES },
185 #if BFD_SUPPORTS_PLUGINS
186 { {"plugin", required_argument, NULL, OPTION_PLUGIN},
187 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
188 { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
189 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
190 { {"plugin-save-temps", no_argument, NULL, OPTION_PLUGIN_SAVE_TEMPS},
191 '\0', NULL, N_("Store plugin intermediate files permanently"),
192 ONE_DASH },
193 { {"flto", optional_argument, NULL, OPTION_IGNORE},
194 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
195 ONE_DASH },
196 { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
197 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
198 ONE_DASH },
199 #else
200 { {"plugin", required_argument, NULL, OPTION_IGNORE},
201 '\0', N_("PLUGIN"), N_("Load named plugin (ignored)"), ONE_DASH },
202 { {"plugin-opt", required_argument, NULL, OPTION_IGNORE},
203 '\0', N_("ARG"), N_("Send arg to last-loaded plugin (ignored)"), ONE_DASH },
204 #endif /* BFD_SUPPORTS_PLUGINS */
205 { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE},
206 '\0', NULL, N_("Ignored for GCC linker option compatibility"),
207 ONE_DASH },
208 { {"map-whole-files", optional_argument, NULL, OPTION_IGNORE},
209 '\0', NULL, N_("Ignored for gold option compatibility"),
210 TWO_DASHES },
211 { {"no-map-whole-files", optional_argument, NULL, OPTION_IGNORE},
212 '\0', NULL, N_("Ignored for gold option compatibility"),
213 TWO_DASHES },
214 { {"Qy", no_argument, NULL, OPTION_IGNORE},
215 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
216 { {"emit-relocs", no_argument, NULL, 'q'},
217 'q', NULL, "Generate relocations in final output", TWO_DASHES },
218 { {"relocatable", no_argument, NULL, 'r'},
219 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
220 { {NULL, no_argument, NULL, '\0'},
221 'i', NULL, NULL, ONE_DASH },
222 { {"just-symbols", required_argument, NULL, 'R'},
223 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
224 TWO_DASHES },
226 { {"remap-inputs-file", required_argument, NULL, OPTION_REMAP_INPUTS_FILE},
227 '\0', N_("FILE"), "Provide a FILE containing input remapings", TWO_DASHES },
228 { {"remap-inputs", required_argument, NULL, OPTION_REMAP_INPUTS},
229 '\0', N_("PATTERN=FILE"), "Remap input files matching PATTERN to FILE", TWO_DASHES },
231 { {"strip-all", no_argument, NULL, 's'},
232 's', NULL, N_("Strip all symbols"), TWO_DASHES },
233 { {"strip-debug", no_argument, NULL, 'S'},
234 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
235 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
236 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
237 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
238 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
239 { {"trace", no_argument, NULL, 't'},
240 't', NULL, N_("Trace file opens"), TWO_DASHES },
241 { {"script", required_argument, NULL, 'T'},
242 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
243 { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
244 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
245 { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
246 '\0', NULL, NULL, ONE_DASH },
247 { {"undefined", required_argument, NULL, 'u'},
248 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
249 TWO_DASHES },
250 { {"require-defined", required_argument, NULL, OPTION_REQUIRE_DEFINED_SYMBOL},
251 '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"),
252 TWO_DASHES },
253 { {"unique", optional_argument, NULL, OPTION_UNIQUE},
254 '\0', N_("[=SECTION]"),
255 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
256 { {"Ur", no_argument, NULL, OPTION_UR},
257 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
258 { {"version", no_argument, NULL, OPTION_VERSION},
259 'v', NULL, N_("Print version information"), TWO_DASHES },
260 { {NULL, no_argument, NULL, '\0'},
261 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
262 { {"discard-all", no_argument, NULL, 'x'},
263 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
264 { {"discard-locals", no_argument, NULL, 'X'},
265 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
266 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
267 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
268 { {"trace-symbol", required_argument, NULL, 'y'},
269 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
270 { {NULL, required_argument, NULL, '\0'},
271 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
272 ONE_DASH },
273 { {"start-group", no_argument, NULL, '('},
274 '(', NULL, N_("Start a group"), TWO_DASHES },
275 { {"end-group", no_argument, NULL, ')'},
276 ')', NULL, N_("End a group"), TWO_DASHES },
277 { {"accept-unknown-input-arch", no_argument, NULL,
278 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
279 '\0', NULL,
280 N_("Accept input files whose architecture cannot be determined"),
281 TWO_DASHES },
282 { {"no-accept-unknown-input-arch", no_argument, NULL,
283 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
284 '\0', NULL, N_("Reject input files whose architecture is unknown"),
285 TWO_DASHES },
287 /* The next two options are deprecated because of their similarity to
288 --as-needed and --no-as-needed. They have been replaced by
289 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
290 { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
291 '\0', NULL, NULL, NO_HELP },
292 { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
293 '\0', NULL, NULL, NO_HELP },
295 { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
296 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
297 TWO_DASHES },
298 { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
299 '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
300 " the command line"),
301 TWO_DASHES },
302 { {"assert", required_argument, NULL, OPTION_ASSERT},
303 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
304 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
305 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
306 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
307 '\0', NULL, NULL, ONE_DASH },
308 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
309 '\0', NULL, NULL, ONE_DASH },
310 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
311 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
312 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
313 '\0', NULL, NULL, ONE_DASH },
314 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
315 '\0', NULL, NULL, ONE_DASH },
316 { {"static", no_argument, NULL, OPTION_NON_SHARED},
317 '\0', NULL, NULL, ONE_DASH },
318 { {"Bno-symbolic", no_argument, NULL, OPTION_NO_SYMBOLIC},
319 '\0', NULL, N_("Don't bind global references locally"), ONE_DASH },
320 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
321 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
322 { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
323 '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
324 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
325 '\0', NULL, N_("Check section addresses for overlaps (default)"),
326 TWO_DASHES },
327 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
328 '\0', NULL, N_("Do not check section addresses for overlaps"),
329 TWO_DASHES },
330 { {"copy-dt-needed-entries", no_argument, NULL,
331 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
332 '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
333 TWO_DASHES },
334 { {"no-copy-dt-needed-entries", no_argument, NULL,
335 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
336 '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
337 TWO_DASHES },
339 { {"cref", no_argument, NULL, OPTION_CREF},
340 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
341 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
342 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
343 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
344 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
345 TWO_DASHES },
346 { {"disable-multiple-abs-defs", no_argument, NULL,
347 OPTION_DISABLE_MULTIPLE_DEFS_ABS},
348 '\0', NULL, N_("Do not allow multiple definitions with symbols included\n"
349 " in filename invoked by -R "
350 "or --just-symbols"),
351 TWO_DASHES},
352 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
353 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
354 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
355 '\0', NULL, N_("Treat warnings as errors"),
356 TWO_DASHES },
357 { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL},
358 '\0', NULL, N_("Do not treat warnings as errors (default)"),
359 TWO_DASHES },
360 { {"fini", required_argument, NULL, OPTION_FINI},
361 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
362 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
363 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
364 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
365 '\0', NULL, N_("Remove unused sections (on some targets)"),
366 TWO_DASHES },
367 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
368 '\0', NULL, N_("Don't remove unused sections (default)"),
369 TWO_DASHES },
370 { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
371 '\0', NULL, N_("List removed unused sections on stderr"),
372 TWO_DASHES },
373 { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
374 '\0', NULL, N_("Do not list removed unused sections"),
375 TWO_DASHES },
376 { {"gc-keep-exported", no_argument, NULL, OPTION_GC_KEEP_EXPORTED},
377 '\0', NULL, N_("Keep exported symbols when removing unused sections"),
378 TWO_DASHES },
379 { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
380 '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
381 TWO_DASHES },
382 { {"help", no_argument, NULL, OPTION_HELP},
383 '\0', NULL, N_("Print option help"), TWO_DASHES },
384 { {"init", required_argument, NULL, OPTION_INIT},
385 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
386 { {"Map", required_argument, NULL, OPTION_MAP},
387 '\0', N_("FILE/DIR"), N_("Write a linker map to FILE or DIR/<outputname>.map"), ONE_DASH },
388 { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
389 '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
390 { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
391 '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
392 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
393 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
394 { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
395 '\0', NULL, N_("Do not allow unresolved references in object files"),
396 TWO_DASHES },
397 { {"no-warnings", no_argument, NULL, OPTION_NO_WARNINGS},
398 'w', NULL, N_("Do not display any warning or error messages"),
399 TWO_DASHES },
400 { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
401 '\0', NULL, N_("Allow unresolved references in shared libraries"),
402 TWO_DASHES },
403 { {"no-allow-shlib-undefined", no_argument, NULL,
404 OPTION_NO_ALLOW_SHLIB_UNDEFINED},
405 '\0', NULL, N_("Do not allow unresolved references in shared libs"),
406 TWO_DASHES },
407 { {"allow-multiple-definition", no_argument, NULL,
408 OPTION_ALLOW_MULTIPLE_DEFINITION},
409 '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
410 #if SUPPORT_ERROR_HANDLING_SCRIPT
411 { {"error-handling-script", required_argument, NULL,
412 OPTION_ERROR_HANDLING_SCRIPT},
413 '\0', N_("SCRIPT"), N_("Provide a script to help with undefined symbol errors"), TWO_DASHES},
414 #endif
415 { {"undefined-version", no_argument, NULL, OPTION_UNDEFINED_VERSION},
416 '\0', NULL, N_("Allow undefined version"), EXACTLY_TWO_DASHES },
417 { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
418 '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
419 { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
420 '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
421 { {"default-imported-symver", no_argument, NULL,
422 OPTION_DEFAULT_IMPORTED_SYMVER},
423 '\0', NULL, N_("Create default symbol version for imported symbols"),
424 TWO_DASHES },
425 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
426 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
427 { {"no-warn-search-mismatch", no_argument, NULL,
428 OPTION_NO_WARN_SEARCH_MISMATCH},
429 '\0', NULL, N_("Don't warn on finding an incompatible library"),
430 TWO_DASHES},
431 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
432 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
433 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
434 '\0', NULL, N_("Create an output file even if errors occur"),
435 TWO_DASHES },
436 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
437 '\0', NULL, NULL, NO_HELP },
438 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
439 '\0', NULL, N_("Only use library directories specified on\n"
440 " the command line"),
441 ONE_DASH },
442 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
443 '\0', N_("TARGET"), N_("Specify target of output file"),
444 EXACTLY_TWO_DASHES },
445 { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
446 '\0', NULL, N_("Print default output format"), TWO_DASHES },
447 { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT},
448 '\0', NULL, N_("Print current sysroot"), TWO_DASHES },
449 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
450 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
451 { {"reduce-memory-overheads", no_argument, NULL,
452 OPTION_REDUCE_MEMORY_OVERHEADS},
453 '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
454 TWO_DASHES },
455 { {"max-cache-size=SIZE", required_argument, NULL,
456 OPTION_MAX_CACHE_SIZE},
457 '\0', NULL, N_("Set the maximum cache size to SIZE bytes"),
458 TWO_DASHES },
459 { {"relax", no_argument, NULL, OPTION_RELAX},
460 '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
461 { {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
462 '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES },
463 { {"retain-symbols-file", required_argument, NULL,
464 OPTION_RETAIN_SYMBOLS_FILE},
465 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
466 { {"rpath", required_argument, NULL, OPTION_RPATH},
467 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
468 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
469 '\0', N_("PATH"), N_("Set link time shared library search path"),
470 ONE_DASH },
471 { {"shared", no_argument, NULL, OPTION_SHARED},
472 '\0', NULL, N_("Create a shared library"), ONE_DASH },
473 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
474 '\0', NULL, NULL, ONE_DASH },
475 { {"pie", no_argument, NULL, OPTION_PIE},
476 '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
477 { {"pic-executable", no_argument, NULL, OPTION_PIE},
478 '\0', NULL, NULL, TWO_DASHES },
479 { {"no-pie", no_argument, NULL, OPTION_NO_PIE},
480 '\0', NULL, N_("Create a position dependent executable (default)"), ONE_DASH },
481 { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
482 '\0', N_("[=ascending|descending]"),
483 N_("Sort common symbols by alignment [in specified order]"),
484 TWO_DASHES },
485 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
486 '\0', NULL, NULL, NO_HELP },
487 { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
488 '\0', N_("name|alignment"),
489 N_("Sort sections by name or maximum alignment"), TWO_DASHES },
490 { {"section-ordering-file", required_argument, NULL, OPTION_SECTION_ORDERING_FILE},
491 '\0', N_("FILE"),
492 N_("Sort sections by statements in FILE"), TWO_DASHES },
493 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
494 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
495 TWO_DASHES },
496 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
497 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
498 TWO_DASHES },
499 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
500 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
501 TWO_DASHES },
502 { {"stats", no_argument, NULL, OPTION_STATS},
503 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
504 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
505 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
506 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
507 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
508 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
509 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
510 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
511 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
512 TWO_DASHES },
513 { {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
514 '\0', N_("ADDRESS"), N_("Set image base address"), TWO_DASHES },
515 { {"Tbss", required_argument, NULL, OPTION_TBSS},
516 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
517 { {"Tdata", required_argument, NULL, OPTION_TDATA},
518 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
519 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
520 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
521 { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT},
522 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH },
523 { {"Trodata-segment", required_argument, NULL, OPTION_TRODATA_SEGMENT},
524 '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH },
525 { {"Tldata-segment", required_argument, NULL, OPTION_TLDATA_SEGMENT},
526 '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH },
527 { {"unresolved-symbols=<method>", required_argument, NULL,
528 OPTION_UNRESOLVED_SYMBOLS},
529 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n"
530 " ignore-all, report-all, ignore-in-object-files,\n"
531 " ignore-in-shared-libs"),
532 TWO_DASHES },
533 { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
534 '\0', N_("[=NUMBER]"),
535 N_("Output lots of information during link"), TWO_DASHES },
536 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
537 '\0', NULL, NULL, NO_HELP },
538 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
539 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
540 { {"version-exports-section", required_argument, NULL,
541 OPTION_VERSION_EXPORTS_SECTION },
542 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
543 " SYMBOL as the version."),
544 TWO_DASHES },
545 { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
546 '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
547 { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
548 '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
549 { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
550 '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
551 { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
552 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
553 { {"export-dynamic-symbol", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL},
554 '\0', N_("SYMBOL"), N_("Export the specified symbol"), EXACTLY_TWO_DASHES },
555 { {"export-dynamic-symbol-list", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL_LIST},
556 '\0', N_("FILE"), N_("Read export dynamic symbol list"), EXACTLY_TWO_DASHES },
557 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
558 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
559 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
560 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
561 TWO_DASHES },
563 { {"error-execstack", no_argument, NULL, OPTION_ERROR_EXECSTACK},
564 '\0', NULL, NULL, TWO_DASHES },
565 { {"no-error-execstack", no_argument, NULL, OPTION_NO_ERROR_EXECSTACK},
566 '\0', NULL, NULL, TWO_DASHES },
567 { {"warn-execstack-objects", no_argument, NULL, OPTION_WARN_EXECSTACK_OBJECTS},
568 '\0', NULL, NULL, TWO_DASHES },
569 { {"warn-execstack", no_argument, NULL, OPTION_WARN_EXECSTACK},
570 '\0', NULL, NULL, TWO_DASHES },
571 { {"no-warn-execstack", no_argument, NULL, OPTION_NO_WARN_EXECSTACK},
572 '\0', NULL, NULL, TWO_DASHES },
574 { {"error-rwx-segments", no_argument, NULL, OPTION_ERROR_RWX_SEGMENTS},
575 '\0', NULL, NULL, TWO_DASHES },
576 { {"no-error-rwx-segments", no_argument, NULL, OPTION_NO_ERROR_RWX_SEGMENTS},
577 '\0', NULL, NULL, TWO_DASHES },
578 { {"warn-rwx-segments", no_argument, NULL, OPTION_WARN_RWX_SEGMENTS},
579 '\0', NULL, NULL, TWO_DASHES },
580 { {"no-warn-rwx-segments", no_argument, NULL, OPTION_NO_WARN_RWX_SEGMENTS},
581 '\0', NULL, NULL, TWO_DASHES },
583 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
584 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
585 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
586 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
587 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
588 '\0', NULL, N_("Warn if start of section changes due to alignment"),
589 TWO_DASHES },
590 { {"warn-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
591 '\0', NULL,
592 #if DEFAULT_LD_TEXTREL_CHECK_WARNING
593 N_("Warn if output has DT_TEXTREL (default)"),
594 #else
595 N_("Warn if output has DT_TEXTREL"),
596 #endif
597 TWO_DASHES },
598 { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
599 '\0', NULL, NULL, NO_HELP },
600 { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
601 '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
602 TWO_DASHES },
603 { {"warn-unresolved-symbols", no_argument, NULL,
604 OPTION_WARN_UNRESOLVED_SYMBOLS},
605 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
606 { {"error-unresolved-symbols", no_argument, NULL,
607 OPTION_ERROR_UNRESOLVED_SYMBOLS},
608 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
609 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
610 '\0', NULL, N_("Include all objects from following archives"),
611 TWO_DASHES },
612 { {"wrap", required_argument, NULL, OPTION_WRAP},
613 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
614 { {"ignore-unresolved-symbol", required_argument, NULL,
615 OPTION_IGNORE_UNRESOLVED_SYMBOL},
616 '\0', N_("SYMBOL"),
617 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
618 { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
619 '\0', NULL, N_("Push state of flags governing input file handling"),
620 TWO_DASHES },
621 { {"pop-state", no_argument, NULL, OPTION_POP_STATE},
622 '\0', NULL, N_("Pop state of flags governing input file handling"),
623 TWO_DASHES },
624 { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE},
625 '\0', NULL, N_("Report target memory usage"), TWO_DASHES },
626 { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING},
627 '\0', N_("=MODE"), N_("Control how orphan sections are handled."),
628 TWO_DASHES },
629 { {"print-map-discarded", no_argument, NULL, OPTION_PRINT_MAP_DISCARDED},
630 '\0', NULL, N_("Show discarded sections in map file output (default)"),
631 TWO_DASHES },
632 { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISCARDED},
633 '\0', NULL, N_("Do not show discarded sections in map file output"),
634 TWO_DASHES },
635 { {"print-map-locals", no_argument, NULL, OPTION_PRINT_MAP_LOCALS},
636 '\0', NULL, N_("Show local symbols in map file output"),
637 TWO_DASHES },
638 { {"no-print-map-locals", no_argument, NULL, OPTION_NO_PRINT_MAP_LOCALS},
639 '\0', NULL, N_("Do not show local symbols in map file output (default)"),
640 TWO_DASHES },
641 { {"ctf-variables", no_argument, NULL, OPTION_CTF_VARIABLES},
642 '\0', NULL, N_("Emit names and types of static variables in CTF"),
643 TWO_DASHES },
644 { {"no-ctf-variables", no_argument, NULL, OPTION_NO_CTF_VARIABLES},
645 '\0', NULL, N_("Do not emit names and types of static variables in CTF"),
646 TWO_DASHES },
647 { {"ctf-share-types=<method>", required_argument, NULL,
648 OPTION_CTF_SHARE_TYPES},
649 '\0', NULL, N_("How to share CTF types between translation units.\n"
650 " <method> is: share-unconflicted (default),\n"
651 " share-duplicated"),
652 TWO_DASHES },
655 #define OPTION_COUNT ARRAY_SIZE (ld_options)
657 void
658 parse_args (unsigned argc, char **argv)
660 unsigned i;
661 int is, il, irl;
662 int ingroup = 0;
663 char *default_dirlist = NULL;
664 char *shortopts;
665 struct option *longopts;
666 struct option *really_longopts;
667 int last_optind;
668 enum symbolic_enum
670 symbolic_unset = 0,
671 symbolic,
672 symbolic_functions,
673 } opt_symbolic = symbolic_unset;
674 enum dynamic_list_enum
676 dynamic_list_unset = 0,
677 dynamic_list_data,
678 dynamic_list
679 } opt_dynamic_list = dynamic_list_unset;
680 struct bfd_elf_dynamic_list *export_list = NULL;
682 shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
683 longopts = (struct option *)
684 xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
685 really_longopts = (struct option *)
686 xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
688 /* Starting the short option string with '-' is for programs that
689 expect options and other ARGV-elements in any order and that care about
690 the ordering of the two. We describe each non-option ARGV-element
691 as if it were the argument of an option with character code 1. */
692 shortopts[0] = '-';
693 is = 1;
694 il = 0;
695 irl = 0;
696 for (i = 0; i < OPTION_COUNT; i++)
698 if (ld_options[i].shortopt != '\0')
700 shortopts[is] = ld_options[i].shortopt;
701 ++is;
702 if (ld_options[i].opt.has_arg == required_argument
703 || ld_options[i].opt.has_arg == optional_argument)
705 shortopts[is] = ':';
706 ++is;
707 if (ld_options[i].opt.has_arg == optional_argument)
709 shortopts[is] = ':';
710 ++is;
714 if (ld_options[i].opt.name != NULL)
716 if (ld_options[i].control == EXACTLY_TWO_DASHES)
718 really_longopts[irl] = ld_options[i].opt;
719 ++irl;
721 else
723 longopts[il] = ld_options[i].opt;
724 ++il;
728 shortopts[is] = '\0';
729 longopts[il].name = NULL;
730 really_longopts[irl].name = NULL;
732 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
734 /* The -G option is ambiguous on different platforms. Sometimes it
735 specifies the largest data size to put into the small data
736 section. Sometimes it is equivalent to --shared. Unfortunately,
737 the first form takes an argument, while the second does not.
739 We need to permit the --shared form because on some platforms,
740 such as Solaris, gcc -shared will pass -G to the linker.
742 To permit either usage, we look through the argument list. If we
743 find -G not followed by a number, we change it into --shared.
744 This will work for most normal cases. */
745 for (i = 1; i < argc; i++)
746 if (strcmp (argv[i], "-G") == 0
747 && (i + 1 >= argc
748 || ! ISDIGIT (argv[i + 1][0])))
749 argv[i] = (char *) "--shared";
751 /* Because we permit long options to start with a single dash, and
752 we have a --library option, and the -l option is conventionally
753 used with an immediately following argument, we can have bad
754 results if somebody tries to use -l with a library whose name
755 happens to start with "ibrary", as in -li. We avoid problems by
756 simply turning -l into --library. This means that users will
757 have to use two dashes in order to use --library, which is OK
758 since that's how it is documented.
760 FIXME: It's possible that this problem can arise for other short
761 options as well, although the user does always have the recourse
762 of adding a space between the option and the argument. */
763 for (i = 1; i < argc; i++)
765 if (argv[i][0] == '-'
766 && argv[i][1] == 'l'
767 && argv[i][2] != '\0')
769 char *n;
771 n = (char *) xmalloc (strlen (argv[i]) + 20);
772 sprintf (n, "--library=%s", argv[i] + 2);
773 argv[i] = n;
777 last_optind = -1;
778 while (1)
780 int longind = 0;
781 int optc;
782 static unsigned int defsym_count;
784 /* Using last_optind lets us avoid calling ldemul_parse_args
785 multiple times on a single option, which would lead to
786 confusion in the internal static variables maintained by
787 getopt. This could otherwise happen for an argument like
788 -nx, in which the -n is parsed as a single option, and we
789 loop around to pick up the -x. */
790 if (optind != last_optind)
791 if (ldemul_parse_args (argc, argv))
792 continue;
794 /* getopt_long_only is like getopt_long, but '-' as well as '--'
795 can indicate a long option. */
796 opterr = 0;
797 last_optind = optind;
798 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
799 if (optc == '?')
801 optind = last_optind;
802 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
804 /* Attempt to detect grouped short options, eg: "-non-start".
805 Accepting such options is error prone as it is not clear if the user
806 intended "-n -o n-start" or "--non-start". */
807 else if (longind == 0 /* This is a short option. */
808 && optc > 32 /* It is a valid option. */
809 /* The character is not the second character of argv[last_optind]. */
810 && optc != argv[last_optind][1])
812 if (optarg)
813 einfo (_("%F%P: Error: unable to disambiguate: %s (did you mean -%s ?)\n"),
814 argv[last_optind], argv[last_optind]);
815 else
816 einfo (_("%P: Warning: grouped short command line options are deprecated: %s\n"), argv[last_optind]);
819 if (ldemul_handle_option (optc))
820 continue;
822 if (optc == -1)
823 break;
825 switch (optc)
827 case '?':
829 /* If the last word on the command line is an option that
830 requires an argument, getopt will refuse to recognise it.
831 Try to catch such options here and issue a more helpful
832 error message than just "unrecognized option". */
833 int opt;
835 for (opt = ARRAY_SIZE (ld_options); opt--;)
836 if (ld_options[opt].opt.has_arg == required_argument
837 /* FIXME: There are a few short options that do not
838 have long equivalents, but which require arguments.
839 We should handle them too. */
840 && ld_options[opt].opt.name != NULL
841 && strcmp (argv[last_optind] + ld_options[opt].control, ld_options[opt].opt.name) == 0)
843 einfo (_("%P: %s: missing argument\n"), argv[last_optind]);
844 break;
847 if (opt == -1)
848 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
850 /* Fall through. */
852 default:
853 einfo (_("%F%P: use the --help option for usage information\n"));
854 break;
856 case 1: /* File name. */
857 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
858 break;
860 case OPTION_IGNORE:
861 break;
862 case 'a':
863 /* For HP/UX compatibility. Actually -a shared should mean
864 ``use only shared libraries'' but, then, we don't
865 currently support shared libraries on HP/UX anyhow. */
866 if (strcmp (optarg, "archive") == 0)
867 input_flags.dynamic = false;
868 else if (strcmp (optarg, "shared") == 0
869 || strcmp (optarg, "default") == 0)
870 input_flags.dynamic = true;
871 else
872 einfo (_("%F%P: unrecognized -a option `%s'\n"), optarg);
873 break;
874 case OPTION_ASSERT:
875 /* FIXME: We just ignore these, but we should handle them. */
876 if (strcmp (optarg, "definitions") == 0)
878 else if (strcmp (optarg, "nodefinitions") == 0)
880 else if (strcmp (optarg, "nosymbolic") == 0)
882 else if (strcmp (optarg, "pure-text") == 0)
884 else
885 einfo (_("%F%P: unrecognized -assert option `%s'\n"), optarg);
886 break;
887 case 'A':
888 ldfile_add_arch (optarg);
889 break;
890 case 'b':
891 lang_add_target (optarg);
892 break;
893 case 'c':
894 ldfile_open_command_file (optarg);
895 parser_input = input_mri_script;
896 yyparse ();
897 break;
898 case OPTION_CALL_SHARED:
899 input_flags.dynamic = true;
900 break;
901 case OPTION_NON_SHARED:
902 input_flags.dynamic = false;
903 break;
904 case OPTION_CREF:
905 command_line.cref = true;
906 link_info.notice_all = true;
907 break;
908 case 'd':
909 command_line.force_common_definition = true;
910 break;
911 case OPTION_FORCE_GROUP_ALLOCATION:
912 command_line.force_group_allocation = true;
913 break;
914 case OPTION_DEFSYM:
915 lex_string = optarg;
916 lex_redirect (optarg, "--defsym", ++defsym_count);
917 parser_input = input_defsym;
918 yyparse ();
919 lex_string = NULL;
920 break;
921 case OPTION_DEMANGLE:
922 demangling = true;
923 if (optarg != NULL)
925 enum demangling_styles style;
927 style = cplus_demangle_name_to_style (optarg);
928 if (style == unknown_demangling)
929 einfo (_("%F%P: unknown demangling style `%s'\n"),
930 optarg);
932 cplus_demangle_set_style (style);
934 break;
935 case 'I': /* Used on Solaris. */
936 case OPTION_DYNAMIC_LINKER:
937 command_line.interpreter = optarg;
938 link_info.nointerp = 0;
939 break;
940 case OPTION_NO_DYNAMIC_LINKER:
941 link_info.nointerp = 1;
942 break;
943 case OPTION_SYSROOT:
944 /* Already handled in ldmain.c. */
945 break;
946 case OPTION_EB:
947 command_line.endian = ENDIAN_BIG;
948 break;
949 case OPTION_EL:
950 command_line.endian = ENDIAN_LITTLE;
951 break;
952 case OPTION_EMBEDDED_RELOCS:
953 command_line.embedded_relocs = true;
954 break;
955 case OPTION_EXPORT_DYNAMIC:
956 case 'E': /* HP/UX compatibility. */
957 link_info.export_dynamic = true;
958 break;
959 case OPTION_NO_EXPORT_DYNAMIC:
960 link_info.export_dynamic = false;
961 break;
962 case OPTION_NON_CONTIGUOUS_REGIONS:
963 link_info.non_contiguous_regions = true;
964 break;
965 case OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS:
966 link_info.non_contiguous_regions_warnings = true;
967 break;
969 case OPTION_ERROR_EXECSTACK:
970 link_info.error_execstack = 1;
971 break;
972 case OPTION_NO_ERROR_EXECSTACK:
973 link_info.error_execstack = 0;
974 break;
975 case OPTION_WARN_EXECSTACK_OBJECTS:
976 link_info.warn_execstack = 2;
977 break;
978 case OPTION_WARN_EXECSTACK:
979 link_info.warn_execstack = 1;
980 break;
981 case OPTION_NO_WARN_EXECSTACK:
982 link_info.warn_execstack = 0;
983 break;
985 case OPTION_ERROR_RWX_SEGMENTS:
986 link_info.warn_is_error_for_rwx_segments = 1;
987 break;
988 case OPTION_NO_ERROR_RWX_SEGMENTS:
989 link_info.warn_is_error_for_rwx_segments = 0;
990 break;
991 case OPTION_WARN_RWX_SEGMENTS:
992 link_info.no_warn_rwx_segments = 0;
993 link_info.user_warn_rwx_segments = 1;
994 break;
995 case OPTION_NO_WARN_RWX_SEGMENTS:
996 link_info.no_warn_rwx_segments = 1;
997 link_info.user_warn_rwx_segments = 1;
998 break;
1000 case 'e':
1001 lang_add_entry (optarg, true);
1002 break;
1003 case 'f':
1004 if (command_line.auxiliary_filters == NULL)
1006 command_line.auxiliary_filters = (char **)
1007 xmalloc (2 * sizeof (char *));
1008 command_line.auxiliary_filters[0] = optarg;
1009 command_line.auxiliary_filters[1] = NULL;
1011 else
1013 int c;
1014 char **p;
1016 c = 0;
1017 for (p = command_line.auxiliary_filters; *p != NULL; p++)
1018 ++c;
1019 command_line.auxiliary_filters = (char **)
1020 xrealloc (command_line.auxiliary_filters,
1021 (c + 2) * sizeof (char *));
1022 command_line.auxiliary_filters[c] = optarg;
1023 command_line.auxiliary_filters[c + 1] = NULL;
1025 break;
1026 case 'F':
1027 command_line.filter_shlib = optarg;
1028 break;
1029 case OPTION_FORCE_EXE_SUFFIX:
1030 command_line.force_exe_suffix = true;
1031 break;
1032 case 'G':
1034 char *end;
1035 g_switch_value = strtoul (optarg, &end, 0);
1036 if (*end)
1037 einfo (_("%F%P: invalid number `%s'\n"), optarg);
1039 break;
1040 case 'g':
1041 /* Ignore. */
1042 break;
1043 case OPTION_GC_SECTIONS:
1044 link_info.gc_sections = true;
1045 break;
1046 case OPTION_PRINT_GC_SECTIONS:
1047 link_info.print_gc_sections = true;
1048 break;
1049 case OPTION_GC_KEEP_EXPORTED:
1050 link_info.gc_keep_exported = true;
1051 break;
1052 case OPTION_HELP:
1053 help ();
1054 xexit (0);
1055 break;
1056 case 'L':
1057 ldfile_add_library_path (optarg, true);
1058 break;
1059 case 'l':
1060 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
1061 break;
1062 case 'M':
1063 config.map_filename = "-";
1064 break;
1065 case 'm':
1066 /* Ignore. Was handled in a pre-parse. */
1067 break;
1068 case OPTION_MAP:
1069 config.map_filename = optarg;
1070 break;
1071 case 'N':
1072 config.text_read_only = false;
1073 config.magic_demand_paged = false;
1074 input_flags.dynamic = false;
1075 break;
1076 case OPTION_NO_OMAGIC:
1077 config.text_read_only = true;
1078 config.magic_demand_paged = true;
1079 /* NB/ Does not set input_flags.dynamic to TRUE.
1080 Use --call-shared or -Bdynamic for this. */
1081 break;
1082 case 'n':
1083 config.text_read_only = true;
1084 config.magic_demand_paged = false;
1085 input_flags.dynamic = false;
1086 break;
1087 case OPTION_NO_DEFINE_COMMON:
1088 link_info.inhibit_common_definition = true;
1089 break;
1090 case OPTION_NO_DEMANGLE:
1091 demangling = false;
1092 break;
1093 case OPTION_NO_GC_SECTIONS:
1094 link_info.gc_sections = false;
1095 break;
1096 case OPTION_NO_PRINT_GC_SECTIONS:
1097 link_info.print_gc_sections = false;
1098 break;
1099 case OPTION_NO_KEEP_MEMORY:
1100 link_info.keep_memory = false;
1101 break;
1102 case OPTION_NO_UNDEFINED:
1103 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
1104 break;
1105 case OPTION_ALLOW_SHLIB_UNDEFINED:
1106 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1107 break;
1108 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
1109 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
1110 break;
1111 case OPTION_UNRESOLVED_SYMBOLS:
1112 if (strcmp (optarg, "ignore-all") == 0)
1114 link_info.unresolved_syms_in_objects = RM_IGNORE;
1115 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1117 else if (strcmp (optarg, "report-all") == 0)
1119 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
1120 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
1122 else if (strcmp (optarg, "ignore-in-object-files") == 0)
1124 link_info.unresolved_syms_in_objects = RM_IGNORE;
1125 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
1127 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
1129 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
1130 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1132 else
1133 einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg);
1134 break;
1135 case OPTION_WARN_UNRESOLVED_SYMBOLS:
1136 link_info.warn_unresolved_syms = true;
1137 break;
1138 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
1139 link_info.warn_unresolved_syms = false;
1140 break;
1141 case OPTION_ALLOW_MULTIPLE_DEFINITION:
1142 link_info.allow_multiple_definition = true;
1143 break;
1145 #if SUPPORT_ERROR_HANDLING_SCRIPT
1146 case OPTION_ERROR_HANDLING_SCRIPT:
1147 /* FIXME: Should we warn if the script is being overridden by another ?
1148 Or maybe they should be chained together ? */
1149 error_handling_script = optarg;
1150 break;
1151 #endif
1153 case OPTION_ENABLE_LINKER_VERSION:
1154 enable_linker_version = true;
1155 break;
1156 case OPTION_DISABLE_LINKER_VERSION:
1157 enable_linker_version = false;
1158 break;
1160 case OPTION_UNDEFINED_VERSION:
1161 link_info.allow_undefined_version = true;
1162 break;
1163 case OPTION_NO_UNDEFINED_VERSION:
1164 link_info.allow_undefined_version = false;
1165 break;
1166 case OPTION_DEFAULT_SYMVER:
1167 link_info.create_default_symver = true;
1168 break;
1169 case OPTION_DEFAULT_IMPORTED_SYMVER:
1170 link_info.default_imported_symver = true;
1171 break;
1172 case OPTION_NO_WARN_MISMATCH:
1173 command_line.warn_mismatch = false;
1174 break;
1175 case OPTION_NO_WARN_SEARCH_MISMATCH:
1176 command_line.warn_search_mismatch = false;
1177 break;
1178 case OPTION_NOINHIBIT_EXEC:
1179 force_make_executable = true;
1180 break;
1181 case OPTION_NOSTDLIB:
1182 config.only_cmd_line_lib_dirs = true;
1183 break;
1184 case OPTION_NO_WHOLE_ARCHIVE:
1185 input_flags.whole_archive = false;
1186 break;
1187 case 'O':
1188 /* FIXME "-O<non-digits> <value>" used to set the address of
1189 section <non-digits>. Was this for compatibility with
1190 something, or can we create a new option to do that
1191 (with a syntax similar to -defsym)?
1192 getopt can't handle two args to an option without kludges. */
1194 /* Enable optimizations of output files. */
1195 link_info.optimize = strtoul (optarg, NULL, 0) != 0;
1196 break;
1197 case 'o':
1198 lang_add_output (optarg, 0);
1199 break;
1200 case OPTION_OFORMAT:
1201 lang_add_output_format (optarg, NULL, NULL, 0);
1202 break;
1203 case OPTION_OUT_IMPLIB:
1204 command_line.out_implib_filename = xstrdup (optarg);
1205 break;
1206 case OPTION_PRINT_SYSROOT:
1207 if (*ld_sysroot)
1208 puts (ld_sysroot);
1209 xexit (0);
1210 break;
1211 case OPTION_PRINT_OUTPUT_FORMAT:
1212 command_line.print_output_format = true;
1213 break;
1214 #if BFD_SUPPORTS_PLUGINS
1215 case OPTION_PLUGIN:
1216 plugin_opt_plugin (optarg);
1217 break;
1218 case OPTION_PLUGIN_OPT:
1219 if (plugin_opt_plugin_arg (optarg))
1220 einfo (_("%F%P: bad -plugin-opt option\n"));
1221 break;
1222 case OPTION_PLUGIN_SAVE_TEMPS:
1223 config.plugin_save_temps = true;
1224 break;
1225 #endif /* BFD_SUPPORTS_PLUGINS */
1226 case 'q':
1227 link_info.emitrelocations = true;
1228 break;
1229 case 'i':
1230 case 'r':
1231 if (optind == last_optind)
1232 /* This can happen if the user put "-rpath,a" on the command
1233 line. (Or something similar. The comma is important).
1234 Getopt becomes confused and thinks that this is a -r option
1235 but it cannot parse the text after the -r so it refuses to
1236 increment the optind counter. Detect this case and issue
1237 an error message here. We cannot just make this a warning,
1238 increment optind, and continue because getopt is too confused
1239 and will seg-fault the next time around. */
1240 einfo(_("%F%P: unrecognised option: %s\n"), argv[optind]);
1242 if (bfd_link_pic (&link_info))
1243 einfo (_("%F%P: -r and %s may not be used together\n"),
1244 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1246 link_info.type = type_relocatable;
1247 config.build_constructors = false;
1248 config.magic_demand_paged = false;
1249 config.text_read_only = false;
1250 input_flags.dynamic = false;
1251 break;
1252 case 'R':
1253 /* The GNU linker traditionally uses -R to mean to include
1254 only the symbols from a file. The Solaris linker uses -R
1255 to set the path used by the runtime linker to find
1256 libraries. This is the GNU linker -rpath argument. We
1257 try to support both simultaneously by checking the file
1258 named. If it is a directory, rather than a regular file,
1259 we assume -rpath was meant. */
1261 struct stat s;
1263 if (stat (optarg, &s) >= 0
1264 && ! S_ISDIR (s.st_mode))
1266 lang_add_input_file (optarg,
1267 lang_input_file_is_symbols_only_enum,
1268 NULL);
1269 break;
1272 /* Fall through. */
1273 case OPTION_RPATH:
1274 if (command_line.rpath == NULL)
1275 command_line.rpath = xstrdup (optarg);
1276 else
1278 size_t rpath_len = strlen (command_line.rpath);
1279 size_t optarg_len = strlen (optarg);
1280 char *buf;
1281 char *cp = command_line.rpath;
1283 /* First see whether OPTARG is already in the path. */
1286 if (strncmp (optarg, cp, optarg_len) == 0
1287 && (cp[optarg_len] == 0
1288 || cp[optarg_len] == config.rpath_separator))
1289 /* We found it. */
1290 break;
1292 /* Not yet found. */
1293 cp = strchr (cp, config.rpath_separator);
1294 if (cp != NULL)
1295 ++cp;
1297 while (cp != NULL);
1299 if (cp == NULL)
1301 buf = (char *) xmalloc (rpath_len + optarg_len + 2);
1302 sprintf (buf, "%s%c%s", command_line.rpath,
1303 config.rpath_separator, optarg);
1304 free (command_line.rpath);
1305 command_line.rpath = buf;
1308 break;
1309 case OPTION_RPATH_LINK:
1310 if (command_line.rpath_link == NULL)
1311 command_line.rpath_link = xstrdup (optarg);
1312 else
1314 char *buf;
1316 buf = (char *) xmalloc (strlen (command_line.rpath_link)
1317 + strlen (optarg)
1318 + 2);
1319 sprintf (buf, "%s%c%s", command_line.rpath_link,
1320 config.rpath_separator, optarg);
1321 free (command_line.rpath_link);
1322 command_line.rpath_link = buf;
1324 break;
1325 case OPTION_NO_RELAX:
1326 DISABLE_RELAXATION;
1327 break;
1328 case OPTION_RELAX:
1329 ENABLE_RELAXATION;
1330 break;
1331 case OPTION_RETAIN_SYMBOLS_FILE:
1332 add_keepsyms_file (optarg);
1333 break;
1334 case 'S':
1335 link_info.strip = strip_debugger;
1336 break;
1337 case 's':
1338 link_info.strip = strip_all;
1339 break;
1340 case OPTION_STRIP_DISCARDED:
1341 link_info.strip_discarded = true;
1342 break;
1343 case OPTION_NO_STRIP_DISCARDED:
1344 link_info.strip_discarded = false;
1345 break;
1346 case OPTION_DISABLE_MULTIPLE_DEFS_ABS:
1347 link_info.prohibit_multiple_definition_absolute = true;
1348 break;
1349 case OPTION_SHARED:
1350 if (config.has_shared)
1352 if (bfd_link_relocatable (&link_info))
1353 einfo (_("%F%P: -r and %s may not be used together\n"),
1354 "-shared");
1356 link_info.type = type_dll;
1357 /* When creating a shared library, the default
1358 behaviour is to ignore any unresolved references. */
1359 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1360 link_info.unresolved_syms_in_objects = RM_IGNORE;
1361 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1362 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1364 else
1365 einfo (_("%F%P: -shared not supported\n"));
1366 break;
1367 case OPTION_NO_PIE:
1368 link_info.type = type_pde;
1369 break;
1370 case OPTION_PIE:
1371 if (config.has_shared)
1373 if (bfd_link_relocatable (&link_info))
1374 einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
1376 link_info.type = type_pie;
1378 else
1379 einfo (_("%F%P: -pie not supported\n"));
1380 break;
1381 case 'h': /* Used on Solaris. */
1382 case OPTION_SONAME:
1383 if (optarg[0] == '\0' && command_line.soname
1384 && command_line.soname[0])
1385 einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
1386 else
1387 command_line.soname = optarg;
1388 break;
1389 case OPTION_SORT_COMMON:
1390 if (optarg == NULL
1391 || strcmp (optarg, N_("descending")) == 0)
1392 config.sort_common = sort_descending;
1393 else if (strcmp (optarg, N_("ascending")) == 0)
1394 config.sort_common = sort_ascending;
1395 else
1396 einfo (_("%F%P: invalid common section sorting option: %s\n"),
1397 optarg);
1398 break;
1399 case OPTION_SORT_SECTION:
1400 if (strcmp (optarg, N_("name")) == 0)
1401 sort_section = by_name;
1402 else if (strcmp (optarg, N_("alignment")) == 0)
1403 sort_section = by_alignment;
1404 else
1405 einfo (_("%F%P: invalid section sorting option: %s\n"),
1406 optarg);
1407 break;
1408 case OPTION_SECTION_ORDERING_FILE:
1409 if (command_line.section_ordering_file != NULL
1410 && strcmp (optarg, command_line.section_ordering_file) != 0)
1411 einfo (_("%P: warning: section ordering file changed. Ignoring earlier definition\n"));
1412 command_line.section_ordering_file = optarg;
1413 break;
1414 case OPTION_STATS:
1415 config.stats = true;
1416 break;
1417 case OPTION_NO_SYMBOLIC:
1418 opt_symbolic = symbolic_unset;
1419 break;
1420 case OPTION_SYMBOLIC:
1421 opt_symbolic = symbolic;
1422 break;
1423 case OPTION_SYMBOLIC_FUNCTIONS:
1424 opt_symbolic = symbolic_functions;
1425 break;
1426 case 't':
1427 ++trace_files;
1428 break;
1429 case 'T':
1430 previous_script_handle = saved_script_handle;
1431 ldfile_open_script_file (optarg);
1432 parser_input = input_script;
1433 yyparse ();
1434 previous_script_handle = NULL;
1435 break;
1436 case OPTION_DEFAULT_SCRIPT:
1437 command_line.default_script = optarg;
1438 break;
1439 case OPTION_SECTION_START:
1441 char *optarg2;
1442 char *sec_name;
1443 int len;
1445 /* Check for <something>=<somthing>... */
1446 optarg2 = strchr (optarg, '=');
1447 if (optarg2 == NULL)
1448 einfo (_("%F%P: invalid argument to option"
1449 " \"--section-start\"\n"));
1451 optarg2++;
1453 /* So far so good. Are all the args present? */
1454 if ((*optarg == '\0') || (*optarg2 == '\0'))
1455 einfo (_("%F%P: missing argument(s) to option"
1456 " \"--section-start\"\n"));
1458 /* We must copy the section name as set_section_start
1459 doesn't do it for us. */
1460 len = optarg2 - optarg;
1461 sec_name = (char *) xmalloc (len);
1462 memcpy (sec_name, optarg, len - 1);
1463 sec_name[len - 1] = 0;
1465 /* Then set it... */
1466 set_section_start (sec_name, optarg2);
1468 break;
1469 case OPTION_TARGET_HELP:
1470 /* Mention any target specific options. */
1471 ldemul_list_emulation_options (stdout);
1472 exit (0);
1473 case OPTION_TBSS:
1474 set_segment_start (".bss", optarg);
1475 break;
1476 case OPTION_TDATA:
1477 set_segment_start (".data", optarg);
1478 break;
1479 case OPTION_TTEXT:
1480 set_segment_start (".text", optarg);
1481 break;
1482 case OPTION_IMAGE_BASE:
1483 /* Unless PE, --image-base and -Ttext-segment behavior is the same
1484 PE-specific functionality is implemented in emultempl/{pe, pep, beos}.em */
1485 case OPTION_TTEXT_SEGMENT:
1486 set_segment_start (".text-segment", optarg);
1487 break;
1488 case OPTION_TRODATA_SEGMENT:
1489 set_segment_start (".rodata-segment", optarg);
1490 break;
1491 case OPTION_TLDATA_SEGMENT:
1492 set_segment_start (".ldata-segment", optarg);
1493 break;
1494 case OPTION_TRADITIONAL_FORMAT:
1495 link_info.traditional_format = true;
1496 break;
1497 case OPTION_TASK_LINK:
1498 link_info.task_link = true;
1499 /* Fall through. */
1500 case OPTION_UR:
1501 if (bfd_link_pic (&link_info))
1502 einfo (_("%F%P: -r and %s may not be used together\n"),
1503 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1505 link_info.type = type_relocatable;
1506 config.build_constructors = true;
1507 config.magic_demand_paged = false;
1508 config.text_read_only = false;
1509 input_flags.dynamic = false;
1510 break;
1511 case 'u':
1512 ldlang_add_undef (optarg, true);
1513 break;
1514 case OPTION_REQUIRE_DEFINED_SYMBOL:
1515 ldlang_add_require_defined (optarg);
1516 break;
1517 case OPTION_UNIQUE:
1518 if (optarg != NULL)
1519 lang_add_unique (optarg);
1520 else
1521 config.unique_orphan_sections = true;
1522 break;
1523 case OPTION_VERBOSE:
1524 ldversion (1);
1525 version_printed = true;
1526 verbose = true;
1527 overflow_cutoff_limit = -2;
1528 if (optarg != NULL)
1530 char *end;
1531 int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
1532 if (*end)
1533 einfo (_("%F%P: invalid number `%s'\n"), optarg);
1534 #if BFD_SUPPORTS_PLUGINS
1535 report_plugin_symbols = level > 1;
1536 #endif /* BFD_SUPPORTS_PLUGINS */
1538 break;
1539 case 'v':
1540 ldversion (0);
1541 version_printed = true;
1542 break;
1543 case 'V':
1544 ldversion (1);
1545 version_printed = true;
1546 break;
1547 case OPTION_VERSION:
1548 ldversion (2);
1549 xexit (0);
1550 break;
1551 case OPTION_VERSION_SCRIPT:
1552 /* This option indicates a small script that only specifies
1553 version information. Read it, but don't assume that
1554 we've seen a linker script. */
1556 FILE *hold_script_handle;
1558 hold_script_handle = saved_script_handle;
1559 ldfile_open_command_file (optarg);
1560 saved_script_handle = hold_script_handle;
1561 parser_input = input_version_script;
1562 yyparse ();
1564 break;
1565 case OPTION_VERSION_EXPORTS_SECTION:
1566 /* This option records a version symbol to be applied to the
1567 symbols listed for export to be found in the object files
1568 .exports sections. */
1569 command_line.version_exports_section = optarg;
1570 break;
1571 case OPTION_DYNAMIC_LIST_DATA:
1572 opt_dynamic_list = dynamic_list_data;
1573 break;
1574 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1575 lang_append_dynamic_list_cpp_typeinfo ();
1576 if (opt_dynamic_list != dynamic_list_data)
1577 opt_dynamic_list = dynamic_list;
1578 break;
1579 case OPTION_DYNAMIC_LIST_CPP_NEW:
1580 lang_append_dynamic_list_cpp_new ();
1581 if (opt_dynamic_list != dynamic_list_data)
1582 opt_dynamic_list = dynamic_list;
1583 break;
1584 case OPTION_DYNAMIC_LIST:
1585 /* This option indicates a small script that only specifies
1586 a dynamic list. Read it, but don't assume that we've
1587 seen a linker script. */
1589 FILE *hold_script_handle;
1591 hold_script_handle = saved_script_handle;
1592 ldfile_open_command_file (optarg);
1593 saved_script_handle = hold_script_handle;
1594 parser_input = input_dynamic_list;
1595 current_dynamic_list_p = &link_info.dynamic_list;
1596 yyparse ();
1598 if (opt_dynamic_list != dynamic_list_data)
1599 opt_dynamic_list = dynamic_list;
1600 break;
1601 case OPTION_EXPORT_DYNAMIC_SYMBOL:
1603 struct bfd_elf_version_expr *expr
1604 = lang_new_vers_pattern (NULL, xstrdup (optarg), NULL,
1605 false);
1606 lang_append_dynamic_list (&export_list, expr);
1608 break;
1609 case OPTION_EXPORT_DYNAMIC_SYMBOL_LIST:
1610 /* This option indicates a small script that only specifies
1611 an export list. Read it, but don't assume that we've
1612 seen a linker script. */
1614 FILE *hold_script_handle;
1616 hold_script_handle = saved_script_handle;
1617 ldfile_open_command_file (optarg);
1618 saved_script_handle = hold_script_handle;
1619 parser_input = input_dynamic_list;
1620 current_dynamic_list_p = &export_list;
1621 yyparse ();
1623 break;
1624 case OPTION_WARN_COMMON:
1625 config.warn_common = true;
1626 break;
1627 case OPTION_WARN_CONSTRUCTORS:
1628 config.warn_constructors = true;
1629 break;
1630 case OPTION_WARN_FATAL:
1631 config.fatal_warnings = true;
1632 break;
1633 case OPTION_NO_WARN_FATAL:
1634 config.fatal_warnings = false;
1635 break;
1636 case OPTION_NO_WARNINGS:
1637 case 'w':
1638 config.no_warnings = true;
1639 config.fatal_warnings = false;
1640 break;
1641 case OPTION_WARN_MULTIPLE_GP:
1642 config.warn_multiple_gp = true;
1643 break;
1644 case OPTION_WARN_ONCE:
1645 config.warn_once = true;
1646 break;
1647 case OPTION_WARN_SECTION_ALIGN:
1648 config.warn_section_align = true;
1649 break;
1650 case OPTION_WARN_TEXTREL:
1651 link_info.textrel_check = textrel_check_warning;
1652 break;
1653 case OPTION_WARN_ALTERNATE_EM:
1654 link_info.warn_alternate_em = true;
1655 break;
1656 case OPTION_WHOLE_ARCHIVE:
1657 input_flags.whole_archive = true;
1658 break;
1659 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
1660 input_flags.add_DT_NEEDED_for_dynamic = true;
1661 break;
1662 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
1663 input_flags.add_DT_NEEDED_for_dynamic = false;
1664 break;
1665 case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
1666 input_flags.add_DT_NEEDED_for_regular = true;
1667 break;
1668 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
1669 input_flags.add_DT_NEEDED_for_regular = false;
1670 break;
1671 case OPTION_WRAP:
1672 add_wrap (optarg);
1673 break;
1674 case OPTION_IGNORE_UNRESOLVED_SYMBOL:
1675 add_ignoresym (&link_info, optarg);
1676 break;
1677 case OPTION_DISCARD_NONE:
1678 link_info.discard = discard_none;
1679 break;
1680 case 'X':
1681 link_info.discard = discard_l;
1682 break;
1683 case 'x':
1684 link_info.discard = discard_all;
1685 break;
1686 case 'Y':
1687 if (startswith (optarg, "P,"))
1688 optarg += 2;
1689 free (default_dirlist);
1690 default_dirlist = xstrdup (optarg);
1691 break;
1692 case 'y':
1693 add_ysym (optarg);
1694 break;
1695 case OPTION_SPARE_DYNAMIC_TAGS:
1696 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1697 break;
1698 case OPTION_SPLIT_BY_RELOC:
1699 if (optarg != NULL)
1700 config.split_by_reloc = strtoul (optarg, NULL, 0);
1701 else
1702 config.split_by_reloc = 32768;
1703 break;
1704 case OPTION_SPLIT_BY_FILE:
1705 if (optarg != NULL)
1706 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1707 else
1708 config.split_by_file = 1;
1709 break;
1710 case OPTION_CHECK_SECTIONS:
1711 command_line.check_section_addresses = 1;
1712 break;
1713 case OPTION_NO_CHECK_SECTIONS:
1714 command_line.check_section_addresses = 0;
1715 break;
1716 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1717 command_line.accept_unknown_input_arch = true;
1718 break;
1719 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1720 command_line.accept_unknown_input_arch = false;
1721 break;
1722 case '(':
1723 lang_enter_group ();
1724 ingroup++;
1725 break;
1726 case ')':
1727 if (! ingroup)
1728 einfo (_("%F%P: group ended before it began (--help for usage)\n"));
1730 lang_leave_group ();
1731 ingroup--;
1732 break;
1734 case OPTION_INIT:
1735 link_info.init_function = optarg;
1736 break;
1738 case OPTION_FINI:
1739 link_info.fini_function = optarg;
1740 break;
1742 case OPTION_REMAP_INPUTS_FILE:
1743 if (! ldfile_add_remap_file (optarg))
1744 einfo (_("%F%P: failed to add remap file %s\n"), optarg);
1745 break;
1747 case OPTION_REMAP_INPUTS:
1749 char *optarg2 = strchr (optarg, '=');
1750 if (optarg2 == NULL)
1751 /* FIXME: Should we allow --remap-inputs=@myfile as a synonym
1752 for --remap-inputs-file=myfile ? */
1753 einfo (_("%F%P: invalid argument to option --remap-inputs\n"));
1754 size_t len = optarg2 - optarg;
1755 char * pattern = xmalloc (len + 1);
1756 memcpy (pattern, optarg, len);
1757 pattern[len] = 0;
1758 ldfile_add_remap (pattern, optarg2 + 1);
1759 free (pattern);
1761 break;
1763 case OPTION_REDUCE_MEMORY_OVERHEADS:
1764 link_info.reduce_memory_overheads = true;
1765 if (config.hash_table_size == 0)
1766 config.hash_table_size = 1021;
1767 break;
1769 case OPTION_MAX_CACHE_SIZE:
1771 char *end;
1772 bfd_size_type cache_size = strtoul (optarg, &end, 0);
1773 if (*end != '\0')
1774 einfo (_("%F%P: invalid cache memory size: %s\n"),
1775 optarg);
1776 link_info.max_cache_size = cache_size;
1778 break;
1780 case OPTION_HASH_SIZE:
1782 bfd_size_type new_size;
1784 new_size = strtoul (optarg, NULL, 0);
1785 if (new_size)
1786 config.hash_table_size = new_size;
1787 else
1788 einfo (_("%X%P: --hash-size needs a numeric argument\n"));
1790 break;
1792 case OPTION_PUSH_STATE:
1793 input_flags.pushed = xmemdup (&input_flags,
1794 sizeof (input_flags),
1795 sizeof (input_flags));
1796 break;
1798 case OPTION_POP_STATE:
1799 if (input_flags.pushed == NULL)
1800 einfo (_("%F%P: no state pushed before popping\n"));
1801 else
1803 struct lang_input_statement_flags *oldp = input_flags.pushed;
1804 memcpy (&input_flags, oldp, sizeof (input_flags));
1805 free (oldp);
1807 break;
1809 case OPTION_PRINT_MEMORY_USAGE:
1810 command_line.print_memory_usage = true;
1811 break;
1813 case OPTION_ORPHAN_HANDLING:
1814 if (strcasecmp (optarg, "place") == 0)
1815 config.orphan_handling = orphan_handling_place;
1816 else if (strcasecmp (optarg, "warn") == 0)
1817 config.orphan_handling = orphan_handling_warn;
1818 else if (strcasecmp (optarg, "error") == 0)
1819 config.orphan_handling = orphan_handling_error;
1820 else if (strcasecmp (optarg, "discard") == 0)
1821 config.orphan_handling = orphan_handling_discard;
1822 else
1823 einfo (_("%F%P: invalid argument to option"
1824 " \"--orphan-handling\"\n"));
1825 break;
1827 case OPTION_NO_PRINT_MAP_DISCARDED:
1828 config.print_map_discarded = false;
1829 break;
1831 case OPTION_PRINT_MAP_DISCARDED:
1832 config.print_map_discarded = true;
1833 break;
1835 case OPTION_NO_PRINT_MAP_LOCALS:
1836 config.print_map_locals = false;
1837 break;
1839 case OPTION_PRINT_MAP_LOCALS:
1840 config.print_map_locals = true;
1841 break;
1843 case OPTION_DEPENDENCY_FILE:
1844 config.dependency_file = optarg;
1845 break;
1847 case OPTION_CTF_VARIABLES:
1848 config.ctf_variables = true;
1849 break;
1851 case OPTION_NO_CTF_VARIABLES:
1852 config.ctf_variables = false;
1853 break;
1855 case OPTION_CTF_SHARE_TYPES:
1856 if (strcmp (optarg, "share-unconflicted") == 0)
1857 config.ctf_share_duplicated = false;
1858 else if (strcmp (optarg, "share-duplicated") == 0)
1859 config.ctf_share_duplicated = true;
1860 else
1861 einfo (_("%F%P: bad --ctf-share-types option: %s\n"), optarg);
1862 break;
1866 free (really_longopts);
1867 free (longopts);
1868 free (shortopts);
1870 /* Run a couple of checks on the map filename. */
1871 if (config.map_filename)
1873 char * new_name = NULL;
1874 char * percent;
1876 if (config.map_filename[0] == 0)
1878 einfo (_("%P: no file/directory name provided for map output; ignored\n"));
1879 config.map_filename = NULL;
1881 else if (strcmp (config.map_filename, "-") == 0)
1882 ; /* Write to stdout. Handled in main(). */
1883 else if ((percent = strchr (config.map_filename, '%')) != NULL)
1885 /* FIXME: Check for a second % character and issue an error ? */
1887 /* Construct a map file by replacing the % character with the (full)
1888 output filename. If the % character was the last character in
1889 the original map filename then add a .map extension. */
1890 percent[0] = 0;
1891 new_name = xasprintf ("%s%s%s", config.map_filename,
1892 output_filename,
1893 percent[1] ? percent + 1 : ".map");
1895 /* FIXME: Should we ensure that any directory components in new_name exist ? */
1897 else
1899 struct stat s;
1901 /* If the map filename is actually a directory then create
1902 a file inside it, based upon the output filename. */
1903 if (stat (config.map_filename, &s) < 0)
1905 if (errno != ENOENT)
1906 einfo (_("%P: cannot stat linker map file: %E\n"));
1908 else if (S_ISDIR (s.st_mode))
1910 char lastc = config.map_filename[strlen (config.map_filename) - 1];
1911 new_name = xasprintf ("%s%s%s.map", config.map_filename,
1912 IS_DIR_SEPARATOR (lastc) ? "" : "/",
1913 lbasename (output_filename));
1915 else if (! S_ISREG (s.st_mode))
1917 einfo (_("%P: linker map file is not a regular file\n"));
1918 config.map_filename = NULL;
1920 /* else FIXME: Check write permission ? */
1923 if (new_name != NULL)
1925 /* This is a trivial memory leak. */
1926 config.map_filename = new_name;
1930 if (command_line.soname && command_line.soname[0] == '\0')
1932 einfo (_("%P: SONAME must not be empty string; ignored\n"));
1933 command_line.soname = NULL;
1936 while (ingroup)
1938 einfo (_("%P: missing --end-group; added as last command line option\n"));
1939 lang_leave_group ();
1940 ingroup--;
1943 if (default_dirlist != NULL)
1945 set_default_dirlist (default_dirlist);
1946 free (default_dirlist);
1949 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1950 /* FIXME: Should we allow emulations a chance to set this ? */
1951 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
1953 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1954 /* FIXME: Should we allow emulations a chance to set this ? */
1955 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
1957 if (bfd_link_relocatable (&link_info)
1958 && command_line.check_section_addresses < 0)
1959 command_line.check_section_addresses = 0;
1961 if (export_list)
1963 struct bfd_elf_version_expr *head = export_list->head.list;
1964 struct bfd_elf_version_expr *next;
1966 /* For --export-dynamic-symbol[-list]:
1967 1. When building executable, treat like --dynamic-list.
1968 2. When building shared object:
1969 a. If -Bsymbolic or --dynamic-list are used, treat like
1970 --dynamic-list.
1971 b. Otherwise, ignored.
1973 if (!bfd_link_relocatable (&link_info)
1974 && (bfd_link_executable (&link_info)
1975 || opt_symbolic != symbolic_unset
1976 || opt_dynamic_list != dynamic_list_unset))
1978 /* Append the export list to link_info.dynamic_list. */
1979 if (link_info.dynamic_list)
1981 for (next = head; next->next != NULL; next = next->next)
1983 next->next = link_info.dynamic_list->head.list;
1984 link_info.dynamic_list->head.list = head;
1986 else
1987 link_info.dynamic_list = export_list;
1989 if (opt_dynamic_list != dynamic_list_data)
1990 opt_dynamic_list = dynamic_list;
1992 else
1994 /* Free the export list. */
1995 for (; head->next != NULL; head = next)
1997 next = head->next;
1998 free (head);
2000 free (export_list);
2004 switch (opt_dynamic_list)
2006 case dynamic_list_unset:
2007 break;
2008 case dynamic_list_data:
2009 link_info.dynamic_data = true;
2010 /* Fall through. */
2011 case dynamic_list:
2012 link_info.dynamic = true;
2013 opt_symbolic = symbolic_unset;
2014 break;
2017 /* -Bsymbolic and -Bsymbols-functions are for shared library output. */
2018 if (bfd_link_dll (&link_info))
2019 switch (opt_symbolic)
2021 case symbolic_unset:
2022 break;
2023 case symbolic:
2024 link_info.symbolic = true;
2025 if (link_info.dynamic_list)
2027 struct bfd_elf_version_expr *ent, *next;
2028 for (ent = link_info.dynamic_list->head.list; ent; ent = next)
2030 next = ent->next;
2031 free (ent);
2033 free (link_info.dynamic_list);
2034 link_info.dynamic_list = NULL;
2036 break;
2037 case symbolic_functions:
2038 link_info.dynamic = true;
2039 link_info.dynamic_data = true;
2040 break;
2043 /* -z nosectionheader implies --strip-all. */
2044 if (config.no_section_header)
2046 if (bfd_link_relocatable (&link_info))
2047 einfo (_("%F%P: -r and -z nosectionheader may not be used together\n"));
2049 link_info.strip = strip_all;
2052 if (!bfd_link_dll (&link_info))
2054 if (command_line.filter_shlib)
2055 einfo (_("%F%P: -F may not be used without -shared\n"));
2056 if (command_line.auxiliary_filters)
2057 einfo (_("%F%P: -f may not be used without -shared\n"));
2060 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
2061 don't see how else this can be handled, since in this case we
2062 must preserve all externally visible symbols. */
2063 if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all)
2065 link_info.strip = strip_debugger;
2066 if (link_info.discard == discard_sec_merge)
2067 link_info.discard = discard_all;
2071 /* Add the (colon-separated) elements of DIRLIST_PTR to the
2072 library search path. */
2074 static void
2075 set_default_dirlist (char *dirlist_ptr)
2077 char *p;
2079 while (1)
2081 p = strchr (dirlist_ptr, PATH_SEPARATOR);
2082 if (p != NULL)
2083 *p = '\0';
2084 if (*dirlist_ptr != '\0')
2085 ldfile_add_library_path (dirlist_ptr, true);
2086 if (p == NULL)
2087 break;
2088 dirlist_ptr = p + 1;
2092 static void
2093 set_section_start (char *sect, char *valstr)
2095 const char *end;
2096 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
2097 if (*end)
2098 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
2099 lang_section_start (sect, exp_intop (val), NULL);
2102 static void
2103 set_segment_start (const char *section, char *valstr)
2105 const char *name;
2106 const char *end;
2107 segment_type *seg;
2109 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
2110 if (*end)
2111 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
2112 /* If we already have an entry for this segment, update the existing
2113 value. */
2114 name = section + 1;
2115 for (seg = segments; seg; seg = seg->next)
2116 if (strcmp (seg->name, name) == 0)
2118 seg->value = val;
2119 lang_section_start (section, exp_intop (val), seg);
2120 return;
2122 /* There was no existing value so we must create a new segment
2123 entry. */
2124 seg = stat_alloc (sizeof (*seg));
2125 seg->name = name;
2126 seg->value = val;
2127 seg->used = false;
2128 /* Add it to the linked list of segments. */
2129 seg->next = segments;
2130 segments = seg;
2131 /* Historically, -Ttext and friends set the base address of a
2132 particular section. For backwards compatibility, we still do
2133 that. If a SEGMENT_START directive is seen, the section address
2134 assignment will be disabled. */
2135 lang_section_start (section, exp_intop (val), seg);
2138 static void
2139 elf_shlib_list_options (FILE *file)
2141 fprintf (file, _("\
2142 --audit=AUDITLIB Specify a library to use for auditing\n"));
2143 fprintf (file, _("\
2144 -Bgroup Selects group name lookup rules for DSO\n"));
2145 fprintf (file, _("\
2146 --disable-new-dtags Disable new dynamic tags\n"));
2147 fprintf (file, _("\
2148 --enable-new-dtags Enable new dynamic tags\n"));
2149 fprintf (file, _("\
2150 --eh-frame-hdr Create .eh_frame_hdr section\n"));
2151 fprintf (file, _("\
2152 --no-eh-frame-hdr Do not create .eh_frame_hdr section\n"));
2153 fprintf (file, _("\
2154 --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
2155 fprintf (file, _("\
2156 --hash-style=STYLE Set hash style to sysv/gnu/both. Default: "));
2157 if (DEFAULT_EMIT_SYSV_HASH)
2159 /* Note - these strings are not translated as
2160 they are keywords not descriptive text. */
2161 if (DEFAULT_EMIT_GNU_HASH)
2162 fprintf (file, "both\n");
2163 else
2164 fprintf (file, "sysv\n");
2166 else
2168 if (DEFAULT_EMIT_GNU_HASH)
2169 fprintf (file, "gnu\n");
2170 else
2171 /* FIXME: Can this happen ? */
2172 fprintf (file, "none\n");
2174 fprintf (file, _("\
2175 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
2176 Specify a library to use for auditing dependencies\n"));
2177 fprintf (file, _("\
2178 -z combreloc Merge dynamic relocs into one section and sort\n"));
2179 fprintf (file, _("\
2180 -z nocombreloc Don't merge dynamic relocs into one section\n"));
2181 fprintf (file, _("\
2182 -z global Make symbols in DSO available for subsequently\n\
2183 loaded objects\n"));
2184 fprintf (file, _("\
2185 -z initfirst Mark DSO to be initialized first at runtime\n"));
2186 fprintf (file, _("\
2187 -z interpose Mark object to interpose all DSOs but executable\n"));
2188 fprintf (file, _("\
2189 -z unique Mark DSO to be loaded at most once by default, and only in the main namespace\n"));
2190 fprintf (file, _("\
2191 -z nounique Don't mark DSO as a loadable at most once\n"));
2192 fprintf (file, _("\
2193 -z lazy Mark object lazy runtime binding (default)\n"));
2194 fprintf (file, _("\
2195 -z loadfltr Mark object requiring immediate process\n"));
2196 fprintf (file, _("\
2197 -z nocopyreloc Don't create copy relocs\n"));
2198 fprintf (file, _("\
2199 -z nodefaultlib Mark object not to use default search paths\n"));
2200 fprintf (file, _("\
2201 -z nodelete Mark DSO non-deletable at runtime\n"));
2202 fprintf (file, _("\
2203 -z nodlopen Mark DSO not available to dlopen\n"));
2204 fprintf (file, _("\
2205 -z nodump Mark DSO not available to dldump\n"));
2206 fprintf (file, _("\
2207 -z now Mark object non-lazy runtime binding\n"));
2208 fprintf (file, _("\
2209 -z origin Mark object requiring immediate $ORIGIN\n\
2210 processing at runtime\n"));
2211 #if DEFAULT_LD_Z_RELRO
2212 fprintf (file, _("\
2213 -z relro Create RELRO program header (default)\n"));
2214 fprintf (file, _("\
2215 -z norelro Don't create RELRO program header\n"));
2216 #else
2217 fprintf (file, _("\
2218 -z relro Create RELRO program header\n"));
2219 fprintf (file, _("\
2220 -z norelro Don't create RELRO program header (default)\n"));
2221 #endif
2222 #if DEFAULT_LD_Z_SEPARATE_CODE
2223 fprintf (file, _("\
2224 -z separate-code Create separate code program header (default)\n"));
2225 fprintf (file, _("\
2226 -z noseparate-code Don't create separate code program header\n"));
2227 #else
2228 fprintf (file, _("\
2229 -z separate-code Create separate code program header\n"));
2230 fprintf (file, _("\
2231 -z noseparate-code Don't create separate code program header (default)\n"));
2232 #endif
2233 #if DEFAULT_LD_ROSEGMENT
2234 fprintf (file, _("\
2235 --rosegment With -z separate-code, create a single read-only segment (default)\n"));
2236 fprintf (file, _("\
2237 --no-rosegment With -z separate-code, creste two read-only segments\n"));
2238 #else
2239 fprintf (file, _("\
2240 --rosegment With -z separate-code, create a single read-only segment\n"));
2241 fprintf (file, _("\
2242 --no-rosegment With -z separate-code, creste two read-only segments (default)\n"));
2243 #endif
2244 fprintf (file, _("\
2245 -z common Generate common symbols with STT_COMMON type\n"));
2246 fprintf (file, _("\
2247 -z nocommon Generate common symbols with STT_OBJECT type\n"));
2248 if (link_info.textrel_check == textrel_check_error)
2249 fprintf (file, _("\
2250 -z text Treat DT_TEXTREL in output as error (default)\n"));
2251 else
2252 fprintf (file, _("\
2253 -z text Treat DT_TEXTREL in output as error\n"));
2254 if (link_info.textrel_check == textrel_check_none)
2256 fprintf (file, _("\
2257 -z notext Don't treat DT_TEXTREL in output as error (default)\n"));
2258 fprintf (file, _("\
2259 -z textoff Don't treat DT_TEXTREL in output as error (default)\n"));
2261 else
2263 fprintf (file, _("\
2264 -z notext Don't treat DT_TEXTREL in output as error\n"));
2265 fprintf (file, _("\
2266 -z textoff Don't treat DT_TEXTREL in output as error\n"));
2270 static void
2271 elf_static_list_options (FILE *file)
2273 fprintf (file, _("\
2274 --build-id[=STYLE] Generate build ID note\n"));
2275 /* DEFAULT_BUILD_ID_STYLE n/a here */
2276 #ifdef WITH_XXHASH
2277 fprintf (file, _("\
2278 Styles: none,md5,sha1,xx,uuid,0xHEX\n"));
2279 /* NB: testsuite/ld-elf/build-id.exp depends on this syntax */
2280 #else
2281 fprintf (file, _("\
2282 Styles: none,md5,sha1,uuid,0xHEX\n"));
2283 #endif
2284 fprintf (file, _("\
2285 --package-metadata[=JSON] Generate package metadata note\n"));
2286 fprintf (file, _("\
2287 --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi|zstd]\n\
2288 Compress DWARF debug sections\n"));
2289 fprintf (file, _("\
2290 Default: %s\n"),
2291 bfd_get_compression_algorithm_name (config.compress_debug));
2292 fprintf (file, _("\
2293 -z common-page-size=SIZE Set common page size to SIZE\n"));
2294 fprintf (file, _("\
2295 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
2296 fprintf (file, _("\
2297 -z defs Report unresolved symbols in object files\n"));
2298 fprintf (file, _("\
2299 -z undefs Ignore unresolved symbols in object files\n"));
2300 fprintf (file, _("\
2301 -z muldefs Allow multiple definitions\n"));
2302 fprintf (file, _("\
2303 -z stack-size=SIZE Set size of stack segment\n"));
2305 fprintf (file, _("\
2306 -z execstack Mark executable as requiring executable stack\n"));
2307 fprintf (file, _("\
2308 -z noexecstack Mark executable as not requiring executable stack\n"));
2309 fprintf (file, _("\
2310 --warn-execstack-objects Generate a warning if an object file requests an executable stack\n"));
2311 #if DEFAULT_LD_WARN_EXECSTACK == 0
2312 fprintf (file, _("\
2313 --warn-execstack Generate a warning if creating an executable stack\n"));
2314 #else
2315 fprintf (file, _("\
2316 --warn-execstack Generate a warning if creating an executable stack (default)\n"));
2317 #endif
2318 #if DEFAULT_LD_WARN_EXECSTACK == 0
2319 fprintf (file, _("\
2320 --no-warn-execstack Do not generate a warning if creating an executable stack (default)\n"));
2321 #else
2322 fprintf (file, _("\
2323 --no-warn-execstack Do not generate a warning if creating an executable stack\n"));
2324 #endif
2325 fprintf (file, _("\
2326 --error-execstack Turn warnings about executable stacks into errors\n"));
2327 fprintf (file, _("\
2328 --no-error-execstack Do not turn warnings about executable stacks into errors\n"));
2330 #if DEFAULT_LD_WARN_RWX_SEGMENTS
2331 fprintf (file, _("\
2332 --warn-rwx-segments Generate a warning if a LOAD segment has RWX permissions (default)\n"));
2333 fprintf (file, _("\
2334 --no-warn-rwx-segments Do not generate a warning if a LOAD segments has RWX permissions\n"));
2335 #else
2336 fprintf (file, _("\
2337 --warn-rwx-segments Generate a warning if a LOAD segment has RWX permissions\n"));
2338 fprintf (file, _("\
2339 --no-warn-rwx-segments Do not generate a warning if a LOAD segments has RWX permissions (default)\n"));
2340 #endif
2341 fprintf (file, _("\
2342 --error-rwx-segments Turn warnings about loadable RWX segments into errors\n"));
2343 fprintf (file, _("\
2344 --no-error-rwx-segments Do not turn warnings about loadable RWX segments into errors\n"));
2346 fprintf (file, _("\
2347 -z unique-symbol Avoid duplicated local symbol names\n"));
2348 fprintf (file, _("\
2349 -z nounique-symbol Keep duplicated local symbol names (default)\n"));
2350 fprintf (file, _("\
2351 -z globalaudit Mark executable requiring global auditing\n"));
2352 fprintf (file, _("\
2353 -z start-stop-gc Enable garbage collection on __start/__stop\n"));
2354 fprintf (file, _("\
2355 -z nostart-stop-gc Don't garbage collect __start/__stop (default)\n"));
2356 fprintf (file, _("\
2357 -z start-stop-visibility=V Set visibility of built-in __start/__stop symbols\n\
2358 to DEFAULT, PROTECTED, HIDDEN or INTERNAL\n"));
2359 fprintf (file, _("\
2360 -z sectionheader Generate section header (default)\n"));
2361 fprintf (file, _("\
2362 -z nosectionheader Do not generate section header\n"));
2365 static void
2366 elf_plt_unwind_list_options (FILE *file)
2368 fprintf (file, _("\
2369 --ld-generated-unwind-info Generate exception handling info for PLT\n"));
2370 fprintf (file, _("\
2371 --no-ld-generated-unwind-info\n\
2372 Don't generate exception handling info for PLT\n"));
2375 static void
2376 ld_list_options (FILE *file, bool elf, bool shlib, bool plt_unwind)
2378 if (!elf)
2379 return;
2380 printf (_("ELF emulations:\n"));
2381 if (plt_unwind)
2382 elf_plt_unwind_list_options (file);
2383 elf_static_list_options (file);
2384 if (shlib)
2385 elf_shlib_list_options (file);
2389 /* Print help messages for the options. */
2391 static void
2392 help (void)
2394 unsigned i;
2395 const char **targets, **pp;
2396 int len;
2398 printf (_("Usage: %s [options] file...\n"), program_name);
2400 printf (_("Options:\n"));
2401 for (i = 0; i < OPTION_COUNT; i++)
2403 if (ld_options[i].doc != NULL)
2405 bool comma;
2406 unsigned j;
2408 printf (" ");
2410 comma = false;
2411 len = 2;
2413 j = i;
2416 if (ld_options[j].shortopt != '\0'
2417 && ld_options[j].control != NO_HELP)
2419 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
2420 len += (comma ? 2 : 0) + 2;
2421 if (ld_options[j].arg != NULL)
2423 if (ld_options[j].opt.has_arg != optional_argument)
2425 printf (" ");
2426 ++len;
2428 printf ("%s", _(ld_options[j].arg));
2429 len += strlen (_(ld_options[j].arg));
2431 comma = true;
2433 ++j;
2435 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
2437 j = i;
2440 if (ld_options[j].opt.name != NULL
2441 && ld_options[j].control != NO_HELP)
2443 int two_dashes =
2444 (ld_options[j].control == TWO_DASHES
2445 || ld_options[j].control == EXACTLY_TWO_DASHES);
2447 printf ("%s-%s%s",
2448 comma ? ", " : "",
2449 two_dashes ? "-" : "",
2450 ld_options[j].opt.name);
2451 len += ((comma ? 2 : 0)
2453 + (two_dashes ? 1 : 0)
2454 + strlen (ld_options[j].opt.name));
2455 if (ld_options[j].arg != NULL)
2457 printf (" %s", _(ld_options[j].arg));
2458 len += 1 + strlen (_(ld_options[j].arg));
2460 comma = true;
2462 ++j;
2464 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
2466 if (len >= 30)
2468 printf ("\n");
2469 len = 0;
2472 for (; len < 30; len++)
2473 putchar (' ');
2475 printf ("%s\n", _(ld_options[i].doc));
2478 printf (_(" @FILE"));
2479 for (len = strlen (" @FILE"); len < 30; len++)
2480 putchar (' ');
2481 printf (_("Read options from FILE\n"));
2483 /* Note: Various tools (such as libtool) depend upon the
2484 format of the listings below - do not change them. */
2485 /* xgettext:c-format */
2486 printf (_("%s: supported targets:"), program_name);
2487 targets = bfd_target_list ();
2488 for (pp = targets; *pp != NULL; pp++)
2489 printf (" %s", *pp);
2490 free (targets);
2491 printf ("\n");
2493 /* xgettext:c-format */
2494 printf (_("%s: supported emulations: "), program_name);
2495 ldemul_list_emulations (stdout);
2496 printf ("\n");
2498 /* xgettext:c-format */
2499 printf (_("%s: emulation specific options:\n"), program_name);
2500 ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
2501 ELF_PLT_UNWIND_LIST_OPTIONS);
2502 ldemul_list_emulation_options (stdout);
2503 printf ("\n");
2505 if (REPORT_BUGS_TO[0])
2506 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);