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