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