1 /* Parse options for the GNU linker.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005
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)
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, 51 Franklin Street - Fifth Floor, Boston, MA
26 #include "libiberty.h"
29 #include "safe-ctype.h"
44 #ifndef PATH_SEPARATOR
45 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
46 #define PATH_SEPARATOR ';'
48 #define PATH_SEPARATOR ':'
52 /* Somewhere above, sys/stat.h got included . . . . */
53 #if !defined(S_ISDIR) && defined(S_IFDIR)
54 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
57 static void set_default_dirlist (char *);
58 static void set_section_start (char *, char *);
59 static void set_segment_start (const char *, char *);
60 static void help (void);
62 /* Non-zero if we are processing a --defsym from the command line. */
63 int parsing_defsym
= 0;
65 /* Codes used for the long options with no short synonyms. 150 isn't
66 special; it's just an arbitrary non-ASCII char value. */
74 OPTION_DYNAMIC_LINKER
,
78 OPTION_EMBEDDED_RELOCS
,
79 OPTION_EXPORT_DYNAMIC
,
84 OPTION_NO_KEEP_MEMORY
,
85 OPTION_NO_WARN_MISMATCH
,
86 OPTION_NOINHIBIT_EXEC
,
88 OPTION_NO_WHOLE_ARCHIVE
,
91 OPTION_RETAIN_SYMBOLS_FILE
,
104 OPTION_TRADITIONAL_FORMAT
,
108 OPTION_VERSION_SCRIPT
,
109 OPTION_VERSION_EXPORTS_SECTION
,
111 OPTION_DYNAMIC_LIST_CPP_TYPEINFO
,
113 OPTION_WARN_CONSTRUCTORS
,
115 OPTION_WARN_MULTIPLE_GP
,
117 OPTION_WARN_SECTION_ALIGN
,
118 OPTION_SPLIT_BY_RELOC
,
119 OPTION_SPLIT_BY_FILE
,
120 OPTION_WHOLE_ARCHIVE
,
122 OPTION_NO_ADD_NEEDED
,
126 OPTION_FORCE_EXE_SUFFIX
,
128 OPTION_NO_GC_SECTIONS
,
129 OPTION_PRINT_GC_SECTIONS
,
130 OPTION_NO_PRINT_GC_SECTIONS
,
132 OPTION_CHECK_SECTIONS
,
133 OPTION_NO_CHECK_SECTIONS
,
137 OPTION_SECTION_START
,
140 OPTION_ALLOW_SHLIB_UNDEFINED
,
141 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
142 OPTION_ALLOW_MULTIPLE_DEFINITION
,
143 OPTION_NO_UNDEFINED_VERSION
,
144 OPTION_DEFAULT_SYMVER
,
145 OPTION_DEFAULT_IMPORTED_SYMVER
,
147 OPTION_SPARE_DYNAMIC_TAGS
,
148 OPTION_NO_DEFINE_COMMON
,
151 OPTION_STRIP_DISCARDED
,
152 OPTION_NO_STRIP_DISCARDED
,
153 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
154 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
156 OPTION_UNRESOLVED_SYMBOLS
,
157 OPTION_WARN_UNRESOLVED_SYMBOLS
,
158 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
159 OPTION_WARN_SHARED_TEXTREL
,
160 OPTION_REDUCE_MEMORY_OVERHEADS
163 /* The long options. This structure is used for both the option
164 parsing and the help text. */
168 /* The long option information. */
170 /* The short option with the same meaning ('\0' if none). */
172 /* The name of the argument (NULL if none). */
174 /* The documentation string. If this is NULL, this is a synonym for
175 the previous option. */
178 /* Use one dash before long option name. */
180 /* Use two dashes before long option name. */
182 /* Only accept two dashes before the long option name.
183 This is an overloading of the use of this enum, since originally it
184 was only intended to tell the --help display function how to display
185 the long option name. This feature was added in order to resolve
186 the confusion about the -omagic command line switch. Is it setting
187 the output file name to "magic" or is it setting the NMAGIC flag on
188 the output ? It has been decided that it is setting the output file
189 name, and that if you want to set the NMAGIC flag you should use -N
192 /* Don't mention this option in --help output. */
197 static const struct ld_option ld_options
[] =
199 { {NULL
, required_argument
, NULL
, '\0'},
200 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
202 { {"architecture", required_argument
, NULL
, 'A'},
203 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
204 { {"format", required_argument
, NULL
, 'b'},
205 'b', N_("TARGET"), N_("Specify target for following input files"),
207 { {"mri-script", required_argument
, NULL
, 'c'},
208 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
209 { {"dc", no_argument
, NULL
, 'd'},
210 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
211 { {"dp", no_argument
, NULL
, 'd'},
212 '\0', NULL
, NULL
, ONE_DASH
},
213 { {"entry", required_argument
, NULL
, 'e'},
214 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
215 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
216 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
217 { {"EB", no_argument
, NULL
, OPTION_EB
},
218 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
219 { {"EL", no_argument
, NULL
, OPTION_EL
},
220 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
221 { {"auxiliary", required_argument
, NULL
, 'f'},
222 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
224 { {"filter", required_argument
, NULL
, 'F'},
225 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
227 { {NULL
, no_argument
, NULL
, '\0'},
228 'g', NULL
, N_("Ignored"), ONE_DASH
},
229 { {"gpsize", required_argument
, NULL
, 'G'},
230 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
232 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
233 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
234 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
235 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
237 { {"library", required_argument
, NULL
, 'l'},
238 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
239 { {"library-path", required_argument
, NULL
, 'L'},
240 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
242 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
243 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
244 { {NULL
, required_argument
, NULL
, '\0'},
245 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
246 { {"print-map", no_argument
, NULL
, 'M'},
247 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
248 { {"nmagic", no_argument
, NULL
, 'n'},
249 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
250 { {"omagic", no_argument
, NULL
, 'N'},
251 'N', NULL
, N_("Do not page align data, do not make text readonly"),
252 EXACTLY_TWO_DASHES
},
253 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
254 '\0', NULL
, N_("Page align data, make text readonly"),
255 EXACTLY_TWO_DASHES
},
256 { {"output", required_argument
, NULL
, 'o'},
257 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
258 { {NULL
, required_argument
, NULL
, '\0'},
259 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
260 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
261 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
262 { {"emit-relocs", no_argument
, NULL
, 'q'},
263 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
264 { {"relocatable", no_argument
, NULL
, 'r'},
265 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
266 { {NULL
, no_argument
, NULL
, '\0'},
267 'i', NULL
, NULL
, ONE_DASH
},
268 { {"just-symbols", required_argument
, NULL
, 'R'},
269 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
271 { {"strip-all", no_argument
, NULL
, 's'},
272 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
273 { {"strip-debug", no_argument
, NULL
, 'S'},
274 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
275 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
276 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
277 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
278 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
279 { {"trace", no_argument
, NULL
, 't'},
280 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
281 { {"script", required_argument
, NULL
, 'T'},
282 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
283 { {"undefined", required_argument
, NULL
, 'u'},
284 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
286 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
287 '\0', N_("[=SECTION]"),
288 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
289 { {"Ur", no_argument
, NULL
, OPTION_UR
},
290 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
291 { {"version", no_argument
, NULL
, OPTION_VERSION
},
292 'v', NULL
, N_("Print version information"), TWO_DASHES
},
293 { {NULL
, no_argument
, NULL
, '\0'},
294 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
295 { {"discard-all", no_argument
, NULL
, 'x'},
296 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
297 { {"discard-locals", no_argument
, NULL
, 'X'},
298 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
299 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
300 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
301 { {"trace-symbol", required_argument
, NULL
, 'y'},
302 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
303 { {NULL
, required_argument
, NULL
, '\0'},
304 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
306 { {"start-group", no_argument
, NULL
, '('},
307 '(', NULL
, N_("Start a group"), TWO_DASHES
},
308 { {"end-group", no_argument
, NULL
, ')'},
309 ')', NULL
, N_("End a group"), TWO_DASHES
},
310 { {"accept-unknown-input-arch", no_argument
, NULL
,
311 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
313 N_("Accept input files whose architecture cannot be determined"),
315 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
316 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
317 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
319 { {"add-needed", no_argument
, NULL
, OPTION_ADD_NEEDED
},
320 '\0', NULL
, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
321 "\t\t\t\tfollowing dynamic libs"), TWO_DASHES
},
322 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_NEEDED
},
323 '\0', NULL
, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
324 "\t\t\t\tin following dynamic libs"), TWO_DASHES
},
325 { {"as-needed", no_argument
, NULL
, OPTION_AS_NEEDED
},
326 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
328 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_AS_NEEDED
},
329 '\0', NULL
, N_("Always set DT_NEEDED for following dynamic libs"),
331 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
332 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
333 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
334 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
335 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
336 '\0', NULL
, NULL
, ONE_DASH
},
337 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
338 '\0', NULL
, NULL
, ONE_DASH
},
339 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
340 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
341 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
342 '\0', NULL
, NULL
, ONE_DASH
},
343 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
344 '\0', NULL
, NULL
, ONE_DASH
},
345 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
346 '\0', NULL
, NULL
, ONE_DASH
},
347 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
348 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
349 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
350 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
352 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
353 '\0', NULL
, N_("Do not check section addresses for overlaps"),
355 { {"cref", no_argument
, NULL
, OPTION_CREF
},
356 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
357 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
358 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
359 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
360 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
362 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
363 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
364 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
365 '\0', NULL
, N_("Treat warnings as errors"),
367 { {"fini", required_argument
, NULL
, OPTION_FINI
},
368 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
369 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
370 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
371 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
372 '\0', NULL
, N_("Remove unused sections (on some targets)"),
374 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
375 '\0', NULL
, N_("Don't remove unused sections (default)"),
377 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
378 '\0', NULL
, N_("List removed unused sections on stderr"),
380 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
381 '\0', NULL
, N_("Do not list removed unused sections"),
383 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
384 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
386 { {"help", no_argument
, NULL
, OPTION_HELP
},
387 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
388 { {"init", required_argument
, NULL
, OPTION_INIT
},
389 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
390 { {"Map", required_argument
, NULL
, OPTION_MAP
},
391 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
392 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
393 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
394 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
395 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
396 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
397 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
398 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
399 '\0', NULL
, N_("Do not allow unresolved references in object files"),
401 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
402 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
404 { {"no-allow-shlib-undefined", no_argument
, NULL
,
405 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
406 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
408 { {"allow-multiple-definition", no_argument
, NULL
,
409 OPTION_ALLOW_MULTIPLE_DEFINITION
},
410 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
411 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
412 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
413 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
414 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
415 { {"default-imported-symver", no_argument
, NULL
,
416 OPTION_DEFAULT_IMPORTED_SYMVER
},
417 '\0', NULL
, N_("Create default symbol version for imported symbols"),
419 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
420 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
421 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
422 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
423 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
424 '\0', NULL
, N_("Create an output file even if errors occur"),
426 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
427 '\0', NULL
, NULL
, NO_HELP
},
428 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
429 '\0', NULL
, N_("Only use library directories specified on\n"
430 "\t\t\t\tthe command line"), ONE_DASH
},
431 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
432 '\0', N_("TARGET"), N_("Specify target of output file"),
433 EXACTLY_TWO_DASHES
},
434 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
435 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
436 { {"reduce-memory-overheads", no_argument
, NULL
,
437 OPTION_REDUCE_MEMORY_OVERHEADS
},
438 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
440 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
441 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
442 { {"retain-symbols-file", required_argument
, NULL
,
443 OPTION_RETAIN_SYMBOLS_FILE
},
444 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
445 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
446 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
447 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
448 '\0', N_("PATH"), N_("Set link time shared library search path"),
450 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
451 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
452 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
453 '\0', NULL
, NULL
, ONE_DASH
},
454 { {"pie", no_argument
, NULL
, OPTION_PIE
},
455 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
456 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
457 '\0', NULL
, NULL
, TWO_DASHES
},
458 { {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
459 '\0', NULL
, N_("Sort common symbols by size"), TWO_DASHES
},
460 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
461 '\0', NULL
, NULL
, NO_HELP
},
462 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
463 '\0', N_("name|alignment"),
464 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
465 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
466 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
468 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
469 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
471 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
472 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
474 { {"stats", no_argument
, NULL
, OPTION_STATS
},
475 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
476 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
477 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
478 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
479 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
480 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
481 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
482 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
483 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
485 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
486 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
487 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
488 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
489 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
490 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
491 { {"unresolved-symbols=<method>", required_argument
, NULL
,
492 OPTION_UNRESOLVED_SYMBOLS
},
493 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
494 "\t\t\t\tignore-all, report-all, ignore-in-object-files,\n"
495 "\t\t\t\tignore-in-shared-libs"), TWO_DASHES
},
496 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
497 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
498 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
499 '\0', NULL
, NULL
, NO_HELP
},
500 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
501 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
502 { {"version-exports-section", required_argument
, NULL
,
503 OPTION_VERSION_EXPORTS_SECTION
},
504 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
505 "\t\t\t\tSYMBOL as the version."), TWO_DASHES
},
506 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
507 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
508 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
509 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
510 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
511 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
512 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
513 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
515 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
516 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
517 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
518 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
519 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
520 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
522 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
523 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
525 { {"warn-unresolved-symbols", no_argument
, NULL
,
526 OPTION_WARN_UNRESOLVED_SYMBOLS
},
527 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
528 { {"error-unresolved-symbols", no_argument
, NULL
,
529 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
530 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
531 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
532 '\0', NULL
, N_("Include all objects from following archives"),
534 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
535 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
538 #define OPTION_COUNT ARRAY_SIZE (ld_options)
541 parse_args (unsigned argc
, char **argv
)
546 char *default_dirlist
= NULL
;
548 struct option
*longopts
;
549 struct option
*really_longopts
;
551 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
553 shortopts
= xmalloc (OPTION_COUNT
* 3 + 2);
554 longopts
= xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
555 really_longopts
= xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
557 /* Starting the short option string with '-' is for programs that
558 expect options and other ARGV-elements in any order and that care about
559 the ordering of the two. We describe each non-option ARGV-element
560 as if it were the argument of an option with character code 1. */
565 for (i
= 0; i
< OPTION_COUNT
; i
++)
567 if (ld_options
[i
].shortopt
!= '\0')
569 shortopts
[is
] = ld_options
[i
].shortopt
;
571 if (ld_options
[i
].opt
.has_arg
== required_argument
572 || ld_options
[i
].opt
.has_arg
== optional_argument
)
576 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
583 if (ld_options
[i
].opt
.name
!= NULL
)
585 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
587 really_longopts
[irl
] = ld_options
[i
].opt
;
592 longopts
[il
] = ld_options
[i
].opt
;
597 shortopts
[is
] = '\0';
598 longopts
[il
].name
= NULL
;
599 really_longopts
[irl
].name
= NULL
;
601 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
603 /* The -G option is ambiguous on different platforms. Sometimes it
604 specifies the largest data size to put into the small data
605 section. Sometimes it is equivalent to --shared. Unfortunately,
606 the first form takes an argument, while the second does not.
608 We need to permit the --shared form because on some platforms,
609 such as Solaris, gcc -shared will pass -G to the linker.
611 To permit either usage, we look through the argument list. If we
612 find -G not followed by a number, we change it into --shared.
613 This will work for most normal cases. */
614 for (i
= 1; i
< argc
; i
++)
615 if (strcmp (argv
[i
], "-G") == 0
617 || ! ISDIGIT (argv
[i
+ 1][0])))
618 argv
[i
] = (char *) "--shared";
620 /* Because we permit long options to start with a single dash, and
621 we have a --library option, and the -l option is conventionally
622 used with an immediately following argument, we can have bad
623 results if somebody tries to use -l with a library whose name
624 happens to start with "ibrary", as in -li. We avoid problems by
625 simply turning -l into --library. This means that users will
626 have to use two dashes in order to use --library, which is OK
627 since that's how it is documented.
629 FIXME: It's possible that this problem can arise for other short
630 options as well, although the user does always have the recourse
631 of adding a space between the option and the argument. */
632 for (i
= 1; i
< argc
; i
++)
634 if (argv
[i
][0] == '-'
636 && argv
[i
][2] != '\0')
640 n
= xmalloc (strlen (argv
[i
]) + 20);
641 sprintf (n
, "--library=%s", argv
[i
] + 2);
652 /* Using last_optind lets us avoid calling ldemul_parse_args
653 multiple times on a single option, which would lead to
654 confusion in the internal static variables maintained by
655 getopt. This could otherwise happen for an argument like
656 -nx, in which the -n is parsed as a single option, and we
657 loop around to pick up the -x. */
658 if (optind
!= last_optind
)
659 if (ldemul_parse_args (argc
, argv
))
662 /* getopt_long_only is like getopt_long, but '-' as well as '--'
663 can indicate a long option. */
665 last_optind
= optind
;
666 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
669 optind
= last_optind
;
670 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
673 if (ldemul_handle_option (optc
))
682 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
686 einfo (_("%P%F: use the --help option for usage information\n"));
688 case 1: /* File name. */
689 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
695 /* For HP/UX compatibility. Actually -a shared should mean
696 ``use only shared libraries'' but, then, we don't
697 currently support shared libraries on HP/UX anyhow. */
698 if (strcmp (optarg
, "archive") == 0)
699 config
.dynamic_link
= FALSE
;
700 else if (strcmp (optarg
, "shared") == 0
701 || strcmp (optarg
, "default") == 0)
702 config
.dynamic_link
= TRUE
;
704 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
707 /* FIXME: We just ignore these, but we should handle them. */
708 if (strcmp (optarg
, "definitions") == 0)
710 else if (strcmp (optarg
, "nodefinitions") == 0)
712 else if (strcmp (optarg
, "nosymbolic") == 0)
714 else if (strcmp (optarg
, "pure-text") == 0)
717 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
720 ldfile_add_arch (optarg
);
723 lang_add_target (optarg
);
726 ldfile_open_command_file (optarg
);
727 parser_input
= input_mri_script
;
730 case OPTION_CALL_SHARED
:
731 config
.dynamic_link
= TRUE
;
733 case OPTION_NON_SHARED
:
734 config
.dynamic_link
= FALSE
;
737 command_line
.cref
= TRUE
;
738 link_info
.notice_all
= TRUE
;
741 command_line
.force_common_definition
= TRUE
;
745 lex_redirect (optarg
);
746 parser_input
= input_defsym
;
752 case OPTION_DEMANGLE
:
756 enum demangling_styles style
;
758 style
= cplus_demangle_name_to_style (optarg
);
759 if (style
== unknown_demangling
)
760 einfo (_("%F%P: unknown demangling style `%s'"),
763 cplus_demangle_set_style (style
);
766 case 'I': /* Used on Solaris. */
767 case OPTION_DYNAMIC_LINKER
:
768 command_line
.interpreter
= optarg
;
771 /* Already handled in ldmain.c. */
774 command_line
.endian
= ENDIAN_BIG
;
777 command_line
.endian
= ENDIAN_LITTLE
;
779 case OPTION_EMBEDDED_RELOCS
:
780 command_line
.embedded_relocs
= TRUE
;
782 case OPTION_EXPORT_DYNAMIC
:
783 case 'E': /* HP/UX compatibility. */
784 link_info
.export_dynamic
= TRUE
;
787 lang_add_entry (optarg
, TRUE
);
790 if (command_line
.auxiliary_filters
== NULL
)
792 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
793 command_line
.auxiliary_filters
[0] = optarg
;
794 command_line
.auxiliary_filters
[1] = NULL
;
802 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
804 command_line
.auxiliary_filters
805 = xrealloc (command_line
.auxiliary_filters
,
806 (c
+ 2) * sizeof (char *));
807 command_line
.auxiliary_filters
[c
] = optarg
;
808 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
812 command_line
.filter_shlib
= optarg
;
814 case OPTION_FORCE_EXE_SUFFIX
:
815 command_line
.force_exe_suffix
= TRUE
;
820 g_switch_value
= strtoul (optarg
, &end
, 0);
822 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
828 case OPTION_GC_SECTIONS
:
829 link_info
.gc_sections
= TRUE
;
831 case OPTION_PRINT_GC_SECTIONS
:
832 link_info
.print_gc_sections
= TRUE
;
839 ldfile_add_library_path (optarg
, TRUE
);
842 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
845 config
.map_filename
= "-";
848 /* Ignore. Was handled in a pre-parse. */
851 config
.map_filename
= optarg
;
854 config
.text_read_only
= FALSE
;
855 config
.magic_demand_paged
= FALSE
;
856 config
.dynamic_link
= FALSE
;
858 case OPTION_NO_OMAGIC
:
859 config
.text_read_only
= TRUE
;
860 config
.magic_demand_paged
= TRUE
;
861 /* NB/ Does not set dynamic_link to TRUE.
862 Use --call-shared or -Bdynamic for this. */
865 config
.magic_demand_paged
= FALSE
;
866 config
.dynamic_link
= FALSE
;
868 case OPTION_NO_DEFINE_COMMON
:
869 command_line
.inhibit_common_definition
= TRUE
;
871 case OPTION_NO_DEMANGLE
:
874 case OPTION_NO_GC_SECTIONS
:
875 link_info
.gc_sections
= FALSE
;
877 case OPTION_NO_PRINT_GC_SECTIONS
:
878 link_info
.print_gc_sections
= FALSE
;
880 case OPTION_NO_KEEP_MEMORY
:
881 link_info
.keep_memory
= FALSE
;
883 case OPTION_NO_UNDEFINED
:
884 link_info
.unresolved_syms_in_objects
885 = how_to_report_unresolved_symbols
;
887 case OPTION_ALLOW_SHLIB_UNDEFINED
:
888 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
890 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
891 link_info
.unresolved_syms_in_shared_libs
892 = how_to_report_unresolved_symbols
;
894 case OPTION_UNRESOLVED_SYMBOLS
:
895 if (strcmp (optarg
, "ignore-all") == 0)
897 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
898 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
900 else if (strcmp (optarg
, "report-all") == 0)
902 link_info
.unresolved_syms_in_objects
903 = how_to_report_unresolved_symbols
;
904 link_info
.unresolved_syms_in_shared_libs
905 = how_to_report_unresolved_symbols
;
907 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
909 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
910 link_info
.unresolved_syms_in_shared_libs
911 = how_to_report_unresolved_symbols
;
913 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
915 link_info
.unresolved_syms_in_objects
916 = how_to_report_unresolved_symbols
;
917 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
920 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
922 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
923 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
924 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
925 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
926 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
927 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
930 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
931 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
932 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
933 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
934 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
935 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
937 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
938 link_info
.allow_multiple_definition
= TRUE
;
940 case OPTION_NO_UNDEFINED_VERSION
:
941 link_info
.allow_undefined_version
= FALSE
;
943 case OPTION_DEFAULT_SYMVER
:
944 link_info
.create_default_symver
= TRUE
;
946 case OPTION_DEFAULT_IMPORTED_SYMVER
:
947 link_info
.default_imported_symver
= TRUE
;
949 case OPTION_NO_WARN_MISMATCH
:
950 command_line
.warn_mismatch
= FALSE
;
952 case OPTION_NOINHIBIT_EXEC
:
953 force_make_executable
= TRUE
;
955 case OPTION_NOSTDLIB
:
956 config
.only_cmd_line_lib_dirs
= TRUE
;
958 case OPTION_NO_WHOLE_ARCHIVE
:
959 whole_archive
= FALSE
;
962 /* FIXME "-O<non-digits> <value>" used to set the address of
963 section <non-digits>. Was this for compatibility with
964 something, or can we create a new option to do that
965 (with a syntax similar to -defsym)?
966 getopt can't handle two args to an option without kludges. */
968 /* Enable optimizations of output files. */
969 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
972 lang_add_output (optarg
, 0);
975 lang_add_output_format (optarg
, NULL
, NULL
, 0);
978 link_info
.emitrelocations
= TRUE
;
982 if (optind
== last_optind
)
983 /* This can happen if the user put "-rpath,a" on the command
984 line. (Or something similar. The comma is important).
985 Getopt becomes confused and thinks that this is a -r option
986 but it cannot parse the text after the -r so it refuses to
987 increment the optind counter. Detect this case and issue
988 an error message here. We cannot just make this a warning,
989 increment optind, and continue because getopt is too confused
990 and will seg-fault the next time around. */
991 einfo(_("%P%F: bad -rpath option\n"));
993 link_info
.relocatable
= TRUE
;
994 config
.build_constructors
= FALSE
;
995 config
.magic_demand_paged
= FALSE
;
996 config
.text_read_only
= FALSE
;
997 config
.dynamic_link
= FALSE
;
1000 /* The GNU linker traditionally uses -R to mean to include
1001 only the symbols from a file. The Solaris linker uses -R
1002 to set the path used by the runtime linker to find
1003 libraries. This is the GNU linker -rpath argument. We
1004 try to support both simultaneously by checking the file
1005 named. If it is a directory, rather than a regular file,
1006 we assume -rpath was meant. */
1010 if (stat (optarg
, &s
) >= 0
1011 && ! S_ISDIR (s
.st_mode
))
1013 lang_add_input_file (optarg
,
1014 lang_input_file_is_symbols_only_enum
,
1021 if (command_line
.rpath
== NULL
)
1022 command_line
.rpath
= xstrdup (optarg
);
1025 size_t rpath_len
= strlen (command_line
.rpath
);
1026 size_t optarg_len
= strlen (optarg
);
1028 char *cp
= command_line
.rpath
;
1030 /* First see whether OPTARG is already in the path. */
1035 while (optarg
[idx
] != '\0' && optarg
[idx
] == cp
[idx
])
1037 if (optarg
[idx
] == '\0'
1038 && (cp
[idx
] == '\0' || cp
[idx
] == ':'))
1042 /* Not yet found. */
1043 cp
= strchr (cp
, ':');
1051 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1052 sprintf (buf
, "%s:%s", command_line
.rpath
, optarg
);
1053 free (command_line
.rpath
);
1054 command_line
.rpath
= buf
;
1058 case OPTION_RPATH_LINK
:
1059 if (command_line
.rpath_link
== NULL
)
1060 command_line
.rpath_link
= xstrdup (optarg
);
1065 buf
= xmalloc (strlen (command_line
.rpath_link
)
1068 sprintf (buf
, "%s:%s", command_line
.rpath_link
, optarg
);
1069 free (command_line
.rpath_link
);
1070 command_line
.rpath_link
= buf
;
1074 command_line
.relax
= TRUE
;
1076 case OPTION_RETAIN_SYMBOLS_FILE
:
1077 add_keepsyms_file (optarg
);
1080 link_info
.strip
= strip_debugger
;
1083 link_info
.strip
= strip_all
;
1085 case OPTION_STRIP_DISCARDED
:
1086 link_info
.strip_discarded
= TRUE
;
1088 case OPTION_NO_STRIP_DISCARDED
:
1089 link_info
.strip_discarded
= FALSE
;
1092 if (config
.has_shared
)
1094 link_info
.shared
= TRUE
;
1095 /* When creating a shared library, the default
1096 behaviour is to ignore any unresolved references. */
1097 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1098 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1099 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1100 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1103 einfo (_("%P%F: -shared not supported\n"));
1106 if (config
.has_shared
)
1108 link_info
.shared
= TRUE
;
1109 link_info
.pie
= TRUE
;
1112 einfo (_("%P%F: -pie not supported\n"));
1114 case 'h': /* Used on Solaris. */
1116 command_line
.soname
= optarg
;
1118 case OPTION_SORT_COMMON
:
1119 config
.sort_common
= TRUE
;
1121 case OPTION_SORT_SECTION
:
1122 if (strcmp (optarg
, N_("name")) == 0)
1123 sort_section
= by_name
;
1124 else if (strcmp (optarg
, N_("alignment")) == 0)
1125 sort_section
= by_alignment
;
1127 einfo (_("%P%F: invalid section sorting option: %s\n"),
1131 config
.stats
= TRUE
;
1133 case OPTION_SYMBOLIC
:
1134 link_info
.symbolic
= TRUE
;
1140 ldfile_open_command_file (optarg
);
1141 parser_input
= input_script
;
1144 case OPTION_SECTION_START
:
1150 /* Check for <something>=<somthing>... */
1151 optarg2
= strchr (optarg
, '=');
1152 if (optarg2
== NULL
)
1153 einfo (_("%P%F: invalid argument to option"
1154 " \"--section-start\"\n"));
1158 /* So far so good. Are all the args present? */
1159 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1160 einfo (_("%P%F: missing argument(s) to option"
1161 " \"--section-start\"\n"));
1163 /* We must copy the section name as set_section_start
1164 doesn't do it for us. */
1165 len
= optarg2
- optarg
;
1166 sec_name
= xmalloc (len
);
1167 memcpy (sec_name
, optarg
, len
- 1);
1168 sec_name
[len
- 1] = 0;
1170 /* Then set it... */
1171 set_section_start (sec_name
, optarg2
);
1174 case OPTION_TARGET_HELP
:
1175 /* Mention any target specific options. */
1176 ldemul_list_emulation_options (stdout
);
1179 set_segment_start (".bss", optarg
);
1182 set_segment_start (".data", optarg
);
1185 set_segment_start (".text", optarg
);
1187 case OPTION_TRADITIONAL_FORMAT
:
1188 link_info
.traditional_format
= TRUE
;
1190 case OPTION_TASK_LINK
:
1191 link_info
.task_link
= TRUE
;
1192 /* Fall through - do an implied -r option. */
1194 link_info
.relocatable
= TRUE
;
1195 config
.build_constructors
= TRUE
;
1196 config
.magic_demand_paged
= FALSE
;
1197 config
.text_read_only
= FALSE
;
1198 config
.dynamic_link
= FALSE
;
1201 ldlang_add_undef (optarg
);
1205 lang_add_unique (optarg
);
1207 config
.unique_orphan_sections
= TRUE
;
1209 case OPTION_VERBOSE
:
1211 version_printed
= TRUE
;
1212 trace_file_tries
= TRUE
;
1213 overflow_cutoff_limit
= -2;
1217 version_printed
= TRUE
;
1221 version_printed
= TRUE
;
1223 case OPTION_VERSION
:
1227 case OPTION_VERSION_SCRIPT
:
1228 /* This option indicates a small script that only specifies
1229 version information. Read it, but don't assume that
1230 we've seen a linker script. */
1232 FILE *hold_script_handle
;
1234 hold_script_handle
= saved_script_handle
;
1235 ldfile_open_command_file (optarg
);
1236 saved_script_handle
= hold_script_handle
;
1237 parser_input
= input_version_script
;
1241 case OPTION_VERSION_EXPORTS_SECTION
:
1242 /* This option records a version symbol to be applied to the
1243 symbols listed for export to be found in the object files
1244 .exports sections. */
1245 command_line
.version_exports_section
= optarg
;
1247 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1248 lang_append_dynamic_list_cpp_typeinfo ();
1250 case OPTION_DYNAMIC_LIST
:
1251 /* This option indicates a small script that only specifies
1252 a dynamic list. Read it, but don't assume that we've
1253 seen a linker script. */
1255 FILE *hold_script_handle
;
1257 hold_script_handle
= saved_script_handle
;
1258 ldfile_open_command_file (optarg
);
1259 saved_script_handle
= hold_script_handle
;
1260 parser_input
= input_dynamic_list
;
1264 case OPTION_WARN_COMMON
:
1265 config
.warn_common
= TRUE
;
1267 case OPTION_WARN_CONSTRUCTORS
:
1268 config
.warn_constructors
= TRUE
;
1270 case OPTION_WARN_FATAL
:
1271 config
.fatal_warnings
= TRUE
;
1273 case OPTION_WARN_MULTIPLE_GP
:
1274 config
.warn_multiple_gp
= TRUE
;
1276 case OPTION_WARN_ONCE
:
1277 config
.warn_once
= TRUE
;
1279 case OPTION_WARN_SECTION_ALIGN
:
1280 config
.warn_section_align
= TRUE
;
1282 case OPTION_WARN_SHARED_TEXTREL
:
1283 link_info
.warn_shared_textrel
= TRUE
;
1285 case OPTION_WHOLE_ARCHIVE
:
1286 whole_archive
= TRUE
;
1288 case OPTION_ADD_NEEDED
:
1291 case OPTION_NO_ADD_NEEDED
:
1294 case OPTION_AS_NEEDED
:
1297 case OPTION_NO_AS_NEEDED
:
1303 case OPTION_DISCARD_NONE
:
1304 link_info
.discard
= discard_none
;
1307 link_info
.discard
= discard_l
;
1310 link_info
.discard
= discard_all
;
1313 if (CONST_STRNEQ (optarg
, "P,"))
1315 if (default_dirlist
!= NULL
)
1316 free (default_dirlist
);
1317 default_dirlist
= xstrdup (optarg
);
1322 case OPTION_SPARE_DYNAMIC_TAGS
:
1323 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1325 case OPTION_SPLIT_BY_RELOC
:
1327 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1329 config
.split_by_reloc
= 32768;
1331 case OPTION_SPLIT_BY_FILE
:
1333 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1335 config
.split_by_file
= 1;
1337 case OPTION_CHECK_SECTIONS
:
1338 command_line
.check_section_addresses
= TRUE
;
1340 case OPTION_NO_CHECK_SECTIONS
:
1341 command_line
.check_section_addresses
= FALSE
;
1343 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1344 command_line
.accept_unknown_input_arch
= TRUE
;
1346 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1347 command_line
.accept_unknown_input_arch
= FALSE
;
1351 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1353 lang_enter_group ();
1358 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1360 lang_leave_group ();
1365 link_info
.init_function
= optarg
;
1369 link_info
.fini_function
= optarg
;
1372 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1373 link_info
.reduce_memory_overheads
= TRUE
;
1374 if (config
.hash_table_size
== 0)
1375 config
.hash_table_size
= 1021;
1378 case OPTION_HASH_SIZE
:
1380 bfd_size_type new_size
;
1382 new_size
= strtoul (optarg
, NULL
, 0);
1384 config
.hash_table_size
= new_size
;
1386 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1393 lang_leave_group ();
1395 if (default_dirlist
!= NULL
)
1397 set_default_dirlist (default_dirlist
);
1398 free (default_dirlist
);
1401 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1402 /* FIXME: Should we allow emulations a chance to set this ? */
1403 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1405 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1406 /* FIXME: Should we allow emulations a chance to set this ? */
1407 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1410 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1411 library search path. */
1414 set_default_dirlist (char *dirlist_ptr
)
1420 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1423 if (*dirlist_ptr
!= '\0')
1424 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1427 dirlist_ptr
= p
+ 1;
1432 set_section_start (char *sect
, char *valstr
)
1435 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1437 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1438 lang_section_start (sect
, exp_intop (val
), NULL
);
1442 set_segment_start (const char *section
, char *valstr
)
1448 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1450 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1451 /* If we already have an entry for this segment, update the existing
1454 for (seg
= segments
; seg
; seg
= seg
->next
)
1455 if (strcmp (seg
->name
, name
) == 0)
1460 /* There was no existing value so we must create a new segment
1462 seg
= stat_alloc (sizeof (*seg
));
1466 /* Add it to the linked list of segments. */
1467 seg
->next
= segments
;
1469 /* Historically, -Ttext and friends set the base address of a
1470 particular section. For backwards compatibility, we still do
1471 that. If a SEGMENT_START directive is seen, the section address
1472 assignment will be disabled. */
1473 lang_section_start (section
, exp_intop (val
), seg
);
1477 /* Print help messages for the options. */
1483 const char **targets
, **pp
;
1486 printf (_("Usage: %s [options] file...\n"), program_name
);
1488 printf (_("Options:\n"));
1489 for (i
= 0; i
< OPTION_COUNT
; i
++)
1491 if (ld_options
[i
].doc
!= NULL
)
1504 if (ld_options
[j
].shortopt
!= '\0'
1505 && ld_options
[j
].control
!= NO_HELP
)
1507 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1508 len
+= (comma
? 2 : 0) + 2;
1509 if (ld_options
[j
].arg
!= NULL
)
1511 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1516 printf ("%s", _(ld_options
[j
].arg
));
1517 len
+= strlen (_(ld_options
[j
].arg
));
1523 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1528 if (ld_options
[j
].opt
.name
!= NULL
1529 && ld_options
[j
].control
!= NO_HELP
)
1532 (ld_options
[j
].control
== TWO_DASHES
1533 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1537 two_dashes
? "-" : "",
1538 ld_options
[j
].opt
.name
);
1539 len
+= ((comma
? 2 : 0)
1541 + (two_dashes
? 1 : 0)
1542 + strlen (ld_options
[j
].opt
.name
));
1543 if (ld_options
[j
].arg
!= NULL
)
1545 printf (" %s", _(ld_options
[j
].arg
));
1546 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1552 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1560 for (; len
< 30; len
++)
1563 printf ("%s\n", _(ld_options
[i
].doc
));
1566 printf (_(" @FILE"));
1567 for (len
= strlen (" @FILE"); len
< 30; len
++)
1569 printf (_("Read options from FILE\n"));
1571 /* Note: Various tools (such as libtool) depend upon the
1572 format of the listings below - do not change them. */
1573 /* xgettext:c-format */
1574 printf (_("%s: supported targets:"), program_name
);
1575 targets
= bfd_target_list ();
1576 for (pp
= targets
; *pp
!= NULL
; pp
++)
1577 printf (" %s", *pp
);
1581 /* xgettext:c-format */
1582 printf (_("%s: supported emulations: "), program_name
);
1583 ldemul_list_emulations (stdout
);
1586 /* xgettext:c-format */
1587 printf (_("%s: emulation specific options:\n"), program_name
);
1588 ldemul_list_emulation_options (stdout
);
1591 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);