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