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