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
,
100 OPTION_SYMBOLIC_FUNCTIONS
,
105 OPTION_TRADITIONAL_FORMAT
,
109 OPTION_VERSION_SCRIPT
,
110 OPTION_VERSION_EXPORTS_SECTION
,
112 OPTION_DYNAMIC_LIST_CPP_NEW
,
113 OPTION_DYNAMIC_LIST_CPP_TYPEINFO
,
114 OPTION_DYNAMIC_LIST_DATA
,
116 OPTION_WARN_CONSTRUCTORS
,
118 OPTION_WARN_MULTIPLE_GP
,
120 OPTION_WARN_SECTION_ALIGN
,
121 OPTION_SPLIT_BY_RELOC
,
122 OPTION_SPLIT_BY_FILE
,
123 OPTION_WHOLE_ARCHIVE
,
125 OPTION_NO_ADD_NEEDED
,
129 OPTION_FORCE_EXE_SUFFIX
,
131 OPTION_NO_GC_SECTIONS
,
132 OPTION_PRINT_GC_SECTIONS
,
133 OPTION_NO_PRINT_GC_SECTIONS
,
135 OPTION_CHECK_SECTIONS
,
136 OPTION_NO_CHECK_SECTIONS
,
140 OPTION_SECTION_START
,
143 OPTION_ALLOW_SHLIB_UNDEFINED
,
144 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
145 OPTION_ALLOW_MULTIPLE_DEFINITION
,
146 OPTION_NO_UNDEFINED_VERSION
,
147 OPTION_DEFAULT_SYMVER
,
148 OPTION_DEFAULT_IMPORTED_SYMVER
,
150 OPTION_SPARE_DYNAMIC_TAGS
,
151 OPTION_NO_DEFINE_COMMON
,
154 OPTION_STRIP_DISCARDED
,
155 OPTION_NO_STRIP_DISCARDED
,
156 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
157 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
159 OPTION_UNRESOLVED_SYMBOLS
,
160 OPTION_WARN_UNRESOLVED_SYMBOLS
,
161 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
162 OPTION_WARN_SHARED_TEXTREL
,
163 OPTION_REDUCE_MEMORY_OVERHEADS
,
164 OPTION_DEFAULT_SCRIPT
167 /* The long options. This structure is used for both the option
168 parsing and the help text. */
172 /* The long option information. */
174 /* The short option with the same meaning ('\0' if none). */
176 /* The name of the argument (NULL if none). */
178 /* The documentation string. If this is NULL, this is a synonym for
179 the previous option. */
182 /* Use one dash before long option name. */
184 /* Use two dashes before long option name. */
186 /* Only accept two dashes before the long option name.
187 This is an overloading of the use of this enum, since originally it
188 was only intended to tell the --help display function how to display
189 the long option name. This feature was added in order to resolve
190 the confusion about the -omagic command line switch. Is it setting
191 the output file name to "magic" or is it setting the NMAGIC flag on
192 the output ? It has been decided that it is setting the output file
193 name, and that if you want to set the NMAGIC flag you should use -N
196 /* Don't mention this option in --help output. */
201 static const struct ld_option ld_options
[] =
203 { {NULL
, required_argument
, NULL
, '\0'},
204 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
206 { {"architecture", required_argument
, NULL
, 'A'},
207 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
208 { {"format", required_argument
, NULL
, 'b'},
209 'b', N_("TARGET"), N_("Specify target for following input files"),
211 { {"mri-script", required_argument
, NULL
, 'c'},
212 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
213 { {"dc", no_argument
, NULL
, 'd'},
214 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
215 { {"dp", no_argument
, NULL
, 'd'},
216 '\0', NULL
, NULL
, ONE_DASH
},
217 { {"entry", required_argument
, NULL
, 'e'},
218 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
219 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
220 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
221 { {"EB", no_argument
, NULL
, OPTION_EB
},
222 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
223 { {"EL", no_argument
, NULL
, OPTION_EL
},
224 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
225 { {"auxiliary", required_argument
, NULL
, 'f'},
226 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
228 { {"filter", required_argument
, NULL
, 'F'},
229 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
231 { {NULL
, no_argument
, NULL
, '\0'},
232 'g', NULL
, N_("Ignored"), ONE_DASH
},
233 { {"gpsize", required_argument
, NULL
, 'G'},
234 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
236 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
237 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
238 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
239 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
241 { {"library", required_argument
, NULL
, 'l'},
242 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
243 { {"library-path", required_argument
, NULL
, 'L'},
244 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
246 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
247 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
248 { {NULL
, required_argument
, NULL
, '\0'},
249 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
250 { {"print-map", no_argument
, NULL
, 'M'},
251 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
252 { {"nmagic", no_argument
, NULL
, 'n'},
253 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
254 { {"omagic", no_argument
, NULL
, 'N'},
255 'N', NULL
, N_("Do not page align data, do not make text readonly"),
256 EXACTLY_TWO_DASHES
},
257 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
258 '\0', NULL
, N_("Page align data, make text readonly"),
259 EXACTLY_TWO_DASHES
},
260 { {"output", required_argument
, NULL
, 'o'},
261 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
262 { {NULL
, required_argument
, NULL
, '\0'},
263 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
264 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
265 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
266 { {"emit-relocs", no_argument
, NULL
, 'q'},
267 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
268 { {"relocatable", no_argument
, NULL
, 'r'},
269 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
270 { {NULL
, no_argument
, NULL
, '\0'},
271 'i', NULL
, NULL
, ONE_DASH
},
272 { {"just-symbols", required_argument
, NULL
, 'R'},
273 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
275 { {"strip-all", no_argument
, NULL
, 's'},
276 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
277 { {"strip-debug", no_argument
, NULL
, 'S'},
278 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
279 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
280 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
281 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
282 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
283 { {"trace", no_argument
, NULL
, 't'},
284 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
285 { {"script", required_argument
, NULL
, 'T'},
286 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
287 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
288 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
289 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
290 '\0', NULL
, NULL
, ONE_DASH
},
291 { {"undefined", required_argument
, NULL
, 'u'},
292 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
294 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
295 '\0', N_("[=SECTION]"),
296 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
297 { {"Ur", no_argument
, NULL
, OPTION_UR
},
298 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
299 { {"version", no_argument
, NULL
, OPTION_VERSION
},
300 'v', NULL
, N_("Print version information"), TWO_DASHES
},
301 { {NULL
, no_argument
, NULL
, '\0'},
302 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
303 { {"discard-all", no_argument
, NULL
, 'x'},
304 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
305 { {"discard-locals", no_argument
, NULL
, 'X'},
306 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
307 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
308 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
309 { {"trace-symbol", required_argument
, NULL
, 'y'},
310 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
311 { {NULL
, required_argument
, NULL
, '\0'},
312 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
314 { {"start-group", no_argument
, NULL
, '('},
315 '(', NULL
, N_("Start a group"), TWO_DASHES
},
316 { {"end-group", no_argument
, NULL
, ')'},
317 ')', NULL
, N_("End a group"), TWO_DASHES
},
318 { {"accept-unknown-input-arch", no_argument
, NULL
,
319 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
321 N_("Accept input files whose architecture cannot be determined"),
323 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
324 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
325 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
327 { {"add-needed", no_argument
, NULL
, OPTION_ADD_NEEDED
},
328 '\0', NULL
, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
329 "\t\t\t\tfollowing dynamic libs"), TWO_DASHES
},
330 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_NEEDED
},
331 '\0', NULL
, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
332 "\t\t\t\tin following dynamic libs"), TWO_DASHES
},
333 { {"as-needed", no_argument
, NULL
, OPTION_AS_NEEDED
},
334 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
336 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_AS_NEEDED
},
337 '\0', NULL
, N_("Always set DT_NEEDED for following dynamic libs"),
339 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
340 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
341 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
342 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
343 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
344 '\0', NULL
, NULL
, ONE_DASH
},
345 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
346 '\0', NULL
, NULL
, ONE_DASH
},
347 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
348 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
349 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
350 '\0', NULL
, NULL
, ONE_DASH
},
351 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
352 '\0', NULL
, NULL
, ONE_DASH
},
353 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
354 '\0', NULL
, NULL
, ONE_DASH
},
355 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
356 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
357 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
358 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
359 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
360 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
362 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
363 '\0', NULL
, N_("Do not check section addresses for overlaps"),
365 { {"cref", no_argument
, NULL
, OPTION_CREF
},
366 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
367 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
368 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
369 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
370 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
372 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
373 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
374 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
375 '\0', NULL
, N_("Treat warnings as errors"),
377 { {"fini", required_argument
, NULL
, OPTION_FINI
},
378 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
379 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
380 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
381 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
382 '\0', NULL
, N_("Remove unused sections (on some targets)"),
384 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
385 '\0', NULL
, N_("Don't remove unused sections (default)"),
387 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
388 '\0', NULL
, N_("List removed unused sections on stderr"),
390 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
391 '\0', NULL
, N_("Do not list removed unused sections"),
393 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
394 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
396 { {"help", no_argument
, NULL
, OPTION_HELP
},
397 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
398 { {"init", required_argument
, NULL
, OPTION_INIT
},
399 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
400 { {"Map", required_argument
, NULL
, OPTION_MAP
},
401 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
402 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
403 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
404 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
405 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
406 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
407 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
408 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
409 '\0', NULL
, N_("Do not allow unresolved references in object files"),
411 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
412 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
414 { {"no-allow-shlib-undefined", no_argument
, NULL
,
415 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
416 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
418 { {"allow-multiple-definition", no_argument
, NULL
,
419 OPTION_ALLOW_MULTIPLE_DEFINITION
},
420 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
421 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
422 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
423 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
424 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
425 { {"default-imported-symver", no_argument
, NULL
,
426 OPTION_DEFAULT_IMPORTED_SYMVER
},
427 '\0', NULL
, N_("Create default symbol version for imported symbols"),
429 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
430 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
431 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
432 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
433 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
434 '\0', NULL
, N_("Create an output file even if errors occur"),
436 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
437 '\0', NULL
, NULL
, NO_HELP
},
438 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
439 '\0', NULL
, N_("Only use library directories specified on\n"
440 "\t\t\t\tthe command line"), ONE_DASH
},
441 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
442 '\0', N_("TARGET"), N_("Specify target of output file"),
443 EXACTLY_TWO_DASHES
},
444 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
445 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
446 { {"reduce-memory-overheads", no_argument
, NULL
,
447 OPTION_REDUCE_MEMORY_OVERHEADS
},
448 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
450 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
451 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
452 { {"retain-symbols-file", required_argument
, NULL
,
453 OPTION_RETAIN_SYMBOLS_FILE
},
454 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
455 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
456 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
457 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
458 '\0', N_("PATH"), N_("Set link time shared library search path"),
460 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
461 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
462 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
463 '\0', NULL
, NULL
, ONE_DASH
},
464 { {"pie", no_argument
, NULL
, OPTION_PIE
},
465 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
466 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
467 '\0', NULL
, NULL
, TWO_DASHES
},
468 { {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
469 '\0', NULL
, N_("Sort common symbols by size"), TWO_DASHES
},
470 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
471 '\0', NULL
, NULL
, NO_HELP
},
472 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
473 '\0', N_("name|alignment"),
474 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
475 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
476 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
478 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
479 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
481 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
482 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
484 { {"stats", no_argument
, NULL
, OPTION_STATS
},
485 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
486 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
487 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
488 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
489 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
490 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
491 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
492 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
493 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
495 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
496 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
497 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
498 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
499 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
500 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
501 { {"unresolved-symbols=<method>", required_argument
, NULL
,
502 OPTION_UNRESOLVED_SYMBOLS
},
503 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
504 "\t\t\t\tignore-all, report-all, ignore-in-object-files,\n"
505 "\t\t\t\tignore-in-shared-libs"), TWO_DASHES
},
506 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
507 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
508 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
509 '\0', NULL
, NULL
, NO_HELP
},
510 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
511 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
512 { {"version-exports-section", required_argument
, NULL
,
513 OPTION_VERSION_EXPORTS_SECTION
},
514 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
515 "\t\t\t\tSYMBOL as the version."), TWO_DASHES
},
516 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
517 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
518 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
519 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
520 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
521 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
522 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
523 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
524 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
525 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
526 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
527 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
529 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
530 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
531 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
532 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
533 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
534 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
536 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
537 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
539 { {"warn-unresolved-symbols", no_argument
, NULL
,
540 OPTION_WARN_UNRESOLVED_SYMBOLS
},
541 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
542 { {"error-unresolved-symbols", no_argument
, NULL
,
543 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
544 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
545 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
546 '\0', NULL
, N_("Include all objects from following archives"),
548 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
549 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
552 #define OPTION_COUNT ARRAY_SIZE (ld_options)
555 parse_args (unsigned argc
, char **argv
)
560 char *default_dirlist
= NULL
;
562 struct option
*longopts
;
563 struct option
*really_longopts
;
565 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
567 shortopts
= xmalloc (OPTION_COUNT
* 3 + 2);
568 longopts
= xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
569 really_longopts
= xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
571 /* Starting the short option string with '-' is for programs that
572 expect options and other ARGV-elements in any order and that care about
573 the ordering of the two. We describe each non-option ARGV-element
574 as if it were the argument of an option with character code 1. */
579 for (i
= 0; i
< OPTION_COUNT
; i
++)
581 if (ld_options
[i
].shortopt
!= '\0')
583 shortopts
[is
] = ld_options
[i
].shortopt
;
585 if (ld_options
[i
].opt
.has_arg
== required_argument
586 || ld_options
[i
].opt
.has_arg
== optional_argument
)
590 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
597 if (ld_options
[i
].opt
.name
!= NULL
)
599 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
601 really_longopts
[irl
] = ld_options
[i
].opt
;
606 longopts
[il
] = ld_options
[i
].opt
;
611 shortopts
[is
] = '\0';
612 longopts
[il
].name
= NULL
;
613 really_longopts
[irl
].name
= NULL
;
615 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
617 /* The -G option is ambiguous on different platforms. Sometimes it
618 specifies the largest data size to put into the small data
619 section. Sometimes it is equivalent to --shared. Unfortunately,
620 the first form takes an argument, while the second does not.
622 We need to permit the --shared form because on some platforms,
623 such as Solaris, gcc -shared will pass -G to the linker.
625 To permit either usage, we look through the argument list. If we
626 find -G not followed by a number, we change it into --shared.
627 This will work for most normal cases. */
628 for (i
= 1; i
< argc
; i
++)
629 if (strcmp (argv
[i
], "-G") == 0
631 || ! ISDIGIT (argv
[i
+ 1][0])))
632 argv
[i
] = (char *) "--shared";
634 /* Because we permit long options to start with a single dash, and
635 we have a --library option, and the -l option is conventionally
636 used with an immediately following argument, we can have bad
637 results if somebody tries to use -l with a library whose name
638 happens to start with "ibrary", as in -li. We avoid problems by
639 simply turning -l into --library. This means that users will
640 have to use two dashes in order to use --library, which is OK
641 since that's how it is documented.
643 FIXME: It's possible that this problem can arise for other short
644 options as well, although the user does always have the recourse
645 of adding a space between the option and the argument. */
646 for (i
= 1; i
< argc
; i
++)
648 if (argv
[i
][0] == '-'
650 && argv
[i
][2] != '\0')
654 n
= xmalloc (strlen (argv
[i
]) + 20);
655 sprintf (n
, "--library=%s", argv
[i
] + 2);
666 /* Using last_optind lets us avoid calling ldemul_parse_args
667 multiple times on a single option, which would lead to
668 confusion in the internal static variables maintained by
669 getopt. This could otherwise happen for an argument like
670 -nx, in which the -n is parsed as a single option, and we
671 loop around to pick up the -x. */
672 if (optind
!= last_optind
)
673 if (ldemul_parse_args (argc
, argv
))
676 /* getopt_long_only is like getopt_long, but '-' as well as '--'
677 can indicate a long option. */
679 last_optind
= optind
;
680 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
683 optind
= last_optind
;
684 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
687 if (ldemul_handle_option (optc
))
696 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
700 einfo (_("%P%F: use the --help option for usage information\n"));
702 case 1: /* File name. */
703 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
709 /* For HP/UX compatibility. Actually -a shared should mean
710 ``use only shared libraries'' but, then, we don't
711 currently support shared libraries on HP/UX anyhow. */
712 if (strcmp (optarg
, "archive") == 0)
713 config
.dynamic_link
= FALSE
;
714 else if (strcmp (optarg
, "shared") == 0
715 || strcmp (optarg
, "default") == 0)
716 config
.dynamic_link
= TRUE
;
718 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
721 /* FIXME: We just ignore these, but we should handle them. */
722 if (strcmp (optarg
, "definitions") == 0)
724 else if (strcmp (optarg
, "nodefinitions") == 0)
726 else if (strcmp (optarg
, "nosymbolic") == 0)
728 else if (strcmp (optarg
, "pure-text") == 0)
731 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
734 ldfile_add_arch (optarg
);
737 lang_add_target (optarg
);
740 ldfile_open_command_file (optarg
);
741 parser_input
= input_mri_script
;
744 case OPTION_CALL_SHARED
:
745 config
.dynamic_link
= TRUE
;
747 case OPTION_NON_SHARED
:
748 config
.dynamic_link
= FALSE
;
751 command_line
.cref
= TRUE
;
752 link_info
.notice_all
= TRUE
;
755 command_line
.force_common_definition
= TRUE
;
759 lex_redirect (optarg
);
760 parser_input
= input_defsym
;
766 case OPTION_DEMANGLE
:
770 enum demangling_styles style
;
772 style
= cplus_demangle_name_to_style (optarg
);
773 if (style
== unknown_demangling
)
774 einfo (_("%F%P: unknown demangling style `%s'"),
777 cplus_demangle_set_style (style
);
780 case 'I': /* Used on Solaris. */
781 case OPTION_DYNAMIC_LINKER
:
782 command_line
.interpreter
= optarg
;
785 /* Already handled in ldmain.c. */
788 command_line
.endian
= ENDIAN_BIG
;
791 command_line
.endian
= ENDIAN_LITTLE
;
793 case OPTION_EMBEDDED_RELOCS
:
794 command_line
.embedded_relocs
= TRUE
;
796 case OPTION_EXPORT_DYNAMIC
:
797 case 'E': /* HP/UX compatibility. */
798 link_info
.export_dynamic
= TRUE
;
801 lang_add_entry (optarg
, TRUE
);
804 if (command_line
.auxiliary_filters
== NULL
)
806 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
807 command_line
.auxiliary_filters
[0] = optarg
;
808 command_line
.auxiliary_filters
[1] = NULL
;
816 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
818 command_line
.auxiliary_filters
819 = xrealloc (command_line
.auxiliary_filters
,
820 (c
+ 2) * sizeof (char *));
821 command_line
.auxiliary_filters
[c
] = optarg
;
822 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
826 command_line
.filter_shlib
= optarg
;
828 case OPTION_FORCE_EXE_SUFFIX
:
829 command_line
.force_exe_suffix
= TRUE
;
834 g_switch_value
= strtoul (optarg
, &end
, 0);
836 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
842 case OPTION_GC_SECTIONS
:
843 link_info
.gc_sections
= TRUE
;
845 case OPTION_PRINT_GC_SECTIONS
:
846 link_info
.print_gc_sections
= TRUE
;
853 ldfile_add_library_path (optarg
, TRUE
);
856 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
859 config
.map_filename
= "-";
862 /* Ignore. Was handled in a pre-parse. */
865 config
.map_filename
= optarg
;
868 config
.text_read_only
= FALSE
;
869 config
.magic_demand_paged
= FALSE
;
870 config
.dynamic_link
= FALSE
;
872 case OPTION_NO_OMAGIC
:
873 config
.text_read_only
= TRUE
;
874 config
.magic_demand_paged
= TRUE
;
875 /* NB/ Does not set dynamic_link to TRUE.
876 Use --call-shared or -Bdynamic for this. */
879 config
.magic_demand_paged
= FALSE
;
880 config
.dynamic_link
= FALSE
;
882 case OPTION_NO_DEFINE_COMMON
:
883 command_line
.inhibit_common_definition
= TRUE
;
885 case OPTION_NO_DEMANGLE
:
888 case OPTION_NO_GC_SECTIONS
:
889 link_info
.gc_sections
= FALSE
;
891 case OPTION_NO_PRINT_GC_SECTIONS
:
892 link_info
.print_gc_sections
= FALSE
;
894 case OPTION_NO_KEEP_MEMORY
:
895 link_info
.keep_memory
= FALSE
;
897 case OPTION_NO_UNDEFINED
:
898 link_info
.unresolved_syms_in_objects
899 = how_to_report_unresolved_symbols
;
901 case OPTION_ALLOW_SHLIB_UNDEFINED
:
902 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
904 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
905 link_info
.unresolved_syms_in_shared_libs
906 = how_to_report_unresolved_symbols
;
908 case OPTION_UNRESOLVED_SYMBOLS
:
909 if (strcmp (optarg
, "ignore-all") == 0)
911 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
912 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
914 else if (strcmp (optarg
, "report-all") == 0)
916 link_info
.unresolved_syms_in_objects
917 = how_to_report_unresolved_symbols
;
918 link_info
.unresolved_syms_in_shared_libs
919 = how_to_report_unresolved_symbols
;
921 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
923 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
924 link_info
.unresolved_syms_in_shared_libs
925 = how_to_report_unresolved_symbols
;
927 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
929 link_info
.unresolved_syms_in_objects
930 = how_to_report_unresolved_symbols
;
931 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
934 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
936 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
937 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
938 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
939 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
940 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
941 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
944 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
945 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
946 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
947 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
948 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
949 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
951 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
952 link_info
.allow_multiple_definition
= TRUE
;
954 case OPTION_NO_UNDEFINED_VERSION
:
955 link_info
.allow_undefined_version
= FALSE
;
957 case OPTION_DEFAULT_SYMVER
:
958 link_info
.create_default_symver
= TRUE
;
960 case OPTION_DEFAULT_IMPORTED_SYMVER
:
961 link_info
.default_imported_symver
= TRUE
;
963 case OPTION_NO_WARN_MISMATCH
:
964 command_line
.warn_mismatch
= FALSE
;
966 case OPTION_NOINHIBIT_EXEC
:
967 force_make_executable
= TRUE
;
969 case OPTION_NOSTDLIB
:
970 config
.only_cmd_line_lib_dirs
= TRUE
;
972 case OPTION_NO_WHOLE_ARCHIVE
:
973 whole_archive
= FALSE
;
976 /* FIXME "-O<non-digits> <value>" used to set the address of
977 section <non-digits>. Was this for compatibility with
978 something, or can we create a new option to do that
979 (with a syntax similar to -defsym)?
980 getopt can't handle two args to an option without kludges. */
982 /* Enable optimizations of output files. */
983 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
986 lang_add_output (optarg
, 0);
989 lang_add_output_format (optarg
, NULL
, NULL
, 0);
992 link_info
.emitrelocations
= TRUE
;
996 if (optind
== last_optind
)
997 /* This can happen if the user put "-rpath,a" on the command
998 line. (Or something similar. The comma is important).
999 Getopt becomes confused and thinks that this is a -r option
1000 but it cannot parse the text after the -r so it refuses to
1001 increment the optind counter. Detect this case and issue
1002 an error message here. We cannot just make this a warning,
1003 increment optind, and continue because getopt is too confused
1004 and will seg-fault the next time around. */
1005 einfo(_("%P%F: bad -rpath option\n"));
1007 link_info
.relocatable
= TRUE
;
1008 config
.build_constructors
= FALSE
;
1009 config
.magic_demand_paged
= FALSE
;
1010 config
.text_read_only
= FALSE
;
1011 config
.dynamic_link
= FALSE
;
1014 /* The GNU linker traditionally uses -R to mean to include
1015 only the symbols from a file. The Solaris linker uses -R
1016 to set the path used by the runtime linker to find
1017 libraries. This is the GNU linker -rpath argument. We
1018 try to support both simultaneously by checking the file
1019 named. If it is a directory, rather than a regular file,
1020 we assume -rpath was meant. */
1024 if (stat (optarg
, &s
) >= 0
1025 && ! S_ISDIR (s
.st_mode
))
1027 lang_add_input_file (optarg
,
1028 lang_input_file_is_symbols_only_enum
,
1035 if (command_line
.rpath
== NULL
)
1036 command_line
.rpath
= xstrdup (optarg
);
1039 size_t rpath_len
= strlen (command_line
.rpath
);
1040 size_t optarg_len
= strlen (optarg
);
1042 char *cp
= command_line
.rpath
;
1044 /* First see whether OPTARG is already in the path. */
1049 while (optarg
[idx
] != '\0' && optarg
[idx
] == cp
[idx
])
1051 if (optarg
[idx
] == '\0'
1052 && (cp
[idx
] == '\0' || cp
[idx
] == ':'))
1056 /* Not yet found. */
1057 cp
= strchr (cp
, ':');
1065 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1066 sprintf (buf
, "%s:%s", command_line
.rpath
, optarg
);
1067 free (command_line
.rpath
);
1068 command_line
.rpath
= buf
;
1072 case OPTION_RPATH_LINK
:
1073 if (command_line
.rpath_link
== NULL
)
1074 command_line
.rpath_link
= xstrdup (optarg
);
1079 buf
= xmalloc (strlen (command_line
.rpath_link
)
1082 sprintf (buf
, "%s:%s", command_line
.rpath_link
, optarg
);
1083 free (command_line
.rpath_link
);
1084 command_line
.rpath_link
= buf
;
1088 command_line
.relax
= TRUE
;
1090 case OPTION_RETAIN_SYMBOLS_FILE
:
1091 add_keepsyms_file (optarg
);
1094 link_info
.strip
= strip_debugger
;
1097 link_info
.strip
= strip_all
;
1099 case OPTION_STRIP_DISCARDED
:
1100 link_info
.strip_discarded
= TRUE
;
1102 case OPTION_NO_STRIP_DISCARDED
:
1103 link_info
.strip_discarded
= FALSE
;
1106 if (config
.has_shared
)
1108 link_info
.shared
= TRUE
;
1109 /* When creating a shared library, the default
1110 behaviour is to ignore any unresolved references. */
1111 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1112 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1113 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1114 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1117 einfo (_("%P%F: -shared not supported\n"));
1120 if (config
.has_shared
)
1122 link_info
.shared
= TRUE
;
1123 link_info
.pie
= TRUE
;
1126 einfo (_("%P%F: -pie not supported\n"));
1128 case 'h': /* Used on Solaris. */
1130 command_line
.soname
= optarg
;
1132 case OPTION_SORT_COMMON
:
1133 config
.sort_common
= TRUE
;
1135 case OPTION_SORT_SECTION
:
1136 if (strcmp (optarg
, N_("name")) == 0)
1137 sort_section
= by_name
;
1138 else if (strcmp (optarg
, N_("alignment")) == 0)
1139 sort_section
= by_alignment
;
1141 einfo (_("%P%F: invalid section sorting option: %s\n"),
1145 config
.stats
= TRUE
;
1147 case OPTION_SYMBOLIC
:
1148 command_line
.symbolic
= symbolic
;
1150 case OPTION_SYMBOLIC_FUNCTIONS
:
1151 command_line
.symbolic
= symbolic_functions
;
1157 ldfile_open_command_file (optarg
);
1158 parser_input
= input_script
;
1161 case OPTION_DEFAULT_SCRIPT
:
1162 command_line
.default_script
= optarg
;
1164 case OPTION_SECTION_START
:
1170 /* Check for <something>=<somthing>... */
1171 optarg2
= strchr (optarg
, '=');
1172 if (optarg2
== NULL
)
1173 einfo (_("%P%F: invalid argument to option"
1174 " \"--section-start\"\n"));
1178 /* So far so good. Are all the args present? */
1179 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1180 einfo (_("%P%F: missing argument(s) to option"
1181 " \"--section-start\"\n"));
1183 /* We must copy the section name as set_section_start
1184 doesn't do it for us. */
1185 len
= optarg2
- optarg
;
1186 sec_name
= xmalloc (len
);
1187 memcpy (sec_name
, optarg
, len
- 1);
1188 sec_name
[len
- 1] = 0;
1190 /* Then set it... */
1191 set_section_start (sec_name
, optarg2
);
1194 case OPTION_TARGET_HELP
:
1195 /* Mention any target specific options. */
1196 ldemul_list_emulation_options (stdout
);
1199 set_segment_start (".bss", optarg
);
1202 set_segment_start (".data", optarg
);
1205 set_segment_start (".text", optarg
);
1207 case OPTION_TRADITIONAL_FORMAT
:
1208 link_info
.traditional_format
= TRUE
;
1210 case OPTION_TASK_LINK
:
1211 link_info
.task_link
= TRUE
;
1212 /* Fall through - do an implied -r option. */
1214 link_info
.relocatable
= TRUE
;
1215 config
.build_constructors
= TRUE
;
1216 config
.magic_demand_paged
= FALSE
;
1217 config
.text_read_only
= FALSE
;
1218 config
.dynamic_link
= FALSE
;
1221 ldlang_add_undef (optarg
);
1225 lang_add_unique (optarg
);
1227 config
.unique_orphan_sections
= TRUE
;
1229 case OPTION_VERBOSE
:
1231 version_printed
= TRUE
;
1232 trace_file_tries
= TRUE
;
1233 overflow_cutoff_limit
= -2;
1237 version_printed
= TRUE
;
1241 version_printed
= TRUE
;
1243 case OPTION_VERSION
:
1247 case OPTION_VERSION_SCRIPT
:
1248 /* This option indicates a small script that only specifies
1249 version information. Read it, but don't assume that
1250 we've seen a linker script. */
1252 FILE *hold_script_handle
;
1254 hold_script_handle
= saved_script_handle
;
1255 ldfile_open_command_file (optarg
);
1256 saved_script_handle
= hold_script_handle
;
1257 parser_input
= input_version_script
;
1261 case OPTION_VERSION_EXPORTS_SECTION
:
1262 /* This option records a version symbol to be applied to the
1263 symbols listed for export to be found in the object files
1264 .exports sections. */
1265 command_line
.version_exports_section
= optarg
;
1267 case OPTION_DYNAMIC_LIST_DATA
:
1268 command_line
.dynamic_list
= dynamic_list_data
;
1269 if (command_line
.symbolic
== symbolic
)
1270 command_line
.symbolic
= symbolic_unset
;
1272 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1273 lang_append_dynamic_list_cpp_typeinfo ();
1274 if (command_line
.dynamic_list
!= dynamic_list_data
)
1275 command_line
.dynamic_list
= dynamic_list
;
1276 if (command_line
.symbolic
== symbolic
)
1277 command_line
.symbolic
= symbolic_unset
;
1279 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1280 lang_append_dynamic_list_cpp_new ();
1281 if (command_line
.dynamic_list
!= dynamic_list_data
)
1282 command_line
.dynamic_list
= dynamic_list
;
1283 if (command_line
.symbolic
== symbolic
)
1284 command_line
.symbolic
= symbolic_unset
;
1286 case OPTION_DYNAMIC_LIST
:
1287 /* This option indicates a small script that only specifies
1288 a dynamic list. Read it, but don't assume that we've
1289 seen a linker script. */
1291 FILE *hold_script_handle
;
1293 hold_script_handle
= saved_script_handle
;
1294 ldfile_open_command_file (optarg
);
1295 saved_script_handle
= hold_script_handle
;
1296 parser_input
= input_dynamic_list
;
1299 if (command_line
.dynamic_list
!= dynamic_list_data
)
1300 command_line
.dynamic_list
= dynamic_list
;
1301 if (command_line
.symbolic
== symbolic
)
1302 command_line
.symbolic
= symbolic_unset
;
1304 case OPTION_WARN_COMMON
:
1305 config
.warn_common
= TRUE
;
1307 case OPTION_WARN_CONSTRUCTORS
:
1308 config
.warn_constructors
= TRUE
;
1310 case OPTION_WARN_FATAL
:
1311 config
.fatal_warnings
= TRUE
;
1313 case OPTION_WARN_MULTIPLE_GP
:
1314 config
.warn_multiple_gp
= TRUE
;
1316 case OPTION_WARN_ONCE
:
1317 config
.warn_once
= TRUE
;
1319 case OPTION_WARN_SECTION_ALIGN
:
1320 config
.warn_section_align
= TRUE
;
1322 case OPTION_WARN_SHARED_TEXTREL
:
1323 link_info
.warn_shared_textrel
= TRUE
;
1325 case OPTION_WHOLE_ARCHIVE
:
1326 whole_archive
= TRUE
;
1328 case OPTION_ADD_NEEDED
:
1331 case OPTION_NO_ADD_NEEDED
:
1334 case OPTION_AS_NEEDED
:
1337 case OPTION_NO_AS_NEEDED
:
1343 case OPTION_DISCARD_NONE
:
1344 link_info
.discard
= discard_none
;
1347 link_info
.discard
= discard_l
;
1350 link_info
.discard
= discard_all
;
1353 if (CONST_STRNEQ (optarg
, "P,"))
1355 if (default_dirlist
!= NULL
)
1356 free (default_dirlist
);
1357 default_dirlist
= xstrdup (optarg
);
1362 case OPTION_SPARE_DYNAMIC_TAGS
:
1363 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1365 case OPTION_SPLIT_BY_RELOC
:
1367 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1369 config
.split_by_reloc
= 32768;
1371 case OPTION_SPLIT_BY_FILE
:
1373 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1375 config
.split_by_file
= 1;
1377 case OPTION_CHECK_SECTIONS
:
1378 command_line
.check_section_addresses
= TRUE
;
1380 case OPTION_NO_CHECK_SECTIONS
:
1381 command_line
.check_section_addresses
= FALSE
;
1383 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1384 command_line
.accept_unknown_input_arch
= TRUE
;
1386 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1387 command_line
.accept_unknown_input_arch
= FALSE
;
1391 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1393 lang_enter_group ();
1398 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1400 lang_leave_group ();
1405 link_info
.init_function
= optarg
;
1409 link_info
.fini_function
= optarg
;
1412 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1413 link_info
.reduce_memory_overheads
= TRUE
;
1414 if (config
.hash_table_size
== 0)
1415 config
.hash_table_size
= 1021;
1418 case OPTION_HASH_SIZE
:
1420 bfd_size_type new_size
;
1422 new_size
= strtoul (optarg
, NULL
, 0);
1424 config
.hash_table_size
= new_size
;
1426 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1433 lang_leave_group ();
1435 if (default_dirlist
!= NULL
)
1437 set_default_dirlist (default_dirlist
);
1438 free (default_dirlist
);
1441 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1442 /* FIXME: Should we allow emulations a chance to set this ? */
1443 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1445 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1446 /* FIXME: Should we allow emulations a chance to set this ? */
1447 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1450 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1451 library search path. */
1454 set_default_dirlist (char *dirlist_ptr
)
1460 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1463 if (*dirlist_ptr
!= '\0')
1464 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1467 dirlist_ptr
= p
+ 1;
1472 set_section_start (char *sect
, char *valstr
)
1475 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1477 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1478 lang_section_start (sect
, exp_intop (val
), NULL
);
1482 set_segment_start (const char *section
, char *valstr
)
1488 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1490 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1491 /* If we already have an entry for this segment, update the existing
1494 for (seg
= segments
; seg
; seg
= seg
->next
)
1495 if (strcmp (seg
->name
, name
) == 0)
1500 /* There was no existing value so we must create a new segment
1502 seg
= stat_alloc (sizeof (*seg
));
1506 /* Add it to the linked list of segments. */
1507 seg
->next
= segments
;
1509 /* Historically, -Ttext and friends set the base address of a
1510 particular section. For backwards compatibility, we still do
1511 that. If a SEGMENT_START directive is seen, the section address
1512 assignment will be disabled. */
1513 lang_section_start (section
, exp_intop (val
), seg
);
1517 /* Print help messages for the options. */
1523 const char **targets
, **pp
;
1526 printf (_("Usage: %s [options] file...\n"), program_name
);
1528 printf (_("Options:\n"));
1529 for (i
= 0; i
< OPTION_COUNT
; i
++)
1531 if (ld_options
[i
].doc
!= NULL
)
1544 if (ld_options
[j
].shortopt
!= '\0'
1545 && ld_options
[j
].control
!= NO_HELP
)
1547 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1548 len
+= (comma
? 2 : 0) + 2;
1549 if (ld_options
[j
].arg
!= NULL
)
1551 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1556 printf ("%s", _(ld_options
[j
].arg
));
1557 len
+= strlen (_(ld_options
[j
].arg
));
1563 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1568 if (ld_options
[j
].opt
.name
!= NULL
1569 && ld_options
[j
].control
!= NO_HELP
)
1572 (ld_options
[j
].control
== TWO_DASHES
1573 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1577 two_dashes
? "-" : "",
1578 ld_options
[j
].opt
.name
);
1579 len
+= ((comma
? 2 : 0)
1581 + (two_dashes
? 1 : 0)
1582 + strlen (ld_options
[j
].opt
.name
));
1583 if (ld_options
[j
].arg
!= NULL
)
1585 printf (" %s", _(ld_options
[j
].arg
));
1586 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1592 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1600 for (; len
< 30; len
++)
1603 printf ("%s\n", _(ld_options
[i
].doc
));
1606 printf (_(" @FILE"));
1607 for (len
= strlen (" @FILE"); len
< 30; len
++)
1609 printf (_("Read options from FILE\n"));
1611 /* Note: Various tools (such as libtool) depend upon the
1612 format of the listings below - do not change them. */
1613 /* xgettext:c-format */
1614 printf (_("%s: supported targets:"), program_name
);
1615 targets
= bfd_target_list ();
1616 for (pp
= targets
; *pp
!= NULL
; pp
++)
1617 printf (" %s", *pp
);
1621 /* xgettext:c-format */
1622 printf (_("%s: supported emulations: "), program_name
);
1623 ldemul_list_emulations (stdout
);
1626 /* xgettext:c-format */
1627 printf (_("%s: emulation specific options:\n"), program_name
);
1628 ldemul_list_emulation_options (stdout
);
1631 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);