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