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