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