Fix the behaviour of --allow-shlib-undefined, so that it does what it claims
[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
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)
ae9a127f
NC
129#define OPTION_NO_ALLOW_SHLIB_UNDEFINED (OPTION_ALLOW_SHLIB_UNDEFINED + 1)
130#define OPTION_ALLOW_MULTIPLE_DEFINITION (OPTION_NO_ALLOW_SHLIB_UNDEFINED + 1)
31941635
L
131#define OPTION_NO_UNDEFINED_VERSION (OPTION_ALLOW_MULTIPLE_DEFINITION + 1)
132#define OPTION_DISCARD_NONE (OPTION_NO_UNDEFINED_VERSION + 1)
db6751f2 133#define OPTION_SPARE_DYNAMIC_TAGS (OPTION_DISCARD_NONE + 1)
4818e05f 134#define OPTION_NO_DEFINE_COMMON (OPTION_SPARE_DYNAMIC_TAGS + 1)
361b220e 135#define OPTION_NOSTDLIB (OPTION_NO_DEFINE_COMMON + 1)
63fd3b82 136#define OPTION_NO_OMAGIC (OPTION_NOSTDLIB + 1)
d5cd3933
AM
137#define OPTION_STRIP_DISCARDED (OPTION_NO_OMAGIC + 1)
138#define OPTION_NO_STRIP_DISCARDED (OPTION_STRIP_DISCARDED + 1)
139#define OPTION_ACCEPT_UNKNOWN_INPUT_ARCH (OPTION_NO_STRIP_DISCARDED + 1)
312b768e 140#define OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH (OPTION_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 },
079a8e4a
NC
236 { {"relocateable", no_argument, NULL, 'r'},
237 'r', NULL, N_("Generate relocateable 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 },
373 { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
374 '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES },
375 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
376 '\0', NULL, NULL, NO_HELP },
db6751f2
JJ
377 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
378 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"), TWO_DASHES },
a854a4a7
AM
379 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
380 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"), TWO_DASHES },
381 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
382 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"), TWO_DASHES },
252b5132
RH
383 { {"stats", no_argument, NULL, OPTION_STATS},
384 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
ea20a7da
CC
385 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
386 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
252b5132
RH
387 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
388 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
389 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
390 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
176355da
NC
391 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
392 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"), TWO_DASHES },
252b5132
RH
393 { {"Tbss", required_argument, NULL, OPTION_TBSS},
394 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
395 { {"Tdata", required_argument, NULL, OPTION_TDATA},
396 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
397 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
398 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
399 { {"verbose", no_argument, NULL, OPTION_VERBOSE},
400 '\0', NULL, N_("Output lots of information during link"), TWO_DASHES },
401 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
402 '\0', NULL, NULL, NO_HELP },
403 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
404 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
405 { {"version-exports-section", required_argument, NULL,
406 OPTION_VERSION_EXPORTS_SECTION },
b3043ee4 407 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n\t\t\t\tSYMBOL as the version."),
252b5132
RH
408 TWO_DASHES },
409 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
410 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
411 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
412 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
413 TWO_DASHES },
414 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
415 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
416 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
417 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
418 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
419 '\0', NULL, N_("Warn if start of section changes due to alignment"),
420 TWO_DASHES },
7ce691ae
C
421 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
422 '\0', NULL, N_("Treat warnings as errors"),
423 TWO_DASHES },
252b5132
RH
424 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
425 '\0', NULL, N_("Include all objects from following archives"), TWO_DASHES },
426 { {"wrap", required_argument, NULL, OPTION_WRAP},
427 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
428 { {"mpc860c0", optional_argument, NULL, OPTION_MPC860C0},
b3043ee4 429 '\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
430};
431
e4897a32 432#define OPTION_COUNT ARRAY_SIZE (ld_options)
252b5132 433
3d9f6277
ILT
434/* Test STRING for containing a string of digits that form a number
435 between MIN and MAX. The return value is the number or ERR. */
436
437static int
438is_num (string, min, max, err)
439 const char *string;
440 int min;
441 int max;
442 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
462parse_args (argc, argv)
e4897a32 463 unsigned argc;
252b5132
RH
464 char **argv;
465{
e4897a32
NC
466 unsigned i;
467 int is, il, irl;
252b5132
RH
468 int ingroup = 0;
469 char *default_dirlist = NULL;
470 char shortopts[OPTION_COUNT * 3 + 2];
471 struct option longopts[OPTION_COUNT + 1];
e4897a32 472 struct option really_longopts[OPTION_COUNT + 1];
252b5132
RH
473 int last_optind;
474
475 /* Starting the short option string with '-' is for programs that
476 expect options and other ARGV-elements in any order and that care about
477 the ordering of the two. We describe each non-option ARGV-element
478 as if it were the argument of an option with character code 1. */
479 shortopts[0] = '-';
480 is = 1;
481 il = 0;
e4897a32 482 irl = 0;
252b5132
RH
483 for (i = 0; i < OPTION_COUNT; i++)
484 {
485 if (ld_options[i].shortopt != '\0')
486 {
487 shortopts[is] = ld_options[i].shortopt;
488 ++is;
489 if (ld_options[i].opt.has_arg == required_argument
490 || ld_options[i].opt.has_arg == optional_argument)
491 {
492 shortopts[is] = ':';
493 ++is;
494 if (ld_options[i].opt.has_arg == optional_argument)
495 {
496 shortopts[is] = ':';
497 ++is;
498 }
499 }
500 }
501 if (ld_options[i].opt.name != NULL)
502 {
e4897a32
NC
503 if (ld_options[i].control == EXACTLY_TWO_DASHES)
504 {
505 really_longopts[irl] = ld_options[i].opt;
506 ++irl;
507 }
508 else
509 {
510 longopts[il] = ld_options[i].opt;
511 ++il;
512 }
252b5132
RH
513 }
514 }
515 shortopts[is] = '\0';
516 longopts[il].name = NULL;
e4897a32 517 really_longopts[irl].name = NULL;
252b5132
RH
518
519 /* The -G option is ambiguous on different platforms. Sometimes it
520 specifies the largest data size to put into the small data
521 section. Sometimes it is equivalent to --shared. Unfortunately,
522 the first form takes an argument, while the second does not.
523
524 We need to permit the --shared form because on some platforms,
525 such as Solaris, gcc -shared will pass -G to the linker.
526
527 To permit either usage, we look through the argument list. If we
528 find -G not followed by a number, we change it into --shared.
529 This will work for most normal cases. */
530 for (i = 1; i < argc; i++)
531 if (strcmp (argv[i], "-G") == 0
532 && (i + 1 >= argc
3882b010 533 || ! ISDIGIT (argv[i + 1][0])))
252b5132
RH
534 argv[i] = (char *) "--shared";
535
536 /* Because we permit long options to start with a single dash, and
537 we have a --library option, and the -l option is conventionally
538 used with an immediately following argument, we can have bad
539 results if somebody tries to use -l with a library whose name
540 happens to start with "ibrary", as in -li. We avoid problems by
541 simply turning -l into --library. This means that users will
542 have to use two dashes in order to use --library, which is OK
543 since that's how it is documented.
544
545 FIXME: It's possible that this problem can arise for other short
546 options as well, although the user does always have the recourse
547 of adding a space between the option and the argument. */
548 for (i = 1; i < argc; i++)
549 {
550 if (argv[i][0] == '-'
551 && argv[i][1] == 'l'
552 && argv[i][2] != '\0')
553 {
554 char *n;
555
556 n = (char *) xmalloc (strlen (argv[i]) + 20);
557 sprintf (n, "--library=%s", argv[i] + 2);
558 argv[i] = n;
559 }
560 }
561
562 last_optind = -1;
563 while (1)
564 {
89894c62 565 int longind;
252b5132
RH
566 int optc;
567
568 /* Using last_optind lets us avoid calling ldemul_parse_args
569 multiple times on a single option, which would lead to
570 confusion in the internal static variables maintained by
571 getopt. This could otherwise happen for an argument like
572 -nx, in which the -n is parsed as a single option, and we
573 loop around to pick up the -x. */
574 if (optind != last_optind)
89894c62
AM
575 if (ldemul_parse_args (argc, argv))
576 continue;
252b5132
RH
577
578 /* getopt_long_only is like getopt_long, but '-' as well as '--'
579 can indicate a long option. */
0fc3347a 580 opterr = 0;
89894c62 581 last_optind = optind;
252b5132 582 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
0fc3347a
NC
583 if (optc == '?')
584 {
89894c62
AM
585 optind = last_optind;
586 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
0fc3347a 587 }
b7ed8fad 588
252b5132
RH
589 if (optc == -1)
590 break;
0fc3347a 591
252b5132
RH
592 switch (optc)
593 {
0fc3347a 594 case '?':
89894c62 595 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
252b5132 596 default:
210a7bd1
NC
597 einfo (_("%P%F: use the --help option for usage information\n"));
598
252b5132
RH
599 case 1: /* File name. */
600 lang_add_input_file (optarg, lang_input_file_is_file_enum,
601 (char *) NULL);
602 break;
603
604 case OPTION_IGNORE:
605 break;
606 case 'a':
607 /* For HP/UX compatibility. Actually -a shared should mean
608 ``use only shared libraries'' but, then, we don't
609 currently support shared libraries on HP/UX anyhow. */
610 if (strcmp (optarg, "archive") == 0)
b34976b6 611 config.dynamic_link = FALSE;
252b5132
RH
612 else if (strcmp (optarg, "shared") == 0
613 || strcmp (optarg, "default") == 0)
b34976b6 614 config.dynamic_link = TRUE;
252b5132
RH
615 else
616 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
617 break;
618 case OPTION_ASSERT:
619 /* FIXME: We just ignore these, but we should handle them. */
620 if (strcmp (optarg, "definitions") == 0)
621 ;
622 else if (strcmp (optarg, "nodefinitions") == 0)
623 ;
624 else if (strcmp (optarg, "nosymbolic") == 0)
625 ;
626 else if (strcmp (optarg, "pure-text") == 0)
627 ;
628 else
629 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
630 break;
631 case 'A':
632 ldfile_add_arch (optarg);
633 break;
634 case 'b':
635 lang_add_target (optarg);
636 break;
637 case 'c':
638 ldfile_open_command_file (optarg);
639 parser_input = input_mri_script;
640 yyparse ();
641 break;
642 case OPTION_CALL_SHARED:
b34976b6 643 config.dynamic_link = TRUE;
252b5132
RH
644 break;
645 case OPTION_NON_SHARED:
b34976b6 646 config.dynamic_link = FALSE;
252b5132
RH
647 break;
648 case OPTION_CREF:
b34976b6
AM
649 command_line.cref = TRUE;
650 link_info.notice_all = TRUE;
252b5132
RH
651 break;
652 case 'd':
b34976b6 653 command_line.force_common_definition = TRUE;
252b5132
RH
654 break;
655 case OPTION_DEFSYM:
656 lex_string = optarg;
657 lex_redirect (optarg);
658 parser_input = input_defsym;
659 parsing_defsym = 1;
660 yyparse ();
661 parsing_defsym = 0;
662 lex_string = NULL;
663 break;
664 case OPTION_DEMANGLE:
b34976b6 665 demangling = TRUE;
28c309a2
NC
666 if (optarg != NULL)
667 {
668 enum demangling_styles style;
5cc18311 669
28c309a2 670 style = cplus_demangle_name_to_style (optarg);
5cc18311 671 if (style == unknown_demangling)
28c309a2
NC
672 einfo (_("%F%P: unknown demangling style `%s'"),
673 optarg);
5cc18311 674
28c309a2 675 cplus_demangle_set_style (style);
e47d05ad 676 }
252b5132 677 break;
506eee22 678 case 'I': /* Used on Solaris. */
252b5132
RH
679 case OPTION_DYNAMIC_LINKER:
680 command_line.interpreter = optarg;
681 break;
682 case OPTION_EB:
683 command_line.endian = ENDIAN_BIG;
684 break;
685 case OPTION_EL:
686 command_line.endian = ENDIAN_LITTLE;
687 break;
688 case OPTION_EMBEDDED_RELOCS:
b34976b6 689 command_line.embedded_relocs = TRUE;
252b5132
RH
690 break;
691 case OPTION_EXPORT_DYNAMIC:
692 case 'E': /* HP/UX compatibility. */
b34976b6 693 link_info.export_dynamic = TRUE;
252b5132
RH
694 break;
695 case 'e':
b34976b6 696 lang_add_entry (optarg, TRUE);
252b5132
RH
697 break;
698 case 'f':
699 if (command_line.auxiliary_filters == NULL)
700 {
701 command_line.auxiliary_filters =
702 (char **) xmalloc (2 * sizeof (char *));
703 command_line.auxiliary_filters[0] = optarg;
704 command_line.auxiliary_filters[1] = NULL;
705 }
706 else
707 {
708 int c;
709 char **p;
710
711 c = 0;
712 for (p = command_line.auxiliary_filters; *p != NULL; p++)
713 ++c;
714 command_line.auxiliary_filters =
715 (char **) xrealloc (command_line.auxiliary_filters,
716 (c + 2) * sizeof (char *));
717 command_line.auxiliary_filters[c] = optarg;
718 command_line.auxiliary_filters[c + 1] = NULL;
719 }
720 break;
721 case 'F':
722 command_line.filter_shlib = optarg;
723 break;
724 case OPTION_FORCE_EXE_SUFFIX:
b34976b6 725 command_line.force_exe_suffix = TRUE;
252b5132
RH
726 break;
727 case 'G':
728 {
729 char *end;
730 g_switch_value = strtoul (optarg, &end, 0);
731 if (*end)
732 einfo (_("%P%F: invalid number `%s'\n"), optarg);
733 }
734 break;
735 case 'g':
736 /* Ignore. */
737 break;
738 case OPTION_GC_SECTIONS:
b34976b6 739 command_line.gc_sections = TRUE;
252b5132
RH
740 break;
741 case OPTION_HELP:
742 help ();
743 xexit (0);
744 break;
745 case 'L':
b34976b6 746 ldfile_add_library_path (optarg, TRUE);
252b5132
RH
747 break;
748 case 'l':
749 lang_add_input_file (optarg, lang_input_file_is_l_enum,
750 (char *) NULL);
751 break;
752 case 'M':
753 config.map_filename = "-";
754 break;
755 case 'm':
756 /* Ignore. Was handled in a pre-parse. */
757 break;
758 case OPTION_MAP:
759 config.map_filename = optarg;
760 break;
761 case 'N':
b34976b6
AM
762 config.text_read_only = FALSE;
763 config.magic_demand_paged = FALSE;
764 config.dynamic_link = FALSE;
252b5132 765 break;
63fd3b82 766 case OPTION_NO_OMAGIC:
b34976b6
AM
767 config.text_read_only = TRUE;
768 config.magic_demand_paged = TRUE;
769 /* NB/ Does not set dynamic_link to TRUE.
63fd3b82
NC
770 Use --call-shared or -Bdynamic for this. */
771 break;
252b5132 772 case 'n':
b34976b6
AM
773 config.magic_demand_paged = FALSE;
774 config.dynamic_link = FALSE;
252b5132 775 break;
4818e05f 776 case OPTION_NO_DEFINE_COMMON:
b34976b6 777 command_line.inhibit_common_definition = TRUE;
4818e05f 778 break;
252b5132 779 case OPTION_NO_DEMANGLE:
b34976b6 780 demangling = FALSE;
252b5132
RH
781 break;
782 case OPTION_NO_GC_SECTIONS:
b34976b6 783 command_line.gc_sections = FALSE;
252b5132
RH
784 break;
785 case OPTION_NO_KEEP_MEMORY:
b34976b6 786 link_info.keep_memory = FALSE;
252b5132
RH
787 break;
788 case OPTION_NO_UNDEFINED:
b34976b6 789 link_info.no_undefined = TRUE;
252b5132 790 break;
b79e8c78 791 case OPTION_ALLOW_SHLIB_UNDEFINED:
b34976b6 792 link_info.allow_shlib_undefined = TRUE;
b79e8c78 793 break;
ae9a127f
NC
794 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
795 link_info.allow_shlib_undefined = FALSE;
796 break;
aa713662 797 case OPTION_ALLOW_MULTIPLE_DEFINITION:
b34976b6 798 link_info.allow_multiple_definition = TRUE;
aa713662 799 break;
31941635 800 case OPTION_NO_UNDEFINED_VERSION:
b34976b6 801 link_info.allow_undefined_version = FALSE;
31941635 802 break;
252b5132 803 case OPTION_NO_WARN_MISMATCH:
b34976b6 804 command_line.warn_mismatch = FALSE;
252b5132
RH
805 break;
806 case OPTION_NOINHIBIT_EXEC:
b34976b6 807 force_make_executable = TRUE;
252b5132 808 break;
361b220e 809 case OPTION_NOSTDLIB:
b34976b6 810 config.only_cmd_line_lib_dirs = TRUE;
361b220e 811 break;
252b5132 812 case OPTION_NO_WHOLE_ARCHIVE:
b34976b6 813 whole_archive = FALSE;
252b5132
RH
814 break;
815 case 'O':
816 /* FIXME "-O<non-digits> <value>" used to set the address of
817 section <non-digits>. Was this for compatibility with
818 something, or can we create a new option to do that
819 (with a syntax similar to -defsym)?
820 getopt can't handle two args to an option without kludges. */
821
822 /* Enable optimizations of output files. */
b34976b6 823 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
252b5132
RH
824 break;
825 case 'o':
5cc18311 826 lang_add_output (optarg, 0);
252b5132
RH
827 break;
828 case OPTION_OFORMAT:
829 lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0);
830 break;
a712da20 831 case 'q':
b34976b6 832 link_info.emitrelocations = TRUE;
a712da20 833 break;
8c5ff972 834 case 'i':
252b5132 835 case 'r':
210a7bd1
NC
836 if (optind == last_optind)
837 /* This can happen if the user put "-rpath,a" on the command
838 line. (Or something similar. The comma is important).
839 Getopt becomes confused and thinks that this is a -r option
840 but it cannot parse the text after the -r so it refuses to
841 increment the optind counter. Detect this case and issue
842 an error message here. We cannot just make this a warning,
843 increment optind, and continue because getopt is too confused
844 and will seg-fault the next time around. */
845 einfo(_("%P%F: bad -rpath option\n"));
b7a26f91 846
b34976b6
AM
847 link_info.relocateable = TRUE;
848 config.build_constructors = FALSE;
849 config.magic_demand_paged = FALSE;
850 config.text_read_only = FALSE;
851 config.dynamic_link = FALSE;
252b5132
RH
852 break;
853 case 'R':
854 /* The GNU linker traditionally uses -R to mean to include
855 only the symbols from a file. The Solaris linker uses -R
856 to set the path used by the runtime linker to find
857 libraries. This is the GNU linker -rpath argument. We
858 try to support both simultaneously by checking the file
859 named. If it is a directory, rather than a regular file,
860 we assume -rpath was meant. */
861 {
862 struct stat s;
863
864 if (stat (optarg, &s) >= 0
865 && ! S_ISDIR (s.st_mode))
866 {
867 lang_add_input_file (optarg,
868 lang_input_file_is_symbols_only_enum,
869 (char *) NULL);
870 break;
871 }
872 }
873 /* Fall through. */
874 case OPTION_RPATH:
875 if (command_line.rpath == NULL)
d1b2b2dc 876 command_line.rpath = xstrdup (optarg);
252b5132
RH
877 else
878 {
879 size_t rpath_len = strlen (command_line.rpath);
880 size_t optarg_len = strlen (optarg);
881 char *buf;
882 char *cp = command_line.rpath;
883
884 /* First see whether OPTARG is already in the path. */
885 do
886 {
887 size_t idx = 0;
210a7bd1 888
252b5132
RH
889 while (optarg[idx] != '\0' && optarg[idx] == cp[idx])
890 ++idx;
891 if (optarg[idx] == '\0'
892 && (cp[idx] == '\0' || cp[idx] == ':'))
893 /* We found it. */
894 break;
895
896 /* Not yet found. */
897 cp = strchr (cp, ':');
898 if (cp != NULL)
899 ++cp;
900 }
901 while (cp != NULL);
902
903 if (cp == NULL)
904 {
905 buf = xmalloc (rpath_len + optarg_len + 2);
906 sprintf (buf, "%s:%s", command_line.rpath, optarg);
907 free (command_line.rpath);
908 command_line.rpath = buf;
909 }
910 }
911 break;
912 case OPTION_RPATH_LINK:
913 if (command_line.rpath_link == NULL)
d1b2b2dc 914 command_line.rpath_link = xstrdup (optarg);
252b5132
RH
915 else
916 {
917 char *buf;
918
919 buf = xmalloc (strlen (command_line.rpath_link)
920 + strlen (optarg)
921 + 2);
922 sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
923 free (command_line.rpath_link);
924 command_line.rpath_link = buf;
925 }
926 break;
927 case OPTION_RELAX:
b34976b6 928 command_line.relax = TRUE;
252b5132
RH
929 break;
930 case OPTION_RETAIN_SYMBOLS_FILE:
931 add_keepsyms_file (optarg);
932 break;
933 case 'S':
934 link_info.strip = strip_debugger;
935 break;
936 case 's':
937 link_info.strip = strip_all;
938 break;
d5cd3933
AM
939 case OPTION_STRIP_DISCARDED:
940 link_info.strip_discarded = TRUE;
941 break;
942 case OPTION_NO_STRIP_DISCARDED:
943 link_info.strip_discarded = FALSE;
944 break;
252b5132
RH
945 case OPTION_SHARED:
946 if (config.has_shared)
b34976b6 947 link_info.shared = TRUE;
252b5132
RH
948 else
949 einfo (_("%P%F: -shared not supported\n"));
950 break;
951 case 'h': /* Used on Solaris. */
952 case OPTION_SONAME:
953 command_line.soname = optarg;
954 break;
955 case OPTION_SORT_COMMON:
b34976b6 956 config.sort_common = TRUE;
252b5132
RH
957 break;
958 case OPTION_STATS:
b34976b6 959 config.stats = TRUE;
252b5132
RH
960 break;
961 case OPTION_SYMBOLIC:
b34976b6 962 link_info.symbolic = TRUE;
252b5132
RH
963 break;
964 case 't':
b34976b6 965 trace_files = TRUE;
252b5132
RH
966 break;
967 case 'T':
968 ldfile_open_command_file (optarg);
969 parser_input = input_script;
970 yyparse ();
971 break;
176355da
NC
972 case OPTION_SECTION_START:
973 {
974 char *optarg2;
227aeb07
AM
975 char *sec_name;
976 int len;
176355da
NC
977
978 /* Check for <something>=<somthing>... */
979 optarg2 = strchr (optarg, '=');
980 if (optarg2 == NULL)
210a7bd1 981 einfo (_("%P%F: invalid argument to option \"--section-start\"\n"));
176355da 982
e47d05ad 983 optarg2++;
5cc18311 984
176355da
NC
985 /* So far so good. Are all the args present? */
986 if ((*optarg == '\0') || (*optarg2 == '\0'))
210a7bd1 987 einfo (_("%P%F: missing argument(s) to option \"--section-start\"\n"));
176355da 988
227aeb07
AM
989 /* We must copy the section name as set_section_start
990 doesn't do it for us. */
991 len = optarg2 - optarg;
992 sec_name = xmalloc (len);
993 memcpy (sec_name, optarg, len - 1);
994 sec_name[len - 1] = 0;
176355da
NC
995
996 /* Then set it... */
227aeb07 997 set_section_start (sec_name, optarg2);
176355da
NC
998 }
999 break;
ea20a7da
CC
1000 case OPTION_TARGET_HELP:
1001 /* Mention any target specific options. */
b7a26f91
KH
1002 ldemul_list_emulation_options (stdout);
1003 exit (0);
252b5132
RH
1004 case OPTION_TBSS:
1005 set_section_start (".bss", optarg);
1006 break;
1007 case OPTION_TDATA:
1008 set_section_start (".data", optarg);
1009 break;
1010 case OPTION_TTEXT:
1011 set_section_start (".text", optarg);
1012 break;
1013 case OPTION_TRADITIONAL_FORMAT:
b34976b6 1014 link_info.traditional_format = TRUE;
252b5132
RH
1015 break;
1016 case OPTION_TASK_LINK:
b34976b6 1017 link_info.task_link = TRUE;
252b5132
RH
1018 /* Fall through - do an implied -r option. */
1019 case OPTION_UR:
b34976b6
AM
1020 link_info.relocateable = TRUE;
1021 config.build_constructors = TRUE;
1022 config.magic_demand_paged = FALSE;
1023 config.text_read_only = FALSE;
1024 config.dynamic_link = FALSE;
252b5132
RH
1025 break;
1026 case 'u':
1027 ldlang_add_undef (optarg);
1028 break;
a854a4a7 1029 case OPTION_UNIQUE:
577a0623
AM
1030 if (optarg != NULL)
1031 lang_add_unique (optarg);
1032 else
b34976b6 1033 config.unique_orphan_sections = TRUE;
a854a4a7 1034 break;
252b5132
RH
1035 case OPTION_VERBOSE:
1036 ldversion (1);
b34976b6
AM
1037 version_printed = TRUE;
1038 trace_file_tries = TRUE;
252b5132
RH
1039 break;
1040 case 'v':
1041 ldversion (0);
b34976b6 1042 version_printed = TRUE;
252b5132
RH
1043 break;
1044 case 'V':
1045 ldversion (1);
b34976b6 1046 version_printed = TRUE;
252b5132
RH
1047 break;
1048 case OPTION_VERSION:
d32820f2 1049 ldversion (2);
252b5132
RH
1050 xexit (0);
1051 break;
1052 case OPTION_VERSION_SCRIPT:
1053 /* This option indicates a small script that only specifies
1054 version information. Read it, but don't assume that
1055 we've seen a linker script. */
1056 {
b7a26f91 1057 FILE *hold_script_handle;
252b5132 1058
b9a8de1e 1059 hold_script_handle = saved_script_handle;
252b5132 1060 ldfile_open_command_file (optarg);
b9a8de1e 1061 saved_script_handle = hold_script_handle;
252b5132
RH
1062 parser_input = input_version_script;
1063 yyparse ();
1064 }
1065 break;
1066 case OPTION_VERSION_EXPORTS_SECTION:
1067 /* This option records a version symbol to be applied to the
1068 symbols listed for export to be found in the object files
1069 .exports sections. */
1070 command_line.version_exports_section = optarg;
1071 break;
1072 case OPTION_WARN_COMMON:
b34976b6 1073 config.warn_common = TRUE;
252b5132
RH
1074 break;
1075 case OPTION_WARN_CONSTRUCTORS:
b34976b6 1076 config.warn_constructors = TRUE;
252b5132 1077 break;
7ce691ae 1078 case OPTION_WARN_FATAL:
b34976b6 1079 config.fatal_warnings = TRUE;
7ce691ae 1080 break;
252b5132 1081 case OPTION_WARN_MULTIPLE_GP:
b34976b6 1082 config.warn_multiple_gp = TRUE;
252b5132
RH
1083 break;
1084 case OPTION_WARN_ONCE:
b34976b6 1085 config.warn_once = TRUE;
252b5132
RH
1086 break;
1087 case OPTION_WARN_SECTION_ALIGN:
b34976b6 1088 config.warn_section_align = TRUE;
252b5132
RH
1089 break;
1090 case OPTION_WHOLE_ARCHIVE:
b34976b6 1091 whole_archive = TRUE;
252b5132
RH
1092 break;
1093 case OPTION_WRAP:
1094 add_wrap (optarg);
1095 break;
f5fa8ca2
JJ
1096 case OPTION_DISCARD_NONE:
1097 link_info.discard = discard_none;
1098 break;
252b5132
RH
1099 case 'X':
1100 link_info.discard = discard_l;
1101 break;
1102 case 'x':
1103 link_info.discard = discard_all;
1104 break;
1105 case 'Y':
1106 if (strncmp (optarg, "P,", 2) == 0)
1107 optarg += 2;
1108 default_dirlist = xstrdup (optarg);
1109 break;
1110 case 'y':
1111 add_ysym (optarg);
1112 break;
db6751f2
JJ
1113 case OPTION_SPARE_DYNAMIC_TAGS:
1114 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1115 break;
252b5132 1116 case OPTION_SPLIT_BY_RELOC:
a854a4a7
AM
1117 if (optarg != NULL)
1118 config.split_by_reloc = strtoul (optarg, NULL, 0);
1119 else
1120 config.split_by_reloc = 32768;
5cc18311 1121 break;
252b5132 1122 case OPTION_SPLIT_BY_FILE:
a854a4a7
AM
1123 if (optarg != NULL)
1124 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1125 else
1126 config.split_by_file = 1;
5cc18311 1127 break;
252b5132 1128 case OPTION_CHECK_SECTIONS:
b34976b6 1129 command_line.check_section_addresses = TRUE;
252b5132
RH
1130 break;
1131 case OPTION_NO_CHECK_SECTIONS:
b34976b6 1132 command_line.check_section_addresses = FALSE;
252b5132 1133 break;
312b768e
NC
1134 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1135 command_line.accept_unknown_input_arch = TRUE;
1136 break;
1137 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1138 command_line.accept_unknown_input_arch = FALSE;
1139 break;
252b5132
RH
1140 case '(':
1141 if (ingroup)
210a7bd1
NC
1142 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1143
252b5132
RH
1144 lang_enter_group ();
1145 ingroup = 1;
1146 break;
1147 case ')':
1148 if (! ingroup)
210a7bd1
NC
1149 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1150
252b5132
RH
1151 lang_leave_group ();
1152 ingroup = 0;
1153 break;
e47d05ad 1154 case OPTION_MPC860C0:
210a7bd1
NC
1155 /* Default value (in bytes). */
1156 link_info.mpc860c0 = 20;
e47d05ad
KH
1157 if (optarg)
1158 {
1159 unsigned words;
252b5132 1160
e47d05ad
KH
1161 words = is_num (optarg, 1, 10, 0);
1162 if (words == 0)
210a7bd1
NC
1163 einfo (_("%P%F: invalid argument to option \"mpc860c0\"\n"));
1164
1165 /* Convert words to bytes. */
1166 link_info.mpc860c0 = words * 4;
e47d05ad 1167 }
b34976b6 1168 command_line.relax = TRUE;
e47d05ad 1169 break;
3dbf70a2
MM
1170
1171 case OPTION_INIT:
1172 link_info.init_function = optarg;
1173 break;
5cc18311 1174
3dbf70a2
MM
1175 case OPTION_FINI:
1176 link_info.fini_function = optarg;
1177 break;
252b5132
RH
1178 }
1179 }
1180
1181 if (ingroup)
1182 lang_leave_group ();
1183
1184 if (default_dirlist != NULL)
1185 set_default_dirlist (default_dirlist);
1186
1187}
1188
1189/* Add the (colon-separated) elements of DIRLIST_PTR to the
1190 library search path. */
1191
1192static void
1193set_default_dirlist (dirlist_ptr)
1194 char *dirlist_ptr;
1195{
1196 char *p;
1197
1198 while (1)
1199 {
1200 p = strchr (dirlist_ptr, PATH_SEPARATOR);
1201 if (p != NULL)
1202 *p = '\0';
1203 if (*dirlist_ptr != '\0')
b34976b6 1204 ldfile_add_library_path (dirlist_ptr, TRUE);
252b5132
RH
1205 if (p == NULL)
1206 break;
1207 dirlist_ptr = p + 1;
1208 }
1209}
1210
1211static void
1212set_section_start (sect, valstr)
1213 char *sect, *valstr;
1214{
93697284
AM
1215 const char *end;
1216 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
252b5132
RH
1217 if (*end)
1218 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1219 lang_section_start (sect, exp_intop (val));
1220}
1221\f
1222/* Print help messages for the options. */
1223
1224static void
1225help ()
1226{
e4897a32 1227 unsigned i;
252b5132
RH
1228 const char **targets, **pp;
1229
1230 printf (_("Usage: %s [options] file...\n"), program_name);
1231
1232 printf (_("Options:\n"));
1233 for (i = 0; i < OPTION_COUNT; i++)
1234 {
1235 if (ld_options[i].doc != NULL)
1236 {
b34976b6 1237 bfd_boolean comma;
252b5132 1238 int len;
e4897a32 1239 unsigned j;
252b5132
RH
1240
1241 printf (" ");
1242
b34976b6 1243 comma = FALSE;
252b5132
RH
1244 len = 2;
1245
1246 j = i;
1247 do
1248 {
1249 if (ld_options[j].shortopt != '\0'
1250 && ld_options[j].control != NO_HELP)
1251 {
1252 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1253 len += (comma ? 2 : 0) + 2;
1254 if (ld_options[j].arg != NULL)
1255 {
1256 if (ld_options[j].opt.has_arg != optional_argument)
1257 {
1258 printf (" ");
1259 ++len;
1260 }
1261 printf ("%s", _(ld_options[j].arg));
1262 len += strlen (_(ld_options[j].arg));
1263 }
b34976b6 1264 comma = TRUE;
252b5132
RH
1265 }
1266 ++j;
1267 }
1268 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1269
1270 j = i;
1271 do
1272 {
1273 if (ld_options[j].opt.name != NULL
1274 && ld_options[j].control != NO_HELP)
1275 {
e4897a32
NC
1276 int two_dashes =
1277 (ld_options[j].control == TWO_DASHES
1278 || ld_options[j].control == EXACTLY_TWO_DASHES);
b7a26f91 1279
252b5132
RH
1280 printf ("%s-%s%s",
1281 comma ? ", " : "",
e4897a32 1282 two_dashes ? "-" : "",
252b5132
RH
1283 ld_options[j].opt.name);
1284 len += ((comma ? 2 : 0)
1285 + 1
e4897a32 1286 + (two_dashes ? 1 : 0)
252b5132
RH
1287 + strlen (ld_options[j].opt.name));
1288 if (ld_options[j].arg != NULL)
1289 {
1290 printf (" %s", _(ld_options[j].arg));
1291 len += 1 + strlen (_(ld_options[j].arg));
1292 }
b34976b6 1293 comma = TRUE;
252b5132
RH
1294 }
1295 ++j;
1296 }
1297 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1298
1299 if (len >= 30)
1300 {
1301 printf ("\n");
1302 len = 0;
1303 }
1304
1305 for (; len < 30; len++)
1306 putchar (' ');
1307
1308 printf ("%s\n", _(ld_options[i].doc));
1309 }
1310 }
1311
f75692fe
NC
1312 /* Note: Various tools (such as libtool) depend upon the
1313 format of the listings below - do not change them. */
252b5132 1314 /* xgettext:c-format */
f75692fe 1315 printf (_("%s: supported targets:"), program_name);
252b5132
RH
1316 targets = bfd_target_list ();
1317 for (pp = targets; *pp != NULL; pp++)
1318 printf (" %s", *pp);
1319 free (targets);
1320 printf ("\n");
1321
1322 /* xgettext:c-format */
f75692fe 1323 printf (_("%s: supported emulations: "), program_name);
252b5132
RH
1324 ldemul_list_emulations (stdout);
1325 printf ("\n");
1326
1327 /* xgettext:c-format */
1328 printf (_("%s: emulation specific options:\n"), program_name);
1329 ldemul_list_emulation_options (stdout);
1330 printf ("\n");
c20f4f8c 1331
8ad3436c 1332 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
252b5132 1333}
This page took 0.226619 seconds and 4 git commands to generate.