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