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