Add fuse-ld= for GCC linker option compatibility
[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, 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   { {"unresolved-symbols=<method>", required_argument, NULL,
450      OPTION_UNRESOLVED_SYMBOLS},
451     '\0', NULL, N_("How to handle unresolved symbols.  <method> is:\n"
452                    "                                ignore-all, report-all, ignore-in-object-files,\n"
453                    "                                ignore-in-shared-libs"),
454     TWO_DASHES },
455   { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
456     '\0', N_("[=NUMBER]"),
457     N_("Output lots of information during link"), TWO_DASHES },
458   { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux.  */
459     '\0', NULL, NULL, NO_HELP },
460   { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
461     '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
462   { {"version-exports-section", required_argument, NULL,
463      OPTION_VERSION_EXPORTS_SECTION },
464     '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
465                            "                                SYMBOL as the version."),
466     TWO_DASHES },
467   { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
468     '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
469   { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
470     '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
471   { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
472     '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
473   { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
474     '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
475   { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
476     '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
477   { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
478     '\0', NULL, N_("Warn if global constructors/destructors are seen"),
479     TWO_DASHES },
480   { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
481     '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
482   { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
483     '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
484   { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
485     '\0', NULL, N_("Warn if start of section changes due to alignment"),
486     TWO_DASHES },
487   { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
488     '\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
489     TWO_DASHES },
490   { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
491     '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
492     TWO_DASHES },
493   { {"warn-unresolved-symbols", no_argument, NULL,
494      OPTION_WARN_UNRESOLVED_SYMBOLS},
495     '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
496   { {"error-unresolved-symbols", no_argument, NULL,
497      OPTION_ERROR_UNRESOLVED_SYMBOLS},
498     '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
499   { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
500     '\0', NULL, N_("Include all objects from following archives"),
501     TWO_DASHES },
502   { {"wrap", required_argument, NULL, OPTION_WRAP},
503     '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
504   { {"ignore-unresolved-symbol", required_argument, NULL,
505     OPTION_IGNORE_UNRESOLVED_SYMBOL},
506     '\0', N_("SYMBOL"),
507     N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
508 };
509
510 #define OPTION_COUNT ARRAY_SIZE (ld_options)
511
512 void
513 parse_args (unsigned argc, char **argv)
514 {
515   unsigned i;
516   int is, il, irl;
517   int ingroup = 0;
518   char *default_dirlist = NULL;
519   char *shortopts;
520   struct option *longopts;
521   struct option *really_longopts;
522   int last_optind;
523   enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
524
525   shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
526   longopts = (struct option *)
527       xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
528   really_longopts = (struct option *)
529       malloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
530
531   /* Starting the short option string with '-' is for programs that
532      expect options and other ARGV-elements in any order and that care about
533      the ordering of the two.  We describe each non-option ARGV-element
534      as if it were the argument of an option with character code 1.  */
535   shortopts[0] = '-';
536   is = 1;
537   il = 0;
538   irl = 0;
539   for (i = 0; i < OPTION_COUNT; i++)
540     {
541       if (ld_options[i].shortopt != '\0')
542         {
543           shortopts[is] = ld_options[i].shortopt;
544           ++is;
545           if (ld_options[i].opt.has_arg == required_argument
546               || ld_options[i].opt.has_arg == optional_argument)
547             {
548               shortopts[is] = ':';
549               ++is;
550               if (ld_options[i].opt.has_arg == optional_argument)
551                 {
552                   shortopts[is] = ':';
553                   ++is;
554                 }
555             }
556         }
557       if (ld_options[i].opt.name != NULL)
558         {
559           if (ld_options[i].control == EXACTLY_TWO_DASHES)
560             {
561               really_longopts[irl] = ld_options[i].opt;
562               ++irl;
563             }
564           else
565             {
566               longopts[il] = ld_options[i].opt;
567               ++il;
568             }
569         }
570     }
571   shortopts[is] = '\0';
572   longopts[il].name = NULL;
573   really_longopts[irl].name = NULL;
574
575   ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
576
577   /* The -G option is ambiguous on different platforms.  Sometimes it
578      specifies the largest data size to put into the small data
579      section.  Sometimes it is equivalent to --shared.  Unfortunately,
580      the first form takes an argument, while the second does not.
581
582      We need to permit the --shared form because on some platforms,
583      such as Solaris, gcc -shared will pass -G to the linker.
584
585      To permit either usage, we look through the argument list.  If we
586      find -G not followed by a number, we change it into --shared.
587      This will work for most normal cases.  */
588   for (i = 1; i < argc; i++)
589     if (strcmp (argv[i], "-G") == 0
590         && (i + 1 >= argc
591             || ! ISDIGIT (argv[i + 1][0])))
592       argv[i] = (char *) "--shared";
593
594   /* Because we permit long options to start with a single dash, and
595      we have a --library option, and the -l option is conventionally
596      used with an immediately following argument, we can have bad
597      results if somebody tries to use -l with a library whose name
598      happens to start with "ibrary", as in -li.  We avoid problems by
599      simply turning -l into --library.  This means that users will
600      have to use two dashes in order to use --library, which is OK
601      since that's how it is documented.
602
603      FIXME: It's possible that this problem can arise for other short
604      options as well, although the user does always have the recourse
605      of adding a space between the option and the argument.  */
606   for (i = 1; i < argc; i++)
607     {
608       if (argv[i][0] == '-'
609           && argv[i][1] == 'l'
610           && argv[i][2] != '\0')
611         {
612           char *n;
613
614           n = (char *) xmalloc (strlen (argv[i]) + 20);
615           sprintf (n, "--library=%s", argv[i] + 2);
616           argv[i] = n;
617         }
618     }
619
620   last_optind = -1;
621   while (1)
622     {
623       int longind;
624       int optc;
625       static unsigned int defsym_count;
626
627       /* Using last_optind lets us avoid calling ldemul_parse_args
628          multiple times on a single option, which would lead to
629          confusion in the internal static variables maintained by
630          getopt.  This could otherwise happen for an argument like
631          -nx, in which the -n is parsed as a single option, and we
632          loop around to pick up the -x.  */
633       if (optind != last_optind)
634         if (ldemul_parse_args (argc, argv))
635           continue;
636
637       /* getopt_long_only is like getopt_long, but '-' as well as '--'
638          can indicate a long option.  */
639       opterr = 0;
640       last_optind = optind;
641       optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
642       if (optc == '?')
643         {
644           optind = last_optind;
645           optc = getopt_long (argc, argv, "-", really_longopts, &longind);
646         }
647
648       if (ldemul_handle_option (optc))
649         continue;
650
651       if (optc == -1)
652         break;
653
654       switch (optc)
655         {
656         case '?':
657           einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
658           /* Fall through.  */
659
660         default:
661           einfo (_("%P%F: use the --help option for usage information\n"));
662
663         case 1:                 /* File name.  */
664           lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
665           break;
666
667         case OPTION_IGNORE:
668           break;
669         case 'a':
670           /* For HP/UX compatibility.  Actually -a shared should mean
671              ``use only shared libraries'' but, then, we don't
672              currently support shared libraries on HP/UX anyhow.  */
673           if (strcmp (optarg, "archive") == 0)
674             input_flags.dynamic = FALSE;
675           else if (strcmp (optarg, "shared") == 0
676                    || strcmp (optarg, "default") == 0)
677             input_flags.dynamic = TRUE;
678           else
679             einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
680           break;
681         case OPTION_ASSERT:
682           /* FIXME: We just ignore these, but we should handle them.  */
683           if (strcmp (optarg, "definitions") == 0)
684             ;
685           else if (strcmp (optarg, "nodefinitions") == 0)
686             ;
687           else if (strcmp (optarg, "nosymbolic") == 0)
688             ;
689           else if (strcmp (optarg, "pure-text") == 0)
690             ;
691           else
692             einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
693           break;
694         case 'A':
695           ldfile_add_arch (optarg);
696           break;
697         case 'b':
698           lang_add_target (optarg);
699           break;
700         case 'c':
701           ldfile_open_command_file (optarg);
702           parser_input = input_mri_script;
703           yyparse ();
704           break;
705         case OPTION_CALL_SHARED:
706           input_flags.dynamic = TRUE;
707           break;
708         case OPTION_NON_SHARED:
709           input_flags.dynamic = FALSE;
710           break;
711         case OPTION_CREF:
712           command_line.cref = TRUE;
713           link_info.notice_all = TRUE;
714           break;
715         case 'd':
716           command_line.force_common_definition = TRUE;
717           break;
718         case OPTION_DEFSYM:
719           lex_string = optarg;
720           lex_redirect (optarg, "--defsym", ++defsym_count);
721           parser_input = input_defsym;
722           yyparse ();
723           lex_string = NULL;
724           break;
725         case OPTION_DEMANGLE:
726           demangling = TRUE;
727           if (optarg != NULL)
728             {
729               enum demangling_styles style;
730
731               style = cplus_demangle_name_to_style (optarg);
732               if (style == unknown_demangling)
733                 einfo (_("%F%P: unknown demangling style `%s'\n"),
734                        optarg);
735
736               cplus_demangle_set_style (style);
737             }
738           break;
739         case 'I':               /* Used on Solaris.  */
740         case OPTION_DYNAMIC_LINKER:
741           command_line.interpreter = optarg;
742           break;
743         case OPTION_SYSROOT:
744           /* Already handled in ldmain.c.  */
745           break;
746         case OPTION_EB:
747           command_line.endian = ENDIAN_BIG;
748           break;
749         case OPTION_EL:
750           command_line.endian = ENDIAN_LITTLE;
751           break;
752         case OPTION_EMBEDDED_RELOCS:
753           command_line.embedded_relocs = TRUE;
754           break;
755         case OPTION_EXPORT_DYNAMIC:
756         case 'E': /* HP/UX compatibility.  */
757           link_info.export_dynamic = TRUE;
758           break;
759         case OPTION_NO_EXPORT_DYNAMIC:
760           link_info.export_dynamic = FALSE;
761           break;
762         case 'e':
763           lang_add_entry (optarg, TRUE);
764           break;
765         case 'f':
766           if (command_line.auxiliary_filters == NULL)
767             {
768               command_line.auxiliary_filters = (char **)
769                   xmalloc (2 * sizeof (char *));
770               command_line.auxiliary_filters[0] = optarg;
771               command_line.auxiliary_filters[1] = NULL;
772             }
773           else
774             {
775               int c;
776               char **p;
777
778               c = 0;
779               for (p = command_line.auxiliary_filters; *p != NULL; p++)
780                 ++c;
781               command_line.auxiliary_filters = (char **)
782                   xrealloc (command_line.auxiliary_filters,
783                             (c + 2) * sizeof (char *));
784               command_line.auxiliary_filters[c] = optarg;
785               command_line.auxiliary_filters[c + 1] = NULL;
786             }
787           break;
788         case 'F':
789           command_line.filter_shlib = optarg;
790           break;
791         case OPTION_FORCE_EXE_SUFFIX:
792           command_line.force_exe_suffix = TRUE;
793           break;
794         case 'G':
795           {
796             char *end;
797             g_switch_value = strtoul (optarg, &end, 0);
798             if (*end)
799               einfo (_("%P%F: invalid number `%s'\n"), optarg);
800           }
801           break;
802         case 'g':
803           /* Ignore.  */
804           break;
805         case OPTION_GC_SECTIONS:
806           link_info.gc_sections = TRUE;
807           break;
808         case OPTION_PRINT_GC_SECTIONS:
809           link_info.print_gc_sections = TRUE;
810           break;
811         case OPTION_HELP:
812           help ();
813           xexit (0);
814           break;
815         case 'L':
816           ldfile_add_library_path (optarg, TRUE);
817           break;
818         case 'l':
819           lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
820           break;
821         case 'M':
822           config.map_filename = "-";
823           break;
824         case 'm':
825           /* Ignore.  Was handled in a pre-parse.   */
826           break;
827         case OPTION_MAP:
828           config.map_filename = optarg;
829           break;
830         case 'N':
831           config.text_read_only = FALSE;
832           config.magic_demand_paged = FALSE;
833           input_flags.dynamic = FALSE;
834           break;
835         case OPTION_NO_OMAGIC:
836           config.text_read_only = TRUE;
837           config.magic_demand_paged = TRUE;
838           /* NB/ Does not set input_flags.dynamic to TRUE.
839              Use --call-shared or -Bdynamic for this.  */
840           break;
841         case 'n':
842           config.magic_demand_paged = FALSE;
843           input_flags.dynamic = FALSE;
844           break;
845         case OPTION_NO_DEFINE_COMMON:
846           command_line.inhibit_common_definition = TRUE;
847           break;
848         case OPTION_NO_DEMANGLE:
849           demangling = FALSE;
850           break;
851         case OPTION_NO_GC_SECTIONS:
852           link_info.gc_sections = FALSE;
853           break;
854         case OPTION_NO_PRINT_GC_SECTIONS:
855           link_info.print_gc_sections = FALSE;
856           break;
857         case OPTION_NO_KEEP_MEMORY:
858           link_info.keep_memory = FALSE;
859           break;
860         case OPTION_NO_UNDEFINED:
861           link_info.unresolved_syms_in_objects
862             = how_to_report_unresolved_symbols;
863           break;
864         case OPTION_ALLOW_SHLIB_UNDEFINED:
865           link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
866           break;
867         case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
868           link_info.unresolved_syms_in_shared_libs
869             = how_to_report_unresolved_symbols;
870           break;
871         case OPTION_UNRESOLVED_SYMBOLS:
872           if (strcmp (optarg, "ignore-all") == 0)
873             {
874               link_info.unresolved_syms_in_objects = RM_IGNORE;
875               link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
876             }
877           else if (strcmp (optarg, "report-all") == 0)
878             {
879               link_info.unresolved_syms_in_objects
880                 = how_to_report_unresolved_symbols;
881               link_info.unresolved_syms_in_shared_libs
882                 = how_to_report_unresolved_symbols;
883             }
884           else if (strcmp (optarg, "ignore-in-object-files") == 0)
885             {
886               link_info.unresolved_syms_in_objects = RM_IGNORE;
887               link_info.unresolved_syms_in_shared_libs
888                 = how_to_report_unresolved_symbols;
889             }
890           else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
891             {
892               link_info.unresolved_syms_in_objects
893                 = how_to_report_unresolved_symbols;
894               link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
895             }
896           else
897             einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg);
898           break;
899         case OPTION_WARN_UNRESOLVED_SYMBOLS:
900           how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
901           if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
902             link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
903           if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
904             link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
905           break;
906
907         case OPTION_ERROR_UNRESOLVED_SYMBOLS:
908           how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
909           if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
910             link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
911           if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
912             link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
913           break;
914         case OPTION_ALLOW_MULTIPLE_DEFINITION:
915           link_info.allow_multiple_definition = TRUE;
916           break;
917         case OPTION_NO_UNDEFINED_VERSION:
918           link_info.allow_undefined_version = FALSE;
919           break;
920         case OPTION_DEFAULT_SYMVER:
921           link_info.create_default_symver = TRUE;
922           break;
923         case OPTION_DEFAULT_IMPORTED_SYMVER:
924           link_info.default_imported_symver = TRUE;
925           break;
926         case OPTION_NO_WARN_MISMATCH:
927           command_line.warn_mismatch = FALSE;
928           break;
929         case OPTION_NO_WARN_SEARCH_MISMATCH:
930           command_line.warn_search_mismatch = FALSE;
931           break;
932         case OPTION_NOINHIBIT_EXEC:
933           force_make_executable = TRUE;
934           break;
935         case OPTION_NOSTDLIB:
936           config.only_cmd_line_lib_dirs = TRUE;
937           break;
938         case OPTION_NO_WHOLE_ARCHIVE:
939           input_flags.whole_archive = FALSE;
940           break;
941         case 'O':
942           /* FIXME "-O<non-digits> <value>" used to set the address of
943              section <non-digits>.  Was this for compatibility with
944              something, or can we create a new option to do that
945              (with a syntax similar to -defsym)?
946              getopt can't handle two args to an option without kludges.  */
947
948           /* Enable optimizations of output files.  */
949           link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
950           break;
951         case 'o':
952           lang_add_output (optarg, 0);
953           break;
954         case OPTION_OFORMAT:
955           lang_add_output_format (optarg, NULL, NULL, 0);
956           break;
957         case OPTION_PRINT_OUTPUT_FORMAT:
958           command_line.print_output_format = TRUE;
959           break;
960 #ifdef ENABLE_PLUGINS
961         case OPTION_PLUGIN:
962           plugin_opt_plugin (optarg);
963           break;
964         case OPTION_PLUGIN_OPT:
965           if (plugin_opt_plugin_arg (optarg))
966             einfo(_("%P%F: bad -plugin-opt option\n"));
967           break;
968 #endif /* ENABLE_PLUGINS */
969         case 'q':
970           link_info.emitrelocations = TRUE;
971           break;
972         case 'i':
973         case 'r':
974           if (optind == last_optind)
975             /* This can happen if the user put "-rpath,a" on the command
976                line.  (Or something similar.  The comma is important).
977                Getopt becomes confused and thinks that this is a -r option
978                but it cannot parse the text after the -r so it refuses to
979                increment the optind counter.  Detect this case and issue
980                an error message here.  We cannot just make this a warning,
981                increment optind, and continue because getopt is too confused
982                and will seg-fault the next time around.  */
983             einfo(_("%P%F: bad -rpath option\n"));
984
985           link_info.relocatable = TRUE;
986           config.build_constructors = FALSE;
987           config.magic_demand_paged = FALSE;
988           config.text_read_only = FALSE;
989           input_flags.dynamic = FALSE;
990           break;
991         case 'R':
992           /* The GNU linker traditionally uses -R to mean to include
993              only the symbols from a file.  The Solaris linker uses -R
994              to set the path used by the runtime linker to find
995              libraries.  This is the GNU linker -rpath argument.  We
996              try to support both simultaneously by checking the file
997              named.  If it is a directory, rather than a regular file,
998              we assume -rpath was meant.  */
999           {
1000             struct stat s;
1001
1002             if (stat (optarg, &s) >= 0
1003                 && ! S_ISDIR (s.st_mode))
1004               {
1005                 lang_add_input_file (optarg,
1006                                      lang_input_file_is_symbols_only_enum,
1007                                      NULL);
1008                 break;
1009               }
1010           }
1011           /* Fall through.  */
1012         case OPTION_RPATH:
1013           if (command_line.rpath == NULL)
1014             command_line.rpath = xstrdup (optarg);
1015           else
1016             {
1017               size_t rpath_len = strlen (command_line.rpath);
1018               size_t optarg_len = strlen (optarg);
1019               char *buf;
1020               char *cp = command_line.rpath;
1021
1022               /* First see whether OPTARG is already in the path.  */
1023               do
1024                 {
1025                   if (strncmp (optarg, cp, optarg_len) == 0
1026                       && (cp[optarg_len] == 0
1027                           || cp[optarg_len] == config.rpath_separator))
1028                     /* We found it.  */
1029                     break;
1030
1031                   /* Not yet found.  */
1032                   cp = strchr (cp, config.rpath_separator);
1033                   if (cp != NULL)
1034                     ++cp;
1035                 }
1036               while (cp != NULL);
1037
1038               if (cp == NULL)
1039                 {
1040                   buf = (char *) xmalloc (rpath_len + optarg_len + 2);
1041                   sprintf (buf, "%s%c%s", command_line.rpath,
1042                            config.rpath_separator, optarg);
1043                   free (command_line.rpath);
1044                   command_line.rpath = buf;
1045                 }
1046             }
1047           break;
1048         case OPTION_RPATH_LINK:
1049           if (command_line.rpath_link == NULL)
1050             command_line.rpath_link = xstrdup (optarg);
1051           else
1052             {
1053               char *buf;
1054
1055               buf = (char *) xmalloc (strlen (command_line.rpath_link)
1056                                       + strlen (optarg)
1057                                       + 2);
1058               sprintf (buf, "%s%c%s", command_line.rpath_link,
1059                        config.rpath_separator, optarg);
1060               free (command_line.rpath_link);
1061               command_line.rpath_link = buf;
1062             }
1063           break;
1064         case OPTION_NO_RELAX:
1065           DISABLE_RELAXATION;
1066           break;
1067         case OPTION_RELAX:
1068           ENABLE_RELAXATION;
1069           break;
1070         case OPTION_RETAIN_SYMBOLS_FILE:
1071           add_keepsyms_file (optarg);
1072           break;
1073         case 'S':
1074           link_info.strip = strip_debugger;
1075           break;
1076         case 's':
1077           link_info.strip = strip_all;
1078           break;
1079         case OPTION_STRIP_DISCARDED:
1080           link_info.strip_discarded = TRUE;
1081           break;
1082         case OPTION_NO_STRIP_DISCARDED:
1083           link_info.strip_discarded = FALSE;
1084           break;
1085         case OPTION_SHARED:
1086           if (config.has_shared)
1087             {
1088               link_info.shared = TRUE;
1089               /* When creating a shared library, the default
1090                  behaviour is to ignore any unresolved references.  */
1091               if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1092                 link_info.unresolved_syms_in_objects = RM_IGNORE;
1093               if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1094                 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1095             }
1096           else
1097             einfo (_("%P%F: -shared not supported\n"));
1098           break;
1099         case OPTION_PIE:
1100           if (config.has_shared)
1101             {
1102               link_info.shared = TRUE;
1103               link_info.pie = TRUE;
1104             }
1105           else
1106             einfo (_("%P%F: -pie not supported\n"));
1107           break;
1108         case 'h':               /* Used on Solaris.  */
1109         case OPTION_SONAME:
1110           command_line.soname = optarg;
1111           break;
1112         case OPTION_SORT_COMMON:
1113           if (optarg == NULL
1114               || strcmp (optarg, N_("descending")) == 0)
1115             config.sort_common = sort_descending;
1116           else if (strcmp (optarg, N_("ascending")) == 0)
1117             config.sort_common = sort_ascending;
1118           else
1119             einfo (_("%P%F: invalid common section sorting option: %s\n"),
1120                    optarg);
1121           break;
1122         case OPTION_SORT_SECTION:
1123           if (strcmp (optarg, N_("name")) == 0)
1124             sort_section = by_name;
1125           else if (strcmp (optarg, N_("alignment")) == 0)
1126             sort_section = by_alignment;
1127           else
1128             einfo (_("%P%F: invalid section sorting option: %s\n"),
1129                    optarg);
1130           break;
1131         case OPTION_STATS:
1132           config.stats = TRUE;
1133           break;
1134         case OPTION_SYMBOLIC:
1135           command_line.symbolic = symbolic;
1136           break;
1137         case OPTION_SYMBOLIC_FUNCTIONS:
1138           command_line.symbolic = symbolic_functions;
1139           break;
1140         case 't':
1141           trace_files = TRUE;
1142           break;
1143         case 'T':
1144           previous_script_handle = saved_script_handle;
1145           ldfile_open_command_file (optarg);
1146           parser_input = input_script;
1147           yyparse ();
1148           previous_script_handle = NULL;
1149           break;
1150         case OPTION_DEFAULT_SCRIPT:
1151           command_line.default_script = optarg;
1152           break;
1153         case OPTION_SECTION_START:
1154           {
1155             char *optarg2;
1156             char *sec_name;
1157             int len;
1158
1159             /* Check for <something>=<somthing>...  */
1160             optarg2 = strchr (optarg, '=');
1161             if (optarg2 == NULL)
1162               einfo (_("%P%F: invalid argument to option"
1163                        " \"--section-start\"\n"));
1164
1165             optarg2++;
1166
1167             /* So far so good.  Are all the args present?  */
1168             if ((*optarg == '\0') || (*optarg2 == '\0'))
1169               einfo (_("%P%F: missing argument(s) to option"
1170                        " \"--section-start\"\n"));
1171
1172             /* We must copy the section name as set_section_start
1173                doesn't do it for us.  */
1174             len = optarg2 - optarg;
1175             sec_name = (char *) xmalloc (len);
1176             memcpy (sec_name, optarg, len - 1);
1177             sec_name[len - 1] = 0;
1178
1179             /* Then set it...  */
1180             set_section_start (sec_name, optarg2);
1181           }
1182           break;
1183         case OPTION_TARGET_HELP:
1184           /* Mention any target specific options.  */
1185           ldemul_list_emulation_options (stdout);
1186           exit (0);
1187         case OPTION_TBSS:
1188           set_segment_start (".bss", optarg);
1189           break;
1190         case OPTION_TDATA:
1191           set_segment_start (".data", optarg);
1192           break;
1193         case OPTION_TTEXT:
1194           set_segment_start (".text", optarg);
1195           break;
1196         case OPTION_TTEXT_SEGMENT:
1197           set_segment_start (".text-segment", optarg);
1198           break;
1199         case OPTION_TRODATA_SEGMENT:
1200           set_segment_start (".rodata-segment", optarg);
1201           break;
1202         case OPTION_TRADITIONAL_FORMAT:
1203           link_info.traditional_format = TRUE;
1204           break;
1205         case OPTION_TASK_LINK:
1206           link_info.task_link = TRUE;
1207           /* Fall through - do an implied -r option.  */
1208         case OPTION_UR:
1209           link_info.relocatable = TRUE;
1210           config.build_constructors = TRUE;
1211           config.magic_demand_paged = FALSE;
1212           config.text_read_only = FALSE;
1213           input_flags.dynamic = FALSE;
1214           break;
1215         case 'u':
1216           ldlang_add_undef (optarg, TRUE);
1217           break;
1218         case OPTION_UNIQUE:
1219           if (optarg != NULL)
1220             lang_add_unique (optarg);
1221           else
1222             config.unique_orphan_sections = TRUE;
1223           break;
1224         case OPTION_VERBOSE:
1225           ldversion (1);
1226           version_printed = TRUE;
1227           verbose = TRUE;
1228           overflow_cutoff_limit = -2;
1229           if (optarg != NULL)
1230             {
1231               char *end;
1232               int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
1233               if (*end)
1234                 einfo (_("%P%F: invalid number `%s'\n"), optarg);
1235 #ifdef ENABLE_PLUGINS
1236               report_plugin_symbols = level > 1;
1237 #endif /* ENABLE_PLUGINS */
1238             }
1239           break;
1240         case 'v':
1241           ldversion (0);
1242           version_printed = TRUE;
1243           break;
1244         case 'V':
1245           ldversion (1);
1246           version_printed = TRUE;
1247           break;
1248         case OPTION_VERSION:
1249           ldversion (2);
1250           xexit (0);
1251           break;
1252         case OPTION_VERSION_SCRIPT:
1253           /* This option indicates a small script that only specifies
1254              version information.  Read it, but don't assume that
1255              we've seen a linker script.  */
1256           {
1257             FILE *hold_script_handle;
1258
1259             hold_script_handle = saved_script_handle;
1260             ldfile_open_command_file (optarg);
1261             saved_script_handle = hold_script_handle;
1262             parser_input = input_version_script;
1263             yyparse ();
1264           }
1265           break;
1266         case OPTION_VERSION_EXPORTS_SECTION:
1267           /* This option records a version symbol to be applied to the
1268              symbols listed for export to be found in the object files
1269              .exports sections.  */
1270           command_line.version_exports_section = optarg;
1271           break;
1272         case OPTION_DYNAMIC_LIST_DATA:
1273           command_line.dynamic_list = dynamic_list_data;
1274           if (command_line.symbolic == symbolic)
1275             command_line.symbolic = symbolic_unset;
1276           break;
1277         case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1278           lang_append_dynamic_list_cpp_typeinfo ();
1279           if (command_line.dynamic_list != dynamic_list_data)
1280             command_line.dynamic_list = dynamic_list;
1281           if (command_line.symbolic == symbolic)
1282             command_line.symbolic = symbolic_unset;
1283           break;
1284         case OPTION_DYNAMIC_LIST_CPP_NEW:
1285           lang_append_dynamic_list_cpp_new ();
1286           if (command_line.dynamic_list != dynamic_list_data)
1287             command_line.dynamic_list = dynamic_list;
1288           if (command_line.symbolic == symbolic)
1289             command_line.symbolic = symbolic_unset;
1290           break;
1291         case OPTION_DYNAMIC_LIST:
1292           /* This option indicates a small script that only specifies
1293              a dynamic list.  Read it, but don't assume that we've
1294              seen a linker script.  */
1295           {
1296             FILE *hold_script_handle;
1297
1298             hold_script_handle = saved_script_handle;
1299             ldfile_open_command_file (optarg);
1300             saved_script_handle = hold_script_handle;
1301             parser_input = input_dynamic_list;
1302             yyparse ();
1303           }
1304           if (command_line.dynamic_list != dynamic_list_data)
1305             command_line.dynamic_list = dynamic_list;
1306           if (command_line.symbolic == symbolic)
1307             command_line.symbolic = symbolic_unset;
1308           break;
1309         case OPTION_WARN_COMMON:
1310           config.warn_common = TRUE;
1311           break;
1312         case OPTION_WARN_CONSTRUCTORS:
1313           config.warn_constructors = TRUE;
1314           break;
1315         case OPTION_WARN_FATAL:
1316           config.fatal_warnings = TRUE;
1317           break;
1318         case OPTION_NO_WARN_FATAL:
1319           config.fatal_warnings = FALSE;
1320           break;
1321         case OPTION_WARN_MULTIPLE_GP:
1322           config.warn_multiple_gp = TRUE;
1323           break;
1324         case OPTION_WARN_ONCE:
1325           config.warn_once = TRUE;
1326           break;
1327         case OPTION_WARN_SECTION_ALIGN:
1328           config.warn_section_align = TRUE;
1329           break;
1330         case OPTION_WARN_SHARED_TEXTREL:
1331           link_info.warn_shared_textrel = TRUE;
1332           break;
1333         case OPTION_WARN_ALTERNATE_EM:
1334           link_info.warn_alternate_em = TRUE;
1335           break;
1336         case OPTION_WHOLE_ARCHIVE:
1337           input_flags.whole_archive = TRUE;
1338           break;
1339         case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
1340           input_flags.add_DT_NEEDED_for_dynamic = TRUE;
1341           break;
1342         case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
1343           input_flags.add_DT_NEEDED_for_dynamic = FALSE;
1344           break;
1345         case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
1346           input_flags.add_DT_NEEDED_for_regular = TRUE;
1347           break;
1348         case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
1349           input_flags.add_DT_NEEDED_for_regular = FALSE;
1350           break;
1351         case OPTION_WRAP:
1352           add_wrap (optarg);
1353           break;
1354         case OPTION_IGNORE_UNRESOLVED_SYMBOL:
1355           add_ignoresym (&link_info, optarg);
1356           break;
1357         case OPTION_DISCARD_NONE:
1358           link_info.discard = discard_none;
1359           break;
1360         case 'X':
1361           link_info.discard = discard_l;
1362           break;
1363         case 'x':
1364           link_info.discard = discard_all;
1365           break;
1366         case 'Y':
1367           if (CONST_STRNEQ (optarg, "P,"))
1368             optarg += 2;
1369           if (default_dirlist != NULL)
1370             free (default_dirlist);
1371           default_dirlist = xstrdup (optarg);
1372           break;
1373         case 'y':
1374           add_ysym (optarg);
1375           break;
1376         case OPTION_SPARE_DYNAMIC_TAGS:
1377           link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1378           break;
1379         case OPTION_SPLIT_BY_RELOC:
1380           if (optarg != NULL)
1381             config.split_by_reloc = strtoul (optarg, NULL, 0);
1382           else
1383             config.split_by_reloc = 32768;
1384           break;
1385         case OPTION_SPLIT_BY_FILE:
1386           if (optarg != NULL)
1387             config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1388           else
1389             config.split_by_file = 1;
1390           break;
1391         case OPTION_CHECK_SECTIONS:
1392           command_line.check_section_addresses = 1;
1393           break;
1394         case OPTION_NO_CHECK_SECTIONS:
1395           command_line.check_section_addresses = 0;
1396           break;
1397         case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1398           command_line.accept_unknown_input_arch = TRUE;
1399           break;
1400         case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1401           command_line.accept_unknown_input_arch = FALSE;
1402           break;
1403         case '(':
1404           lang_enter_group ();
1405           ingroup++;
1406           break;
1407         case ')':
1408           if (! ingroup)
1409             einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1410
1411           lang_leave_group ();
1412           ingroup--;
1413           break;
1414
1415         case OPTION_INIT:
1416           link_info.init_function = optarg;
1417           break;
1418
1419         case OPTION_FINI:
1420           link_info.fini_function = optarg;
1421           break;
1422
1423         case OPTION_REDUCE_MEMORY_OVERHEADS:
1424           link_info.reduce_memory_overheads = TRUE;
1425           if (config.hash_table_size == 0)
1426             config.hash_table_size = 1021;
1427           break;
1428
1429         case OPTION_HASH_SIZE:
1430           {
1431             bfd_size_type new_size;
1432
1433             new_size = strtoul (optarg, NULL, 0);
1434             if (new_size)
1435               config.hash_table_size = new_size;
1436             else
1437               einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1438           }
1439           break;
1440         }
1441     }
1442
1443   while (ingroup)
1444     {
1445       lang_leave_group ();
1446       ingroup--;
1447     }
1448
1449   if (default_dirlist != NULL)
1450     {
1451       set_default_dirlist (default_dirlist);
1452       free (default_dirlist);
1453     }
1454
1455   if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1456     /* FIXME: Should we allow emulations a chance to set this ?  */
1457     link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
1458
1459   if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1460     /* FIXME: Should we allow emulations a chance to set this ?  */
1461     link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
1462
1463   if (link_info.relocatable)
1464     {
1465       if (command_line.check_section_addresses < 0)
1466         command_line.check_section_addresses = 0;
1467       if (link_info.shared)
1468         einfo (_("%P%F: -r and -shared may not be used together\n"));
1469     }
1470
1471   /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data,
1472      --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and
1473      --dynamic-list FILE.  -Bsymbolic and -Bsymbolic-functions are
1474      for shared libraries.  -Bsymbolic overrides all others and vice
1475      versa.  */
1476   switch (command_line.symbolic)
1477     {
1478     case symbolic_unset:
1479       break;
1480     case symbolic:
1481       /* -Bsymbolic is for shared library only.  */
1482       if (link_info.shared)
1483         {
1484           link_info.symbolic = TRUE;
1485           /* Should we free the unused memory?  */
1486           link_info.dynamic_list = NULL;
1487           command_line.dynamic_list = dynamic_list_unset;
1488         }
1489       break;
1490     case symbolic_functions:
1491       /* -Bsymbolic-functions is for shared library only.  */
1492       if (link_info.shared)
1493         command_line.dynamic_list = dynamic_list_data;
1494       break;
1495     }
1496
1497   switch (command_line.dynamic_list)
1498     {
1499     case dynamic_list_unset:
1500       break;
1501     case dynamic_list_data:
1502       link_info.dynamic_data = TRUE;
1503     case dynamic_list:
1504       link_info.dynamic = TRUE;
1505       break;
1506     }
1507
1508   if (! link_info.shared)
1509     {
1510       if (command_line.filter_shlib)
1511         einfo (_("%P%F: -F may not be used without -shared\n"));
1512       if (command_line.auxiliary_filters)
1513         einfo (_("%P%F: -f may not be used without -shared\n"));
1514     }
1515
1516   if (! link_info.shared || link_info.pie)
1517     link_info.executable = TRUE;
1518
1519   /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols).  I
1520      don't see how else this can be handled, since in this case we
1521      must preserve all externally visible symbols.  */
1522   if (link_info.relocatable && link_info.strip == strip_all)
1523     {
1524       link_info.strip = strip_debugger;
1525       if (link_info.discard == discard_sec_merge)
1526         link_info.discard = discard_all;
1527     }
1528 }
1529
1530 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1531    library search path.  */
1532
1533 static void
1534 set_default_dirlist (char *dirlist_ptr)
1535 {
1536   char *p;
1537
1538   while (1)
1539     {
1540       p = strchr (dirlist_ptr, PATH_SEPARATOR);
1541       if (p != NULL)
1542         *p = '\0';
1543       if (*dirlist_ptr != '\0')
1544         ldfile_add_library_path (dirlist_ptr, TRUE);
1545       if (p == NULL)
1546         break;
1547       dirlist_ptr = p + 1;
1548     }
1549 }
1550
1551 static void
1552 set_section_start (char *sect, char *valstr)
1553 {
1554   const char *end;
1555   bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1556   if (*end)
1557     einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1558   lang_section_start (sect, exp_intop (val), NULL);
1559 }
1560
1561 static void
1562 set_segment_start (const char *section, char *valstr)
1563 {
1564   const char *name;
1565   const char *end;
1566   segment_type *seg;
1567
1568   bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1569   if (*end)
1570     einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1571   /* If we already have an entry for this segment, update the existing
1572      value.  */
1573   name = section + 1;
1574   for (seg = segments; seg; seg = seg->next)
1575     if (strcmp (seg->name, name) == 0)
1576       {
1577         seg->value = val;
1578         return;
1579       }
1580   /* There was no existing value so we must create a new segment
1581      entry.  */
1582   seg = (segment_type *) stat_alloc (sizeof (*seg));
1583   seg->name = name;
1584   seg->value = val;
1585   seg->used = FALSE;
1586   /* Add it to the linked list of segments.  */
1587   seg->next = segments;
1588   segments = seg;
1589   /* Historically, -Ttext and friends set the base address of a
1590      particular section.  For backwards compatibility, we still do
1591      that.  If a SEGMENT_START directive is seen, the section address
1592      assignment will be disabled.  */
1593   lang_section_start (section, exp_intop (val), seg);
1594 }
1595
1596 \f
1597 /* Print help messages for the options.  */
1598
1599 static void
1600 help (void)
1601 {
1602   unsigned i;
1603   const char **targets, **pp;
1604   int len;
1605
1606   printf (_("Usage: %s [options] file...\n"), program_name);
1607
1608   printf (_("Options:\n"));
1609   for (i = 0; i < OPTION_COUNT; i++)
1610     {
1611       if (ld_options[i].doc != NULL)
1612         {
1613           bfd_boolean comma;
1614           unsigned j;
1615
1616           printf ("  ");
1617
1618           comma = FALSE;
1619           len = 2;
1620
1621           j = i;
1622           do
1623             {
1624               if (ld_options[j].shortopt != '\0'
1625                   && ld_options[j].control != NO_HELP)
1626                 {
1627                   printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1628                   len += (comma ? 2 : 0) + 2;
1629                   if (ld_options[j].arg != NULL)
1630                     {
1631                       if (ld_options[j].opt.has_arg != optional_argument)
1632                         {
1633                           printf (" ");
1634                           ++len;
1635                         }
1636                       printf ("%s", _(ld_options[j].arg));
1637                       len += strlen (_(ld_options[j].arg));
1638                     }
1639                   comma = TRUE;
1640                 }
1641               ++j;
1642             }
1643           while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1644
1645           j = i;
1646           do
1647             {
1648               if (ld_options[j].opt.name != NULL
1649                   && ld_options[j].control != NO_HELP)
1650                 {
1651                   int two_dashes =
1652                     (ld_options[j].control == TWO_DASHES
1653                      || ld_options[j].control == EXACTLY_TWO_DASHES);
1654
1655                   printf ("%s-%s%s",
1656                           comma ? ", " : "",
1657                           two_dashes ? "-" : "",
1658                           ld_options[j].opt.name);
1659                   len += ((comma ? 2 : 0)
1660                           + 1
1661                           + (two_dashes ? 1 : 0)
1662                           + strlen (ld_options[j].opt.name));
1663                   if (ld_options[j].arg != NULL)
1664                     {
1665                       printf (" %s", _(ld_options[j].arg));
1666                       len += 1 + strlen (_(ld_options[j].arg));
1667                     }
1668                   comma = TRUE;
1669                 }
1670               ++j;
1671             }
1672           while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1673
1674           if (len >= 30)
1675             {
1676               printf ("\n");
1677               len = 0;
1678             }
1679
1680           for (; len < 30; len++)
1681             putchar (' ');
1682
1683           printf ("%s\n", _(ld_options[i].doc));
1684         }
1685     }
1686   printf (_("  @FILE"));
1687   for (len = strlen ("  @FILE"); len < 30; len++)
1688     putchar (' ');
1689   printf (_("Read options from FILE\n"));
1690
1691   /* Note: Various tools (such as libtool) depend upon the
1692      format of the listings below - do not change them.  */
1693   /* xgettext:c-format */
1694   printf (_("%s: supported targets:"), program_name);
1695   targets = bfd_target_list ();
1696   for (pp = targets; *pp != NULL; pp++)
1697     printf (" %s", *pp);
1698   free (targets);
1699   printf ("\n");
1700
1701   /* xgettext:c-format */
1702   printf (_("%s: supported emulations: "), program_name);
1703   ldemul_list_emulations (stdout);
1704   printf ("\n");
1705
1706   /* xgettext:c-format */
1707   printf (_("%s: emulation specific options:\n"), program_name);
1708   ldemul_list_emulation_options (stdout);
1709   printf ("\n");
1710
1711   if (REPORT_BUGS_TO[0])
1712     printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
1713 }