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