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