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