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
]);
684 einfo (_("%P%F: use the --help option for usage information\n"));
686 case 1: /* File name. */
687 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
693 /* For HP/UX compatibility. Actually -a shared should mean
694 ``use only shared libraries'' but, then, we don't
695 currently support shared libraries on HP/UX anyhow. */
696 if (strcmp (optarg
, "archive") == 0)
697 config
.dynamic_link
= FALSE
;
698 else if (strcmp (optarg
, "shared") == 0
699 || strcmp (optarg
, "default") == 0)
700 config
.dynamic_link
= TRUE
;
702 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
705 /* FIXME: We just ignore these, but we should handle them. */
706 if (strcmp (optarg
, "definitions") == 0)
708 else if (strcmp (optarg
, "nodefinitions") == 0)
710 else if (strcmp (optarg
, "nosymbolic") == 0)
712 else if (strcmp (optarg
, "pure-text") == 0)
715 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
718 ldfile_add_arch (optarg
);
721 lang_add_target (optarg
);
724 ldfile_open_command_file (optarg
);
725 parser_input
= input_mri_script
;
728 case OPTION_CALL_SHARED
:
729 config
.dynamic_link
= TRUE
;
731 case OPTION_NON_SHARED
:
732 config
.dynamic_link
= FALSE
;
735 command_line
.cref
= TRUE
;
736 link_info
.notice_all
= TRUE
;
739 command_line
.force_common_definition
= TRUE
;
743 lex_redirect (optarg
);
744 parser_input
= input_defsym
;
750 case OPTION_DEMANGLE
:
754 enum demangling_styles style
;
756 style
= cplus_demangle_name_to_style (optarg
);
757 if (style
== unknown_demangling
)
758 einfo (_("%F%P: unknown demangling style `%s'"),
761 cplus_demangle_set_style (style
);
764 case 'I': /* Used on Solaris. */
765 case OPTION_DYNAMIC_LINKER
:
766 command_line
.interpreter
= optarg
;
769 /* Already handled in ldmain.c. */
772 command_line
.endian
= ENDIAN_BIG
;
775 command_line
.endian
= ENDIAN_LITTLE
;
777 case OPTION_EMBEDDED_RELOCS
:
778 command_line
.embedded_relocs
= TRUE
;
780 case OPTION_EXPORT_DYNAMIC
:
781 case 'E': /* HP/UX compatibility. */
782 link_info
.export_dynamic
= TRUE
;
785 lang_add_entry (optarg
, TRUE
);
788 if (command_line
.auxiliary_filters
== NULL
)
790 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
791 command_line
.auxiliary_filters
[0] = optarg
;
792 command_line
.auxiliary_filters
[1] = NULL
;
800 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
802 command_line
.auxiliary_filters
803 = xrealloc (command_line
.auxiliary_filters
,
804 (c
+ 2) * sizeof (char *));
805 command_line
.auxiliary_filters
[c
] = optarg
;
806 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
810 command_line
.filter_shlib
= optarg
;
812 case OPTION_FORCE_EXE_SUFFIX
:
813 command_line
.force_exe_suffix
= TRUE
;
818 g_switch_value
= strtoul (optarg
, &end
, 0);
820 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
826 case OPTION_GC_SECTIONS
:
827 link_info
.gc_sections
= TRUE
;
829 case OPTION_PRINT_GC_SECTIONS
:
830 link_info
.print_gc_sections
= TRUE
;
837 ldfile_add_library_path (optarg
, TRUE
);
840 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
843 config
.map_filename
= "-";
846 /* Ignore. Was handled in a pre-parse. */
849 config
.map_filename
= optarg
;
852 config
.text_read_only
= FALSE
;
853 config
.magic_demand_paged
= FALSE
;
854 config
.dynamic_link
= FALSE
;
856 case OPTION_NO_OMAGIC
:
857 config
.text_read_only
= TRUE
;
858 config
.magic_demand_paged
= TRUE
;
859 /* NB/ Does not set dynamic_link to TRUE.
860 Use --call-shared or -Bdynamic for this. */
863 config
.magic_demand_paged
= FALSE
;
864 config
.dynamic_link
= FALSE
;
866 case OPTION_NO_DEFINE_COMMON
:
867 command_line
.inhibit_common_definition
= TRUE
;
869 case OPTION_NO_DEMANGLE
:
872 case OPTION_NO_GC_SECTIONS
:
873 link_info
.gc_sections
= FALSE
;
875 case OPTION_NO_PRINT_GC_SECTIONS
:
876 link_info
.print_gc_sections
= FALSE
;
878 case OPTION_NO_KEEP_MEMORY
:
879 link_info
.keep_memory
= FALSE
;
881 case OPTION_NO_UNDEFINED
:
882 link_info
.unresolved_syms_in_objects
883 = how_to_report_unresolved_symbols
;
885 case OPTION_ALLOW_SHLIB_UNDEFINED
:
886 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
888 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
889 link_info
.unresolved_syms_in_shared_libs
890 = how_to_report_unresolved_symbols
;
892 case OPTION_UNRESOLVED_SYMBOLS
:
893 if (strcmp (optarg
, "ignore-all") == 0)
895 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
896 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
898 else if (strcmp (optarg
, "report-all") == 0)
900 link_info
.unresolved_syms_in_objects
901 = how_to_report_unresolved_symbols
;
902 link_info
.unresolved_syms_in_shared_libs
903 = how_to_report_unresolved_symbols
;
905 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
907 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
908 link_info
.unresolved_syms_in_shared_libs
909 = how_to_report_unresolved_symbols
;
911 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
913 link_info
.unresolved_syms_in_objects
914 = how_to_report_unresolved_symbols
;
915 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
918 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
920 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
921 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
922 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
923 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
924 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
925 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
928 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
929 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
930 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
931 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
932 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
933 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
935 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
936 link_info
.allow_multiple_definition
= TRUE
;
938 case OPTION_NO_UNDEFINED_VERSION
:
939 link_info
.allow_undefined_version
= FALSE
;
941 case OPTION_DEFAULT_SYMVER
:
942 link_info
.create_default_symver
= TRUE
;
944 case OPTION_DEFAULT_IMPORTED_SYMVER
:
945 link_info
.default_imported_symver
= TRUE
;
947 case OPTION_NO_WARN_MISMATCH
:
948 command_line
.warn_mismatch
= FALSE
;
950 case OPTION_NOINHIBIT_EXEC
:
951 force_make_executable
= TRUE
;
953 case OPTION_NOSTDLIB
:
954 config
.only_cmd_line_lib_dirs
= TRUE
;
956 case OPTION_NO_WHOLE_ARCHIVE
:
957 whole_archive
= FALSE
;
960 /* FIXME "-O<non-digits> <value>" used to set the address of
961 section <non-digits>. Was this for compatibility with
962 something, or can we create a new option to do that
963 (with a syntax similar to -defsym)?
964 getopt can't handle two args to an option without kludges. */
966 /* Enable optimizations of output files. */
967 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
970 lang_add_output (optarg
, 0);
973 lang_add_output_format (optarg
, NULL
, NULL
, 0);
976 link_info
.emitrelocations
= TRUE
;
980 if (optind
== last_optind
)
981 /* This can happen if the user put "-rpath,a" on the command
982 line. (Or something similar. The comma is important).
983 Getopt becomes confused and thinks that this is a -r option
984 but it cannot parse the text after the -r so it refuses to
985 increment the optind counter. Detect this case and issue
986 an error message here. We cannot just make this a warning,
987 increment optind, and continue because getopt is too confused
988 and will seg-fault the next time around. */
989 einfo(_("%P%F: bad -rpath option\n"));
991 link_info
.relocatable
= TRUE
;
992 config
.build_constructors
= FALSE
;
993 config
.magic_demand_paged
= FALSE
;
994 config
.text_read_only
= FALSE
;
995 config
.dynamic_link
= FALSE
;
998 /* The GNU linker traditionally uses -R to mean to include
999 only the symbols from a file. The Solaris linker uses -R
1000 to set the path used by the runtime linker to find
1001 libraries. This is the GNU linker -rpath argument. We
1002 try to support both simultaneously by checking the file
1003 named. If it is a directory, rather than a regular file,
1004 we assume -rpath was meant. */
1008 if (stat (optarg
, &s
) >= 0
1009 && ! S_ISDIR (s
.st_mode
))
1011 lang_add_input_file (optarg
,
1012 lang_input_file_is_symbols_only_enum
,
1019 if (command_line
.rpath
== NULL
)
1020 command_line
.rpath
= xstrdup (optarg
);
1023 size_t rpath_len
= strlen (command_line
.rpath
);
1024 size_t optarg_len
= strlen (optarg
);
1026 char *cp
= command_line
.rpath
;
1028 /* First see whether OPTARG is already in the path. */
1033 while (optarg
[idx
] != '\0' && optarg
[idx
] == cp
[idx
])
1035 if (optarg
[idx
] == '\0'
1036 && (cp
[idx
] == '\0' || cp
[idx
] == ':'))
1040 /* Not yet found. */
1041 cp
= strchr (cp
, ':');
1049 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1050 sprintf (buf
, "%s:%s", command_line
.rpath
, optarg
);
1051 free (command_line
.rpath
);
1052 command_line
.rpath
= buf
;
1056 case OPTION_RPATH_LINK
:
1057 if (command_line
.rpath_link
== NULL
)
1058 command_line
.rpath_link
= xstrdup (optarg
);
1063 buf
= xmalloc (strlen (command_line
.rpath_link
)
1066 sprintf (buf
, "%s:%s", command_line
.rpath_link
, optarg
);
1067 free (command_line
.rpath_link
);
1068 command_line
.rpath_link
= buf
;
1072 command_line
.relax
= TRUE
;
1074 case OPTION_RETAIN_SYMBOLS_FILE
:
1075 add_keepsyms_file (optarg
);
1078 link_info
.strip
= strip_debugger
;
1081 link_info
.strip
= strip_all
;
1083 case OPTION_STRIP_DISCARDED
:
1084 link_info
.strip_discarded
= TRUE
;
1086 case OPTION_NO_STRIP_DISCARDED
:
1087 link_info
.strip_discarded
= FALSE
;
1090 if (config
.has_shared
)
1092 link_info
.shared
= TRUE
;
1093 /* When creating a shared library, the default
1094 behaviour is to ignore any unresolved references. */
1095 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1096 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1097 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1098 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1101 einfo (_("%P%F: -shared not supported\n"));
1104 if (config
.has_shared
)
1106 link_info
.shared
= TRUE
;
1107 link_info
.pie
= TRUE
;
1110 einfo (_("%P%F: -pie not supported\n"));
1112 case 'h': /* Used on Solaris. */
1114 command_line
.soname
= optarg
;
1116 case OPTION_SORT_COMMON
:
1117 config
.sort_common
= TRUE
;
1119 case OPTION_SORT_SECTION
:
1120 if (strcmp (optarg
, N_("name")) == 0)
1121 sort_section
= by_name
;
1122 else if (strcmp (optarg
, N_("alignment")) == 0)
1123 sort_section
= by_alignment
;
1125 einfo (_("%P%F: invalid section sorting option: %s\n"),
1129 config
.stats
= TRUE
;
1131 case OPTION_SYMBOLIC
:
1132 link_info
.symbolic
= TRUE
;
1138 ldfile_open_command_file (optarg
);
1139 parser_input
= input_script
;
1142 case OPTION_SECTION_START
:
1148 /* Check for <something>=<somthing>... */
1149 optarg2
= strchr (optarg
, '=');
1150 if (optarg2
== NULL
)
1151 einfo (_("%P%F: invalid argument to option"
1152 " \"--section-start\"\n"));
1156 /* So far so good. Are all the args present? */
1157 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1158 einfo (_("%P%F: missing argument(s) to option"
1159 " \"--section-start\"\n"));
1161 /* We must copy the section name as set_section_start
1162 doesn't do it for us. */
1163 len
= optarg2
- optarg
;
1164 sec_name
= xmalloc (len
);
1165 memcpy (sec_name
, optarg
, len
- 1);
1166 sec_name
[len
- 1] = 0;
1168 /* Then set it... */
1169 set_section_start (sec_name
, optarg2
);
1172 case OPTION_TARGET_HELP
:
1173 /* Mention any target specific options. */
1174 ldemul_list_emulation_options (stdout
);
1177 set_segment_start (".bss", optarg
);
1180 set_segment_start (".data", optarg
);
1183 set_segment_start (".text", optarg
);
1185 case OPTION_TRADITIONAL_FORMAT
:
1186 link_info
.traditional_format
= TRUE
;
1188 case OPTION_TASK_LINK
:
1189 link_info
.task_link
= TRUE
;
1190 /* Fall through - do an implied -r option. */
1192 link_info
.relocatable
= TRUE
;
1193 config
.build_constructors
= TRUE
;
1194 config
.magic_demand_paged
= FALSE
;
1195 config
.text_read_only
= FALSE
;
1196 config
.dynamic_link
= FALSE
;
1199 ldlang_add_undef (optarg
);
1203 lang_add_unique (optarg
);
1205 config
.unique_orphan_sections
= TRUE
;
1207 case OPTION_VERBOSE
:
1209 version_printed
= TRUE
;
1210 trace_file_tries
= TRUE
;
1211 overflow_cutoff_limit
= -2;
1215 version_printed
= TRUE
;
1219 version_printed
= TRUE
;
1221 case OPTION_VERSION
:
1225 case OPTION_VERSION_SCRIPT
:
1226 /* This option indicates a small script that only specifies
1227 version information. Read it, but don't assume that
1228 we've seen a linker script. */
1230 FILE *hold_script_handle
;
1232 hold_script_handle
= saved_script_handle
;
1233 ldfile_open_command_file (optarg
);
1234 saved_script_handle
= hold_script_handle
;
1235 parser_input
= input_version_script
;
1239 case OPTION_VERSION_EXPORTS_SECTION
:
1240 /* This option records a version symbol to be applied to the
1241 symbols listed for export to be found in the object files
1242 .exports sections. */
1243 command_line
.version_exports_section
= optarg
;
1245 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1246 lang_append_dynamic_list_cpp_typeinfo ();
1248 case OPTION_DYNAMIC_LIST
:
1249 /* This option indicates a small script that only specifies
1250 a dynamic list. Read it, but don't assume that we've
1251 seen a linker script. */
1253 FILE *hold_script_handle
;
1255 hold_script_handle
= saved_script_handle
;
1256 ldfile_open_command_file (optarg
);
1257 saved_script_handle
= hold_script_handle
;
1258 parser_input
= input_dynamic_list
;
1262 case OPTION_WARN_COMMON
:
1263 config
.warn_common
= TRUE
;
1265 case OPTION_WARN_CONSTRUCTORS
:
1266 config
.warn_constructors
= TRUE
;
1268 case OPTION_WARN_FATAL
:
1269 config
.fatal_warnings
= TRUE
;
1271 case OPTION_WARN_MULTIPLE_GP
:
1272 config
.warn_multiple_gp
= TRUE
;
1274 case OPTION_WARN_ONCE
:
1275 config
.warn_once
= TRUE
;
1277 case OPTION_WARN_SECTION_ALIGN
:
1278 config
.warn_section_align
= TRUE
;
1280 case OPTION_WARN_SHARED_TEXTREL
:
1281 link_info
.warn_shared_textrel
= TRUE
;
1283 case OPTION_WHOLE_ARCHIVE
:
1284 whole_archive
= TRUE
;
1286 case OPTION_ADD_NEEDED
:
1289 case OPTION_NO_ADD_NEEDED
:
1292 case OPTION_AS_NEEDED
:
1295 case OPTION_NO_AS_NEEDED
:
1301 case OPTION_DISCARD_NONE
:
1302 link_info
.discard
= discard_none
;
1305 link_info
.discard
= discard_l
;
1308 link_info
.discard
= discard_all
;
1311 if (CONST_STRNEQ (optarg
, "P,"))
1313 if (default_dirlist
!= NULL
)
1314 free (default_dirlist
);
1315 default_dirlist
= xstrdup (optarg
);
1320 case OPTION_SPARE_DYNAMIC_TAGS
:
1321 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1323 case OPTION_SPLIT_BY_RELOC
:
1325 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1327 config
.split_by_reloc
= 32768;
1329 case OPTION_SPLIT_BY_FILE
:
1331 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1333 config
.split_by_file
= 1;
1335 case OPTION_CHECK_SECTIONS
:
1336 command_line
.check_section_addresses
= TRUE
;
1338 case OPTION_NO_CHECK_SECTIONS
:
1339 command_line
.check_section_addresses
= FALSE
;
1341 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1342 command_line
.accept_unknown_input_arch
= TRUE
;
1344 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1345 command_line
.accept_unknown_input_arch
= FALSE
;
1349 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1351 lang_enter_group ();
1356 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1358 lang_leave_group ();
1363 link_info
.init_function
= optarg
;
1367 link_info
.fini_function
= optarg
;
1370 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1371 command_line
.reduce_memory_overheads
= TRUE
;
1372 if (config
.hash_table_size
== 0)
1373 config
.hash_table_size
= 1021;
1376 case OPTION_HASH_SIZE
:
1378 bfd_size_type new_size
;
1380 new_size
= strtoul (optarg
, NULL
, 0);
1382 config
.hash_table_size
= new_size
;
1384 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1391 lang_leave_group ();
1393 if (default_dirlist
!= NULL
)
1395 set_default_dirlist (default_dirlist
);
1396 free (default_dirlist
);
1399 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1400 /* FIXME: Should we allow emulations a chance to set this ? */
1401 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1403 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1404 /* FIXME: Should we allow emulations a chance to set this ? */
1405 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1408 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1409 library search path. */
1412 set_default_dirlist (char *dirlist_ptr
)
1418 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1421 if (*dirlist_ptr
!= '\0')
1422 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1425 dirlist_ptr
= p
+ 1;
1430 set_section_start (char *sect
, char *valstr
)
1433 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1435 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1436 lang_section_start (sect
, exp_intop (val
), NULL
);
1440 set_segment_start (const char *section
, char *valstr
)
1446 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1448 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1449 /* If we already have an entry for this segment, update the existing
1452 for (seg
= segments
; seg
; seg
= seg
->next
)
1453 if (strcmp (seg
->name
, name
) == 0)
1458 /* There was no existing value so we must create a new segment
1460 seg
= stat_alloc (sizeof (*seg
));
1464 /* Add it to the linked list of segments. */
1465 seg
->next
= segments
;
1467 /* Historically, -Ttext and friends set the base address of a
1468 particular section. For backwards compatibility, we still do
1469 that. If a SEGMENT_START directive is seen, the section address
1470 assignment will be disabled. */
1471 lang_section_start (section
, exp_intop (val
), seg
);
1475 /* Print help messages for the options. */
1481 const char **targets
, **pp
;
1484 printf (_("Usage: %s [options] file...\n"), program_name
);
1486 printf (_("Options:\n"));
1487 for (i
= 0; i
< OPTION_COUNT
; i
++)
1489 if (ld_options
[i
].doc
!= NULL
)
1502 if (ld_options
[j
].shortopt
!= '\0'
1503 && ld_options
[j
].control
!= NO_HELP
)
1505 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1506 len
+= (comma
? 2 : 0) + 2;
1507 if (ld_options
[j
].arg
!= NULL
)
1509 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1514 printf ("%s", _(ld_options
[j
].arg
));
1515 len
+= strlen (_(ld_options
[j
].arg
));
1521 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1526 if (ld_options
[j
].opt
.name
!= NULL
1527 && ld_options
[j
].control
!= NO_HELP
)
1530 (ld_options
[j
].control
== TWO_DASHES
1531 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1535 two_dashes
? "-" : "",
1536 ld_options
[j
].opt
.name
);
1537 len
+= ((comma
? 2 : 0)
1539 + (two_dashes
? 1 : 0)
1540 + strlen (ld_options
[j
].opt
.name
));
1541 if (ld_options
[j
].arg
!= NULL
)
1543 printf (" %s", _(ld_options
[j
].arg
));
1544 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1550 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1558 for (; len
< 30; len
++)
1561 printf ("%s\n", _(ld_options
[i
].doc
));
1564 printf (_(" @FILE"));
1565 for (len
= strlen (" @FILE"); len
< 30; len
++)
1567 printf (_("Read options from FILE\n"));
1569 /* Note: Various tools (such as libtool) depend upon the
1570 format of the listings below - do not change them. */
1571 /* xgettext:c-format */
1572 printf (_("%s: supported targets:"), program_name
);
1573 targets
= bfd_target_list ();
1574 for (pp
= targets
; *pp
!= NULL
; pp
++)
1575 printf (" %s", *pp
);
1579 /* xgettext:c-format */
1580 printf (_("%s: supported emulations: "), program_name
);
1581 ldemul_list_emulations (stdout
);
1584 /* xgettext:c-format */
1585 printf (_("%s: emulation specific options:\n"), program_name
);
1586 ldemul_list_emulation_options (stdout
);
1589 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);