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