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