OSDN Git Service

* elf-bfd.h (enum elf_reloc_type_class): New.
[pf3gnuchains/pf3gnuchains3x.git] / ld / lexsup.c
1 /* Parse options for the GNU linker.
2    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3    2001
4    Free Software Foundation, Inc.
5
6 This file is part of GLD, the Gnu Linker.
7
8 GLD 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 2, or (at your option)
11 any later version.
12
13 GLD 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 GLD; see the file COPYING.  If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA.  */
22
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libiberty.h"
26 #include <stdio.h>
27 #include <string.h>
28 #include <ctype.h>
29 #include "getopt.h"
30 #include "bfdlink.h"
31 #include "ld.h"
32 #include "ldmain.h"
33 #include "ldmisc.h"
34 #include "ldexp.h"
35 #include "ldlang.h"
36 #include "ldgram.h"
37 #include "ldlex.h"
38 #include "ldfile.h"
39 #include "ldver.h"
40 #include "ldemul.h"
41 #include "demangle.h"
42
43 #ifndef PATH_SEPARATOR
44 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
45 #define PATH_SEPARATOR ';'
46 #else
47 #define PATH_SEPARATOR ':'
48 #endif
49 #endif
50
51 /* Somewhere above, sys/stat.h got included . . . .  */
52 #if !defined(S_ISDIR) && defined(S_IFDIR)
53 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
54 #endif
55
56 /* Omit args to avoid the possibility of clashing with a system header
57    that might disagree about consts.  */
58 unsigned long strtoul ();
59
60 static int is_num PARAMS ((const char *, int, int, int));
61 static void set_default_dirlist PARAMS ((char *dirlist_ptr));
62 static void set_section_start PARAMS ((char *sect, char *valstr));
63 static void help PARAMS ((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
71 #define OPTION_ASSERT                   150
72 #define OPTION_CALL_SHARED              (OPTION_ASSERT + 1)
73 #define OPTION_CREF                     (OPTION_CALL_SHARED + 1)
74 #define OPTION_DEFSYM                   (OPTION_CREF + 1)
75 #define OPTION_DEMANGLE                 (OPTION_DEFSYM + 1)
76 #define OPTION_DYNAMIC_LINKER           (OPTION_DEMANGLE + 1)
77 #define OPTION_EB                       (OPTION_DYNAMIC_LINKER + 1)
78 #define OPTION_EL                       (OPTION_EB + 1)
79 #define OPTION_EMBEDDED_RELOCS          (OPTION_EL + 1)
80 #define OPTION_EXPORT_DYNAMIC           (OPTION_EMBEDDED_RELOCS + 1)
81 #define OPTION_HELP                     (OPTION_EXPORT_DYNAMIC + 1)
82 #define OPTION_IGNORE                   (OPTION_HELP + 1)
83 #define OPTION_MAP                      (OPTION_IGNORE + 1)
84 #define OPTION_NO_DEMANGLE              (OPTION_MAP + 1)
85 #define OPTION_NO_KEEP_MEMORY           (OPTION_NO_DEMANGLE + 1)
86 #define OPTION_NO_WARN_MISMATCH         (OPTION_NO_KEEP_MEMORY + 1)
87 #define OPTION_NOINHIBIT_EXEC           (OPTION_NO_WARN_MISMATCH + 1)
88 #define OPTION_NON_SHARED               (OPTION_NOINHIBIT_EXEC + 1)
89 #define OPTION_NO_WHOLE_ARCHIVE         (OPTION_NON_SHARED + 1)
90 #define OPTION_OFORMAT                  (OPTION_NO_WHOLE_ARCHIVE + 1)
91 #define OPTION_RELAX                    (OPTION_OFORMAT + 1)
92 #define OPTION_RETAIN_SYMBOLS_FILE      (OPTION_RELAX + 1)
93 #define OPTION_RPATH                    (OPTION_RETAIN_SYMBOLS_FILE + 1)
94 #define OPTION_RPATH_LINK               (OPTION_RPATH + 1)
95 #define OPTION_SHARED                   (OPTION_RPATH_LINK + 1)
96 #define OPTION_SONAME                   (OPTION_SHARED + 1)
97 #define OPTION_SORT_COMMON              (OPTION_SONAME + 1)
98 #define OPTION_STATS                    (OPTION_SORT_COMMON + 1)
99 #define OPTION_SYMBOLIC                 (OPTION_STATS + 1)
100 #define OPTION_TASK_LINK                (OPTION_SYMBOLIC + 1)
101 #define OPTION_TBSS                     (OPTION_TASK_LINK + 1)
102 #define OPTION_TDATA                    (OPTION_TBSS + 1)
103 #define OPTION_TTEXT                    (OPTION_TDATA + 1)
104 #define OPTION_TRADITIONAL_FORMAT       (OPTION_TTEXT + 1)
105 #define OPTION_UR                       (OPTION_TRADITIONAL_FORMAT + 1)
106 #define OPTION_VERBOSE                  (OPTION_UR + 1)
107 #define OPTION_VERSION                  (OPTION_VERBOSE + 1)
108 #define OPTION_VERSION_SCRIPT           (OPTION_VERSION + 1)
109 #define OPTION_VERSION_EXPORTS_SECTION  (OPTION_VERSION_SCRIPT + 1)
110 #define OPTION_WARN_COMMON              (OPTION_VERSION_EXPORTS_SECTION + 1)
111 #define OPTION_WARN_CONSTRUCTORS        (OPTION_WARN_COMMON + 1)
112 #define OPTION_WARN_FATAL               (OPTION_WARN_CONSTRUCTORS + 1)
113 #define OPTION_WARN_MULTIPLE_GP         (OPTION_WARN_FATAL + 1)
114 #define OPTION_WARN_ONCE                (OPTION_WARN_MULTIPLE_GP + 1)
115 #define OPTION_WARN_SECTION_ALIGN       (OPTION_WARN_ONCE + 1)
116 #define OPTION_SPLIT_BY_RELOC           (OPTION_WARN_SECTION_ALIGN + 1)
117 #define OPTION_SPLIT_BY_FILE            (OPTION_SPLIT_BY_RELOC + 1)
118 #define OPTION_WHOLE_ARCHIVE            (OPTION_SPLIT_BY_FILE + 1)
119 #define OPTION_WRAP                     (OPTION_WHOLE_ARCHIVE + 1)
120 #define OPTION_FORCE_EXE_SUFFIX         (OPTION_WRAP + 1)
121 #define OPTION_GC_SECTIONS              (OPTION_FORCE_EXE_SUFFIX + 1)
122 #define OPTION_NO_GC_SECTIONS           (OPTION_GC_SECTIONS + 1)
123 #define OPTION_CHECK_SECTIONS           (OPTION_NO_GC_SECTIONS + 1)
124 #define OPTION_NO_CHECK_SECTIONS        (OPTION_CHECK_SECTIONS + 1)
125 #define OPTION_MPC860C0                 (OPTION_NO_CHECK_SECTIONS + 1)
126 #define OPTION_NO_UNDEFINED             (OPTION_MPC860C0 + 1)
127 #define OPTION_INIT                     (OPTION_NO_UNDEFINED + 1)
128 #define OPTION_FINI                     (OPTION_INIT + 1)
129 #define OPTION_SECTION_START            (OPTION_FINI + 1)
130 #define OPTION_UNIQUE                   (OPTION_SECTION_START + 1)
131 #define OPTION_TARGET_HELP              (OPTION_UNIQUE + 1)
132 #define OPTION_ALLOW_SHLIB_UNDEFINED    (OPTION_TARGET_HELP + 1)
133 #define OPTION_DISCARD_NONE             (OPTION_ALLOW_SHLIB_UNDEFINED + 1)
134 #define OPTION_SPARE_DYNAMIC_TAGS       (OPTION_DISCARD_NONE + 1)
135
136 /* The long options.  This structure is used for both the option
137    parsing and the help text.  */
138
139 struct ld_option
140 {
141   /* The long option information.  */
142   struct option opt;
143   /* The short option with the same meaning ('\0' if none).  */
144   char shortopt;
145   /* The name of the argument (NULL if none).  */
146   const char *arg;
147   /* The documentation string.  If this is NULL, this is a synonym for
148      the previous option.  */
149   const char *doc;
150   enum {
151     /* Use one dash before long option name.  */
152     ONE_DASH,
153     /* Use two dashes before long option name.  */
154     TWO_DASHES,
155     /* Only accept two dashes before the long option name.
156        This is an overloading of the use of this enum, since originally it
157        was only intended to tell the --help display function how to display
158        the long option name.  This feature was added in order to resolve
159        the confusion about the -omagic command line switch.  Is it setting
160        the output file name to "magic" or is it setting the NMAGIC flag on
161        the output ?  It has been decided that it is setting the output file
162        name, and that if you want to set the NMAGIC flag you should use -N
163        or --omagic.  */
164     EXACTLY_TWO_DASHES,
165     /* Don't mention this option in --help output.  */
166     NO_HELP
167   } control;
168 };
169
170 static const struct ld_option ld_options[] =
171 {
172   { {NULL, required_argument, NULL, '\0'},
173       'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
174       ONE_DASH },
175   { {"architecture", required_argument, NULL, 'A'},
176       'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
177   { {"format", required_argument, NULL, 'b'},
178       'b', N_("TARGET"), N_("Specify target for following input files"), TWO_DASHES },
179   { {"mri-script", required_argument, NULL, 'c'},
180       'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
181   { {"dc", no_argument, NULL, 'd'},
182       'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
183   { {"dp", no_argument, NULL, 'd'},
184       '\0', NULL, NULL, ONE_DASH },
185   { {"entry", required_argument, NULL, 'e'},
186       'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
187   { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
188       'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
189   { {"EB", no_argument, NULL, OPTION_EB},
190       '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
191   { {"EL", no_argument, NULL, OPTION_EL},
192       '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
193   { {"auxiliary", required_argument, NULL, 'f'},
194       'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
195       TWO_DASHES },
196   { {"filter", required_argument, NULL, 'F'},
197       'F', N_("SHLIB"), N_("Filter for shared object symbol table"), TWO_DASHES },
198   { {NULL, no_argument, NULL, '\0'},
199       'g', NULL, N_("Ignored"), ONE_DASH },
200   { {"gpsize", required_argument, NULL, 'G'},
201       'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
202       TWO_DASHES },
203   { {"soname", required_argument, NULL, OPTION_SONAME},
204       'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
205   { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
206       'I', N_("PROGRAM"), N_("Set the dynamic linker to use"), TWO_DASHES },
207   { {"library", required_argument, NULL, 'l'},
208       'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
209   { {"library-path", required_argument, NULL, 'L'},
210       'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), TWO_DASHES },
211   { {NULL, required_argument, NULL, '\0'},
212       'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
213   { {"print-map", no_argument, NULL, 'M'},
214       'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
215   { {"nmagic", no_argument, NULL, 'n'},
216       'n', NULL, N_("Do not page align data"), TWO_DASHES },
217   { {"omagic", no_argument, NULL, 'N'},
218       'N', NULL, N_("Do not page align data, do not make text readonly"),
219       EXACTLY_TWO_DASHES },
220   { {"output", required_argument, NULL, 'o'},
221       'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
222   { {NULL, required_argument, NULL, '\0'},
223       'O', NULL, N_("Optimize output file"), ONE_DASH },
224   { {"Qy", no_argument, NULL, OPTION_IGNORE},
225       '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
226   { {"emit-relocs", no_argument, NULL, 'q'},
227       'q', NULL, "Generate relocations in final output", TWO_DASHES },
228   { {"relocateable", no_argument, NULL, 'r'},
229       'r', NULL, N_("Generate relocateable output"), TWO_DASHES },
230   { {NULL, no_argument, NULL, '\0'},
231       'i', NULL, NULL, ONE_DASH },
232   { {"just-symbols", required_argument, NULL, 'R'},
233       'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
234       TWO_DASHES },
235   { {"strip-all", no_argument, NULL, 's'},
236       's', NULL, N_("Strip all symbols"), TWO_DASHES },
237   { {"strip-debug", no_argument, NULL, 'S'},
238       'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
239   { {"trace", no_argument, NULL, 't'},
240       't', NULL, N_("Trace file opens"), TWO_DASHES },
241   { {"script", required_argument, NULL, 'T'},
242       'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
243   { {"undefined", required_argument, NULL, 'u'},
244       'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), TWO_DASHES },
245   { {"unique", optional_argument, NULL, OPTION_UNIQUE},
246       '\0', N_("[=SECTION]"), N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
247   { {"Ur", no_argument, NULL, OPTION_UR},
248       '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
249   { {"version", no_argument, NULL, OPTION_VERSION},
250       'v', NULL, N_("Print version information"), TWO_DASHES },
251   { {NULL, no_argument, NULL, '\0'},
252       'V', NULL, N_("Print version and emulation information"), ONE_DASH },
253   { {"discard-all", no_argument, NULL, 'x'},
254       'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
255   { {"discard-locals", no_argument, NULL, 'X'},
256       'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
257   { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
258       '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
259   { {"trace-symbol", required_argument, NULL, 'y'},
260       'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
261   { {NULL, required_argument, NULL, '\0'},
262       'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), ONE_DASH },
263   { {"start-group", no_argument, NULL, '('},
264       '(', NULL, N_("Start a group"), TWO_DASHES },
265   { {"end-group", no_argument, NULL, ')'},
266       ')', NULL, N_("End a group"), TWO_DASHES },
267   { {"assert", required_argument, NULL, OPTION_ASSERT},
268       '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
269   { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
270       '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
271   { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
272       '\0', NULL, NULL, ONE_DASH },
273   { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
274       '\0', NULL, NULL, ONE_DASH },
275   { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
276       '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
277   { {"dn", no_argument, NULL, OPTION_NON_SHARED},
278       '\0', NULL, NULL, ONE_DASH },
279   { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
280       '\0', NULL, NULL, ONE_DASH },
281   { {"static", no_argument, NULL, OPTION_NON_SHARED},
282       '\0', NULL, NULL, ONE_DASH },
283   { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
284       '\0', NULL, N_("Bind global references locally"), ONE_DASH },
285   { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
286       '\0', NULL, N_("Check section addresses for overlaps (default)"), TWO_DASHES },
287   { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
288       '\0', NULL, N_("Do not check section addresses for overlaps"),
289       TWO_DASHES },
290   { {"cref", no_argument, NULL, OPTION_CREF},
291       '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
292   { {"defsym", required_argument, NULL, OPTION_DEFSYM},
293       '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
294   { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
295       '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"), TWO_DASHES },
296   { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
297       '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
298   { {"fini", required_argument, NULL, OPTION_FINI},
299      '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
300   { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
301       '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
302   { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
303       '\0', NULL, N_("Remove unused sections (on some targets)"),
304       TWO_DASHES },
305   { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
306       '\0', NULL, N_("Don't remove unused sections (default)"),
307       TWO_DASHES },
308   { {"help", no_argument, NULL, OPTION_HELP},
309       '\0', NULL, N_("Print option help"), TWO_DASHES },
310   { {"init", required_argument, NULL, OPTION_INIT},
311      '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
312   { {"Map", required_argument, NULL, OPTION_MAP},
313       '\0', N_("FILE"), N_("Write a map file"), ONE_DASH },
314   { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
315       '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
316   { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
317       '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
318   { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
319      '\0', NULL, N_("Allow no undefined symbols"), TWO_DASHES },
320   { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
321      '\0', NULL, N_("Allow undefined symbols in shared objects"), TWO_DASHES },
322   { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
323       '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
324   { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
325       '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
326   { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
327       '\0', NULL, N_("Create an output file even if errors occur"), TWO_DASHES },
328   { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
329       '\0', NULL, NULL, NO_HELP },
330   { {"oformat", required_argument, NULL, OPTION_OFORMAT},
331       '\0', N_("TARGET"), N_("Specify target of output file"), EXACTLY_TWO_DASHES },
332   { {"qmagic", no_argument, NULL, OPTION_IGNORE},
333       '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
334   { {"relax", no_argument, NULL, OPTION_RELAX},
335       '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES },
336   { {"retain-symbols-file", required_argument, NULL,
337        OPTION_RETAIN_SYMBOLS_FILE},
338       '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
339   { {"rpath", required_argument, NULL, OPTION_RPATH},
340       '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
341   { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
342       '\0', N_("PATH"), N_("Set link time shared library search path"), ONE_DASH },
343   { {"shared", no_argument, NULL, OPTION_SHARED},
344       '\0', NULL, N_("Create a shared library"), ONE_DASH },
345   { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD.  */
346       '\0', NULL, NULL, ONE_DASH },
347   { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
348       '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES },
349   { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
350       '\0', NULL, NULL, NO_HELP },
351   { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
352       '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"), TWO_DASHES },
353   { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
354       '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"), TWO_DASHES },
355   { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
356       '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"), TWO_DASHES },
357   { {"stats", no_argument, NULL, OPTION_STATS},
358       '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
359   { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
360       '\0', NULL, N_("Display target specific options"), TWO_DASHES },
361   { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
362       '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
363   { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
364       '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
365   { {"section-start", required_argument, NULL, OPTION_SECTION_START},
366       '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"), TWO_DASHES },
367   { {"Tbss", required_argument, NULL, OPTION_TBSS},
368       '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
369   { {"Tdata", required_argument, NULL, OPTION_TDATA},
370       '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
371   { {"Ttext", required_argument, NULL, OPTION_TTEXT},
372       '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
373   { {"verbose", no_argument, NULL, OPTION_VERBOSE},
374       '\0', NULL, N_("Output lots of information during link"), TWO_DASHES },
375   { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux.  */
376       '\0', NULL, NULL, NO_HELP },
377   { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
378       '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
379   { {"version-exports-section", required_argument, NULL,
380      OPTION_VERSION_EXPORTS_SECTION },
381     '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n\t\t\t\tSYMBOL as the version."),
382     TWO_DASHES },
383   { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
384       '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
385   { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
386       '\0', NULL, N_("Warn if global constructors/destructors are seen"),
387       TWO_DASHES },
388   { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
389       '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
390   { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
391       '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
392   { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
393       '\0', NULL, N_("Warn if start of section changes due to alignment"),
394       TWO_DASHES },
395   { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
396      '\0', NULL, N_("Treat warnings as errors"),
397      TWO_DASHES },
398   { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
399       '\0', NULL, N_("Include all objects from following archives"), TWO_DASHES },
400   { {"wrap", required_argument, NULL, OPTION_WRAP},
401       '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
402   { {"mpc860c0", optional_argument, NULL, OPTION_MPC860C0},
403       '\0', N_("[=WORDS]"), N_("Modify problematic branches in last WORDS (1-10,\n\t\t\t\tdefault 5) words of a page"), TWO_DASHES }
404 };
405
406 #define OPTION_COUNT ARRAY_SIZE (ld_options)
407
408 /* Test STRING for containing a string of digits that form a number
409    between MIN and MAX.  The return value is the number or ERR.  */
410
411 static int
412 is_num (string, min, max, err)
413      const char *string;
414      int min;
415      int max;
416      int err;
417 {
418   int result = 0;
419
420   for (; *string; ++string)
421     {
422       if (! isdigit (*string))
423         {
424           result = err;
425           break;
426         }
427       result = result * 10 + (*string - '0');
428     }
429   if (result < min || result > max)
430     result = err;
431
432   return result;
433 }
434
435 void
436 parse_args (argc, argv)
437      unsigned argc;
438      char **argv;
439 {
440   unsigned i;
441   int is, il, irl;
442   int ingroup = 0;
443   char *default_dirlist = NULL;
444   char shortopts[OPTION_COUNT * 3 + 2];
445   struct option longopts[OPTION_COUNT + 1];
446   struct option really_longopts[OPTION_COUNT + 1];
447   int last_optind;
448
449   /* Starting the short option string with '-' is for programs that
450      expect options and other ARGV-elements in any order and that care about
451      the ordering of the two.  We describe each non-option ARGV-element
452      as if it were the argument of an option with character code 1.  */
453   shortopts[0] = '-';
454   is = 1;
455   il = 0;
456   irl = 0;
457   for (i = 0; i < OPTION_COUNT; i++)
458     {
459       if (ld_options[i].shortopt != '\0')
460         {
461           shortopts[is] = ld_options[i].shortopt;
462           ++is;
463           if (ld_options[i].opt.has_arg == required_argument
464               || ld_options[i].opt.has_arg == optional_argument)
465             {
466               shortopts[is] = ':';
467               ++is;
468               if (ld_options[i].opt.has_arg == optional_argument)
469                 {
470                   shortopts[is] = ':';
471                   ++is;
472                 }
473             }
474         }
475       if (ld_options[i].opt.name != NULL)
476         {
477           if (ld_options[i].control == EXACTLY_TWO_DASHES)
478             {
479               really_longopts[irl] = ld_options[i].opt;
480               ++irl;
481             }
482           else
483             {
484               longopts[il] = ld_options[i].opt;
485               ++il;
486             }
487         }
488     }
489   shortopts[is] = '\0';
490   longopts[il].name = NULL;
491   really_longopts[irl].name = NULL;
492
493   /* The -G option is ambiguous on different platforms.  Sometimes it
494      specifies the largest data size to put into the small data
495      section.  Sometimes it is equivalent to --shared.  Unfortunately,
496      the first form takes an argument, while the second does not.
497
498      We need to permit the --shared form because on some platforms,
499      such as Solaris, gcc -shared will pass -G to the linker.
500
501      To permit either usage, we look through the argument list.  If we
502      find -G not followed by a number, we change it into --shared.
503      This will work for most normal cases.  */
504   for (i = 1; i < argc; i++)
505     if (strcmp (argv[i], "-G") == 0
506         && (i + 1 >= argc
507             || ! isdigit ((unsigned char) argv[i + 1][0])))
508       argv[i] = (char *) "--shared";
509
510   /* Because we permit long options to start with a single dash, and
511      we have a --library option, and the -l option is conventionally
512      used with an immediately following argument, we can have bad
513      results if somebody tries to use -l with a library whose name
514      happens to start with "ibrary", as in -li.  We avoid problems by
515      simply turning -l into --library.  This means that users will
516      have to use two dashes in order to use --library, which is OK
517      since that's how it is documented.
518
519      FIXME: It's possible that this problem can arise for other short
520      options as well, although the user does always have the recourse
521      of adding a space between the option and the argument.  */
522   for (i = 1; i < argc; i++)
523     {
524       if (argv[i][0] == '-'
525           && argv[i][1] == 'l'
526           && argv[i][2] != '\0')
527         {
528           char *n;
529
530           n = (char *) xmalloc (strlen (argv[i]) + 20);
531           sprintf (n, "--library=%s", argv[i] + 2);
532           argv[i] = n;
533         }
534     }
535
536   last_optind = -1;
537   while (1)
538     {
539       int longind, errind;
540       int optc;
541
542       /* Using last_optind lets us avoid calling ldemul_parse_args
543          multiple times on a single option, which would lead to
544          confusion in the internal static variables maintained by
545          getopt.  This could otherwise happen for an argument like
546          -nx, in which the -n is parsed as a single option, and we
547          loop around to pick up the -x.  */
548       if (optind != last_optind)
549         {
550           if (ldemul_parse_args (argc, argv))
551             continue;
552           last_optind = optind;
553         }
554
555       /* getopt_long_only is like getopt_long, but '-' as well as '--'
556          can indicate a long option.  */
557       opterr = 0;
558       errind = optind;
559       optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
560       if (optc == '?')
561         {
562           --optind;
563           optc = getopt_long (argc, argv, shortopts, really_longopts, &longind);
564         }
565
566       if (optc == -1)
567         break;
568
569       switch (optc)
570         {
571         case '?':
572           fprintf (stderr, _("%s: unrecognized option '%s'\n"),
573                    program_name, argv[errind]);
574         default:
575           fprintf (stderr,
576                    _("%s: use the --help option for usage information\n"),
577                    program_name);
578           xexit (1);
579         case 1:                 /* File name.  */
580           lang_add_input_file (optarg, lang_input_file_is_file_enum,
581                                (char *) NULL);
582           break;
583
584         case OPTION_IGNORE:
585           break;
586         case 'a':
587           /* For HP/UX compatibility.  Actually -a shared should mean
588              ``use only shared libraries'' but, then, we don't
589              currently support shared libraries on HP/UX anyhow.  */
590           if (strcmp (optarg, "archive") == 0)
591             config.dynamic_link = false;
592           else if (strcmp (optarg, "shared") == 0
593                    || strcmp (optarg, "default") == 0)
594             config.dynamic_link = true;
595           else
596             einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
597           break;
598         case OPTION_ASSERT:
599           /* FIXME: We just ignore these, but we should handle them.  */
600           if (strcmp (optarg, "definitions") == 0)
601             ;
602           else if (strcmp (optarg, "nodefinitions") == 0)
603             ;
604           else if (strcmp (optarg, "nosymbolic") == 0)
605             ;
606           else if (strcmp (optarg, "pure-text") == 0)
607             ;
608           else
609             einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
610           break;
611         case 'A':
612           ldfile_add_arch (optarg);
613           break;
614         case 'b':
615           lang_add_target (optarg);
616           break;
617         case 'c':
618           ldfile_open_command_file (optarg);
619           parser_input = input_mri_script;
620           yyparse ();
621           break;
622         case OPTION_CALL_SHARED:
623           config.dynamic_link = true;
624           break;
625         case OPTION_NON_SHARED:
626           config.dynamic_link = false;
627           break;
628         case OPTION_CREF:
629           command_line.cref = true;
630           link_info.notice_all = true;
631           break;
632         case 'd':
633           command_line.force_common_definition = true;
634           break;
635         case OPTION_DEFSYM:
636           lex_string = optarg;
637           lex_redirect (optarg);
638           parser_input = input_defsym;
639           parsing_defsym = 1;
640           yyparse ();
641           parsing_defsym = 0;
642           lex_string = NULL;
643           break;
644         case OPTION_DEMANGLE:
645           demangling = true;
646           if (optarg != NULL)
647             {
648               enum demangling_styles style;
649
650               style = cplus_demangle_name_to_style (optarg);
651               if (style == unknown_demangling)
652                 einfo (_("%F%P: unknown demangling style `%s'"),
653                        optarg);
654
655               cplus_demangle_set_style (style);
656             }
657           break;
658         case 'I':               /* Used on Solaris.  */
659         case OPTION_DYNAMIC_LINKER:
660           command_line.interpreter = optarg;
661           break;
662         case OPTION_EB:
663           command_line.endian = ENDIAN_BIG;
664           break;
665         case OPTION_EL:
666           command_line.endian = ENDIAN_LITTLE;
667           break;
668         case OPTION_EMBEDDED_RELOCS:
669           command_line.embedded_relocs = true;
670           break;
671         case OPTION_EXPORT_DYNAMIC:
672         case 'E': /* HP/UX compatibility.  */
673           link_info.export_dynamic = true;
674           break;
675         case 'e':
676           lang_add_entry (optarg, true);
677           break;
678         case 'f':
679           if (command_line.auxiliary_filters == NULL)
680             {
681               command_line.auxiliary_filters =
682                 (char **) xmalloc (2 * sizeof (char *));
683               command_line.auxiliary_filters[0] = optarg;
684               command_line.auxiliary_filters[1] = NULL;
685             }
686           else
687             {
688               int c;
689               char **p;
690
691               c = 0;
692               for (p = command_line.auxiliary_filters; *p != NULL; p++)
693                 ++c;
694               command_line.auxiliary_filters =
695                 (char **) xrealloc (command_line.auxiliary_filters,
696                                     (c + 2) * sizeof (char *));
697               command_line.auxiliary_filters[c] = optarg;
698               command_line.auxiliary_filters[c + 1] = NULL;
699             }
700           break;
701         case 'F':
702           command_line.filter_shlib = optarg;
703           break;
704         case OPTION_FORCE_EXE_SUFFIX:
705           command_line.force_exe_suffix = true;
706           break;
707         case 'G':
708           {
709             char *end;
710             g_switch_value = strtoul (optarg, &end, 0);
711             if (*end)
712               einfo (_("%P%F: invalid number `%s'\n"), optarg);
713           }
714           break;
715         case 'g':
716           /* Ignore.  */
717           break;
718         case OPTION_GC_SECTIONS:
719           command_line.gc_sections = true;
720           break;
721         case OPTION_HELP:
722           help ();
723           xexit (0);
724           break;
725         case 'L':
726           ldfile_add_library_path (optarg, true);
727           break;
728         case 'l':
729           lang_add_input_file (optarg, lang_input_file_is_l_enum,
730                                (char *) NULL);
731           break;
732         case 'M':
733           config.map_filename = "-";
734           break;
735         case 'm':
736           /* Ignore.  Was handled in a pre-parse.   */
737           break;
738         case OPTION_MAP:
739           config.map_filename = optarg;
740           break;
741         case 'N':
742           config.text_read_only = false;
743           config.magic_demand_paged = false;
744           config.dynamic_link = false;
745           break;
746         case 'n':
747           config.magic_demand_paged = false;
748           config.dynamic_link = false;
749           break;
750         case OPTION_NO_DEMANGLE:
751           demangling = false;
752           break;
753         case OPTION_NO_GC_SECTIONS:
754           command_line.gc_sections = false;
755           break;
756         case OPTION_NO_KEEP_MEMORY:
757           link_info.keep_memory = false;
758           break;
759         case OPTION_NO_UNDEFINED:
760           link_info.no_undefined = true;
761           break;
762         case OPTION_ALLOW_SHLIB_UNDEFINED:
763           link_info.allow_shlib_undefined = true;
764           break;
765         case OPTION_NO_WARN_MISMATCH:
766           command_line.warn_mismatch = false;
767           break;
768         case OPTION_NOINHIBIT_EXEC:
769           force_make_executable = true;
770           break;
771         case OPTION_NO_WHOLE_ARCHIVE:
772           whole_archive = false;
773           break;
774         case 'O':
775           /* FIXME "-O<non-digits> <value>" used to set the address of
776              section <non-digits>.  Was this for compatibility with
777              something, or can we create a new option to do that
778              (with a syntax similar to -defsym)?
779              getopt can't handle two args to an option without kludges.  */
780
781           /* Enable optimizations of output files.  */
782           link_info.optimize = strtoul (optarg, NULL, 0) ? true : false;
783           break;
784         case 'o':
785           lang_add_output (optarg, 0);
786           break;
787         case OPTION_OFORMAT:
788           lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0);
789           break;
790         case 'q':
791           link_info.emitrelocations = true;
792           break;
793         case 'i':
794         case 'r':
795           link_info.relocateable = true;
796           config.build_constructors = false;
797           config.magic_demand_paged = false;
798           config.text_read_only = false;
799           config.dynamic_link = false;
800           break;
801         case 'R':
802           /* The GNU linker traditionally uses -R to mean to include
803              only the symbols from a file.  The Solaris linker uses -R
804              to set the path used by the runtime linker to find
805              libraries.  This is the GNU linker -rpath argument.  We
806              try to support both simultaneously by checking the file
807              named.  If it is a directory, rather than a regular file,
808              we assume -rpath was meant.  */
809           {
810             struct stat s;
811
812             if (stat (optarg, &s) >= 0
813                 && ! S_ISDIR (s.st_mode))
814               {
815                 lang_add_input_file (optarg,
816                                      lang_input_file_is_symbols_only_enum,
817                                      (char *) NULL);
818                 break;
819               }
820           }
821           /* Fall through.  */
822         case OPTION_RPATH:
823           if (command_line.rpath == NULL)
824             command_line.rpath = xstrdup (optarg);
825           else
826             {
827               size_t rpath_len = strlen (command_line.rpath);
828               size_t optarg_len = strlen (optarg);
829               char *buf;
830               char *cp = command_line.rpath;
831
832               /* First see whether OPTARG is already in the path.  */
833               do
834                 {
835                   size_t idx = 0;
836                   while (optarg[idx] != '\0' && optarg[idx] == cp[idx])
837                     ++idx;
838                   if (optarg[idx] == '\0'
839                       && (cp[idx] == '\0' || cp[idx] == ':'))
840                     /* We found it.  */
841                     break;
842
843                   /* Not yet found.  */
844                   cp = strchr (cp, ':');
845                   if (cp != NULL)
846                     ++cp;
847                 }
848               while (cp != NULL);
849
850               if (cp == NULL)
851                 {
852                   buf = xmalloc (rpath_len + optarg_len + 2);
853                   sprintf (buf, "%s:%s", command_line.rpath, optarg);
854                   free (command_line.rpath);
855                   command_line.rpath = buf;
856                 }
857             }
858           break;
859         case OPTION_RPATH_LINK:
860           if (command_line.rpath_link == NULL)
861             command_line.rpath_link = xstrdup (optarg);
862           else
863             {
864               char *buf;
865
866               buf = xmalloc (strlen (command_line.rpath_link)
867                              + strlen (optarg)
868                              + 2);
869               sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
870               free (command_line.rpath_link);
871               command_line.rpath_link = buf;
872             }
873           break;
874         case OPTION_RELAX:
875           command_line.relax = true;
876           break;
877         case OPTION_RETAIN_SYMBOLS_FILE:
878           add_keepsyms_file (optarg);
879           break;
880         case 'S':
881           link_info.strip = strip_debugger;
882           break;
883         case 's':
884           link_info.strip = strip_all;
885           break;
886         case OPTION_SHARED:
887           if (config.has_shared)
888             link_info.shared = true;
889           else
890             einfo (_("%P%F: -shared not supported\n"));
891           break;
892         case 'h':               /* Used on Solaris.  */
893         case OPTION_SONAME:
894           command_line.soname = optarg;
895           break;
896         case OPTION_SORT_COMMON:
897           config.sort_common = true;
898           break;
899         case OPTION_STATS:
900           config.stats = true;
901           break;
902         case OPTION_SYMBOLIC:
903           link_info.symbolic = true;
904           break;
905         case 't':
906           trace_files = true;
907           break;
908         case 'T':
909           ldfile_open_command_file (optarg);
910           parser_input = input_script;
911           yyparse ();
912           break;
913         case OPTION_SECTION_START:
914           {
915             char *optarg2;
916             char *sec_name;
917             int len;
918
919             /* Check for <something>=<somthing>...  */
920             optarg2 = strchr (optarg, '=');
921             if (optarg2 == NULL)
922               {
923                 fprintf (stderr,
924                          _("%s: Invalid argument to option \"--section-start\"\n"),
925                          program_name);
926                 xexit (1);
927               }
928
929             optarg2++;
930
931             /* So far so good.  Are all the args present?  */
932             if ((*optarg == '\0') || (*optarg2 == '\0'))
933               {
934                 fprintf (stderr,
935                          _("%s: Missing argument(s) to option \"--section-start\"\n"),
936                          program_name);
937                 xexit (1);
938               }
939
940             /* We must copy the section name as set_section_start
941                doesn't do it for us.  */
942             len = optarg2 - optarg;
943             sec_name = xmalloc (len);
944             memcpy (sec_name, optarg, len - 1);
945             sec_name[len - 1] = 0;
946
947             /* Then set it...  */
948             set_section_start (sec_name, optarg2);
949           }
950           break;
951         case OPTION_TARGET_HELP:
952           /* Mention any target specific options.  */
953           ldemul_list_emulation_options (stdout);
954           exit (0);
955         case OPTION_TBSS:
956           set_section_start (".bss", optarg);
957           break;
958         case OPTION_TDATA:
959           set_section_start (".data", optarg);
960           break;
961         case OPTION_TTEXT:
962           set_section_start (".text", optarg);
963           break;
964         case OPTION_TRADITIONAL_FORMAT:
965           link_info.traditional_format = true;
966           break;
967         case OPTION_TASK_LINK:
968           link_info.task_link = true;
969           /* Fall through - do an implied -r option.  */
970         case OPTION_UR:
971           link_info.relocateable = true;
972           config.build_constructors = true;
973           config.magic_demand_paged = false;
974           config.text_read_only = false;
975           config.dynamic_link = false;
976           break;
977         case 'u':
978           ldlang_add_undef (optarg);
979           break;
980         case OPTION_UNIQUE:
981           if (optarg != NULL)
982             lang_add_unique (optarg);
983           else
984             config.unique_orphan_sections = true;
985           break;
986         case OPTION_VERBOSE:
987           ldversion (1);
988           version_printed = true;
989           trace_file_tries = true;
990           break;
991         case 'v':
992           ldversion (0);
993           version_printed = true;
994           break;
995         case 'V':
996           ldversion (1);
997           version_printed = true;
998           break;
999         case OPTION_VERSION:
1000           /* This output is intended to follow the GNU standards document.  */
1001           printf ("GNU ld %s\n", ld_program_version);
1002           printf (_("Copyright 2001 Free Software Foundation, Inc.\n"));
1003           printf (_("\
1004 This program is free software; you may redistribute it under the terms of\n\
1005 the GNU General Public License.  This program has absolutely no warranty.\n"));
1006           {
1007             ld_emulation_xfer_type **ptr = ld_emulations;
1008
1009             printf (_("  Supported emulations:\n"));
1010             while (*ptr)
1011               {
1012                 printf ("   %s\n", (*ptr)->emulation_name);
1013                 ptr++;
1014               }
1015           }
1016           xexit (0);
1017           break;
1018         case OPTION_VERSION_SCRIPT:
1019           /* This option indicates a small script that only specifies
1020              version information.  Read it, but don't assume that
1021              we've seen a linker script.  */
1022           {
1023             FILE * hold_script_handle;
1024
1025             hold_script_handle = saved_script_handle;
1026             ldfile_open_command_file (optarg);
1027             saved_script_handle = hold_script_handle;
1028             parser_input = input_version_script;
1029             yyparse ();
1030           }
1031           break;
1032         case OPTION_VERSION_EXPORTS_SECTION:
1033           /* This option records a version symbol to be applied to the
1034              symbols listed for export to be found in the object files
1035              .exports sections.  */
1036           command_line.version_exports_section = optarg;
1037           break;
1038         case OPTION_WARN_COMMON:
1039           config.warn_common = true;
1040           break;
1041         case OPTION_WARN_CONSTRUCTORS:
1042           config.warn_constructors = true;
1043           break;
1044         case OPTION_WARN_FATAL:
1045           config.fatal_warnings = true;
1046           break;
1047         case OPTION_WARN_MULTIPLE_GP:
1048           config.warn_multiple_gp = true;
1049           break;
1050         case OPTION_WARN_ONCE:
1051           config.warn_once = true;
1052           break;
1053         case OPTION_WARN_SECTION_ALIGN:
1054           config.warn_section_align = true;
1055           break;
1056         case OPTION_WHOLE_ARCHIVE:
1057           whole_archive = true;
1058           break;
1059         case OPTION_WRAP:
1060           add_wrap (optarg);
1061           break;
1062         case OPTION_DISCARD_NONE:
1063           link_info.discard = discard_none;
1064           break;
1065         case 'X':
1066           link_info.discard = discard_l;
1067           break;
1068         case 'x':
1069           link_info.discard = discard_all;
1070           break;
1071         case 'Y':
1072           if (strncmp (optarg, "P,", 2) == 0)
1073             optarg += 2;
1074           default_dirlist = xstrdup (optarg);
1075           break;
1076         case 'y':
1077           add_ysym (optarg);
1078           break;
1079         case OPTION_SPARE_DYNAMIC_TAGS:
1080           link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1081           break;
1082         case OPTION_SPLIT_BY_RELOC:
1083           if (optarg != NULL)
1084             config.split_by_reloc = strtoul (optarg, NULL, 0);
1085           else
1086             config.split_by_reloc = 32768;
1087           break;
1088         case OPTION_SPLIT_BY_FILE:
1089           if (optarg != NULL)
1090             config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1091           else
1092             config.split_by_file = 1;
1093           break;
1094         case OPTION_CHECK_SECTIONS:
1095           command_line.check_section_addresses = true;
1096           break;
1097         case OPTION_NO_CHECK_SECTIONS:
1098           command_line.check_section_addresses = false;
1099           break;
1100         case '(':
1101           if (ingroup)
1102             {
1103               fprintf (stderr,
1104                        _("%s: may not nest groups (--help for usage)\n"),
1105                        program_name);
1106               xexit (1);
1107             }
1108           lang_enter_group ();
1109           ingroup = 1;
1110           break;
1111         case ')':
1112           if (! ingroup)
1113             {
1114               fprintf (stderr,
1115                        _("%s: group ended before it began (--help for usage)\n"),
1116                        program_name);
1117               xexit (1);
1118             }
1119           lang_leave_group ();
1120           ingroup = 0;
1121           break;
1122         case OPTION_MPC860C0:
1123           link_info.mpc860c0 = 20;      /* default value (in bytes) */
1124           if (optarg)
1125             {
1126               unsigned words;
1127
1128               words = is_num (optarg, 1, 10, 0);
1129               if (words == 0)
1130                 {
1131                   fprintf (stderr,
1132                            _("%s: Invalid argument to option \"mpc860c0\"\n"),
1133                            program_name);
1134                   xexit (1);
1135                 }
1136               link_info.mpc860c0 = words * 4;   /* convert words to bytes */
1137             }
1138           command_line.relax = true;
1139           break;
1140
1141         case OPTION_INIT:
1142           link_info.init_function = optarg;
1143           break;
1144
1145         case OPTION_FINI:
1146           link_info.fini_function = optarg;
1147           break;
1148         }
1149     }
1150
1151   if (ingroup)
1152     lang_leave_group ();
1153
1154   if (default_dirlist != NULL)
1155     set_default_dirlist (default_dirlist);
1156
1157 }
1158
1159 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1160    library search path.  */
1161
1162 static void
1163 set_default_dirlist (dirlist_ptr)
1164      char *dirlist_ptr;
1165 {
1166   char *p;
1167
1168   while (1)
1169     {
1170       p = strchr (dirlist_ptr, PATH_SEPARATOR);
1171       if (p != NULL)
1172         *p = '\0';
1173       if (*dirlist_ptr != '\0')
1174         ldfile_add_library_path (dirlist_ptr, true);
1175       if (p == NULL)
1176         break;
1177       dirlist_ptr = p + 1;
1178     }
1179 }
1180
1181 static void
1182 set_section_start (sect, valstr)
1183      char *sect, *valstr;
1184 {
1185   const char *end;
1186   bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1187   if (*end)
1188     einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1189   lang_section_start (sect, exp_intop (val));
1190 }
1191 \f
1192 /* Print help messages for the options.  */
1193
1194 static void
1195 help ()
1196 {
1197   unsigned i;
1198   const char **targets, **pp;
1199
1200   printf (_("Usage: %s [options] file...\n"), program_name);
1201
1202   printf (_("Options:\n"));
1203   for (i = 0; i < OPTION_COUNT; i++)
1204     {
1205       if (ld_options[i].doc != NULL)
1206         {
1207           boolean comma;
1208           int len;
1209           unsigned j;
1210
1211           printf ("  ");
1212
1213           comma = false;
1214           len = 2;
1215
1216           j = i;
1217           do
1218             {
1219               if (ld_options[j].shortopt != '\0'
1220                   && ld_options[j].control != NO_HELP)
1221                 {
1222                   printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1223                   len += (comma ? 2 : 0) + 2;
1224                   if (ld_options[j].arg != NULL)
1225                     {
1226                       if (ld_options[j].opt.has_arg != optional_argument)
1227                         {
1228                           printf (" ");
1229                           ++len;
1230                         }
1231                       printf ("%s", _(ld_options[j].arg));
1232                       len += strlen (_(ld_options[j].arg));
1233                     }
1234                   comma = true;
1235                 }
1236               ++j;
1237             }
1238           while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1239
1240           j = i;
1241           do
1242             {
1243               if (ld_options[j].opt.name != NULL
1244                   && ld_options[j].control != NO_HELP)
1245                 {
1246                   int two_dashes =
1247                     (ld_options[j].control == TWO_DASHES
1248                      || ld_options[j].control == EXACTLY_TWO_DASHES);
1249                   
1250                   printf ("%s-%s%s",
1251                           comma ? ", " : "",
1252                           two_dashes ? "-" : "",
1253                           ld_options[j].opt.name);
1254                   len += ((comma ? 2 : 0)
1255                           + 1
1256                           + (two_dashes ? 1 : 0)
1257                           + strlen (ld_options[j].opt.name));
1258                   if (ld_options[j].arg != NULL)
1259                     {
1260                       printf (" %s", _(ld_options[j].arg));
1261                       len += 1 + strlen (_(ld_options[j].arg));
1262                     }
1263                   comma = true;
1264                 }
1265               ++j;
1266             }
1267           while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1268
1269           if (len >= 30)
1270             {
1271               printf ("\n");
1272               len = 0;
1273             }
1274
1275           for (; len < 30; len++)
1276             putchar (' ');
1277
1278           printf ("%s\n", _(ld_options[i].doc));
1279         }
1280     }
1281
1282   /* Note: Various tools (such as libtool) depend upon the
1283      format of the listings below - do not change them.  */
1284   /* xgettext:c-format */
1285   printf (_("%s: supported targets:"), program_name);
1286   targets = bfd_target_list ();
1287   for (pp = targets; *pp != NULL; pp++)
1288     printf (" %s", *pp);
1289   free (targets);
1290   printf ("\n");
1291
1292   /* xgettext:c-format */
1293   printf (_("%s: supported emulations: "), program_name);
1294   ldemul_list_emulations (stdout);
1295   printf ("\n");
1296
1297   /* xgettext:c-format */
1298   printf (_("%s: emulation specific options:\n"), program_name);
1299   ldemul_list_emulation_options (stdout);
1300   printf ("\n");
1301
1302   printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
1303 }