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