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, 2006, 2007
4 Free Software Foundation, Inc.
6 This file is part of the GNU Binutils.
8 This program 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 3 of the License, or
11 (at your option) any later version.
13 This program 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 this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
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_NO_WARN_SEARCH_MISMATCH
,
87 OPTION_NOINHIBIT_EXEC
,
89 OPTION_NO_WHOLE_ARCHIVE
,
92 OPTION_RETAIN_SYMBOLS_FILE
,
101 OPTION_SYMBOLIC_FUNCTIONS
,
106 OPTION_TRADITIONAL_FORMAT
,
110 OPTION_VERSION_SCRIPT
,
111 OPTION_VERSION_EXPORTS_SECTION
,
113 OPTION_DYNAMIC_LIST_CPP_NEW
,
114 OPTION_DYNAMIC_LIST_CPP_TYPEINFO
,
115 OPTION_DYNAMIC_LIST_DATA
,
117 OPTION_WARN_CONSTRUCTORS
,
119 OPTION_WARN_MULTIPLE_GP
,
121 OPTION_WARN_SECTION_ALIGN
,
122 OPTION_SPLIT_BY_RELOC
,
123 OPTION_SPLIT_BY_FILE
,
124 OPTION_WHOLE_ARCHIVE
,
126 OPTION_NO_ADD_NEEDED
,
130 OPTION_FORCE_EXE_SUFFIX
,
132 OPTION_NO_GC_SECTIONS
,
133 OPTION_PRINT_GC_SECTIONS
,
134 OPTION_NO_PRINT_GC_SECTIONS
,
136 OPTION_CHECK_SECTIONS
,
137 OPTION_NO_CHECK_SECTIONS
,
141 OPTION_SECTION_START
,
144 OPTION_ALLOW_SHLIB_UNDEFINED
,
145 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
146 OPTION_ALLOW_MULTIPLE_DEFINITION
,
147 OPTION_NO_UNDEFINED_VERSION
,
148 OPTION_DEFAULT_SYMVER
,
149 OPTION_DEFAULT_IMPORTED_SYMVER
,
151 OPTION_SPARE_DYNAMIC_TAGS
,
152 OPTION_NO_DEFINE_COMMON
,
155 OPTION_STRIP_DISCARDED
,
156 OPTION_NO_STRIP_DISCARDED
,
157 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
158 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
160 OPTION_UNRESOLVED_SYMBOLS
,
161 OPTION_WARN_UNRESOLVED_SYMBOLS
,
162 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
163 OPTION_WARN_SHARED_TEXTREL
,
164 OPTION_REDUCE_MEMORY_OVERHEADS
,
165 OPTION_DEFAULT_SCRIPT
168 /* The long options. This structure is used for both the option
169 parsing and the help text. */
173 /* The long option information. */
175 /* The short option with the same meaning ('\0' if none). */
177 /* The name of the argument (NULL if none). */
179 /* The documentation string. If this is NULL, this is a synonym for
180 the previous option. */
183 /* Use one dash before long option name. */
185 /* Use two dashes before long option name. */
187 /* Only accept two dashes before the long option name.
188 This is an overloading of the use of this enum, since originally it
189 was only intended to tell the --help display function how to display
190 the long option name. This feature was added in order to resolve
191 the confusion about the -omagic command line switch. Is it setting
192 the output file name to "magic" or is it setting the NMAGIC flag on
193 the output ? It has been decided that it is setting the output file
194 name, and that if you want to set the NMAGIC flag you should use -N
197 /* Don't mention this option in --help output. */
202 static const struct ld_option ld_options
[] =
204 { {NULL
, required_argument
, NULL
, '\0'},
205 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
207 { {"architecture", required_argument
, NULL
, 'A'},
208 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
209 { {"format", required_argument
, NULL
, 'b'},
210 'b', N_("TARGET"), N_("Specify target for following input files"),
212 { {"mri-script", required_argument
, NULL
, 'c'},
213 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
214 { {"dc", no_argument
, NULL
, 'd'},
215 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
216 { {"dp", no_argument
, NULL
, 'd'},
217 '\0', NULL
, NULL
, ONE_DASH
},
218 { {"entry", required_argument
, NULL
, 'e'},
219 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
220 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
221 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
222 { {"EB", no_argument
, NULL
, OPTION_EB
},
223 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
224 { {"EL", no_argument
, NULL
, OPTION_EL
},
225 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
226 { {"auxiliary", required_argument
, NULL
, 'f'},
227 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
229 { {"filter", required_argument
, NULL
, 'F'},
230 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
232 { {NULL
, no_argument
, NULL
, '\0'},
233 'g', NULL
, N_("Ignored"), ONE_DASH
},
234 { {"gpsize", required_argument
, NULL
, 'G'},
235 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
237 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
238 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
239 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
240 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
242 { {"library", required_argument
, NULL
, 'l'},
243 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
244 { {"library-path", required_argument
, NULL
, 'L'},
245 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
247 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
248 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
249 { {NULL
, required_argument
, NULL
, '\0'},
250 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
251 { {"print-map", no_argument
, NULL
, 'M'},
252 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
253 { {"nmagic", no_argument
, NULL
, 'n'},
254 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
255 { {"omagic", no_argument
, NULL
, 'N'},
256 'N', NULL
, N_("Do not page align data, do not make text readonly"),
257 EXACTLY_TWO_DASHES
},
258 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
259 '\0', NULL
, N_("Page align data, make text readonly"),
260 EXACTLY_TWO_DASHES
},
261 { {"output", required_argument
, NULL
, 'o'},
262 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
263 { {NULL
, required_argument
, NULL
, '\0'},
264 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
265 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
266 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
267 { {"emit-relocs", no_argument
, NULL
, 'q'},
268 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
269 { {"relocatable", no_argument
, NULL
, 'r'},
270 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
271 { {NULL
, no_argument
, NULL
, '\0'},
272 'i', NULL
, NULL
, ONE_DASH
},
273 { {"just-symbols", required_argument
, NULL
, 'R'},
274 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
276 { {"strip-all", no_argument
, NULL
, 's'},
277 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
278 { {"strip-debug", no_argument
, NULL
, 'S'},
279 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
280 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
281 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
282 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
283 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
284 { {"trace", no_argument
, NULL
, 't'},
285 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
286 { {"script", required_argument
, NULL
, 'T'},
287 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
288 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
289 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
290 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
291 '\0', NULL
, NULL
, ONE_DASH
},
292 { {"undefined", required_argument
, NULL
, 'u'},
293 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
295 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
296 '\0', N_("[=SECTION]"),
297 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
298 { {"Ur", no_argument
, NULL
, OPTION_UR
},
299 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
300 { {"version", no_argument
, NULL
, OPTION_VERSION
},
301 'v', NULL
, N_("Print version information"), TWO_DASHES
},
302 { {NULL
, no_argument
, NULL
, '\0'},
303 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
304 { {"discard-all", no_argument
, NULL
, 'x'},
305 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
306 { {"discard-locals", no_argument
, NULL
, 'X'},
307 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
308 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
309 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
310 { {"trace-symbol", required_argument
, NULL
, 'y'},
311 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
312 { {NULL
, required_argument
, NULL
, '\0'},
313 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
315 { {"start-group", no_argument
, NULL
, '('},
316 '(', NULL
, N_("Start a group"), TWO_DASHES
},
317 { {"end-group", no_argument
, NULL
, ')'},
318 ')', NULL
, N_("End a group"), TWO_DASHES
},
319 { {"accept-unknown-input-arch", no_argument
, NULL
,
320 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
322 N_("Accept input files whose architecture cannot be determined"),
324 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
325 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
326 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
328 { {"add-needed", no_argument
, NULL
, OPTION_ADD_NEEDED
},
329 '\0', NULL
, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
330 " following dynamic libs"),
332 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_NEEDED
},
333 '\0', NULL
, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
334 " in following dynamic libs"),
336 { {"as-needed", no_argument
, NULL
, OPTION_AS_NEEDED
},
337 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
339 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_AS_NEEDED
},
340 '\0', NULL
, N_("Always set DT_NEEDED for following dynamic libs"),
342 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
343 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
344 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
345 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
346 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
347 '\0', NULL
, NULL
, ONE_DASH
},
348 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
349 '\0', NULL
, NULL
, ONE_DASH
},
350 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
351 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
352 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
353 '\0', NULL
, NULL
, ONE_DASH
},
354 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
355 '\0', NULL
, NULL
, ONE_DASH
},
356 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
357 '\0', NULL
, NULL
, ONE_DASH
},
358 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
359 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
360 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
361 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
362 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
363 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
365 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
366 '\0', NULL
, N_("Do not check section addresses for overlaps"),
368 { {"cref", no_argument
, NULL
, OPTION_CREF
},
369 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
370 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
371 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
372 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
373 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
375 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
376 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
377 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
378 '\0', NULL
, N_("Treat warnings as errors"),
380 { {"fini", required_argument
, NULL
, OPTION_FINI
},
381 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
382 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
383 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
384 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
385 '\0', NULL
, N_("Remove unused sections (on some targets)"),
387 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
388 '\0', NULL
, N_("Don't remove unused sections (default)"),
390 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
391 '\0', NULL
, N_("List removed unused sections on stderr"),
393 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
394 '\0', NULL
, N_("Do not list removed unused sections"),
396 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
397 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
399 { {"help", no_argument
, NULL
, OPTION_HELP
},
400 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
401 { {"init", required_argument
, NULL
, OPTION_INIT
},
402 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
403 { {"Map", required_argument
, NULL
, OPTION_MAP
},
404 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
405 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
406 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
407 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
408 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
409 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
410 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
411 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
412 '\0', NULL
, N_("Do not allow unresolved references in object files"),
414 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
415 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
417 { {"no-allow-shlib-undefined", no_argument
, NULL
,
418 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
419 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
421 { {"allow-multiple-definition", no_argument
, NULL
,
422 OPTION_ALLOW_MULTIPLE_DEFINITION
},
423 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
424 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
425 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
426 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
427 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
428 { {"default-imported-symver", no_argument
, NULL
,
429 OPTION_DEFAULT_IMPORTED_SYMVER
},
430 '\0', NULL
, N_("Create default symbol version for imported symbols"),
432 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
433 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
434 { {"no-warn-search-mismatch", no_argument
, NULL
,
435 OPTION_NO_WARN_SEARCH_MISMATCH
},
436 '\0', NULL
, N_("Don't warn on finding an incompatible library"),
438 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
439 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
440 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
441 '\0', NULL
, N_("Create an output file even if errors occur"),
443 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
444 '\0', NULL
, NULL
, NO_HELP
},
445 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
446 '\0', NULL
, N_("Only use library directories specified on\n"
447 " the command line"),
449 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
450 '\0', N_("TARGET"), N_("Specify target of output file"),
451 EXACTLY_TWO_DASHES
},
452 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
453 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
454 { {"reduce-memory-overheads", no_argument
, NULL
,
455 OPTION_REDUCE_MEMORY_OVERHEADS
},
456 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
458 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
459 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
460 { {"retain-symbols-file", required_argument
, NULL
,
461 OPTION_RETAIN_SYMBOLS_FILE
},
462 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
463 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
464 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
465 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
466 '\0', N_("PATH"), N_("Set link time shared library search path"),
468 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
469 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
470 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
471 '\0', NULL
, NULL
, ONE_DASH
},
472 { {"pie", no_argument
, NULL
, OPTION_PIE
},
473 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
474 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
475 '\0', NULL
, NULL
, TWO_DASHES
},
476 { {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
477 '\0', NULL
, N_("Sort common symbols by size"), TWO_DASHES
},
478 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
479 '\0', NULL
, NULL
, NO_HELP
},
480 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
481 '\0', N_("name|alignment"),
482 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
483 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
484 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
486 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
487 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
489 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
490 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
492 { {"stats", no_argument
, NULL
, OPTION_STATS
},
493 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
494 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
495 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
496 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
497 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
498 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
499 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
500 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
501 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
503 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
504 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
505 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
506 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
507 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
508 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
509 { {"unresolved-symbols=<method>", required_argument
, NULL
,
510 OPTION_UNRESOLVED_SYMBOLS
},
511 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
512 " ignore-all, report-all, ignore-in-object-files,\n"
513 " ignore-in-shared-libs"),
515 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
516 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
517 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
518 '\0', NULL
, NULL
, NO_HELP
},
519 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
520 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
521 { {"version-exports-section", required_argument
, NULL
,
522 OPTION_VERSION_EXPORTS_SECTION
},
523 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
524 " SYMBOL as the version."),
526 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
527 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
528 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
529 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
530 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
531 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
532 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
533 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
534 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
535 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
536 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
537 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
539 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
540 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
541 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
542 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
543 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
544 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
546 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
547 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
549 { {"warn-unresolved-symbols", no_argument
, NULL
,
550 OPTION_WARN_UNRESOLVED_SYMBOLS
},
551 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
552 { {"error-unresolved-symbols", no_argument
, NULL
,
553 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
554 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
555 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
556 '\0', NULL
, N_("Include all objects from following archives"),
558 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
559 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
562 #define OPTION_COUNT ARRAY_SIZE (ld_options)
565 parse_args (unsigned argc
, char **argv
)
570 char *default_dirlist
= NULL
;
572 struct option
*longopts
;
573 struct option
*really_longopts
;
575 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
577 shortopts
= xmalloc (OPTION_COUNT
* 3 + 2);
578 longopts
= xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
579 really_longopts
= xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
581 /* Starting the short option string with '-' is for programs that
582 expect options and other ARGV-elements in any order and that care about
583 the ordering of the two. We describe each non-option ARGV-element
584 as if it were the argument of an option with character code 1. */
589 for (i
= 0; i
< OPTION_COUNT
; i
++)
591 if (ld_options
[i
].shortopt
!= '\0')
593 shortopts
[is
] = ld_options
[i
].shortopt
;
595 if (ld_options
[i
].opt
.has_arg
== required_argument
596 || ld_options
[i
].opt
.has_arg
== optional_argument
)
600 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
607 if (ld_options
[i
].opt
.name
!= NULL
)
609 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
611 really_longopts
[irl
] = ld_options
[i
].opt
;
616 longopts
[il
] = ld_options
[i
].opt
;
621 shortopts
[is
] = '\0';
622 longopts
[il
].name
= NULL
;
623 really_longopts
[irl
].name
= NULL
;
625 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
627 /* The -G option is ambiguous on different platforms. Sometimes it
628 specifies the largest data size to put into the small data
629 section. Sometimes it is equivalent to --shared. Unfortunately,
630 the first form takes an argument, while the second does not.
632 We need to permit the --shared form because on some platforms,
633 such as Solaris, gcc -shared will pass -G to the linker.
635 To permit either usage, we look through the argument list. If we
636 find -G not followed by a number, we change it into --shared.
637 This will work for most normal cases. */
638 for (i
= 1; i
< argc
; i
++)
639 if (strcmp (argv
[i
], "-G") == 0
641 || ! ISDIGIT (argv
[i
+ 1][0])))
642 argv
[i
] = (char *) "--shared";
644 /* Because we permit long options to start with a single dash, and
645 we have a --library option, and the -l option is conventionally
646 used with an immediately following argument, we can have bad
647 results if somebody tries to use -l with a library whose name
648 happens to start with "ibrary", as in -li. We avoid problems by
649 simply turning -l into --library. This means that users will
650 have to use two dashes in order to use --library, which is OK
651 since that's how it is documented.
653 FIXME: It's possible that this problem can arise for other short
654 options as well, although the user does always have the recourse
655 of adding a space between the option and the argument. */
656 for (i
= 1; i
< argc
; i
++)
658 if (argv
[i
][0] == '-'
660 && argv
[i
][2] != '\0')
664 n
= xmalloc (strlen (argv
[i
]) + 20);
665 sprintf (n
, "--library=%s", argv
[i
] + 2);
676 /* Using last_optind lets us avoid calling ldemul_parse_args
677 multiple times on a single option, which would lead to
678 confusion in the internal static variables maintained by
679 getopt. This could otherwise happen for an argument like
680 -nx, in which the -n is parsed as a single option, and we
681 loop around to pick up the -x. */
682 if (optind
!= last_optind
)
683 if (ldemul_parse_args (argc
, argv
))
686 /* getopt_long_only is like getopt_long, but '-' as well as '--'
687 can indicate a long option. */
689 last_optind
= optind
;
690 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
693 optind
= last_optind
;
694 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
697 if (ldemul_handle_option (optc
))
706 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
710 einfo (_("%P%F: use the --help option for usage information\n"));
712 case 1: /* File name. */
713 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
719 /* For HP/UX compatibility. Actually -a shared should mean
720 ``use only shared libraries'' but, then, we don't
721 currently support shared libraries on HP/UX anyhow. */
722 if (strcmp (optarg
, "archive") == 0)
723 config
.dynamic_link
= FALSE
;
724 else if (strcmp (optarg
, "shared") == 0
725 || strcmp (optarg
, "default") == 0)
726 config
.dynamic_link
= TRUE
;
728 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
731 /* FIXME: We just ignore these, but we should handle them. */
732 if (strcmp (optarg
, "definitions") == 0)
734 else if (strcmp (optarg
, "nodefinitions") == 0)
736 else if (strcmp (optarg
, "nosymbolic") == 0)
738 else if (strcmp (optarg
, "pure-text") == 0)
741 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
744 ldfile_add_arch (optarg
);
747 lang_add_target (optarg
);
750 ldfile_open_command_file (optarg
);
751 parser_input
= input_mri_script
;
754 case OPTION_CALL_SHARED
:
755 config
.dynamic_link
= TRUE
;
757 case OPTION_NON_SHARED
:
758 config
.dynamic_link
= FALSE
;
761 command_line
.cref
= TRUE
;
762 link_info
.notice_all
= TRUE
;
765 command_line
.force_common_definition
= TRUE
;
769 lex_redirect (optarg
);
770 parser_input
= input_defsym
;
776 case OPTION_DEMANGLE
:
780 enum demangling_styles style
;
782 style
= cplus_demangle_name_to_style (optarg
);
783 if (style
== unknown_demangling
)
784 einfo (_("%F%P: unknown demangling style `%s'"),
787 cplus_demangle_set_style (style
);
790 case 'I': /* Used on Solaris. */
791 case OPTION_DYNAMIC_LINKER
:
792 command_line
.interpreter
= optarg
;
795 /* Already handled in ldmain.c. */
798 command_line
.endian
= ENDIAN_BIG
;
801 command_line
.endian
= ENDIAN_LITTLE
;
803 case OPTION_EMBEDDED_RELOCS
:
804 command_line
.embedded_relocs
= TRUE
;
806 case OPTION_EXPORT_DYNAMIC
:
807 case 'E': /* HP/UX compatibility. */
808 link_info
.export_dynamic
= TRUE
;
811 lang_add_entry (optarg
, TRUE
);
814 if (command_line
.auxiliary_filters
== NULL
)
816 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
817 command_line
.auxiliary_filters
[0] = optarg
;
818 command_line
.auxiliary_filters
[1] = NULL
;
826 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
828 command_line
.auxiliary_filters
829 = xrealloc (command_line
.auxiliary_filters
,
830 (c
+ 2) * sizeof (char *));
831 command_line
.auxiliary_filters
[c
] = optarg
;
832 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
836 command_line
.filter_shlib
= optarg
;
838 case OPTION_FORCE_EXE_SUFFIX
:
839 command_line
.force_exe_suffix
= TRUE
;
844 g_switch_value
= strtoul (optarg
, &end
, 0);
846 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
852 case OPTION_GC_SECTIONS
:
853 link_info
.gc_sections
= TRUE
;
855 case OPTION_PRINT_GC_SECTIONS
:
856 link_info
.print_gc_sections
= TRUE
;
863 ldfile_add_library_path (optarg
, TRUE
);
866 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
869 config
.map_filename
= "-";
872 /* Ignore. Was handled in a pre-parse. */
875 config
.map_filename
= optarg
;
878 config
.text_read_only
= FALSE
;
879 config
.magic_demand_paged
= FALSE
;
880 config
.dynamic_link
= FALSE
;
882 case OPTION_NO_OMAGIC
:
883 config
.text_read_only
= TRUE
;
884 config
.magic_demand_paged
= TRUE
;
885 /* NB/ Does not set dynamic_link to TRUE.
886 Use --call-shared or -Bdynamic for this. */
889 config
.magic_demand_paged
= FALSE
;
890 config
.dynamic_link
= FALSE
;
892 case OPTION_NO_DEFINE_COMMON
:
893 command_line
.inhibit_common_definition
= TRUE
;
895 case OPTION_NO_DEMANGLE
:
898 case OPTION_NO_GC_SECTIONS
:
899 link_info
.gc_sections
= FALSE
;
901 case OPTION_NO_PRINT_GC_SECTIONS
:
902 link_info
.print_gc_sections
= FALSE
;
904 case OPTION_NO_KEEP_MEMORY
:
905 link_info
.keep_memory
= FALSE
;
907 case OPTION_NO_UNDEFINED
:
908 link_info
.unresolved_syms_in_objects
909 = how_to_report_unresolved_symbols
;
911 case OPTION_ALLOW_SHLIB_UNDEFINED
:
912 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
914 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
915 link_info
.unresolved_syms_in_shared_libs
916 = how_to_report_unresolved_symbols
;
918 case OPTION_UNRESOLVED_SYMBOLS
:
919 if (strcmp (optarg
, "ignore-all") == 0)
921 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
922 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
924 else if (strcmp (optarg
, "report-all") == 0)
926 link_info
.unresolved_syms_in_objects
927 = how_to_report_unresolved_symbols
;
928 link_info
.unresolved_syms_in_shared_libs
929 = how_to_report_unresolved_symbols
;
931 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
933 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
934 link_info
.unresolved_syms_in_shared_libs
935 = how_to_report_unresolved_symbols
;
937 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
939 link_info
.unresolved_syms_in_objects
940 = how_to_report_unresolved_symbols
;
941 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
944 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
946 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
947 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
948 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
949 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
950 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
951 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
954 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
955 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
956 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
957 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
958 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
959 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
961 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
962 link_info
.allow_multiple_definition
= TRUE
;
964 case OPTION_NO_UNDEFINED_VERSION
:
965 link_info
.allow_undefined_version
= FALSE
;
967 case OPTION_DEFAULT_SYMVER
:
968 link_info
.create_default_symver
= TRUE
;
970 case OPTION_DEFAULT_IMPORTED_SYMVER
:
971 link_info
.default_imported_symver
= TRUE
;
973 case OPTION_NO_WARN_MISMATCH
:
974 command_line
.warn_mismatch
= FALSE
;
976 case OPTION_NO_WARN_SEARCH_MISMATCH
:
977 command_line
.warn_search_mismatch
= FALSE
;
979 case OPTION_NOINHIBIT_EXEC
:
980 force_make_executable
= TRUE
;
982 case OPTION_NOSTDLIB
:
983 config
.only_cmd_line_lib_dirs
= TRUE
;
985 case OPTION_NO_WHOLE_ARCHIVE
:
986 whole_archive
= FALSE
;
989 /* FIXME "-O<non-digits> <value>" used to set the address of
990 section <non-digits>. Was this for compatibility with
991 something, or can we create a new option to do that
992 (with a syntax similar to -defsym)?
993 getopt can't handle two args to an option without kludges. */
995 /* Enable optimizations of output files. */
996 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
999 lang_add_output (optarg
, 0);
1001 case OPTION_OFORMAT
:
1002 lang_add_output_format (optarg
, NULL
, NULL
, 0);
1005 link_info
.emitrelocations
= TRUE
;
1009 if (optind
== last_optind
)
1010 /* This can happen if the user put "-rpath,a" on the command
1011 line. (Or something similar. The comma is important).
1012 Getopt becomes confused and thinks that this is a -r option
1013 but it cannot parse the text after the -r so it refuses to
1014 increment the optind counter. Detect this case and issue
1015 an error message here. We cannot just make this a warning,
1016 increment optind, and continue because getopt is too confused
1017 and will seg-fault the next time around. */
1018 einfo(_("%P%F: bad -rpath option\n"));
1020 link_info
.relocatable
= TRUE
;
1021 config
.build_constructors
= FALSE
;
1022 config
.magic_demand_paged
= FALSE
;
1023 config
.text_read_only
= FALSE
;
1024 config
.dynamic_link
= FALSE
;
1027 /* The GNU linker traditionally uses -R to mean to include
1028 only the symbols from a file. The Solaris linker uses -R
1029 to set the path used by the runtime linker to find
1030 libraries. This is the GNU linker -rpath argument. We
1031 try to support both simultaneously by checking the file
1032 named. If it is a directory, rather than a regular file,
1033 we assume -rpath was meant. */
1037 if (stat (optarg
, &s
) >= 0
1038 && ! S_ISDIR (s
.st_mode
))
1040 lang_add_input_file (optarg
,
1041 lang_input_file_is_symbols_only_enum
,
1048 if (command_line
.rpath
== NULL
)
1049 command_line
.rpath
= xstrdup (optarg
);
1052 size_t rpath_len
= strlen (command_line
.rpath
);
1053 size_t optarg_len
= strlen (optarg
);
1055 char *cp
= command_line
.rpath
;
1057 /* First see whether OPTARG is already in the path. */
1060 if (strncmp (optarg
, cp
, optarg_len
) == 0
1061 && (cp
[optarg_len
] == 0
1062 || cp
[optarg_len
] == config
.rpath_separator
))
1066 /* Not yet found. */
1067 cp
= strchr (cp
, config
.rpath_separator
);
1075 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1076 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1077 config
.rpath_separator
, optarg
);
1078 free (command_line
.rpath
);
1079 command_line
.rpath
= buf
;
1083 case OPTION_RPATH_LINK
:
1084 if (command_line
.rpath_link
== NULL
)
1085 command_line
.rpath_link
= xstrdup (optarg
);
1090 buf
= xmalloc (strlen (command_line
.rpath_link
)
1093 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1094 config
.rpath_separator
, optarg
);
1095 free (command_line
.rpath_link
);
1096 command_line
.rpath_link
= buf
;
1100 command_line
.relax
= TRUE
;
1102 case OPTION_RETAIN_SYMBOLS_FILE
:
1103 add_keepsyms_file (optarg
);
1106 link_info
.strip
= strip_debugger
;
1109 link_info
.strip
= strip_all
;
1111 case OPTION_STRIP_DISCARDED
:
1112 link_info
.strip_discarded
= TRUE
;
1114 case OPTION_NO_STRIP_DISCARDED
:
1115 link_info
.strip_discarded
= FALSE
;
1118 if (config
.has_shared
)
1120 link_info
.shared
= TRUE
;
1121 /* When creating a shared library, the default
1122 behaviour is to ignore any unresolved references. */
1123 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1124 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1125 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1126 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1129 einfo (_("%P%F: -shared not supported\n"));
1132 if (config
.has_shared
)
1134 link_info
.shared
= TRUE
;
1135 link_info
.pie
= TRUE
;
1138 einfo (_("%P%F: -pie not supported\n"));
1140 case 'h': /* Used on Solaris. */
1142 command_line
.soname
= optarg
;
1144 case OPTION_SORT_COMMON
:
1145 config
.sort_common
= TRUE
;
1147 case OPTION_SORT_SECTION
:
1148 if (strcmp (optarg
, N_("name")) == 0)
1149 sort_section
= by_name
;
1150 else if (strcmp (optarg
, N_("alignment")) == 0)
1151 sort_section
= by_alignment
;
1153 einfo (_("%P%F: invalid section sorting option: %s\n"),
1157 config
.stats
= TRUE
;
1159 case OPTION_SYMBOLIC
:
1160 command_line
.symbolic
= symbolic
;
1162 case OPTION_SYMBOLIC_FUNCTIONS
:
1163 command_line
.symbolic
= symbolic_functions
;
1169 ldfile_open_command_file (optarg
);
1170 parser_input
= input_script
;
1173 case OPTION_DEFAULT_SCRIPT
:
1174 command_line
.default_script
= optarg
;
1176 case OPTION_SECTION_START
:
1182 /* Check for <something>=<somthing>... */
1183 optarg2
= strchr (optarg
, '=');
1184 if (optarg2
== NULL
)
1185 einfo (_("%P%F: invalid argument to option"
1186 " \"--section-start\"\n"));
1190 /* So far so good. Are all the args present? */
1191 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1192 einfo (_("%P%F: missing argument(s) to option"
1193 " \"--section-start\"\n"));
1195 /* We must copy the section name as set_section_start
1196 doesn't do it for us. */
1197 len
= optarg2
- optarg
;
1198 sec_name
= xmalloc (len
);
1199 memcpy (sec_name
, optarg
, len
- 1);
1200 sec_name
[len
- 1] = 0;
1202 /* Then set it... */
1203 set_section_start (sec_name
, optarg2
);
1206 case OPTION_TARGET_HELP
:
1207 /* Mention any target specific options. */
1208 ldemul_list_emulation_options (stdout
);
1211 set_segment_start (".bss", optarg
);
1214 set_segment_start (".data", optarg
);
1217 set_segment_start (".text", optarg
);
1219 case OPTION_TRADITIONAL_FORMAT
:
1220 link_info
.traditional_format
= TRUE
;
1222 case OPTION_TASK_LINK
:
1223 link_info
.task_link
= TRUE
;
1224 /* Fall through - do an implied -r option. */
1226 link_info
.relocatable
= TRUE
;
1227 config
.build_constructors
= TRUE
;
1228 config
.magic_demand_paged
= FALSE
;
1229 config
.text_read_only
= FALSE
;
1230 config
.dynamic_link
= FALSE
;
1233 ldlang_add_undef (optarg
);
1237 lang_add_unique (optarg
);
1239 config
.unique_orphan_sections
= TRUE
;
1241 case OPTION_VERBOSE
:
1243 version_printed
= TRUE
;
1244 trace_file_tries
= TRUE
;
1245 overflow_cutoff_limit
= -2;
1249 version_printed
= TRUE
;
1253 version_printed
= TRUE
;
1255 case OPTION_VERSION
:
1259 case OPTION_VERSION_SCRIPT
:
1260 /* This option indicates a small script that only specifies
1261 version information. Read it, but don't assume that
1262 we've seen a linker script. */
1264 FILE *hold_script_handle
;
1266 hold_script_handle
= saved_script_handle
;
1267 ldfile_open_command_file (optarg
);
1268 saved_script_handle
= hold_script_handle
;
1269 parser_input
= input_version_script
;
1273 case OPTION_VERSION_EXPORTS_SECTION
:
1274 /* This option records a version symbol to be applied to the
1275 symbols listed for export to be found in the object files
1276 .exports sections. */
1277 command_line
.version_exports_section
= optarg
;
1279 case OPTION_DYNAMIC_LIST_DATA
:
1280 command_line
.dynamic_list
= dynamic_list_data
;
1281 if (command_line
.symbolic
== symbolic
)
1282 command_line
.symbolic
= symbolic_unset
;
1284 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1285 lang_append_dynamic_list_cpp_typeinfo ();
1286 if (command_line
.dynamic_list
!= dynamic_list_data
)
1287 command_line
.dynamic_list
= dynamic_list
;
1288 if (command_line
.symbolic
== symbolic
)
1289 command_line
.symbolic
= symbolic_unset
;
1291 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1292 lang_append_dynamic_list_cpp_new ();
1293 if (command_line
.dynamic_list
!= dynamic_list_data
)
1294 command_line
.dynamic_list
= dynamic_list
;
1295 if (command_line
.symbolic
== symbolic
)
1296 command_line
.symbolic
= symbolic_unset
;
1298 case OPTION_DYNAMIC_LIST
:
1299 /* This option indicates a small script that only specifies
1300 a dynamic list. Read it, but don't assume that we've
1301 seen a linker script. */
1303 FILE *hold_script_handle
;
1305 hold_script_handle
= saved_script_handle
;
1306 ldfile_open_command_file (optarg
);
1307 saved_script_handle
= hold_script_handle
;
1308 parser_input
= input_dynamic_list
;
1311 if (command_line
.dynamic_list
!= dynamic_list_data
)
1312 command_line
.dynamic_list
= dynamic_list
;
1313 if (command_line
.symbolic
== symbolic
)
1314 command_line
.symbolic
= symbolic_unset
;
1316 case OPTION_WARN_COMMON
:
1317 config
.warn_common
= TRUE
;
1319 case OPTION_WARN_CONSTRUCTORS
:
1320 config
.warn_constructors
= TRUE
;
1322 case OPTION_WARN_FATAL
:
1323 config
.fatal_warnings
= TRUE
;
1325 case OPTION_WARN_MULTIPLE_GP
:
1326 config
.warn_multiple_gp
= TRUE
;
1328 case OPTION_WARN_ONCE
:
1329 config
.warn_once
= TRUE
;
1331 case OPTION_WARN_SECTION_ALIGN
:
1332 config
.warn_section_align
= TRUE
;
1334 case OPTION_WARN_SHARED_TEXTREL
:
1335 link_info
.warn_shared_textrel
= TRUE
;
1337 case OPTION_WHOLE_ARCHIVE
:
1338 whole_archive
= TRUE
;
1340 case OPTION_ADD_NEEDED
:
1343 case OPTION_NO_ADD_NEEDED
:
1346 case OPTION_AS_NEEDED
:
1349 case OPTION_NO_AS_NEEDED
:
1355 case OPTION_DISCARD_NONE
:
1356 link_info
.discard
= discard_none
;
1359 link_info
.discard
= discard_l
;
1362 link_info
.discard
= discard_all
;
1365 if (CONST_STRNEQ (optarg
, "P,"))
1367 if (default_dirlist
!= NULL
)
1368 free (default_dirlist
);
1369 default_dirlist
= xstrdup (optarg
);
1374 case OPTION_SPARE_DYNAMIC_TAGS
:
1375 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1377 case OPTION_SPLIT_BY_RELOC
:
1379 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1381 config
.split_by_reloc
= 32768;
1383 case OPTION_SPLIT_BY_FILE
:
1385 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1387 config
.split_by_file
= 1;
1389 case OPTION_CHECK_SECTIONS
:
1390 command_line
.check_section_addresses
= TRUE
;
1392 case OPTION_NO_CHECK_SECTIONS
:
1393 command_line
.check_section_addresses
= FALSE
;
1395 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1396 command_line
.accept_unknown_input_arch
= TRUE
;
1398 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1399 command_line
.accept_unknown_input_arch
= FALSE
;
1403 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1405 lang_enter_group ();
1410 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1412 lang_leave_group ();
1417 link_info
.init_function
= optarg
;
1421 link_info
.fini_function
= optarg
;
1424 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1425 link_info
.reduce_memory_overheads
= TRUE
;
1426 if (config
.hash_table_size
== 0)
1427 config
.hash_table_size
= 1021;
1430 case OPTION_HASH_SIZE
:
1432 bfd_size_type new_size
;
1434 new_size
= strtoul (optarg
, NULL
, 0);
1436 config
.hash_table_size
= new_size
;
1438 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1445 lang_leave_group ();
1447 if (default_dirlist
!= NULL
)
1449 set_default_dirlist (default_dirlist
);
1450 free (default_dirlist
);
1453 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1454 /* FIXME: Should we allow emulations a chance to set this ? */
1455 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1457 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1458 /* FIXME: Should we allow emulations a chance to set this ? */
1459 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1462 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1463 library search path. */
1466 set_default_dirlist (char *dirlist_ptr
)
1472 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1475 if (*dirlist_ptr
!= '\0')
1476 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1479 dirlist_ptr
= p
+ 1;
1484 set_section_start (char *sect
, char *valstr
)
1487 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1489 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1490 lang_section_start (sect
, exp_intop (val
), NULL
);
1494 set_segment_start (const char *section
, char *valstr
)
1500 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1502 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1503 /* If we already have an entry for this segment, update the existing
1506 for (seg
= segments
; seg
; seg
= seg
->next
)
1507 if (strcmp (seg
->name
, name
) == 0)
1512 /* There was no existing value so we must create a new segment
1514 seg
= stat_alloc (sizeof (*seg
));
1518 /* Add it to the linked list of segments. */
1519 seg
->next
= segments
;
1521 /* Historically, -Ttext and friends set the base address of a
1522 particular section. For backwards compatibility, we still do
1523 that. If a SEGMENT_START directive is seen, the section address
1524 assignment will be disabled. */
1525 lang_section_start (section
, exp_intop (val
), seg
);
1529 /* Print help messages for the options. */
1535 const char **targets
, **pp
;
1538 printf (_("Usage: %s [options] file...\n"), program_name
);
1540 printf (_("Options:\n"));
1541 for (i
= 0; i
< OPTION_COUNT
; i
++)
1543 if (ld_options
[i
].doc
!= NULL
)
1556 if (ld_options
[j
].shortopt
!= '\0'
1557 && ld_options
[j
].control
!= NO_HELP
)
1559 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1560 len
+= (comma
? 2 : 0) + 2;
1561 if (ld_options
[j
].arg
!= NULL
)
1563 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1568 printf ("%s", _(ld_options
[j
].arg
));
1569 len
+= strlen (_(ld_options
[j
].arg
));
1575 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1580 if (ld_options
[j
].opt
.name
!= NULL
1581 && ld_options
[j
].control
!= NO_HELP
)
1584 (ld_options
[j
].control
== TWO_DASHES
1585 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1589 two_dashes
? "-" : "",
1590 ld_options
[j
].opt
.name
);
1591 len
+= ((comma
? 2 : 0)
1593 + (two_dashes
? 1 : 0)
1594 + strlen (ld_options
[j
].opt
.name
));
1595 if (ld_options
[j
].arg
!= NULL
)
1597 printf (" %s", _(ld_options
[j
].arg
));
1598 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1604 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1612 for (; len
< 30; len
++)
1615 printf ("%s\n", _(ld_options
[i
].doc
));
1618 printf (_(" @FILE"));
1619 for (len
= strlen (" @FILE"); len
< 30; len
++)
1621 printf (_("Read options from FILE\n"));
1623 /* Note: Various tools (such as libtool) depend upon the
1624 format of the listings below - do not change them. */
1625 /* xgettext:c-format */
1626 printf (_("%s: supported targets:"), program_name
);
1627 targets
= bfd_target_list ();
1628 for (pp
= targets
; *pp
!= NULL
; pp
++)
1629 printf (" %s", *pp
);
1633 /* xgettext:c-format */
1634 printf (_("%s: supported emulations: "), program_name
);
1635 ldemul_list_emulations (stdout
);
1638 /* xgettext:c-format */
1639 printf (_("%s: emulation specific options:\n"), program_name
);
1640 ldemul_list_emulation_options (stdout
);
1643 if (REPORT_BUGS_TO
[0])
1644 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);