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