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