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