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_NEW
,
112 OPTION_DYNAMIC_LIST_CPP_TYPEINFO
,
113 OPTION_DYNAMIC_LIST_DATA
,
115 OPTION_WARN_CONSTRUCTORS
,
117 OPTION_WARN_MULTIPLE_GP
,
119 OPTION_WARN_SECTION_ALIGN
,
120 OPTION_SPLIT_BY_RELOC
,
121 OPTION_SPLIT_BY_FILE
,
122 OPTION_WHOLE_ARCHIVE
,
124 OPTION_NO_ADD_NEEDED
,
128 OPTION_FORCE_EXE_SUFFIX
,
130 OPTION_NO_GC_SECTIONS
,
131 OPTION_PRINT_GC_SECTIONS
,
132 OPTION_NO_PRINT_GC_SECTIONS
,
134 OPTION_CHECK_SECTIONS
,
135 OPTION_NO_CHECK_SECTIONS
,
139 OPTION_SECTION_START
,
142 OPTION_ALLOW_SHLIB_UNDEFINED
,
143 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
144 OPTION_ALLOW_MULTIPLE_DEFINITION
,
145 OPTION_NO_UNDEFINED_VERSION
,
146 OPTION_DEFAULT_SYMVER
,
147 OPTION_DEFAULT_IMPORTED_SYMVER
,
149 OPTION_SPARE_DYNAMIC_TAGS
,
150 OPTION_NO_DEFINE_COMMON
,
153 OPTION_STRIP_DISCARDED
,
154 OPTION_NO_STRIP_DISCARDED
,
155 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
156 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
158 OPTION_UNRESOLVED_SYMBOLS
,
159 OPTION_WARN_UNRESOLVED_SYMBOLS
,
160 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
161 OPTION_WARN_SHARED_TEXTREL
,
162 OPTION_REDUCE_MEMORY_OVERHEADS
165 /* The long options. This structure is used for both the option
166 parsing and the help text. */
170 /* The long option information. */
172 /* The short option with the same meaning ('\0' if none). */
174 /* The name of the argument (NULL if none). */
176 /* The documentation string. If this is NULL, this is a synonym for
177 the previous option. */
180 /* Use one dash before long option name. */
182 /* Use two dashes before long option name. */
184 /* Only accept two dashes before the long option name.
185 This is an overloading of the use of this enum, since originally it
186 was only intended to tell the --help display function how to display
187 the long option name. This feature was added in order to resolve
188 the confusion about the -omagic command line switch. Is it setting
189 the output file name to "magic" or is it setting the NMAGIC flag on
190 the output ? It has been decided that it is setting the output file
191 name, and that if you want to set the NMAGIC flag you should use -N
194 /* Don't mention this option in --help output. */
199 static const struct ld_option ld_options
[] =
201 { {NULL
, required_argument
, NULL
, '\0'},
202 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
204 { {"architecture", required_argument
, NULL
, 'A'},
205 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
206 { {"format", required_argument
, NULL
, 'b'},
207 'b', N_("TARGET"), N_("Specify target for following input files"),
209 { {"mri-script", required_argument
, NULL
, 'c'},
210 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
211 { {"dc", no_argument
, NULL
, 'd'},
212 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
213 { {"dp", no_argument
, NULL
, 'd'},
214 '\0', NULL
, NULL
, ONE_DASH
},
215 { {"entry", required_argument
, NULL
, 'e'},
216 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
217 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
218 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
219 { {"EB", no_argument
, NULL
, OPTION_EB
},
220 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
221 { {"EL", no_argument
, NULL
, OPTION_EL
},
222 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
223 { {"auxiliary", required_argument
, NULL
, 'f'},
224 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
226 { {"filter", required_argument
, NULL
, 'F'},
227 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
229 { {NULL
, no_argument
, NULL
, '\0'},
230 'g', NULL
, N_("Ignored"), ONE_DASH
},
231 { {"gpsize", required_argument
, NULL
, 'G'},
232 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
234 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
235 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
236 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
237 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
239 { {"library", required_argument
, NULL
, 'l'},
240 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
241 { {"library-path", required_argument
, NULL
, 'L'},
242 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
244 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
245 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
246 { {NULL
, required_argument
, NULL
, '\0'},
247 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
248 { {"print-map", no_argument
, NULL
, 'M'},
249 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
250 { {"nmagic", no_argument
, NULL
, 'n'},
251 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
252 { {"omagic", no_argument
, NULL
, 'N'},
253 'N', NULL
, N_("Do not page align data, do not make text readonly"),
254 EXACTLY_TWO_DASHES
},
255 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
256 '\0', NULL
, N_("Page align data, make text readonly"),
257 EXACTLY_TWO_DASHES
},
258 { {"output", required_argument
, NULL
, 'o'},
259 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
260 { {NULL
, required_argument
, NULL
, '\0'},
261 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
262 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
263 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
264 { {"emit-relocs", no_argument
, NULL
, 'q'},
265 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
266 { {"relocatable", no_argument
, NULL
, 'r'},
267 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
268 { {NULL
, no_argument
, NULL
, '\0'},
269 'i', NULL
, NULL
, ONE_DASH
},
270 { {"just-symbols", required_argument
, NULL
, 'R'},
271 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
273 { {"strip-all", no_argument
, NULL
, 's'},
274 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
275 { {"strip-debug", no_argument
, NULL
, 'S'},
276 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
277 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
278 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
279 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
280 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
281 { {"trace", no_argument
, NULL
, 't'},
282 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
283 { {"script", required_argument
, NULL
, 'T'},
284 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
285 { {"undefined", required_argument
, NULL
, 'u'},
286 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
288 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
289 '\0', N_("[=SECTION]"),
290 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
291 { {"Ur", no_argument
, NULL
, OPTION_UR
},
292 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
293 { {"version", no_argument
, NULL
, OPTION_VERSION
},
294 'v', NULL
, N_("Print version information"), TWO_DASHES
},
295 { {NULL
, no_argument
, NULL
, '\0'},
296 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
297 { {"discard-all", no_argument
, NULL
, 'x'},
298 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
299 { {"discard-locals", no_argument
, NULL
, 'X'},
300 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
301 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
302 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
303 { {"trace-symbol", required_argument
, NULL
, 'y'},
304 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
305 { {NULL
, required_argument
, NULL
, '\0'},
306 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
308 { {"start-group", no_argument
, NULL
, '('},
309 '(', NULL
, N_("Start a group"), TWO_DASHES
},
310 { {"end-group", no_argument
, NULL
, ')'},
311 ')', NULL
, N_("End a group"), TWO_DASHES
},
312 { {"accept-unknown-input-arch", no_argument
, NULL
,
313 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
315 N_("Accept input files whose architecture cannot be determined"),
317 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
318 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
319 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
321 { {"add-needed", no_argument
, NULL
, OPTION_ADD_NEEDED
},
322 '\0', NULL
, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
323 "\t\t\t\tfollowing dynamic libs"), TWO_DASHES
},
324 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_NEEDED
},
325 '\0', NULL
, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
326 "\t\t\t\tin following dynamic libs"), TWO_DASHES
},
327 { {"as-needed", no_argument
, NULL
, OPTION_AS_NEEDED
},
328 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
330 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_AS_NEEDED
},
331 '\0', NULL
, N_("Always set DT_NEEDED for following dynamic libs"),
333 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
334 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
335 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
336 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
337 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
338 '\0', NULL
, NULL
, ONE_DASH
},
339 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
340 '\0', NULL
, NULL
, ONE_DASH
},
341 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
342 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
343 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
344 '\0', NULL
, NULL
, ONE_DASH
},
345 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
346 '\0', NULL
, NULL
, ONE_DASH
},
347 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
348 '\0', NULL
, NULL
, ONE_DASH
},
349 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
350 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
351 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
352 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
353 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
354 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
356 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
357 '\0', NULL
, N_("Do not check section addresses for overlaps"),
359 { {"cref", no_argument
, NULL
, OPTION_CREF
},
360 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
361 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
362 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
363 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
364 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
366 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
367 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
368 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
369 '\0', NULL
, N_("Treat warnings as errors"),
371 { {"fini", required_argument
, NULL
, OPTION_FINI
},
372 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
373 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
374 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
375 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
376 '\0', NULL
, N_("Remove unused sections (on some targets)"),
378 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
379 '\0', NULL
, N_("Don't remove unused sections (default)"),
381 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
382 '\0', NULL
, N_("List removed unused sections on stderr"),
384 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
385 '\0', NULL
, N_("Do not list removed unused sections"),
387 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
388 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
390 { {"help", no_argument
, NULL
, OPTION_HELP
},
391 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
392 { {"init", required_argument
, NULL
, OPTION_INIT
},
393 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
394 { {"Map", required_argument
, NULL
, OPTION_MAP
},
395 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
396 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
397 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
398 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
399 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
400 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
401 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
402 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
403 '\0', NULL
, N_("Do not allow unresolved references in object files"),
405 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
406 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
408 { {"no-allow-shlib-undefined", no_argument
, NULL
,
409 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
410 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
412 { {"allow-multiple-definition", no_argument
, NULL
,
413 OPTION_ALLOW_MULTIPLE_DEFINITION
},
414 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
415 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
416 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
417 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
418 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
419 { {"default-imported-symver", no_argument
, NULL
,
420 OPTION_DEFAULT_IMPORTED_SYMVER
},
421 '\0', NULL
, N_("Create default symbol version for imported symbols"),
423 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
424 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
425 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
426 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
427 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
428 '\0', NULL
, N_("Create an output file even if errors occur"),
430 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
431 '\0', NULL
, NULL
, NO_HELP
},
432 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
433 '\0', NULL
, N_("Only use library directories specified on\n"
434 "\t\t\t\tthe command line"), ONE_DASH
},
435 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
436 '\0', N_("TARGET"), N_("Specify target of output file"),
437 EXACTLY_TWO_DASHES
},
438 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
439 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
440 { {"reduce-memory-overheads", no_argument
, NULL
,
441 OPTION_REDUCE_MEMORY_OVERHEADS
},
442 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
444 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
445 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
446 { {"retain-symbols-file", required_argument
, NULL
,
447 OPTION_RETAIN_SYMBOLS_FILE
},
448 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
449 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
450 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
451 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
452 '\0', N_("PATH"), N_("Set link time shared library search path"),
454 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
455 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
456 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
457 '\0', NULL
, NULL
, ONE_DASH
},
458 { {"pie", no_argument
, NULL
, OPTION_PIE
},
459 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
460 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
461 '\0', NULL
, NULL
, TWO_DASHES
},
462 { {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
463 '\0', NULL
, N_("Sort common symbols by size"), TWO_DASHES
},
464 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
465 '\0', NULL
, NULL
, NO_HELP
},
466 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
467 '\0', N_("name|alignment"),
468 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
469 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
470 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
472 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
473 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
475 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
476 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
478 { {"stats", no_argument
, NULL
, OPTION_STATS
},
479 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
480 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
481 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
482 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
483 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
484 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
485 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
486 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
487 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
489 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
490 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
491 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
492 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
493 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
494 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
495 { {"unresolved-symbols=<method>", required_argument
, NULL
,
496 OPTION_UNRESOLVED_SYMBOLS
},
497 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
498 "\t\t\t\tignore-all, report-all, ignore-in-object-files,\n"
499 "\t\t\t\tignore-in-shared-libs"), TWO_DASHES
},
500 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
501 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
502 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
503 '\0', NULL
, NULL
, NO_HELP
},
504 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
505 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
506 { {"version-exports-section", required_argument
, NULL
,
507 OPTION_VERSION_EXPORTS_SECTION
},
508 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
509 "\t\t\t\tSYMBOL as the version."), TWO_DASHES
},
510 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
511 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
512 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
513 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
514 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
515 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
516 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
517 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
518 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
519 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
520 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
521 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
523 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
524 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
525 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
526 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
527 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
528 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
530 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
531 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
533 { {"warn-unresolved-symbols", no_argument
, NULL
,
534 OPTION_WARN_UNRESOLVED_SYMBOLS
},
535 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
536 { {"error-unresolved-symbols", no_argument
, NULL
,
537 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
538 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
539 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
540 '\0', NULL
, N_("Include all objects from following archives"),
542 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
543 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
546 #define OPTION_COUNT ARRAY_SIZE (ld_options)
549 parse_args (unsigned argc
, char **argv
)
554 char *default_dirlist
= NULL
;
556 struct option
*longopts
;
557 struct option
*really_longopts
;
559 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
561 shortopts
= xmalloc (OPTION_COUNT
* 3 + 2);
562 longopts
= xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
563 really_longopts
= xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
565 /* Starting the short option string with '-' is for programs that
566 expect options and other ARGV-elements in any order and that care about
567 the ordering of the two. We describe each non-option ARGV-element
568 as if it were the argument of an option with character code 1. */
573 for (i
= 0; i
< OPTION_COUNT
; i
++)
575 if (ld_options
[i
].shortopt
!= '\0')
577 shortopts
[is
] = ld_options
[i
].shortopt
;
579 if (ld_options
[i
].opt
.has_arg
== required_argument
580 || ld_options
[i
].opt
.has_arg
== optional_argument
)
584 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
591 if (ld_options
[i
].opt
.name
!= NULL
)
593 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
595 really_longopts
[irl
] = ld_options
[i
].opt
;
600 longopts
[il
] = ld_options
[i
].opt
;
605 shortopts
[is
] = '\0';
606 longopts
[il
].name
= NULL
;
607 really_longopts
[irl
].name
= NULL
;
609 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
611 /* The -G option is ambiguous on different platforms. Sometimes it
612 specifies the largest data size to put into the small data
613 section. Sometimes it is equivalent to --shared. Unfortunately,
614 the first form takes an argument, while the second does not.
616 We need to permit the --shared form because on some platforms,
617 such as Solaris, gcc -shared will pass -G to the linker.
619 To permit either usage, we look through the argument list. If we
620 find -G not followed by a number, we change it into --shared.
621 This will work for most normal cases. */
622 for (i
= 1; i
< argc
; i
++)
623 if (strcmp (argv
[i
], "-G") == 0
625 || ! ISDIGIT (argv
[i
+ 1][0])))
626 argv
[i
] = (char *) "--shared";
628 /* Because we permit long options to start with a single dash, and
629 we have a --library option, and the -l option is conventionally
630 used with an immediately following argument, we can have bad
631 results if somebody tries to use -l with a library whose name
632 happens to start with "ibrary", as in -li. We avoid problems by
633 simply turning -l into --library. This means that users will
634 have to use two dashes in order to use --library, which is OK
635 since that's how it is documented.
637 FIXME: It's possible that this problem can arise for other short
638 options as well, although the user does always have the recourse
639 of adding a space between the option and the argument. */
640 for (i
= 1; i
< argc
; i
++)
642 if (argv
[i
][0] == '-'
644 && argv
[i
][2] != '\0')
648 n
= xmalloc (strlen (argv
[i
]) + 20);
649 sprintf (n
, "--library=%s", argv
[i
] + 2);
660 /* Using last_optind lets us avoid calling ldemul_parse_args
661 multiple times on a single option, which would lead to
662 confusion in the internal static variables maintained by
663 getopt. This could otherwise happen for an argument like
664 -nx, in which the -n is parsed as a single option, and we
665 loop around to pick up the -x. */
666 if (optind
!= last_optind
)
667 if (ldemul_parse_args (argc
, argv
))
670 /* getopt_long_only is like getopt_long, but '-' as well as '--'
671 can indicate a long option. */
673 last_optind
= optind
;
674 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
677 optind
= last_optind
;
678 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
681 if (ldemul_handle_option (optc
))
690 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
694 einfo (_("%P%F: use the --help option for usage information\n"));
696 case 1: /* File name. */
697 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
703 /* For HP/UX compatibility. Actually -a shared should mean
704 ``use only shared libraries'' but, then, we don't
705 currently support shared libraries on HP/UX anyhow. */
706 if (strcmp (optarg
, "archive") == 0)
707 config
.dynamic_link
= FALSE
;
708 else if (strcmp (optarg
, "shared") == 0
709 || strcmp (optarg
, "default") == 0)
710 config
.dynamic_link
= TRUE
;
712 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
715 /* FIXME: We just ignore these, but we should handle them. */
716 if (strcmp (optarg
, "definitions") == 0)
718 else if (strcmp (optarg
, "nodefinitions") == 0)
720 else if (strcmp (optarg
, "nosymbolic") == 0)
722 else if (strcmp (optarg
, "pure-text") == 0)
725 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
728 ldfile_add_arch (optarg
);
731 lang_add_target (optarg
);
734 ldfile_open_command_file (optarg
);
735 parser_input
= input_mri_script
;
738 case OPTION_CALL_SHARED
:
739 config
.dynamic_link
= TRUE
;
741 case OPTION_NON_SHARED
:
742 config
.dynamic_link
= FALSE
;
745 command_line
.cref
= TRUE
;
746 link_info
.notice_all
= TRUE
;
749 command_line
.force_common_definition
= TRUE
;
753 lex_redirect (optarg
);
754 parser_input
= input_defsym
;
760 case OPTION_DEMANGLE
:
764 enum demangling_styles style
;
766 style
= cplus_demangle_name_to_style (optarg
);
767 if (style
== unknown_demangling
)
768 einfo (_("%F%P: unknown demangling style `%s'"),
771 cplus_demangle_set_style (style
);
774 case 'I': /* Used on Solaris. */
775 case OPTION_DYNAMIC_LINKER
:
776 command_line
.interpreter
= optarg
;
779 /* Already handled in ldmain.c. */
782 command_line
.endian
= ENDIAN_BIG
;
785 command_line
.endian
= ENDIAN_LITTLE
;
787 case OPTION_EMBEDDED_RELOCS
:
788 command_line
.embedded_relocs
= TRUE
;
790 case OPTION_EXPORT_DYNAMIC
:
791 case 'E': /* HP/UX compatibility. */
792 link_info
.export_dynamic
= TRUE
;
795 lang_add_entry (optarg
, TRUE
);
798 if (command_line
.auxiliary_filters
== NULL
)
800 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
801 command_line
.auxiliary_filters
[0] = optarg
;
802 command_line
.auxiliary_filters
[1] = NULL
;
810 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
812 command_line
.auxiliary_filters
813 = xrealloc (command_line
.auxiliary_filters
,
814 (c
+ 2) * sizeof (char *));
815 command_line
.auxiliary_filters
[c
] = optarg
;
816 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
820 command_line
.filter_shlib
= optarg
;
822 case OPTION_FORCE_EXE_SUFFIX
:
823 command_line
.force_exe_suffix
= TRUE
;
828 g_switch_value
= strtoul (optarg
, &end
, 0);
830 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
836 case OPTION_GC_SECTIONS
:
837 link_info
.gc_sections
= TRUE
;
839 case OPTION_PRINT_GC_SECTIONS
:
840 link_info
.print_gc_sections
= TRUE
;
847 ldfile_add_library_path (optarg
, TRUE
);
850 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
853 config
.map_filename
= "-";
856 /* Ignore. Was handled in a pre-parse. */
859 config
.map_filename
= optarg
;
862 config
.text_read_only
= FALSE
;
863 config
.magic_demand_paged
= FALSE
;
864 config
.dynamic_link
= FALSE
;
866 case OPTION_NO_OMAGIC
:
867 config
.text_read_only
= TRUE
;
868 config
.magic_demand_paged
= TRUE
;
869 /* NB/ Does not set dynamic_link to TRUE.
870 Use --call-shared or -Bdynamic for this. */
873 config
.magic_demand_paged
= FALSE
;
874 config
.dynamic_link
= FALSE
;
876 case OPTION_NO_DEFINE_COMMON
:
877 command_line
.inhibit_common_definition
= TRUE
;
879 case OPTION_NO_DEMANGLE
:
882 case OPTION_NO_GC_SECTIONS
:
883 link_info
.gc_sections
= FALSE
;
885 case OPTION_NO_PRINT_GC_SECTIONS
:
886 link_info
.print_gc_sections
= FALSE
;
888 case OPTION_NO_KEEP_MEMORY
:
889 link_info
.keep_memory
= FALSE
;
891 case OPTION_NO_UNDEFINED
:
892 link_info
.unresolved_syms_in_objects
893 = how_to_report_unresolved_symbols
;
895 case OPTION_ALLOW_SHLIB_UNDEFINED
:
896 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
898 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
899 link_info
.unresolved_syms_in_shared_libs
900 = how_to_report_unresolved_symbols
;
902 case OPTION_UNRESOLVED_SYMBOLS
:
903 if (strcmp (optarg
, "ignore-all") == 0)
905 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
906 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
908 else if (strcmp (optarg
, "report-all") == 0)
910 link_info
.unresolved_syms_in_objects
911 = how_to_report_unresolved_symbols
;
912 link_info
.unresolved_syms_in_shared_libs
913 = how_to_report_unresolved_symbols
;
915 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
917 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
918 link_info
.unresolved_syms_in_shared_libs
919 = how_to_report_unresolved_symbols
;
921 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
923 link_info
.unresolved_syms_in_objects
924 = how_to_report_unresolved_symbols
;
925 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
928 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
930 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
931 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
932 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
933 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
934 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
935 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
938 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
939 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
940 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
941 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
942 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
943 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
945 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
946 link_info
.allow_multiple_definition
= TRUE
;
948 case OPTION_NO_UNDEFINED_VERSION
:
949 link_info
.allow_undefined_version
= FALSE
;
951 case OPTION_DEFAULT_SYMVER
:
952 link_info
.create_default_symver
= TRUE
;
954 case OPTION_DEFAULT_IMPORTED_SYMVER
:
955 link_info
.default_imported_symver
= TRUE
;
957 case OPTION_NO_WARN_MISMATCH
:
958 command_line
.warn_mismatch
= FALSE
;
960 case OPTION_NOINHIBIT_EXEC
:
961 force_make_executable
= TRUE
;
963 case OPTION_NOSTDLIB
:
964 config
.only_cmd_line_lib_dirs
= TRUE
;
966 case OPTION_NO_WHOLE_ARCHIVE
:
967 whole_archive
= FALSE
;
970 /* FIXME "-O<non-digits> <value>" used to set the address of
971 section <non-digits>. Was this for compatibility with
972 something, or can we create a new option to do that
973 (with a syntax similar to -defsym)?
974 getopt can't handle two args to an option without kludges. */
976 /* Enable optimizations of output files. */
977 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
980 lang_add_output (optarg
, 0);
983 lang_add_output_format (optarg
, NULL
, NULL
, 0);
986 link_info
.emitrelocations
= TRUE
;
990 if (optind
== last_optind
)
991 /* This can happen if the user put "-rpath,a" on the command
992 line. (Or something similar. The comma is important).
993 Getopt becomes confused and thinks that this is a -r option
994 but it cannot parse the text after the -r so it refuses to
995 increment the optind counter. Detect this case and issue
996 an error message here. We cannot just make this a warning,
997 increment optind, and continue because getopt is too confused
998 and will seg-fault the next time around. */
999 einfo(_("%P%F: bad -rpath option\n"));
1001 link_info
.relocatable
= TRUE
;
1002 config
.build_constructors
= FALSE
;
1003 config
.magic_demand_paged
= FALSE
;
1004 config
.text_read_only
= FALSE
;
1005 config
.dynamic_link
= FALSE
;
1008 /* The GNU linker traditionally uses -R to mean to include
1009 only the symbols from a file. The Solaris linker uses -R
1010 to set the path used by the runtime linker to find
1011 libraries. This is the GNU linker -rpath argument. We
1012 try to support both simultaneously by checking the file
1013 named. If it is a directory, rather than a regular file,
1014 we assume -rpath was meant. */
1018 if (stat (optarg
, &s
) >= 0
1019 && ! S_ISDIR (s
.st_mode
))
1021 lang_add_input_file (optarg
,
1022 lang_input_file_is_symbols_only_enum
,
1029 if (command_line
.rpath
== NULL
)
1030 command_line
.rpath
= xstrdup (optarg
);
1033 size_t rpath_len
= strlen (command_line
.rpath
);
1034 size_t optarg_len
= strlen (optarg
);
1036 char *cp
= command_line
.rpath
;
1038 /* First see whether OPTARG is already in the path. */
1043 while (optarg
[idx
] != '\0' && optarg
[idx
] == cp
[idx
])
1045 if (optarg
[idx
] == '\0'
1046 && (cp
[idx
] == '\0' || cp
[idx
] == ':'))
1050 /* Not yet found. */
1051 cp
= strchr (cp
, ':');
1059 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1060 sprintf (buf
, "%s:%s", command_line
.rpath
, optarg
);
1061 free (command_line
.rpath
);
1062 command_line
.rpath
= buf
;
1066 case OPTION_RPATH_LINK
:
1067 if (command_line
.rpath_link
== NULL
)
1068 command_line
.rpath_link
= xstrdup (optarg
);
1073 buf
= xmalloc (strlen (command_line
.rpath_link
)
1076 sprintf (buf
, "%s:%s", command_line
.rpath_link
, optarg
);
1077 free (command_line
.rpath_link
);
1078 command_line
.rpath_link
= buf
;
1082 command_line
.relax
= TRUE
;
1084 case OPTION_RETAIN_SYMBOLS_FILE
:
1085 add_keepsyms_file (optarg
);
1088 link_info
.strip
= strip_debugger
;
1091 link_info
.strip
= strip_all
;
1093 case OPTION_STRIP_DISCARDED
:
1094 link_info
.strip_discarded
= TRUE
;
1096 case OPTION_NO_STRIP_DISCARDED
:
1097 link_info
.strip_discarded
= FALSE
;
1100 if (config
.has_shared
)
1102 link_info
.shared
= TRUE
;
1103 /* When creating a shared library, the default
1104 behaviour is to ignore any unresolved references. */
1105 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1106 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1107 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1108 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1111 einfo (_("%P%F: -shared not supported\n"));
1114 if (config
.has_shared
)
1116 link_info
.shared
= TRUE
;
1117 link_info
.pie
= TRUE
;
1120 einfo (_("%P%F: -pie not supported\n"));
1122 case 'h': /* Used on Solaris. */
1124 command_line
.soname
= optarg
;
1126 case OPTION_SORT_COMMON
:
1127 config
.sort_common
= TRUE
;
1129 case OPTION_SORT_SECTION
:
1130 if (strcmp (optarg
, N_("name")) == 0)
1131 sort_section
= by_name
;
1132 else if (strcmp (optarg
, N_("alignment")) == 0)
1133 sort_section
= by_alignment
;
1135 einfo (_("%P%F: invalid section sorting option: %s\n"),
1139 config
.stats
= TRUE
;
1141 case OPTION_SYMBOLIC
:
1142 link_info
.symbolic
= TRUE
;
1148 ldfile_open_command_file (optarg
);
1149 parser_input
= input_script
;
1152 case OPTION_SECTION_START
:
1158 /* Check for <something>=<somthing>... */
1159 optarg2
= strchr (optarg
, '=');
1160 if (optarg2
== NULL
)
1161 einfo (_("%P%F: invalid argument to option"
1162 " \"--section-start\"\n"));
1166 /* So far so good. Are all the args present? */
1167 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1168 einfo (_("%P%F: missing argument(s) to option"
1169 " \"--section-start\"\n"));
1171 /* We must copy the section name as set_section_start
1172 doesn't do it for us. */
1173 len
= optarg2
- optarg
;
1174 sec_name
= xmalloc (len
);
1175 memcpy (sec_name
, optarg
, len
- 1);
1176 sec_name
[len
- 1] = 0;
1178 /* Then set it... */
1179 set_section_start (sec_name
, optarg2
);
1182 case OPTION_TARGET_HELP
:
1183 /* Mention any target specific options. */
1184 ldemul_list_emulation_options (stdout
);
1187 set_segment_start (".bss", optarg
);
1190 set_segment_start (".data", optarg
);
1193 set_segment_start (".text", optarg
);
1195 case OPTION_TRADITIONAL_FORMAT
:
1196 link_info
.traditional_format
= TRUE
;
1198 case OPTION_TASK_LINK
:
1199 link_info
.task_link
= TRUE
;
1200 /* Fall through - do an implied -r option. */
1202 link_info
.relocatable
= TRUE
;
1203 config
.build_constructors
= TRUE
;
1204 config
.magic_demand_paged
= FALSE
;
1205 config
.text_read_only
= FALSE
;
1206 config
.dynamic_link
= FALSE
;
1209 ldlang_add_undef (optarg
);
1213 lang_add_unique (optarg
);
1215 config
.unique_orphan_sections
= TRUE
;
1217 case OPTION_VERBOSE
:
1219 version_printed
= TRUE
;
1220 trace_file_tries
= TRUE
;
1221 overflow_cutoff_limit
= -2;
1225 version_printed
= TRUE
;
1229 version_printed
= TRUE
;
1231 case OPTION_VERSION
:
1235 case OPTION_VERSION_SCRIPT
:
1236 /* This option indicates a small script that only specifies
1237 version information. Read it, but don't assume that
1238 we've seen a linker script. */
1240 FILE *hold_script_handle
;
1242 hold_script_handle
= saved_script_handle
;
1243 ldfile_open_command_file (optarg
);
1244 saved_script_handle
= hold_script_handle
;
1245 parser_input
= input_version_script
;
1249 case OPTION_VERSION_EXPORTS_SECTION
:
1250 /* This option records a version symbol to be applied to the
1251 symbols listed for export to be found in the object files
1252 .exports sections. */
1253 command_line
.version_exports_section
= optarg
;
1255 case OPTION_DYNAMIC_LIST_DATA
:
1256 link_info
.dynamic_data
= TRUE
;
1257 link_info
.dynamic
= TRUE
;
1259 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1260 lang_append_dynamic_list_cpp_typeinfo ();
1261 link_info
.dynamic
= TRUE
;
1263 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1264 lang_append_dynamic_list_cpp_new ();
1265 link_info
.dynamic
= TRUE
;
1267 case OPTION_DYNAMIC_LIST
:
1268 /* This option indicates a small script that only specifies
1269 a dynamic list. Read it, but don't assume that we've
1270 seen a linker script. */
1272 FILE *hold_script_handle
;
1274 hold_script_handle
= saved_script_handle
;
1275 ldfile_open_command_file (optarg
);
1276 saved_script_handle
= hold_script_handle
;
1277 parser_input
= input_dynamic_list
;
1280 link_info
.dynamic
= TRUE
;
1282 case OPTION_WARN_COMMON
:
1283 config
.warn_common
= TRUE
;
1285 case OPTION_WARN_CONSTRUCTORS
:
1286 config
.warn_constructors
= TRUE
;
1288 case OPTION_WARN_FATAL
:
1289 config
.fatal_warnings
= TRUE
;
1291 case OPTION_WARN_MULTIPLE_GP
:
1292 config
.warn_multiple_gp
= TRUE
;
1294 case OPTION_WARN_ONCE
:
1295 config
.warn_once
= TRUE
;
1297 case OPTION_WARN_SECTION_ALIGN
:
1298 config
.warn_section_align
= TRUE
;
1300 case OPTION_WARN_SHARED_TEXTREL
:
1301 link_info
.warn_shared_textrel
= TRUE
;
1303 case OPTION_WHOLE_ARCHIVE
:
1304 whole_archive
= TRUE
;
1306 case OPTION_ADD_NEEDED
:
1309 case OPTION_NO_ADD_NEEDED
:
1312 case OPTION_AS_NEEDED
:
1315 case OPTION_NO_AS_NEEDED
:
1321 case OPTION_DISCARD_NONE
:
1322 link_info
.discard
= discard_none
;
1325 link_info
.discard
= discard_l
;
1328 link_info
.discard
= discard_all
;
1331 if (CONST_STRNEQ (optarg
, "P,"))
1333 if (default_dirlist
!= NULL
)
1334 free (default_dirlist
);
1335 default_dirlist
= xstrdup (optarg
);
1340 case OPTION_SPARE_DYNAMIC_TAGS
:
1341 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1343 case OPTION_SPLIT_BY_RELOC
:
1345 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1347 config
.split_by_reloc
= 32768;
1349 case OPTION_SPLIT_BY_FILE
:
1351 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1353 config
.split_by_file
= 1;
1355 case OPTION_CHECK_SECTIONS
:
1356 command_line
.check_section_addresses
= TRUE
;
1358 case OPTION_NO_CHECK_SECTIONS
:
1359 command_line
.check_section_addresses
= FALSE
;
1361 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1362 command_line
.accept_unknown_input_arch
= TRUE
;
1364 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1365 command_line
.accept_unknown_input_arch
= FALSE
;
1369 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1371 lang_enter_group ();
1376 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1378 lang_leave_group ();
1383 link_info
.init_function
= optarg
;
1387 link_info
.fini_function
= optarg
;
1390 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1391 link_info
.reduce_memory_overheads
= TRUE
;
1392 if (config
.hash_table_size
== 0)
1393 config
.hash_table_size
= 1021;
1396 case OPTION_HASH_SIZE
:
1398 bfd_size_type new_size
;
1400 new_size
= strtoul (optarg
, NULL
, 0);
1402 config
.hash_table_size
= new_size
;
1404 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1411 lang_leave_group ();
1413 if (default_dirlist
!= NULL
)
1415 set_default_dirlist (default_dirlist
);
1416 free (default_dirlist
);
1419 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1420 /* FIXME: Should we allow emulations a chance to set this ? */
1421 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1423 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1424 /* FIXME: Should we allow emulations a chance to set this ? */
1425 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1428 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1429 library search path. */
1432 set_default_dirlist (char *dirlist_ptr
)
1438 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1441 if (*dirlist_ptr
!= '\0')
1442 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1445 dirlist_ptr
= p
+ 1;
1450 set_section_start (char *sect
, char *valstr
)
1453 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1455 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1456 lang_section_start (sect
, exp_intop (val
), NULL
);
1460 set_segment_start (const char *section
, char *valstr
)
1466 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1468 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1469 /* If we already have an entry for this segment, update the existing
1472 for (seg
= segments
; seg
; seg
= seg
->next
)
1473 if (strcmp (seg
->name
, name
) == 0)
1478 /* There was no existing value so we must create a new segment
1480 seg
= stat_alloc (sizeof (*seg
));
1484 /* Add it to the linked list of segments. */
1485 seg
->next
= segments
;
1487 /* Historically, -Ttext and friends set the base address of a
1488 particular section. For backwards compatibility, we still do
1489 that. If a SEGMENT_START directive is seen, the section address
1490 assignment will be disabled. */
1491 lang_section_start (section
, exp_intop (val
), seg
);
1495 /* Print help messages for the options. */
1501 const char **targets
, **pp
;
1504 printf (_("Usage: %s [options] file...\n"), program_name
);
1506 printf (_("Options:\n"));
1507 for (i
= 0; i
< OPTION_COUNT
; i
++)
1509 if (ld_options
[i
].doc
!= NULL
)
1522 if (ld_options
[j
].shortopt
!= '\0'
1523 && ld_options
[j
].control
!= NO_HELP
)
1525 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1526 len
+= (comma
? 2 : 0) + 2;
1527 if (ld_options
[j
].arg
!= NULL
)
1529 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1534 printf ("%s", _(ld_options
[j
].arg
));
1535 len
+= strlen (_(ld_options
[j
].arg
));
1541 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1546 if (ld_options
[j
].opt
.name
!= NULL
1547 && ld_options
[j
].control
!= NO_HELP
)
1550 (ld_options
[j
].control
== TWO_DASHES
1551 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1555 two_dashes
? "-" : "",
1556 ld_options
[j
].opt
.name
);
1557 len
+= ((comma
? 2 : 0)
1559 + (two_dashes
? 1 : 0)
1560 + strlen (ld_options
[j
].opt
.name
));
1561 if (ld_options
[j
].arg
!= NULL
)
1563 printf (" %s", _(ld_options
[j
].arg
));
1564 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1570 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1578 for (; len
< 30; len
++)
1581 printf ("%s\n", _(ld_options
[i
].doc
));
1584 printf (_(" @FILE"));
1585 for (len
= strlen (" @FILE"); len
< 30; len
++)
1587 printf (_("Read options from FILE\n"));
1589 /* Note: Various tools (such as libtool) depend upon the
1590 format of the listings below - do not change them. */
1591 /* xgettext:c-format */
1592 printf (_("%s: supported targets:"), program_name
);
1593 targets
= bfd_target_list ();
1594 for (pp
= targets
; *pp
!= NULL
; pp
++)
1595 printf (" %s", *pp
);
1599 /* xgettext:c-format */
1600 printf (_("%s: supported emulations: "), program_name
);
1601 ldemul_list_emulations (stdout
);
1604 /* xgettext:c-format */
1605 printf (_("%s: emulation specific options:\n"), program_name
);
1606 ldemul_list_emulation_options (stdout
);
1609 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);