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