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