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