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