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, 2008, 2009, 2011
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"
45 #endif /* ENABLE_PLUGINS */
47 #ifndef PATH_SEPARATOR
48 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
49 #define PATH_SEPARATOR ';'
51 #define PATH_SEPARATOR ':'
55 /* Somewhere above, sys/stat.h got included . . . . */
56 #if !defined(S_ISDIR) && defined(S_IFDIR)
57 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
60 static void set_default_dirlist (char *);
61 static void set_section_start (char *, char *);
62 static void set_segment_start (const char *, char *);
63 static void help (void);
65 /* Non-zero if we are processing a --defsym from the command line. */
66 int parsing_defsym
= 0;
68 /* Codes used for the long options with no short synonyms. 150 isn't
69 special; it's just an arbitrary non-ASCII char value. */
77 OPTION_DYNAMIC_LINKER
,
81 OPTION_EMBEDDED_RELOCS
,
82 OPTION_EXPORT_DYNAMIC
,
83 OPTION_NO_EXPORT_DYNAMIC
,
88 OPTION_NO_KEEP_MEMORY
,
89 OPTION_NO_WARN_MISMATCH
,
90 OPTION_NO_WARN_SEARCH_MISMATCH
,
91 OPTION_NOINHIBIT_EXEC
,
93 OPTION_NO_WHOLE_ARCHIVE
,
97 OPTION_RETAIN_SYMBOLS_FILE
,
106 OPTION_SYMBOLIC_FUNCTIONS
,
111 OPTION_TTEXT_SEGMENT
,
112 OPTION_TRADITIONAL_FORMAT
,
116 OPTION_VERSION_SCRIPT
,
117 OPTION_VERSION_EXPORTS_SECTION
,
119 OPTION_DYNAMIC_LIST_CPP_NEW
,
120 OPTION_DYNAMIC_LIST_CPP_TYPEINFO
,
121 OPTION_DYNAMIC_LIST_DATA
,
123 OPTION_WARN_CONSTRUCTORS
,
125 OPTION_NO_WARN_FATAL
,
126 OPTION_WARN_MULTIPLE_GP
,
128 OPTION_WARN_SECTION_ALIGN
,
129 OPTION_SPLIT_BY_RELOC
,
130 OPTION_SPLIT_BY_FILE
,
131 OPTION_WHOLE_ARCHIVE
,
132 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
,
133 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
,
134 OPTION_ADD_DT_NEEDED_FOR_REGULAR
,
135 OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
,
137 OPTION_FORCE_EXE_SUFFIX
,
139 OPTION_NO_GC_SECTIONS
,
140 OPTION_PRINT_GC_SECTIONS
,
141 OPTION_NO_PRINT_GC_SECTIONS
,
143 OPTION_CHECK_SECTIONS
,
144 OPTION_NO_CHECK_SECTIONS
,
148 OPTION_SECTION_START
,
151 OPTION_ALLOW_SHLIB_UNDEFINED
,
152 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
153 OPTION_ALLOW_MULTIPLE_DEFINITION
,
154 OPTION_NO_UNDEFINED_VERSION
,
155 OPTION_DEFAULT_SYMVER
,
156 OPTION_DEFAULT_IMPORTED_SYMVER
,
158 OPTION_SPARE_DYNAMIC_TAGS
,
159 OPTION_NO_DEFINE_COMMON
,
162 OPTION_STRIP_DISCARDED
,
163 OPTION_NO_STRIP_DISCARDED
,
164 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
165 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
167 OPTION_UNRESOLVED_SYMBOLS
,
168 OPTION_WARN_UNRESOLVED_SYMBOLS
,
169 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
170 OPTION_WARN_SHARED_TEXTREL
,
171 OPTION_WARN_ALTERNATE_EM
,
172 OPTION_REDUCE_MEMORY_OVERHEADS
,
173 #ifdef ENABLE_PLUGINS
176 #endif /* ENABLE_PLUGINS */
177 OPTION_DEFAULT_SCRIPT
,
178 OPTION_PRINT_OUTPUT_FORMAT
,
181 /* The long options. This structure is used for both the option
182 parsing and the help text. */
185 /* Use one dash before long option name. */
187 /* Use two dashes before long option name. */
189 /* Only accept two dashes before the long option name.
190 This is an overloading of the use of this enum, since originally it
191 was only intended to tell the --help display function how to display
192 the long option name. This feature was added in order to resolve
193 the confusion about the -omagic command line switch. Is it setting
194 the output file name to "magic" or is it setting the NMAGIC flag on
195 the output ? It has been decided that it is setting the output file
196 name, and that if you want to set the NMAGIC flag you should use -N
199 /* Don't mention this option in --help output. */
205 /* The long option information. */
207 /* The short option with the same meaning ('\0' if none). */
209 /* The name of the argument (NULL if none). */
211 /* The documentation string. If this is NULL, this is a synonym for
212 the previous option. */
214 enum control_enum control
;
217 static const struct ld_option ld_options
[] =
219 { {NULL
, required_argument
, NULL
, '\0'},
220 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
222 { {"architecture", required_argument
, NULL
, 'A'},
223 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
224 { {"format", required_argument
, NULL
, 'b'},
225 'b', N_("TARGET"), N_("Specify target for following input files"),
227 { {"mri-script", required_argument
, NULL
, 'c'},
228 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
229 { {"dc", no_argument
, NULL
, 'd'},
230 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
231 { {"dp", no_argument
, NULL
, 'd'},
232 '\0', NULL
, NULL
, ONE_DASH
},
233 { {"entry", required_argument
, NULL
, 'e'},
234 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
235 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
236 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
237 { {"no-export-dynamic", no_argument
, NULL
, OPTION_NO_EXPORT_DYNAMIC
},
238 '\0', NULL
, N_("Undo the effect of --export-dynamic"), TWO_DASHES
},
239 { {"EB", no_argument
, NULL
, OPTION_EB
},
240 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
241 { {"EL", no_argument
, NULL
, OPTION_EL
},
242 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
243 { {"auxiliary", required_argument
, NULL
, 'f'},
244 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
246 { {"filter", required_argument
, NULL
, 'F'},
247 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
249 { {NULL
, no_argument
, NULL
, '\0'},
250 'g', NULL
, N_("Ignored"), ONE_DASH
},
251 { {"gpsize", required_argument
, NULL
, 'G'},
252 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
254 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
255 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
256 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
257 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
259 { {"library", required_argument
, NULL
, 'l'},
260 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
261 { {"library-path", required_argument
, NULL
, 'L'},
262 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
264 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
265 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
266 { {NULL
, required_argument
, NULL
, '\0'},
267 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
268 { {"print-map", no_argument
, NULL
, 'M'},
269 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
270 { {"nmagic", no_argument
, NULL
, 'n'},
271 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
272 { {"omagic", no_argument
, NULL
, 'N'},
273 'N', NULL
, N_("Do not page align data, do not make text readonly"),
274 EXACTLY_TWO_DASHES
},
275 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
276 '\0', NULL
, N_("Page align data, make text readonly"),
277 EXACTLY_TWO_DASHES
},
278 { {"output", required_argument
, NULL
, 'o'},
279 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
280 { {NULL
, required_argument
, NULL
, '\0'},
281 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
282 #ifdef ENABLE_PLUGINS
283 { {"plugin", required_argument
, NULL
, OPTION_PLUGIN
},
284 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH
},
285 { {"plugin-opt", required_argument
, NULL
, OPTION_PLUGIN_OPT
},
286 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH
},
287 { {"flto", optional_argument
, NULL
, OPTION_IGNORE
},
288 '\0', NULL
, N_("Ignored for GCC LTO option compatibility"),
290 { {"flto-partition=", required_argument
, NULL
, OPTION_IGNORE
},
291 '\0', NULL
, N_("Ignored for GCC LTO option compatibility"),
293 #endif /* ENABLE_PLUGINS */
294 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
295 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
296 { {"emit-relocs", no_argument
, NULL
, 'q'},
297 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
298 { {"relocatable", no_argument
, NULL
, 'r'},
299 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
300 { {NULL
, no_argument
, NULL
, '\0'},
301 'i', NULL
, NULL
, ONE_DASH
},
302 { {"just-symbols", required_argument
, NULL
, 'R'},
303 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
305 { {"strip-all", no_argument
, NULL
, 's'},
306 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
307 { {"strip-debug", no_argument
, NULL
, 'S'},
308 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
309 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
310 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
311 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
312 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
313 { {"trace", no_argument
, NULL
, 't'},
314 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
315 { {"script", required_argument
, NULL
, 'T'},
316 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
317 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
318 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
319 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
320 '\0', NULL
, NULL
, ONE_DASH
},
321 { {"undefined", required_argument
, NULL
, 'u'},
322 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
324 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
325 '\0', N_("[=SECTION]"),
326 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
327 { {"Ur", no_argument
, NULL
, OPTION_UR
},
328 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
329 { {"version", no_argument
, NULL
, OPTION_VERSION
},
330 'v', NULL
, N_("Print version information"), TWO_DASHES
},
331 { {NULL
, no_argument
, NULL
, '\0'},
332 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
333 { {"discard-all", no_argument
, NULL
, 'x'},
334 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
335 { {"discard-locals", no_argument
, NULL
, 'X'},
336 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
337 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
338 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
339 { {"trace-symbol", required_argument
, NULL
, 'y'},
340 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
341 { {NULL
, required_argument
, NULL
, '\0'},
342 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
344 { {"start-group", no_argument
, NULL
, '('},
345 '(', NULL
, N_("Start a group"), TWO_DASHES
},
346 { {"end-group", no_argument
, NULL
, ')'},
347 ')', NULL
, N_("End a group"), TWO_DASHES
},
348 { {"accept-unknown-input-arch", no_argument
, NULL
,
349 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
351 N_("Accept input files whose architecture cannot be determined"),
353 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
354 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
355 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
358 /* The next two options are deprecated because of their similarity to
359 --as-needed and --no-as-needed. They have been replaced by
360 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
361 { {"add-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
362 '\0', NULL
, NULL
, NO_HELP
},
363 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
364 '\0', NULL
, NULL
, NO_HELP
},
366 { {"as-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_REGULAR
},
367 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
369 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
},
370 '\0', NULL
, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
371 " the command line"),
373 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
374 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
375 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
376 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
377 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
378 '\0', NULL
, NULL
, ONE_DASH
},
379 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
380 '\0', NULL
, NULL
, ONE_DASH
},
381 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
382 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
383 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
384 '\0', NULL
, NULL
, ONE_DASH
},
385 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
386 '\0', NULL
, NULL
, ONE_DASH
},
387 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
388 '\0', NULL
, NULL
, ONE_DASH
},
389 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
390 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
391 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
392 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
393 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
394 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
396 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
397 '\0', NULL
, N_("Do not check section addresses for overlaps"),
399 { {"copy-dt-needed-entries", no_argument
, NULL
,
400 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
401 '\0', NULL
, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
403 { {"no-copy-dt-needed-entries", no_argument
, NULL
,
404 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
405 '\0', NULL
, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
408 { {"cref", no_argument
, NULL
, OPTION_CREF
},
409 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
410 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
411 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
412 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
413 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
415 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
416 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
417 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
418 '\0', NULL
, N_("Treat warnings as errors"),
420 { {"no-fatal-warnings", no_argument
, NULL
, OPTION_NO_WARN_FATAL
},
421 '\0', NULL
, N_("Do not treat warnings as errors (default)"),
423 { {"fini", required_argument
, NULL
, OPTION_FINI
},
424 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
425 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
426 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
427 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
428 '\0', NULL
, N_("Remove unused sections (on some targets)"),
430 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
431 '\0', NULL
, N_("Don't remove unused sections (default)"),
433 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
434 '\0', NULL
, N_("List removed unused sections on stderr"),
436 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
437 '\0', NULL
, N_("Do not list removed unused sections"),
439 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
440 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
442 { {"help", no_argument
, NULL
, OPTION_HELP
},
443 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
444 { {"init", required_argument
, NULL
, OPTION_INIT
},
445 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
446 { {"Map", required_argument
, NULL
, OPTION_MAP
},
447 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
448 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
449 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
450 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
451 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
452 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
453 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
454 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
455 '\0', NULL
, N_("Do not allow unresolved references in object files"),
457 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
458 '\0', NULL
, N_("Allow unresolved references in shared libraries"),
460 { {"no-allow-shlib-undefined", no_argument
, NULL
,
461 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
462 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
464 { {"allow-multiple-definition", no_argument
, NULL
,
465 OPTION_ALLOW_MULTIPLE_DEFINITION
},
466 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
467 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
468 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
469 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
470 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
471 { {"default-imported-symver", no_argument
, NULL
,
472 OPTION_DEFAULT_IMPORTED_SYMVER
},
473 '\0', NULL
, N_("Create default symbol version for imported symbols"),
475 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
476 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
477 { {"no-warn-search-mismatch", no_argument
, NULL
,
478 OPTION_NO_WARN_SEARCH_MISMATCH
},
479 '\0', NULL
, N_("Don't warn on finding an incompatible library"),
481 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
482 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
483 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
484 '\0', NULL
, N_("Create an output file even if errors occur"),
486 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
487 '\0', NULL
, NULL
, NO_HELP
},
488 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
489 '\0', NULL
, N_("Only use library directories specified on\n"
490 " the command line"),
492 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
493 '\0', N_("TARGET"), N_("Specify target of output file"),
494 EXACTLY_TWO_DASHES
},
495 { {"print-output-format", no_argument
, NULL
, OPTION_PRINT_OUTPUT_FORMAT
},
496 '\0', NULL
, N_("Print default output format"), TWO_DASHES
},
497 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
498 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
499 { {"reduce-memory-overheads", no_argument
, NULL
,
500 OPTION_REDUCE_MEMORY_OVERHEADS
},
501 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
503 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
504 '\0', NULL
, N_("Reduce code size by using target specific optimizations"), TWO_DASHES
},
505 { {"no-relax", no_argument
, NULL
, OPTION_NO_RELAX
},
506 '\0', NULL
, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES
},
507 { {"retain-symbols-file", required_argument
, NULL
,
508 OPTION_RETAIN_SYMBOLS_FILE
},
509 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
510 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
511 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
512 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
513 '\0', N_("PATH"), N_("Set link time shared library search path"),
515 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
516 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
517 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
518 '\0', NULL
, NULL
, ONE_DASH
},
519 { {"pie", no_argument
, NULL
, OPTION_PIE
},
520 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
521 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
522 '\0', NULL
, NULL
, TWO_DASHES
},
523 { {"sort-common", optional_argument
, NULL
, OPTION_SORT_COMMON
},
524 '\0', N_("[=ascending|descending]"),
525 N_("Sort common symbols by alignment [in specified order]"),
527 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
528 '\0', NULL
, NULL
, NO_HELP
},
529 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
530 '\0', N_("name|alignment"),
531 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
532 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
533 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
535 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
536 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
538 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
539 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
541 { {"stats", no_argument
, NULL
, OPTION_STATS
},
542 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
543 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
544 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
545 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
546 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
547 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
548 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
549 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
550 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
552 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
553 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
554 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
555 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
556 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
557 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
558 { {"Ttext-segment", required_argument
, NULL
, OPTION_TTEXT_SEGMENT
},
559 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH
},
560 { {"unresolved-symbols=<method>", required_argument
, NULL
,
561 OPTION_UNRESOLVED_SYMBOLS
},
562 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
563 " ignore-all, report-all, ignore-in-object-files,\n"
564 " ignore-in-shared-libs"),
566 { {"verbose", optional_argument
, NULL
, OPTION_VERBOSE
},
567 '\0', N_("[=NUMBER]"),
568 N_("Output lots of information during link"), TWO_DASHES
},
569 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
570 '\0', NULL
, NULL
, NO_HELP
},
571 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
572 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
573 { {"version-exports-section", required_argument
, NULL
,
574 OPTION_VERSION_EXPORTS_SECTION
},
575 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
576 " SYMBOL as the version."),
578 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
579 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
580 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
581 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
582 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
583 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
584 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
585 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
586 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
587 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
588 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
589 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
591 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
592 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
593 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
594 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
595 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
596 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
598 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
599 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
601 { {"warn-alternate-em", no_argument
, NULL
, OPTION_WARN_ALTERNATE_EM
},
602 '\0', NULL
, N_("Warn if an object has alternate ELF machine code"),
604 { {"warn-unresolved-symbols", no_argument
, NULL
,
605 OPTION_WARN_UNRESOLVED_SYMBOLS
},
606 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
607 { {"error-unresolved-symbols", no_argument
, NULL
,
608 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
609 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
610 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
611 '\0', NULL
, N_("Include all objects from following archives"),
613 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
614 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
617 #define OPTION_COUNT ARRAY_SIZE (ld_options)
620 parse_args (unsigned argc
, char **argv
)
625 char *default_dirlist
= NULL
;
627 struct option
*longopts
;
628 struct option
*really_longopts
;
630 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
632 shortopts
= (char *) xmalloc (OPTION_COUNT
* 3 + 2);
633 longopts
= (struct option
*)
634 xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
635 really_longopts
= (struct option
*)
636 malloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
638 /* Starting the short option string with '-' is for programs that
639 expect options and other ARGV-elements in any order and that care about
640 the ordering of the two. We describe each non-option ARGV-element
641 as if it were the argument of an option with character code 1. */
646 for (i
= 0; i
< OPTION_COUNT
; i
++)
648 if (ld_options
[i
].shortopt
!= '\0')
650 shortopts
[is
] = ld_options
[i
].shortopt
;
652 if (ld_options
[i
].opt
.has_arg
== required_argument
653 || ld_options
[i
].opt
.has_arg
== optional_argument
)
657 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
664 if (ld_options
[i
].opt
.name
!= NULL
)
666 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
668 really_longopts
[irl
] = ld_options
[i
].opt
;
673 longopts
[il
] = ld_options
[i
].opt
;
678 shortopts
[is
] = '\0';
679 longopts
[il
].name
= NULL
;
680 really_longopts
[irl
].name
= NULL
;
682 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
684 /* The -G option is ambiguous on different platforms. Sometimes it
685 specifies the largest data size to put into the small data
686 section. Sometimes it is equivalent to --shared. Unfortunately,
687 the first form takes an argument, while the second does not.
689 We need to permit the --shared form because on some platforms,
690 such as Solaris, gcc -shared will pass -G to the linker.
692 To permit either usage, we look through the argument list. If we
693 find -G not followed by a number, we change it into --shared.
694 This will work for most normal cases. */
695 for (i
= 1; i
< argc
; i
++)
696 if (strcmp (argv
[i
], "-G") == 0
698 || ! ISDIGIT (argv
[i
+ 1][0])))
699 argv
[i
] = (char *) "--shared";
701 /* Because we permit long options to start with a single dash, and
702 we have a --library option, and the -l option is conventionally
703 used with an immediately following argument, we can have bad
704 results if somebody tries to use -l with a library whose name
705 happens to start with "ibrary", as in -li. We avoid problems by
706 simply turning -l into --library. This means that users will
707 have to use two dashes in order to use --library, which is OK
708 since that's how it is documented.
710 FIXME: It's possible that this problem can arise for other short
711 options as well, although the user does always have the recourse
712 of adding a space between the option and the argument. */
713 for (i
= 1; i
< argc
; i
++)
715 if (argv
[i
][0] == '-'
717 && argv
[i
][2] != '\0')
721 n
= (char *) xmalloc (strlen (argv
[i
]) + 20);
722 sprintf (n
, "--library=%s", argv
[i
] + 2);
733 /* Using last_optind lets us avoid calling ldemul_parse_args
734 multiple times on a single option, which would lead to
735 confusion in the internal static variables maintained by
736 getopt. This could otherwise happen for an argument like
737 -nx, in which the -n is parsed as a single option, and we
738 loop around to pick up the -x. */
739 if (optind
!= last_optind
)
740 if (ldemul_parse_args (argc
, argv
))
743 /* getopt_long_only is like getopt_long, but '-' as well as '--'
744 can indicate a long option. */
746 last_optind
= optind
;
747 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
750 optind
= last_optind
;
751 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
754 if (ldemul_handle_option (optc
))
763 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
767 einfo (_("%P%F: use the --help option for usage information\n"));
769 case 1: /* File name. */
770 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
776 /* For HP/UX compatibility. Actually -a shared should mean
777 ``use only shared libraries'' but, then, we don't
778 currently support shared libraries on HP/UX anyhow. */
779 if (strcmp (optarg
, "archive") == 0)
780 config
.dynamic_link
= FALSE
;
781 else if (strcmp (optarg
, "shared") == 0
782 || strcmp (optarg
, "default") == 0)
783 config
.dynamic_link
= TRUE
;
785 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
788 /* FIXME: We just ignore these, but we should handle them. */
789 if (strcmp (optarg
, "definitions") == 0)
791 else if (strcmp (optarg
, "nodefinitions") == 0)
793 else if (strcmp (optarg
, "nosymbolic") == 0)
795 else if (strcmp (optarg
, "pure-text") == 0)
798 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
801 ldfile_add_arch (optarg
);
804 lang_add_target (optarg
);
807 ldfile_open_command_file (optarg
);
808 parser_input
= input_mri_script
;
811 case OPTION_CALL_SHARED
:
812 config
.dynamic_link
= TRUE
;
814 case OPTION_NON_SHARED
:
815 config
.dynamic_link
= FALSE
;
818 command_line
.cref
= TRUE
;
819 link_info
.notice_all
= TRUE
;
822 command_line
.force_common_definition
= TRUE
;
826 lex_redirect (optarg
);
827 parser_input
= input_defsym
;
833 case OPTION_DEMANGLE
:
837 enum demangling_styles style
;
839 style
= cplus_demangle_name_to_style (optarg
);
840 if (style
== unknown_demangling
)
841 einfo (_("%F%P: unknown demangling style `%s'"),
844 cplus_demangle_set_style (style
);
847 case 'I': /* Used on Solaris. */
848 case OPTION_DYNAMIC_LINKER
:
849 command_line
.interpreter
= optarg
;
852 /* Already handled in ldmain.c. */
855 command_line
.endian
= ENDIAN_BIG
;
858 command_line
.endian
= ENDIAN_LITTLE
;
860 case OPTION_EMBEDDED_RELOCS
:
861 command_line
.embedded_relocs
= TRUE
;
863 case OPTION_EXPORT_DYNAMIC
:
864 case 'E': /* HP/UX compatibility. */
865 link_info
.export_dynamic
= TRUE
;
867 case OPTION_NO_EXPORT_DYNAMIC
:
868 link_info
.export_dynamic
= FALSE
;
871 lang_add_entry (optarg
, TRUE
);
874 if (command_line
.auxiliary_filters
== NULL
)
876 command_line
.auxiliary_filters
= (char **)
877 xmalloc (2 * sizeof (char *));
878 command_line
.auxiliary_filters
[0] = optarg
;
879 command_line
.auxiliary_filters
[1] = NULL
;
887 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
889 command_line
.auxiliary_filters
= (char **)
890 xrealloc (command_line
.auxiliary_filters
,
891 (c
+ 2) * sizeof (char *));
892 command_line
.auxiliary_filters
[c
] = optarg
;
893 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
897 command_line
.filter_shlib
= optarg
;
899 case OPTION_FORCE_EXE_SUFFIX
:
900 command_line
.force_exe_suffix
= TRUE
;
905 g_switch_value
= strtoul (optarg
, &end
, 0);
907 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
913 case OPTION_GC_SECTIONS
:
914 link_info
.gc_sections
= TRUE
;
916 case OPTION_PRINT_GC_SECTIONS
:
917 link_info
.print_gc_sections
= TRUE
;
924 ldfile_add_library_path (optarg
, TRUE
);
927 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
930 config
.map_filename
= "-";
933 /* Ignore. Was handled in a pre-parse. */
936 config
.map_filename
= optarg
;
939 config
.text_read_only
= FALSE
;
940 config
.magic_demand_paged
= FALSE
;
941 config
.dynamic_link
= FALSE
;
943 case OPTION_NO_OMAGIC
:
944 config
.text_read_only
= TRUE
;
945 config
.magic_demand_paged
= TRUE
;
946 /* NB/ Does not set dynamic_link to TRUE.
947 Use --call-shared or -Bdynamic for this. */
950 config
.magic_demand_paged
= FALSE
;
951 config
.dynamic_link
= FALSE
;
953 case OPTION_NO_DEFINE_COMMON
:
954 command_line
.inhibit_common_definition
= TRUE
;
956 case OPTION_NO_DEMANGLE
:
959 case OPTION_NO_GC_SECTIONS
:
960 link_info
.gc_sections
= FALSE
;
962 case OPTION_NO_PRINT_GC_SECTIONS
:
963 link_info
.print_gc_sections
= FALSE
;
965 case OPTION_NO_KEEP_MEMORY
:
966 link_info
.keep_memory
= FALSE
;
968 case OPTION_NO_UNDEFINED
:
969 link_info
.unresolved_syms_in_objects
970 = how_to_report_unresolved_symbols
;
972 case OPTION_ALLOW_SHLIB_UNDEFINED
:
973 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
975 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
976 link_info
.unresolved_syms_in_shared_libs
977 = how_to_report_unresolved_symbols
;
979 case OPTION_UNRESOLVED_SYMBOLS
:
980 if (strcmp (optarg
, "ignore-all") == 0)
982 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
983 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
985 else if (strcmp (optarg
, "report-all") == 0)
987 link_info
.unresolved_syms_in_objects
988 = how_to_report_unresolved_symbols
;
989 link_info
.unresolved_syms_in_shared_libs
990 = how_to_report_unresolved_symbols
;
992 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
994 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
995 link_info
.unresolved_syms_in_shared_libs
996 = how_to_report_unresolved_symbols
;
998 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
1000 link_info
.unresolved_syms_in_objects
1001 = how_to_report_unresolved_symbols
;
1002 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1005 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
1007 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
1008 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
1009 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
1010 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
1011 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
1012 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
1015 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
1016 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
1017 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
1018 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
1019 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
1020 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
1022 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
1023 link_info
.allow_multiple_definition
= TRUE
;
1025 case OPTION_NO_UNDEFINED_VERSION
:
1026 link_info
.allow_undefined_version
= FALSE
;
1028 case OPTION_DEFAULT_SYMVER
:
1029 link_info
.create_default_symver
= TRUE
;
1031 case OPTION_DEFAULT_IMPORTED_SYMVER
:
1032 link_info
.default_imported_symver
= TRUE
;
1034 case OPTION_NO_WARN_MISMATCH
:
1035 command_line
.warn_mismatch
= FALSE
;
1037 case OPTION_NO_WARN_SEARCH_MISMATCH
:
1038 command_line
.warn_search_mismatch
= FALSE
;
1040 case OPTION_NOINHIBIT_EXEC
:
1041 force_make_executable
= TRUE
;
1043 case OPTION_NOSTDLIB
:
1044 config
.only_cmd_line_lib_dirs
= TRUE
;
1046 case OPTION_NO_WHOLE_ARCHIVE
:
1047 whole_archive
= FALSE
;
1050 /* FIXME "-O<non-digits> <value>" used to set the address of
1051 section <non-digits>. Was this for compatibility with
1052 something, or can we create a new option to do that
1053 (with a syntax similar to -defsym)?
1054 getopt can't handle two args to an option without kludges. */
1056 /* Enable optimizations of output files. */
1057 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
1060 lang_add_output (optarg
, 0);
1062 case OPTION_OFORMAT
:
1063 lang_add_output_format (optarg
, NULL
, NULL
, 0);
1065 case OPTION_PRINT_OUTPUT_FORMAT
:
1066 command_line
.print_output_format
= TRUE
;
1068 #ifdef ENABLE_PLUGINS
1070 if (plugin_opt_plugin (optarg
))
1071 einfo (_("%P%F: %s: error loading plugin\n"),
1072 plugin_error_plugin ());
1074 case OPTION_PLUGIN_OPT
:
1075 if (plugin_opt_plugin_arg (optarg
))
1076 einfo(_("%P%F: bad -plugin-opt option\n"));
1078 #endif /* ENABLE_PLUGINS */
1080 link_info
.emitrelocations
= TRUE
;
1084 if (optind
== last_optind
)
1085 /* This can happen if the user put "-rpath,a" on the command
1086 line. (Or something similar. The comma is important).
1087 Getopt becomes confused and thinks that this is a -r option
1088 but it cannot parse the text after the -r so it refuses to
1089 increment the optind counter. Detect this case and issue
1090 an error message here. We cannot just make this a warning,
1091 increment optind, and continue because getopt is too confused
1092 and will seg-fault the next time around. */
1093 einfo(_("%P%F: bad -rpath option\n"));
1095 link_info
.relocatable
= TRUE
;
1096 config
.build_constructors
= FALSE
;
1097 config
.magic_demand_paged
= FALSE
;
1098 config
.text_read_only
= FALSE
;
1099 config
.dynamic_link
= FALSE
;
1102 /* The GNU linker traditionally uses -R to mean to include
1103 only the symbols from a file. The Solaris linker uses -R
1104 to set the path used by the runtime linker to find
1105 libraries. This is the GNU linker -rpath argument. We
1106 try to support both simultaneously by checking the file
1107 named. If it is a directory, rather than a regular file,
1108 we assume -rpath was meant. */
1112 if (stat (optarg
, &s
) >= 0
1113 && ! S_ISDIR (s
.st_mode
))
1115 lang_add_input_file (optarg
,
1116 lang_input_file_is_symbols_only_enum
,
1123 if (command_line
.rpath
== NULL
)
1124 command_line
.rpath
= xstrdup (optarg
);
1127 size_t rpath_len
= strlen (command_line
.rpath
);
1128 size_t optarg_len
= strlen (optarg
);
1130 char *cp
= command_line
.rpath
;
1132 /* First see whether OPTARG is already in the path. */
1135 if (strncmp (optarg
, cp
, optarg_len
) == 0
1136 && (cp
[optarg_len
] == 0
1137 || cp
[optarg_len
] == config
.rpath_separator
))
1141 /* Not yet found. */
1142 cp
= strchr (cp
, config
.rpath_separator
);
1150 buf
= (char *) xmalloc (rpath_len
+ optarg_len
+ 2);
1151 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1152 config
.rpath_separator
, optarg
);
1153 free (command_line
.rpath
);
1154 command_line
.rpath
= buf
;
1158 case OPTION_RPATH_LINK
:
1159 if (command_line
.rpath_link
== NULL
)
1160 command_line
.rpath_link
= xstrdup (optarg
);
1165 buf
= (char *) xmalloc (strlen (command_line
.rpath_link
)
1168 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1169 config
.rpath_separator
, optarg
);
1170 free (command_line
.rpath_link
);
1171 command_line
.rpath_link
= buf
;
1174 case OPTION_NO_RELAX
:
1180 case OPTION_RETAIN_SYMBOLS_FILE
:
1181 add_keepsyms_file (optarg
);
1184 link_info
.strip
= strip_debugger
;
1187 link_info
.strip
= strip_all
;
1189 case OPTION_STRIP_DISCARDED
:
1190 link_info
.strip_discarded
= TRUE
;
1192 case OPTION_NO_STRIP_DISCARDED
:
1193 link_info
.strip_discarded
= FALSE
;
1196 if (config
.has_shared
)
1198 link_info
.shared
= TRUE
;
1199 /* When creating a shared library, the default
1200 behaviour is to ignore any unresolved references. */
1201 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1202 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1203 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1204 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1207 einfo (_("%P%F: -shared not supported\n"));
1210 if (config
.has_shared
)
1212 link_info
.shared
= TRUE
;
1213 link_info
.pie
= TRUE
;
1216 einfo (_("%P%F: -pie not supported\n"));
1218 case 'h': /* Used on Solaris. */
1220 command_line
.soname
= optarg
;
1222 case OPTION_SORT_COMMON
:
1224 || strcmp (optarg
, N_("descending")) == 0)
1225 config
.sort_common
= sort_descending
;
1226 else if (strcmp (optarg
, N_("ascending")) == 0)
1227 config
.sort_common
= sort_ascending
;
1229 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1232 case OPTION_SORT_SECTION
:
1233 if (strcmp (optarg
, N_("name")) == 0)
1234 sort_section
= by_name
;
1235 else if (strcmp (optarg
, N_("alignment")) == 0)
1236 sort_section
= by_alignment
;
1238 einfo (_("%P%F: invalid section sorting option: %s\n"),
1242 config
.stats
= TRUE
;
1244 case OPTION_SYMBOLIC
:
1245 command_line
.symbolic
= symbolic
;
1247 case OPTION_SYMBOLIC_FUNCTIONS
:
1248 command_line
.symbolic
= symbolic_functions
;
1254 previous_script_handle
= saved_script_handle
;
1255 ldfile_open_command_file (optarg
);
1256 parser_input
= input_script
;
1258 previous_script_handle
= NULL
;
1260 case OPTION_DEFAULT_SCRIPT
:
1261 command_line
.default_script
= optarg
;
1263 case OPTION_SECTION_START
:
1269 /* Check for <something>=<somthing>... */
1270 optarg2
= strchr (optarg
, '=');
1271 if (optarg2
== NULL
)
1272 einfo (_("%P%F: invalid argument to option"
1273 " \"--section-start\"\n"));
1277 /* So far so good. Are all the args present? */
1278 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1279 einfo (_("%P%F: missing argument(s) to option"
1280 " \"--section-start\"\n"));
1282 /* We must copy the section name as set_section_start
1283 doesn't do it for us. */
1284 len
= optarg2
- optarg
;
1285 sec_name
= (char *) xmalloc (len
);
1286 memcpy (sec_name
, optarg
, len
- 1);
1287 sec_name
[len
- 1] = 0;
1289 /* Then set it... */
1290 set_section_start (sec_name
, optarg2
);
1293 case OPTION_TARGET_HELP
:
1294 /* Mention any target specific options. */
1295 ldemul_list_emulation_options (stdout
);
1298 set_segment_start (".bss", optarg
);
1301 set_segment_start (".data", optarg
);
1304 set_segment_start (".text", optarg
);
1306 case OPTION_TTEXT_SEGMENT
:
1307 set_segment_start (".text-segment", optarg
);
1309 case OPTION_TRADITIONAL_FORMAT
:
1310 link_info
.traditional_format
= TRUE
;
1312 case OPTION_TASK_LINK
:
1313 link_info
.task_link
= TRUE
;
1314 /* Fall through - do an implied -r option. */
1316 link_info
.relocatable
= TRUE
;
1317 config
.build_constructors
= TRUE
;
1318 config
.magic_demand_paged
= FALSE
;
1319 config
.text_read_only
= FALSE
;
1320 config
.dynamic_link
= FALSE
;
1323 ldlang_add_undef (optarg
, TRUE
);
1327 lang_add_unique (optarg
);
1329 config
.unique_orphan_sections
= TRUE
;
1331 case OPTION_VERBOSE
:
1333 version_printed
= TRUE
;
1334 trace_file_tries
= TRUE
;
1335 overflow_cutoff_limit
= -2;
1339 int level ATTRIBUTE_UNUSED
= strtoul (optarg
, &end
, 0);
1341 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
1342 #ifdef ENABLE_PLUGINS
1343 report_plugin_symbols
= level
> 1;
1344 #endif /* ENABLE_PLUGINS */
1349 version_printed
= TRUE
;
1353 version_printed
= TRUE
;
1355 case OPTION_VERSION
:
1359 case OPTION_VERSION_SCRIPT
:
1360 /* This option indicates a small script that only specifies
1361 version information. Read it, but don't assume that
1362 we've seen a linker script. */
1364 FILE *hold_script_handle
;
1366 hold_script_handle
= saved_script_handle
;
1367 ldfile_open_command_file (optarg
);
1368 saved_script_handle
= hold_script_handle
;
1369 parser_input
= input_version_script
;
1373 case OPTION_VERSION_EXPORTS_SECTION
:
1374 /* This option records a version symbol to be applied to the
1375 symbols listed for export to be found in the object files
1376 .exports sections. */
1377 command_line
.version_exports_section
= optarg
;
1379 case OPTION_DYNAMIC_LIST_DATA
:
1380 command_line
.dynamic_list
= dynamic_list_data
;
1381 if (command_line
.symbolic
== symbolic
)
1382 command_line
.symbolic
= symbolic_unset
;
1384 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1385 lang_append_dynamic_list_cpp_typeinfo ();
1386 if (command_line
.dynamic_list
!= dynamic_list_data
)
1387 command_line
.dynamic_list
= dynamic_list
;
1388 if (command_line
.symbolic
== symbolic
)
1389 command_line
.symbolic
= symbolic_unset
;
1391 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1392 lang_append_dynamic_list_cpp_new ();
1393 if (command_line
.dynamic_list
!= dynamic_list_data
)
1394 command_line
.dynamic_list
= dynamic_list
;
1395 if (command_line
.symbolic
== symbolic
)
1396 command_line
.symbolic
= symbolic_unset
;
1398 case OPTION_DYNAMIC_LIST
:
1399 /* This option indicates a small script that only specifies
1400 a dynamic list. Read it, but don't assume that we've
1401 seen a linker script. */
1403 FILE *hold_script_handle
;
1405 hold_script_handle
= saved_script_handle
;
1406 ldfile_open_command_file (optarg
);
1407 saved_script_handle
= hold_script_handle
;
1408 parser_input
= input_dynamic_list
;
1411 if (command_line
.dynamic_list
!= dynamic_list_data
)
1412 command_line
.dynamic_list
= dynamic_list
;
1413 if (command_line
.symbolic
== symbolic
)
1414 command_line
.symbolic
= symbolic_unset
;
1416 case OPTION_WARN_COMMON
:
1417 config
.warn_common
= TRUE
;
1419 case OPTION_WARN_CONSTRUCTORS
:
1420 config
.warn_constructors
= TRUE
;
1422 case OPTION_WARN_FATAL
:
1423 config
.fatal_warnings
= TRUE
;
1425 case OPTION_NO_WARN_FATAL
:
1426 config
.fatal_warnings
= FALSE
;
1428 case OPTION_WARN_MULTIPLE_GP
:
1429 config
.warn_multiple_gp
= TRUE
;
1431 case OPTION_WARN_ONCE
:
1432 config
.warn_once
= TRUE
;
1434 case OPTION_WARN_SECTION_ALIGN
:
1435 config
.warn_section_align
= TRUE
;
1437 case OPTION_WARN_SHARED_TEXTREL
:
1438 link_info
.warn_shared_textrel
= TRUE
;
1440 case OPTION_WARN_ALTERNATE_EM
:
1441 link_info
.warn_alternate_em
= TRUE
;
1443 case OPTION_WHOLE_ARCHIVE
:
1444 whole_archive
= TRUE
;
1446 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
:
1447 add_DT_NEEDED_for_dynamic
= TRUE
;
1449 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
:
1450 add_DT_NEEDED_for_dynamic
= FALSE
;
1452 case OPTION_ADD_DT_NEEDED_FOR_REGULAR
:
1453 add_DT_NEEDED_for_regular
= TRUE
;
1455 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
:
1456 add_DT_NEEDED_for_regular
= FALSE
;
1461 case OPTION_DISCARD_NONE
:
1462 link_info
.discard
= discard_none
;
1465 link_info
.discard
= discard_l
;
1468 link_info
.discard
= discard_all
;
1471 if (CONST_STRNEQ (optarg
, "P,"))
1473 if (default_dirlist
!= NULL
)
1474 free (default_dirlist
);
1475 default_dirlist
= xstrdup (optarg
);
1480 case OPTION_SPARE_DYNAMIC_TAGS
:
1481 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1483 case OPTION_SPLIT_BY_RELOC
:
1485 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1487 config
.split_by_reloc
= 32768;
1489 case OPTION_SPLIT_BY_FILE
:
1491 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1493 config
.split_by_file
= 1;
1495 case OPTION_CHECK_SECTIONS
:
1496 command_line
.check_section_addresses
= 1;
1498 case OPTION_NO_CHECK_SECTIONS
:
1499 command_line
.check_section_addresses
= 0;
1501 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1502 command_line
.accept_unknown_input_arch
= TRUE
;
1504 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1505 command_line
.accept_unknown_input_arch
= FALSE
;
1508 lang_enter_group ();
1513 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1515 lang_leave_group ();
1520 link_info
.init_function
= optarg
;
1524 link_info
.fini_function
= optarg
;
1527 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1528 link_info
.reduce_memory_overheads
= TRUE
;
1529 if (config
.hash_table_size
== 0)
1530 config
.hash_table_size
= 1021;
1533 case OPTION_HASH_SIZE
:
1535 bfd_size_type new_size
;
1537 new_size
= strtoul (optarg
, NULL
, 0);
1539 config
.hash_table_size
= new_size
;
1541 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1549 lang_leave_group ();
1553 if (default_dirlist
!= NULL
)
1555 set_default_dirlist (default_dirlist
);
1556 free (default_dirlist
);
1559 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1560 /* FIXME: Should we allow emulations a chance to set this ? */
1561 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1563 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1564 /* FIXME: Should we allow emulations a chance to set this ? */
1565 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1567 if (link_info
.relocatable
)
1569 if (command_line
.check_section_addresses
< 0)
1570 command_line
.check_section_addresses
= 0;
1571 if (link_info
.shared
)
1572 einfo (_("%P%F: -r and -shared may not be used together\n"));
1575 /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data,
1576 --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and
1577 --dynamic-list FILE. -Bsymbolic and -Bsymbolic-functions are
1578 for shared libraries. -Bsymbolic overrides all others and vice
1580 switch (command_line
.symbolic
)
1582 case symbolic_unset
:
1585 /* -Bsymbolic is for shared library only. */
1586 if (link_info
.shared
)
1588 link_info
.symbolic
= TRUE
;
1589 /* Should we free the unused memory? */
1590 link_info
.dynamic_list
= NULL
;
1591 command_line
.dynamic_list
= dynamic_list_unset
;
1594 case symbolic_functions
:
1595 /* -Bsymbolic-functions is for shared library only. */
1596 if (link_info
.shared
)
1597 command_line
.dynamic_list
= dynamic_list_data
;
1601 switch (command_line
.dynamic_list
)
1603 case dynamic_list_unset
:
1605 case dynamic_list_data
:
1606 link_info
.dynamic_data
= TRUE
;
1608 link_info
.dynamic
= TRUE
;
1612 if (! link_info
.shared
)
1614 if (command_line
.filter_shlib
)
1615 einfo (_("%P%F: -F may not be used without -shared\n"));
1616 if (command_line
.auxiliary_filters
)
1617 einfo (_("%P%F: -f may not be used without -shared\n"));
1620 if (! link_info
.shared
|| link_info
.pie
)
1621 link_info
.executable
= TRUE
;
1623 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1624 don't see how else this can be handled, since in this case we
1625 must preserve all externally visible symbols. */
1626 if (link_info
.relocatable
&& link_info
.strip
== strip_all
)
1628 link_info
.strip
= strip_debugger
;
1629 if (link_info
.discard
== discard_sec_merge
)
1630 link_info
.discard
= discard_all
;
1634 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1635 library search path. */
1638 set_default_dirlist (char *dirlist_ptr
)
1644 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1647 if (*dirlist_ptr
!= '\0')
1648 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1651 dirlist_ptr
= p
+ 1;
1656 set_section_start (char *sect
, char *valstr
)
1659 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1661 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1662 lang_section_start (sect
, exp_intop (val
), NULL
);
1666 set_segment_start (const char *section
, char *valstr
)
1672 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1674 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1675 /* If we already have an entry for this segment, update the existing
1678 for (seg
= segments
; seg
; seg
= seg
->next
)
1679 if (strcmp (seg
->name
, name
) == 0)
1684 /* There was no existing value so we must create a new segment
1686 seg
= (segment_type
*) stat_alloc (sizeof (*seg
));
1690 /* Add it to the linked list of segments. */
1691 seg
->next
= segments
;
1693 /* Historically, -Ttext and friends set the base address of a
1694 particular section. For backwards compatibility, we still do
1695 that. If a SEGMENT_START directive is seen, the section address
1696 assignment will be disabled. */
1697 lang_section_start (section
, exp_intop (val
), seg
);
1701 /* Print help messages for the options. */
1707 const char **targets
, **pp
;
1710 printf (_("Usage: %s [options] file...\n"), program_name
);
1712 printf (_("Options:\n"));
1713 for (i
= 0; i
< OPTION_COUNT
; i
++)
1715 if (ld_options
[i
].doc
!= NULL
)
1728 if (ld_options
[j
].shortopt
!= '\0'
1729 && ld_options
[j
].control
!= NO_HELP
)
1731 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1732 len
+= (comma
? 2 : 0) + 2;
1733 if (ld_options
[j
].arg
!= NULL
)
1735 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1740 printf ("%s", _(ld_options
[j
].arg
));
1741 len
+= strlen (_(ld_options
[j
].arg
));
1747 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1752 if (ld_options
[j
].opt
.name
!= NULL
1753 && ld_options
[j
].control
!= NO_HELP
)
1756 (ld_options
[j
].control
== TWO_DASHES
1757 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1761 two_dashes
? "-" : "",
1762 ld_options
[j
].opt
.name
);
1763 len
+= ((comma
? 2 : 0)
1765 + (two_dashes
? 1 : 0)
1766 + strlen (ld_options
[j
].opt
.name
));
1767 if (ld_options
[j
].arg
!= NULL
)
1769 printf (" %s", _(ld_options
[j
].arg
));
1770 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1776 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1784 for (; len
< 30; len
++)
1787 printf ("%s\n", _(ld_options
[i
].doc
));
1790 printf (_(" @FILE"));
1791 for (len
= strlen (" @FILE"); len
< 30; len
++)
1793 printf (_("Read options from FILE\n"));
1795 /* Note: Various tools (such as libtool) depend upon the
1796 format of the listings below - do not change them. */
1797 /* xgettext:c-format */
1798 printf (_("%s: supported targets:"), program_name
);
1799 targets
= bfd_target_list ();
1800 for (pp
= targets
; *pp
!= NULL
; pp
++)
1801 printf (" %s", *pp
);
1805 /* xgettext:c-format */
1806 printf (_("%s: supported emulations: "), program_name
);
1807 ldemul_list_emulations (stdout
);
1810 /* xgettext:c-format */
1811 printf (_("%s: emulation specific options:\n"), program_name
);
1812 ldemul_list_emulation_options (stdout
);
1815 if (REPORT_BUGS_TO
[0])
1816 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);