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
,
163 OPTION_DEFAULT_SCRIPT
166 /* The long options. This structure is used for both the option
167 parsing and the help text. */
171 /* The long option information. */
173 /* The short option with the same meaning ('\0' if none). */
175 /* The name of the argument (NULL if none). */
177 /* The documentation string. If this is NULL, this is a synonym for
178 the previous option. */
181 /* Use one dash before long option name. */
183 /* Use two dashes before long option name. */
185 /* Only accept two dashes before the long option name.
186 This is an overloading of the use of this enum, since originally it
187 was only intended to tell the --help display function how to display
188 the long option name. This feature was added in order to resolve
189 the confusion about the -omagic command line switch. Is it setting
190 the output file name to "magic" or is it setting the NMAGIC flag on
191 the output ? It has been decided that it is setting the output file
192 name, and that if you want to set the NMAGIC flag you should use -N
195 /* Don't mention this option in --help output. */
200 static const struct ld_option ld_options
[] =
202 { {NULL
, required_argument
, NULL
, '\0'},
203 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
205 { {"architecture", required_argument
, NULL
, 'A'},
206 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
207 { {"format", required_argument
, NULL
, 'b'},
208 'b', N_("TARGET"), N_("Specify target for following input files"),
210 { {"mri-script", required_argument
, NULL
, 'c'},
211 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
212 { {"dc", no_argument
, NULL
, 'd'},
213 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
214 { {"dp", no_argument
, NULL
, 'd'},
215 '\0', NULL
, NULL
, ONE_DASH
},
216 { {"entry", required_argument
, NULL
, 'e'},
217 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
218 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
219 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
220 { {"EB", no_argument
, NULL
, OPTION_EB
},
221 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
222 { {"EL", no_argument
, NULL
, OPTION_EL
},
223 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
224 { {"auxiliary", required_argument
, NULL
, 'f'},
225 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
227 { {"filter", required_argument
, NULL
, 'F'},
228 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
230 { {NULL
, no_argument
, NULL
, '\0'},
231 'g', NULL
, N_("Ignored"), ONE_DASH
},
232 { {"gpsize", required_argument
, NULL
, 'G'},
233 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
235 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
236 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
237 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
238 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
240 { {"library", required_argument
, NULL
, 'l'},
241 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
242 { {"library-path", required_argument
, NULL
, 'L'},
243 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
245 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
246 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
247 { {NULL
, required_argument
, NULL
, '\0'},
248 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
249 { {"print-map", no_argument
, NULL
, 'M'},
250 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
251 { {"nmagic", no_argument
, NULL
, 'n'},
252 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
253 { {"omagic", no_argument
, NULL
, 'N'},
254 'N', NULL
, N_("Do not page align data, do not make text readonly"),
255 EXACTLY_TWO_DASHES
},
256 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
257 '\0', NULL
, N_("Page align data, make text readonly"),
258 EXACTLY_TWO_DASHES
},
259 { {"output", required_argument
, NULL
, 'o'},
260 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
261 { {NULL
, required_argument
, NULL
, '\0'},
262 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
263 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
264 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
265 { {"emit-relocs", no_argument
, NULL
, 'q'},
266 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
267 { {"relocatable", no_argument
, NULL
, 'r'},
268 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
269 { {NULL
, no_argument
, NULL
, '\0'},
270 'i', NULL
, NULL
, ONE_DASH
},
271 { {"just-symbols", required_argument
, NULL
, 'R'},
272 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
274 { {"strip-all", no_argument
, NULL
, 's'},
275 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
276 { {"strip-debug", no_argument
, NULL
, 'S'},
277 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
278 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
279 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
280 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
281 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
282 { {"trace", no_argument
, NULL
, 't'},
283 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
284 { {"script", required_argument
, NULL
, 'T'},
285 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
286 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
287 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
288 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
289 '\0', NULL
, NULL
, ONE_DASH
},
290 { {"undefined", required_argument
, NULL
, 'u'},
291 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
293 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
294 '\0', N_("[=SECTION]"),
295 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
296 { {"Ur", no_argument
, NULL
, OPTION_UR
},
297 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
298 { {"version", no_argument
, NULL
, OPTION_VERSION
},
299 'v', NULL
, N_("Print version information"), TWO_DASHES
},
300 { {NULL
, no_argument
, NULL
, '\0'},
301 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
302 { {"discard-all", no_argument
, NULL
, 'x'},
303 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
304 { {"discard-locals", no_argument
, NULL
, 'X'},
305 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
306 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
307 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
308 { {"trace-symbol", required_argument
, NULL
, 'y'},
309 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
310 { {NULL
, required_argument
, NULL
, '\0'},
311 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
313 { {"start-group", no_argument
, NULL
, '('},
314 '(', NULL
, N_("Start a group"), TWO_DASHES
},
315 { {"end-group", no_argument
, NULL
, ')'},
316 ')', NULL
, N_("End a group"), TWO_DASHES
},
317 { {"accept-unknown-input-arch", no_argument
, NULL
,
318 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
320 N_("Accept input files whose architecture cannot be determined"),
322 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
323 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
324 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
326 { {"add-needed", no_argument
, NULL
, OPTION_ADD_NEEDED
},
327 '\0', NULL
, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
328 "\t\t\t\tfollowing dynamic libs"), TWO_DASHES
},
329 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_NEEDED
},
330 '\0', NULL
, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
331 "\t\t\t\tin following dynamic libs"), TWO_DASHES
},
332 { {"as-needed", no_argument
, NULL
, OPTION_AS_NEEDED
},
333 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
335 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_AS_NEEDED
},
336 '\0', NULL
, N_("Always set DT_NEEDED for following dynamic libs"),
338 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
339 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
340 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
341 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
342 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
343 '\0', NULL
, NULL
, ONE_DASH
},
344 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
345 '\0', NULL
, NULL
, ONE_DASH
},
346 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
347 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
348 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
349 '\0', NULL
, NULL
, ONE_DASH
},
350 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
351 '\0', NULL
, NULL
, ONE_DASH
},
352 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
353 '\0', NULL
, NULL
, ONE_DASH
},
354 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
355 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
356 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
357 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
358 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
359 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
361 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
362 '\0', NULL
, N_("Do not check section addresses for overlaps"),
364 { {"cref", no_argument
, NULL
, OPTION_CREF
},
365 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
366 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
367 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
368 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
369 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
371 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
372 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
373 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
374 '\0', NULL
, N_("Treat warnings as errors"),
376 { {"fini", required_argument
, NULL
, OPTION_FINI
},
377 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
378 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
379 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
380 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
381 '\0', NULL
, N_("Remove unused sections (on some targets)"),
383 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
384 '\0', NULL
, N_("Don't remove unused sections (default)"),
386 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
387 '\0', NULL
, N_("List removed unused sections on stderr"),
389 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
390 '\0', NULL
, N_("Do not list removed unused sections"),
392 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
393 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
395 { {"help", no_argument
, NULL
, OPTION_HELP
},
396 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
397 { {"init", required_argument
, NULL
, OPTION_INIT
},
398 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
399 { {"Map", required_argument
, NULL
, OPTION_MAP
},
400 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
401 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
402 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
403 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
404 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
405 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
406 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
407 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
408 '\0', NULL
, N_("Do not allow unresolved references in object files"),
410 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
411 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
413 { {"no-allow-shlib-undefined", no_argument
, NULL
,
414 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
415 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
417 { {"allow-multiple-definition", no_argument
, NULL
,
418 OPTION_ALLOW_MULTIPLE_DEFINITION
},
419 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
420 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
421 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
422 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
423 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
424 { {"default-imported-symver", no_argument
, NULL
,
425 OPTION_DEFAULT_IMPORTED_SYMVER
},
426 '\0', NULL
, N_("Create default symbol version for imported symbols"),
428 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
429 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
430 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
431 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
432 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
433 '\0', NULL
, N_("Create an output file even if errors occur"),
435 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
436 '\0', NULL
, NULL
, NO_HELP
},
437 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
438 '\0', NULL
, N_("Only use library directories specified on\n"
439 "\t\t\t\tthe command line"), ONE_DASH
},
440 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
441 '\0', N_("TARGET"), N_("Specify target of output file"),
442 EXACTLY_TWO_DASHES
},
443 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
444 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
445 { {"reduce-memory-overheads", no_argument
, NULL
,
446 OPTION_REDUCE_MEMORY_OVERHEADS
},
447 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
449 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
450 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
451 { {"retain-symbols-file", required_argument
, NULL
,
452 OPTION_RETAIN_SYMBOLS_FILE
},
453 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
454 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
455 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
456 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
457 '\0', N_("PATH"), N_("Set link time shared library search path"),
459 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
460 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
461 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
462 '\0', NULL
, NULL
, ONE_DASH
},
463 { {"pie", no_argument
, NULL
, OPTION_PIE
},
464 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
465 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
466 '\0', NULL
, NULL
, TWO_DASHES
},
467 { {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
468 '\0', NULL
, N_("Sort common symbols by size"), TWO_DASHES
},
469 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
470 '\0', NULL
, NULL
, NO_HELP
},
471 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
472 '\0', N_("name|alignment"),
473 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
474 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
475 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
477 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
478 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
480 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
481 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
483 { {"stats", no_argument
, NULL
, OPTION_STATS
},
484 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
485 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
486 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
487 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
488 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
489 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
490 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
491 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
492 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
494 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
495 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
496 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
497 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
498 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
499 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
500 { {"unresolved-symbols=<method>", required_argument
, NULL
,
501 OPTION_UNRESOLVED_SYMBOLS
},
502 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
503 "\t\t\t\tignore-all, report-all, ignore-in-object-files,\n"
504 "\t\t\t\tignore-in-shared-libs"), TWO_DASHES
},
505 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
506 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
507 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
508 '\0', NULL
, NULL
, NO_HELP
},
509 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
510 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
511 { {"version-exports-section", required_argument
, NULL
,
512 OPTION_VERSION_EXPORTS_SECTION
},
513 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
514 "\t\t\t\tSYMBOL as the version."), TWO_DASHES
},
515 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
516 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
517 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
518 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
519 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
520 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
521 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
522 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
523 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
524 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
525 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
526 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
528 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
529 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
530 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
531 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
532 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
533 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
535 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
536 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
538 { {"warn-unresolved-symbols", no_argument
, NULL
,
539 OPTION_WARN_UNRESOLVED_SYMBOLS
},
540 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
541 { {"error-unresolved-symbols", no_argument
, NULL
,
542 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
543 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
544 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
545 '\0', NULL
, N_("Include all objects from following archives"),
547 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
548 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
551 #define OPTION_COUNT ARRAY_SIZE (ld_options)
554 parse_args (unsigned argc
, char **argv
)
559 char *default_dirlist
= NULL
;
561 struct option
*longopts
;
562 struct option
*really_longopts
;
564 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
566 shortopts
= xmalloc (OPTION_COUNT
* 3 + 2);
567 longopts
= xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
568 really_longopts
= xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
570 /* Starting the short option string with '-' is for programs that
571 expect options and other ARGV-elements in any order and that care about
572 the ordering of the two. We describe each non-option ARGV-element
573 as if it were the argument of an option with character code 1. */
578 for (i
= 0; i
< OPTION_COUNT
; i
++)
580 if (ld_options
[i
].shortopt
!= '\0')
582 shortopts
[is
] = ld_options
[i
].shortopt
;
584 if (ld_options
[i
].opt
.has_arg
== required_argument
585 || ld_options
[i
].opt
.has_arg
== optional_argument
)
589 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
596 if (ld_options
[i
].opt
.name
!= NULL
)
598 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
600 really_longopts
[irl
] = ld_options
[i
].opt
;
605 longopts
[il
] = ld_options
[i
].opt
;
610 shortopts
[is
] = '\0';
611 longopts
[il
].name
= NULL
;
612 really_longopts
[irl
].name
= NULL
;
614 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
616 /* The -G option is ambiguous on different platforms. Sometimes it
617 specifies the largest data size to put into the small data
618 section. Sometimes it is equivalent to --shared. Unfortunately,
619 the first form takes an argument, while the second does not.
621 We need to permit the --shared form because on some platforms,
622 such as Solaris, gcc -shared will pass -G to the linker.
624 To permit either usage, we look through the argument list. If we
625 find -G not followed by a number, we change it into --shared.
626 This will work for most normal cases. */
627 for (i
= 1; i
< argc
; i
++)
628 if (strcmp (argv
[i
], "-G") == 0
630 || ! ISDIGIT (argv
[i
+ 1][0])))
631 argv
[i
] = (char *) "--shared";
633 /* Because we permit long options to start with a single dash, and
634 we have a --library option, and the -l option is conventionally
635 used with an immediately following argument, we can have bad
636 results if somebody tries to use -l with a library whose name
637 happens to start with "ibrary", as in -li. We avoid problems by
638 simply turning -l into --library. This means that users will
639 have to use two dashes in order to use --library, which is OK
640 since that's how it is documented.
642 FIXME: It's possible that this problem can arise for other short
643 options as well, although the user does always have the recourse
644 of adding a space between the option and the argument. */
645 for (i
= 1; i
< argc
; i
++)
647 if (argv
[i
][0] == '-'
649 && argv
[i
][2] != '\0')
653 n
= xmalloc (strlen (argv
[i
]) + 20);
654 sprintf (n
, "--library=%s", argv
[i
] + 2);
665 /* Using last_optind lets us avoid calling ldemul_parse_args
666 multiple times on a single option, which would lead to
667 confusion in the internal static variables maintained by
668 getopt. This could otherwise happen for an argument like
669 -nx, in which the -n is parsed as a single option, and we
670 loop around to pick up the -x. */
671 if (optind
!= last_optind
)
672 if (ldemul_parse_args (argc
, argv
))
675 /* getopt_long_only is like getopt_long, but '-' as well as '--'
676 can indicate a long option. */
678 last_optind
= optind
;
679 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
682 optind
= last_optind
;
683 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
686 if (ldemul_handle_option (optc
))
695 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
699 einfo (_("%P%F: use the --help option for usage information\n"));
701 case 1: /* File name. */
702 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
708 /* For HP/UX compatibility. Actually -a shared should mean
709 ``use only shared libraries'' but, then, we don't
710 currently support shared libraries on HP/UX anyhow. */
711 if (strcmp (optarg
, "archive") == 0)
712 config
.dynamic_link
= FALSE
;
713 else if (strcmp (optarg
, "shared") == 0
714 || strcmp (optarg
, "default") == 0)
715 config
.dynamic_link
= TRUE
;
717 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
720 /* FIXME: We just ignore these, but we should handle them. */
721 if (strcmp (optarg
, "definitions") == 0)
723 else if (strcmp (optarg
, "nodefinitions") == 0)
725 else if (strcmp (optarg
, "nosymbolic") == 0)
727 else if (strcmp (optarg
, "pure-text") == 0)
730 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
733 ldfile_add_arch (optarg
);
736 lang_add_target (optarg
);
739 ldfile_open_command_file (optarg
);
740 parser_input
= input_mri_script
;
743 case OPTION_CALL_SHARED
:
744 config
.dynamic_link
= TRUE
;
746 case OPTION_NON_SHARED
:
747 config
.dynamic_link
= FALSE
;
750 command_line
.cref
= TRUE
;
751 link_info
.notice_all
= TRUE
;
754 command_line
.force_common_definition
= TRUE
;
758 lex_redirect (optarg
);
759 parser_input
= input_defsym
;
765 case OPTION_DEMANGLE
:
769 enum demangling_styles style
;
771 style
= cplus_demangle_name_to_style (optarg
);
772 if (style
== unknown_demangling
)
773 einfo (_("%F%P: unknown demangling style `%s'"),
776 cplus_demangle_set_style (style
);
779 case 'I': /* Used on Solaris. */
780 case OPTION_DYNAMIC_LINKER
:
781 command_line
.interpreter
= optarg
;
784 /* Already handled in ldmain.c. */
787 command_line
.endian
= ENDIAN_BIG
;
790 command_line
.endian
= ENDIAN_LITTLE
;
792 case OPTION_EMBEDDED_RELOCS
:
793 command_line
.embedded_relocs
= TRUE
;
795 case OPTION_EXPORT_DYNAMIC
:
796 case 'E': /* HP/UX compatibility. */
797 link_info
.export_dynamic
= TRUE
;
800 lang_add_entry (optarg
, TRUE
);
803 if (command_line
.auxiliary_filters
== NULL
)
805 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
806 command_line
.auxiliary_filters
[0] = optarg
;
807 command_line
.auxiliary_filters
[1] = NULL
;
815 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
817 command_line
.auxiliary_filters
818 = xrealloc (command_line
.auxiliary_filters
,
819 (c
+ 2) * sizeof (char *));
820 command_line
.auxiliary_filters
[c
] = optarg
;
821 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
825 command_line
.filter_shlib
= optarg
;
827 case OPTION_FORCE_EXE_SUFFIX
:
828 command_line
.force_exe_suffix
= TRUE
;
833 g_switch_value
= strtoul (optarg
, &end
, 0);
835 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
841 case OPTION_GC_SECTIONS
:
842 link_info
.gc_sections
= TRUE
;
844 case OPTION_PRINT_GC_SECTIONS
:
845 link_info
.print_gc_sections
= TRUE
;
852 ldfile_add_library_path (optarg
, TRUE
);
855 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
858 config
.map_filename
= "-";
861 /* Ignore. Was handled in a pre-parse. */
864 config
.map_filename
= optarg
;
867 config
.text_read_only
= FALSE
;
868 config
.magic_demand_paged
= FALSE
;
869 config
.dynamic_link
= FALSE
;
871 case OPTION_NO_OMAGIC
:
872 config
.text_read_only
= TRUE
;
873 config
.magic_demand_paged
= TRUE
;
874 /* NB/ Does not set dynamic_link to TRUE.
875 Use --call-shared or -Bdynamic for this. */
878 config
.magic_demand_paged
= FALSE
;
879 config
.dynamic_link
= FALSE
;
881 case OPTION_NO_DEFINE_COMMON
:
882 command_line
.inhibit_common_definition
= TRUE
;
884 case OPTION_NO_DEMANGLE
:
887 case OPTION_NO_GC_SECTIONS
:
888 link_info
.gc_sections
= FALSE
;
890 case OPTION_NO_PRINT_GC_SECTIONS
:
891 link_info
.print_gc_sections
= FALSE
;
893 case OPTION_NO_KEEP_MEMORY
:
894 link_info
.keep_memory
= FALSE
;
896 case OPTION_NO_UNDEFINED
:
897 link_info
.unresolved_syms_in_objects
898 = how_to_report_unresolved_symbols
;
900 case OPTION_ALLOW_SHLIB_UNDEFINED
:
901 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
903 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
904 link_info
.unresolved_syms_in_shared_libs
905 = how_to_report_unresolved_symbols
;
907 case OPTION_UNRESOLVED_SYMBOLS
:
908 if (strcmp (optarg
, "ignore-all") == 0)
910 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
911 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
913 else if (strcmp (optarg
, "report-all") == 0)
915 link_info
.unresolved_syms_in_objects
916 = how_to_report_unresolved_symbols
;
917 link_info
.unresolved_syms_in_shared_libs
918 = how_to_report_unresolved_symbols
;
920 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
922 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
923 link_info
.unresolved_syms_in_shared_libs
924 = how_to_report_unresolved_symbols
;
926 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
928 link_info
.unresolved_syms_in_objects
929 = how_to_report_unresolved_symbols
;
930 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
933 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
935 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
936 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
937 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
938 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
939 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
940 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
943 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
944 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
945 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
946 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
947 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
948 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
950 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
951 link_info
.allow_multiple_definition
= TRUE
;
953 case OPTION_NO_UNDEFINED_VERSION
:
954 link_info
.allow_undefined_version
= FALSE
;
956 case OPTION_DEFAULT_SYMVER
:
957 link_info
.create_default_symver
= TRUE
;
959 case OPTION_DEFAULT_IMPORTED_SYMVER
:
960 link_info
.default_imported_symver
= TRUE
;
962 case OPTION_NO_WARN_MISMATCH
:
963 command_line
.warn_mismatch
= FALSE
;
965 case OPTION_NOINHIBIT_EXEC
:
966 force_make_executable
= TRUE
;
968 case OPTION_NOSTDLIB
:
969 config
.only_cmd_line_lib_dirs
= TRUE
;
971 case OPTION_NO_WHOLE_ARCHIVE
:
972 whole_archive
= FALSE
;
975 /* FIXME "-O<non-digits> <value>" used to set the address of
976 section <non-digits>. Was this for compatibility with
977 something, or can we create a new option to do that
978 (with a syntax similar to -defsym)?
979 getopt can't handle two args to an option without kludges. */
981 /* Enable optimizations of output files. */
982 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
985 lang_add_output (optarg
, 0);
988 lang_add_output_format (optarg
, NULL
, NULL
, 0);
991 link_info
.emitrelocations
= TRUE
;
995 if (optind
== last_optind
)
996 /* This can happen if the user put "-rpath,a" on the command
997 line. (Or something similar. The comma is important).
998 Getopt becomes confused and thinks that this is a -r option
999 but it cannot parse the text after the -r so it refuses to
1000 increment the optind counter. Detect this case and issue
1001 an error message here. We cannot just make this a warning,
1002 increment optind, and continue because getopt is too confused
1003 and will seg-fault the next time around. */
1004 einfo(_("%P%F: bad -rpath option\n"));
1006 link_info
.relocatable
= TRUE
;
1007 config
.build_constructors
= FALSE
;
1008 config
.magic_demand_paged
= FALSE
;
1009 config
.text_read_only
= FALSE
;
1010 config
.dynamic_link
= FALSE
;
1013 /* The GNU linker traditionally uses -R to mean to include
1014 only the symbols from a file. The Solaris linker uses -R
1015 to set the path used by the runtime linker to find
1016 libraries. This is the GNU linker -rpath argument. We
1017 try to support both simultaneously by checking the file
1018 named. If it is a directory, rather than a regular file,
1019 we assume -rpath was meant. */
1023 if (stat (optarg
, &s
) >= 0
1024 && ! S_ISDIR (s
.st_mode
))
1026 lang_add_input_file (optarg
,
1027 lang_input_file_is_symbols_only_enum
,
1034 if (command_line
.rpath
== NULL
)
1035 command_line
.rpath
= xstrdup (optarg
);
1038 size_t rpath_len
= strlen (command_line
.rpath
);
1039 size_t optarg_len
= strlen (optarg
);
1041 char *cp
= command_line
.rpath
;
1043 /* First see whether OPTARG is already in the path. */
1048 while (optarg
[idx
] != '\0' && optarg
[idx
] == cp
[idx
])
1050 if (optarg
[idx
] == '\0'
1051 && (cp
[idx
] == '\0' || cp
[idx
] == ':'))
1055 /* Not yet found. */
1056 cp
= strchr (cp
, ':');
1064 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1065 sprintf (buf
, "%s:%s", command_line
.rpath
, optarg
);
1066 free (command_line
.rpath
);
1067 command_line
.rpath
= buf
;
1071 case OPTION_RPATH_LINK
:
1072 if (command_line
.rpath_link
== NULL
)
1073 command_line
.rpath_link
= xstrdup (optarg
);
1078 buf
= xmalloc (strlen (command_line
.rpath_link
)
1081 sprintf (buf
, "%s:%s", command_line
.rpath_link
, optarg
);
1082 free (command_line
.rpath_link
);
1083 command_line
.rpath_link
= buf
;
1087 command_line
.relax
= TRUE
;
1089 case OPTION_RETAIN_SYMBOLS_FILE
:
1090 add_keepsyms_file (optarg
);
1093 link_info
.strip
= strip_debugger
;
1096 link_info
.strip
= strip_all
;
1098 case OPTION_STRIP_DISCARDED
:
1099 link_info
.strip_discarded
= TRUE
;
1101 case OPTION_NO_STRIP_DISCARDED
:
1102 link_info
.strip_discarded
= FALSE
;
1105 if (config
.has_shared
)
1107 link_info
.shared
= TRUE
;
1108 /* When creating a shared library, the default
1109 behaviour is to ignore any unresolved references. */
1110 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1111 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1112 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1113 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1116 einfo (_("%P%F: -shared not supported\n"));
1119 if (config
.has_shared
)
1121 link_info
.shared
= TRUE
;
1122 link_info
.pie
= TRUE
;
1125 einfo (_("%P%F: -pie not supported\n"));
1127 case 'h': /* Used on Solaris. */
1129 command_line
.soname
= optarg
;
1131 case OPTION_SORT_COMMON
:
1132 config
.sort_common
= TRUE
;
1134 case OPTION_SORT_SECTION
:
1135 if (strcmp (optarg
, N_("name")) == 0)
1136 sort_section
= by_name
;
1137 else if (strcmp (optarg
, N_("alignment")) == 0)
1138 sort_section
= by_alignment
;
1140 einfo (_("%P%F: invalid section sorting option: %s\n"),
1144 config
.stats
= TRUE
;
1146 case OPTION_SYMBOLIC
:
1147 link_info
.symbolic
= TRUE
;
1153 ldfile_open_command_file (optarg
);
1154 parser_input
= input_script
;
1157 case OPTION_DEFAULT_SCRIPT
:
1158 command_line
.default_script
= optarg
;
1160 case OPTION_SECTION_START
:
1166 /* Check for <something>=<somthing>... */
1167 optarg2
= strchr (optarg
, '=');
1168 if (optarg2
== NULL
)
1169 einfo (_("%P%F: invalid argument to option"
1170 " \"--section-start\"\n"));
1174 /* So far so good. Are all the args present? */
1175 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1176 einfo (_("%P%F: missing argument(s) to option"
1177 " \"--section-start\"\n"));
1179 /* We must copy the section name as set_section_start
1180 doesn't do it for us. */
1181 len
= optarg2
- optarg
;
1182 sec_name
= xmalloc (len
);
1183 memcpy (sec_name
, optarg
, len
- 1);
1184 sec_name
[len
- 1] = 0;
1186 /* Then set it... */
1187 set_section_start (sec_name
, optarg2
);
1190 case OPTION_TARGET_HELP
:
1191 /* Mention any target specific options. */
1192 ldemul_list_emulation_options (stdout
);
1195 set_segment_start (".bss", optarg
);
1198 set_segment_start (".data", optarg
);
1201 set_segment_start (".text", optarg
);
1203 case OPTION_TRADITIONAL_FORMAT
:
1204 link_info
.traditional_format
= TRUE
;
1206 case OPTION_TASK_LINK
:
1207 link_info
.task_link
= TRUE
;
1208 /* Fall through - do an implied -r option. */
1210 link_info
.relocatable
= TRUE
;
1211 config
.build_constructors
= TRUE
;
1212 config
.magic_demand_paged
= FALSE
;
1213 config
.text_read_only
= FALSE
;
1214 config
.dynamic_link
= FALSE
;
1217 ldlang_add_undef (optarg
);
1221 lang_add_unique (optarg
);
1223 config
.unique_orphan_sections
= TRUE
;
1225 case OPTION_VERBOSE
:
1227 version_printed
= TRUE
;
1228 trace_file_tries
= TRUE
;
1229 overflow_cutoff_limit
= -2;
1233 version_printed
= TRUE
;
1237 version_printed
= TRUE
;
1239 case OPTION_VERSION
:
1243 case OPTION_VERSION_SCRIPT
:
1244 /* This option indicates a small script that only specifies
1245 version information. Read it, but don't assume that
1246 we've seen a linker script. */
1248 FILE *hold_script_handle
;
1250 hold_script_handle
= saved_script_handle
;
1251 ldfile_open_command_file (optarg
);
1252 saved_script_handle
= hold_script_handle
;
1253 parser_input
= input_version_script
;
1257 case OPTION_VERSION_EXPORTS_SECTION
:
1258 /* This option records a version symbol to be applied to the
1259 symbols listed for export to be found in the object files
1260 .exports sections. */
1261 command_line
.version_exports_section
= optarg
;
1263 case OPTION_DYNAMIC_LIST_DATA
:
1264 link_info
.dynamic_data
= TRUE
;
1265 link_info
.dynamic
= TRUE
;
1267 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1268 lang_append_dynamic_list_cpp_typeinfo ();
1269 link_info
.dynamic
= TRUE
;
1271 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1272 lang_append_dynamic_list_cpp_new ();
1273 link_info
.dynamic
= TRUE
;
1275 case OPTION_DYNAMIC_LIST
:
1276 /* This option indicates a small script that only specifies
1277 a dynamic list. Read it, but don't assume that we've
1278 seen a linker script. */
1280 FILE *hold_script_handle
;
1282 hold_script_handle
= saved_script_handle
;
1283 ldfile_open_command_file (optarg
);
1284 saved_script_handle
= hold_script_handle
;
1285 parser_input
= input_dynamic_list
;
1288 link_info
.dynamic
= TRUE
;
1290 case OPTION_WARN_COMMON
:
1291 config
.warn_common
= TRUE
;
1293 case OPTION_WARN_CONSTRUCTORS
:
1294 config
.warn_constructors
= TRUE
;
1296 case OPTION_WARN_FATAL
:
1297 config
.fatal_warnings
= TRUE
;
1299 case OPTION_WARN_MULTIPLE_GP
:
1300 config
.warn_multiple_gp
= TRUE
;
1302 case OPTION_WARN_ONCE
:
1303 config
.warn_once
= TRUE
;
1305 case OPTION_WARN_SECTION_ALIGN
:
1306 config
.warn_section_align
= TRUE
;
1308 case OPTION_WARN_SHARED_TEXTREL
:
1309 link_info
.warn_shared_textrel
= TRUE
;
1311 case OPTION_WHOLE_ARCHIVE
:
1312 whole_archive
= TRUE
;
1314 case OPTION_ADD_NEEDED
:
1317 case OPTION_NO_ADD_NEEDED
:
1320 case OPTION_AS_NEEDED
:
1323 case OPTION_NO_AS_NEEDED
:
1329 case OPTION_DISCARD_NONE
:
1330 link_info
.discard
= discard_none
;
1333 link_info
.discard
= discard_l
;
1336 link_info
.discard
= discard_all
;
1339 if (CONST_STRNEQ (optarg
, "P,"))
1341 if (default_dirlist
!= NULL
)
1342 free (default_dirlist
);
1343 default_dirlist
= xstrdup (optarg
);
1348 case OPTION_SPARE_DYNAMIC_TAGS
:
1349 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1351 case OPTION_SPLIT_BY_RELOC
:
1353 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1355 config
.split_by_reloc
= 32768;
1357 case OPTION_SPLIT_BY_FILE
:
1359 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1361 config
.split_by_file
= 1;
1363 case OPTION_CHECK_SECTIONS
:
1364 command_line
.check_section_addresses
= TRUE
;
1366 case OPTION_NO_CHECK_SECTIONS
:
1367 command_line
.check_section_addresses
= FALSE
;
1369 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1370 command_line
.accept_unknown_input_arch
= TRUE
;
1372 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1373 command_line
.accept_unknown_input_arch
= FALSE
;
1377 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1379 lang_enter_group ();
1384 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1386 lang_leave_group ();
1391 link_info
.init_function
= optarg
;
1395 link_info
.fini_function
= optarg
;
1398 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1399 link_info
.reduce_memory_overheads
= TRUE
;
1400 if (config
.hash_table_size
== 0)
1401 config
.hash_table_size
= 1021;
1404 case OPTION_HASH_SIZE
:
1406 bfd_size_type new_size
;
1408 new_size
= strtoul (optarg
, NULL
, 0);
1410 config
.hash_table_size
= new_size
;
1412 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1419 lang_leave_group ();
1421 if (default_dirlist
!= NULL
)
1423 set_default_dirlist (default_dirlist
);
1424 free (default_dirlist
);
1427 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1428 /* FIXME: Should we allow emulations a chance to set this ? */
1429 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1431 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1432 /* FIXME: Should we allow emulations a chance to set this ? */
1433 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1436 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1437 library search path. */
1440 set_default_dirlist (char *dirlist_ptr
)
1446 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1449 if (*dirlist_ptr
!= '\0')
1450 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1453 dirlist_ptr
= p
+ 1;
1458 set_section_start (char *sect
, char *valstr
)
1461 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1463 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1464 lang_section_start (sect
, exp_intop (val
), NULL
);
1468 set_segment_start (const char *section
, char *valstr
)
1474 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1476 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1477 /* If we already have an entry for this segment, update the existing
1480 for (seg
= segments
; seg
; seg
= seg
->next
)
1481 if (strcmp (seg
->name
, name
) == 0)
1486 /* There was no existing value so we must create a new segment
1488 seg
= stat_alloc (sizeof (*seg
));
1492 /* Add it to the linked list of segments. */
1493 seg
->next
= segments
;
1495 /* Historically, -Ttext and friends set the base address of a
1496 particular section. For backwards compatibility, we still do
1497 that. If a SEGMENT_START directive is seen, the section address
1498 assignment will be disabled. */
1499 lang_section_start (section
, exp_intop (val
), seg
);
1503 /* Print help messages for the options. */
1509 const char **targets
, **pp
;
1512 printf (_("Usage: %s [options] file...\n"), program_name
);
1514 printf (_("Options:\n"));
1515 for (i
= 0; i
< OPTION_COUNT
; i
++)
1517 if (ld_options
[i
].doc
!= NULL
)
1530 if (ld_options
[j
].shortopt
!= '\0'
1531 && ld_options
[j
].control
!= NO_HELP
)
1533 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1534 len
+= (comma
? 2 : 0) + 2;
1535 if (ld_options
[j
].arg
!= NULL
)
1537 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1542 printf ("%s", _(ld_options
[j
].arg
));
1543 len
+= strlen (_(ld_options
[j
].arg
));
1549 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1554 if (ld_options
[j
].opt
.name
!= NULL
1555 && ld_options
[j
].control
!= NO_HELP
)
1558 (ld_options
[j
].control
== TWO_DASHES
1559 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1563 two_dashes
? "-" : "",
1564 ld_options
[j
].opt
.name
);
1565 len
+= ((comma
? 2 : 0)
1567 + (two_dashes
? 1 : 0)
1568 + strlen (ld_options
[j
].opt
.name
));
1569 if (ld_options
[j
].arg
!= NULL
)
1571 printf (" %s", _(ld_options
[j
].arg
));
1572 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1578 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1586 for (; len
< 30; len
++)
1589 printf ("%s\n", _(ld_options
[i
].doc
));
1592 printf (_(" @FILE"));
1593 for (len
= strlen (" @FILE"); len
< 30; len
++)
1595 printf (_("Read options from FILE\n"));
1597 /* Note: Various tools (such as libtool) depend upon the
1598 format of the listings below - do not change them. */
1599 /* xgettext:c-format */
1600 printf (_("%s: supported targets:"), program_name
);
1601 targets
= bfd_target_list ();
1602 for (pp
= targets
; *pp
!= NULL
; pp
++)
1603 printf (" %s", *pp
);
1607 /* xgettext:c-format */
1608 printf (_("%s: supported emulations: "), program_name
);
1609 ldemul_list_emulations (stdout
);
1612 /* xgettext:c-format */
1613 printf (_("%s: emulation specific options:\n"), program_name
);
1614 ldemul_list_emulation_options (stdout
);
1617 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);