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