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