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