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
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
,
80 OPTION_NO_EXPORT_DYNAMIC
,
85 OPTION_NO_KEEP_MEMORY
,
86 OPTION_NO_WARN_MISMATCH
,
87 OPTION_NO_WARN_SEARCH_MISMATCH
,
88 OPTION_NOINHIBIT_EXEC
,
90 OPTION_NO_WHOLE_ARCHIVE
,
94 OPTION_RETAIN_SYMBOLS_FILE
,
103 OPTION_SYMBOLIC_FUNCTIONS
,
108 OPTION_TTEXT_SEGMENT
,
109 OPTION_TRADITIONAL_FORMAT
,
113 OPTION_VERSION_SCRIPT
,
114 OPTION_VERSION_EXPORTS_SECTION
,
116 OPTION_DYNAMIC_LIST_CPP_NEW
,
117 OPTION_DYNAMIC_LIST_CPP_TYPEINFO
,
118 OPTION_DYNAMIC_LIST_DATA
,
120 OPTION_WARN_CONSTRUCTORS
,
122 OPTION_NO_WARN_FATAL
,
123 OPTION_WARN_MULTIPLE_GP
,
125 OPTION_WARN_SECTION_ALIGN
,
126 OPTION_SPLIT_BY_RELOC
,
127 OPTION_SPLIT_BY_FILE
,
128 OPTION_WHOLE_ARCHIVE
,
129 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
,
130 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
,
131 OPTION_ADD_DT_NEEDED_FOR_REGULAR
,
132 OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
,
134 OPTION_FORCE_EXE_SUFFIX
,
136 OPTION_NO_GC_SECTIONS
,
137 OPTION_PRINT_GC_SECTIONS
,
138 OPTION_NO_PRINT_GC_SECTIONS
,
140 OPTION_CHECK_SECTIONS
,
141 OPTION_NO_CHECK_SECTIONS
,
145 OPTION_SECTION_START
,
148 OPTION_ALLOW_SHLIB_UNDEFINED
,
149 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
150 OPTION_ALLOW_MULTIPLE_DEFINITION
,
151 OPTION_NO_UNDEFINED_VERSION
,
152 OPTION_DEFAULT_SYMVER
,
153 OPTION_DEFAULT_IMPORTED_SYMVER
,
155 OPTION_SPARE_DYNAMIC_TAGS
,
156 OPTION_NO_DEFINE_COMMON
,
159 OPTION_STRIP_DISCARDED
,
160 OPTION_NO_STRIP_DISCARDED
,
161 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
162 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
164 OPTION_UNRESOLVED_SYMBOLS
,
165 OPTION_WARN_UNRESOLVED_SYMBOLS
,
166 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
167 OPTION_WARN_SHARED_TEXTREL
,
168 OPTION_WARN_ALTERNATE_EM
,
169 OPTION_REDUCE_MEMORY_OVERHEADS
,
170 OPTION_DEFAULT_SCRIPT
173 /* The long options. This structure is used for both the option
174 parsing and the help text. */
177 /* Use one dash before long option name. */
179 /* Use two dashes before long option name. */
181 /* Only accept two dashes before the long option name.
182 This is an overloading of the use of this enum, since originally it
183 was only intended to tell the --help display function how to display
184 the long option name. This feature was added in order to resolve
185 the confusion about the -omagic command line switch. Is it setting
186 the output file name to "magic" or is it setting the NMAGIC flag on
187 the output ? It has been decided that it is setting the output file
188 name, and that if you want to set the NMAGIC flag you should use -N
191 /* Don't mention this option in --help output. */
197 /* The long option information. */
199 /* The short option with the same meaning ('\0' if none). */
201 /* The name of the argument (NULL if none). */
203 /* The documentation string. If this is NULL, this is a synonym for
204 the previous option. */
206 enum control_enum control
;
209 static const struct ld_option ld_options
[] =
211 { {NULL
, required_argument
, NULL
, '\0'},
212 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
214 { {"architecture", required_argument
, NULL
, 'A'},
215 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
216 { {"format", required_argument
, NULL
, 'b'},
217 'b', N_("TARGET"), N_("Specify target for following input files"),
219 { {"mri-script", required_argument
, NULL
, 'c'},
220 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
221 { {"dc", no_argument
, NULL
, 'd'},
222 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
223 { {"dp", no_argument
, NULL
, 'd'},
224 '\0', NULL
, NULL
, ONE_DASH
},
225 { {"entry", required_argument
, NULL
, 'e'},
226 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
227 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
228 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
229 { {"no-export-dynamic", no_argument
, NULL
, OPTION_NO_EXPORT_DYNAMIC
},
230 '\0', NULL
, N_("Undo the effect of --export-dynamic"), TWO_DASHES
},
231 { {"EB", no_argument
, NULL
, OPTION_EB
},
232 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
233 { {"EL", no_argument
, NULL
, OPTION_EL
},
234 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
235 { {"auxiliary", required_argument
, NULL
, 'f'},
236 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
238 { {"filter", required_argument
, NULL
, 'F'},
239 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
241 { {NULL
, no_argument
, NULL
, '\0'},
242 'g', NULL
, N_("Ignored"), ONE_DASH
},
243 { {"gpsize", required_argument
, NULL
, 'G'},
244 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
246 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
247 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
248 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
249 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
251 { {"library", required_argument
, NULL
, 'l'},
252 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
253 { {"library-path", required_argument
, NULL
, 'L'},
254 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
256 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
257 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
258 { {NULL
, required_argument
, NULL
, '\0'},
259 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
260 { {"print-map", no_argument
, NULL
, 'M'},
261 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
262 { {"nmagic", no_argument
, NULL
, 'n'},
263 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
264 { {"omagic", no_argument
, NULL
, 'N'},
265 'N', NULL
, N_("Do not page align data, do not make text readonly"),
266 EXACTLY_TWO_DASHES
},
267 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
268 '\0', NULL
, N_("Page align data, make text readonly"),
269 EXACTLY_TWO_DASHES
},
270 { {"output", required_argument
, NULL
, 'o'},
271 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
272 { {NULL
, required_argument
, NULL
, '\0'},
273 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
274 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
275 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
276 { {"emit-relocs", no_argument
, NULL
, 'q'},
277 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
278 { {"relocatable", no_argument
, NULL
, 'r'},
279 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
280 { {NULL
, no_argument
, NULL
, '\0'},
281 'i', NULL
, NULL
, ONE_DASH
},
282 { {"just-symbols", required_argument
, NULL
, 'R'},
283 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
285 { {"strip-all", no_argument
, NULL
, 's'},
286 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
287 { {"strip-debug", no_argument
, NULL
, 'S'},
288 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
289 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
290 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
291 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
292 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
293 { {"trace", no_argument
, NULL
, 't'},
294 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
295 { {"script", required_argument
, NULL
, 'T'},
296 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
297 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
298 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
299 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
300 '\0', NULL
, NULL
, ONE_DASH
},
301 { {"undefined", required_argument
, NULL
, 'u'},
302 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
304 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
305 '\0', N_("[=SECTION]"),
306 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
307 { {"Ur", no_argument
, NULL
, OPTION_UR
},
308 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
309 { {"version", no_argument
, NULL
, OPTION_VERSION
},
310 'v', NULL
, N_("Print version information"), TWO_DASHES
},
311 { {NULL
, no_argument
, NULL
, '\0'},
312 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
313 { {"discard-all", no_argument
, NULL
, 'x'},
314 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
315 { {"discard-locals", no_argument
, NULL
, 'X'},
316 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
317 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
318 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
319 { {"trace-symbol", required_argument
, NULL
, 'y'},
320 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
321 { {NULL
, required_argument
, NULL
, '\0'},
322 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
324 { {"start-group", no_argument
, NULL
, '('},
325 '(', NULL
, N_("Start a group"), TWO_DASHES
},
326 { {"end-group", no_argument
, NULL
, ')'},
327 ')', NULL
, N_("End a group"), TWO_DASHES
},
328 { {"accept-unknown-input-arch", no_argument
, NULL
,
329 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
331 N_("Accept input files whose architecture cannot be determined"),
333 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
334 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
335 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
338 /* The next two options are deprecated because of their similarity to
339 --as-needed and --no-as-needed. They have been replaced by
340 --resolve-implicit-dynamic-symbols and
341 --no-resolve-implicit-dynamic-symbols. */
342 { {"add-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
343 '\0', NULL
, NULL
, NO_HELP
},
344 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
345 '\0', NULL
, NULL
, NO_HELP
},
347 { {"as-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_REGULAR
},
348 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
350 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
},
351 '\0', NULL
, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
352 " the command line"),
354 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
355 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
356 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
357 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
358 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
359 '\0', NULL
, NULL
, ONE_DASH
},
360 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
361 '\0', NULL
, NULL
, ONE_DASH
},
362 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
363 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
364 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
365 '\0', NULL
, NULL
, ONE_DASH
},
366 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
367 '\0', NULL
, NULL
, ONE_DASH
},
368 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
369 '\0', NULL
, NULL
, ONE_DASH
},
370 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
371 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
372 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
373 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
374 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
375 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
377 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
378 '\0', NULL
, N_("Do not check section addresses for overlaps"),
380 { {"copy-dt-needed-entries", no_argument
, NULL
,
381 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
382 '\0', NULL
, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
384 { {"no-copy-dt-needed-entries", no_argument
, NULL
,
385 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
386 '\0', NULL
, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
389 { {"cref", no_argument
, NULL
, OPTION_CREF
},
390 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
391 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
392 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
393 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
394 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
396 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
397 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
398 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
399 '\0', NULL
, N_("Treat warnings as errors"),
401 { {"no-fatal-warnings", no_argument
, NULL
, OPTION_NO_WARN_FATAL
},
402 '\0', NULL
, N_("Do not treat warnings as errors (default)"),
404 { {"fini", required_argument
, NULL
, OPTION_FINI
},
405 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
406 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
407 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
408 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
409 '\0', NULL
, N_("Remove unused sections (on some targets)"),
411 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
412 '\0', NULL
, N_("Don't remove unused sections (default)"),
414 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
415 '\0', NULL
, N_("List removed unused sections on stderr"),
417 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
418 '\0', NULL
, N_("Do not list removed unused sections"),
420 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
421 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
423 { {"help", no_argument
, NULL
, OPTION_HELP
},
424 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
425 { {"init", required_argument
, NULL
, OPTION_INIT
},
426 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
427 { {"Map", required_argument
, NULL
, OPTION_MAP
},
428 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
429 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
430 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
431 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
432 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
433 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
434 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
435 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
436 '\0', NULL
, N_("Do not allow unresolved references in object files"),
438 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
439 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
441 { {"no-allow-shlib-undefined", no_argument
, NULL
,
442 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
443 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
445 { {"allow-multiple-definition", no_argument
, NULL
,
446 OPTION_ALLOW_MULTIPLE_DEFINITION
},
447 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
448 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
449 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
450 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
451 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
452 { {"default-imported-symver", no_argument
, NULL
,
453 OPTION_DEFAULT_IMPORTED_SYMVER
},
454 '\0', NULL
, N_("Create default symbol version for imported symbols"),
456 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
457 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
458 { {"no-warn-search-mismatch", no_argument
, NULL
,
459 OPTION_NO_WARN_SEARCH_MISMATCH
},
460 '\0', NULL
, N_("Don't warn on finding an incompatible library"),
462 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
463 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
464 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
465 '\0', NULL
, N_("Create an output file even if errors occur"),
467 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
468 '\0', NULL
, NULL
, NO_HELP
},
469 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
470 '\0', NULL
, N_("Only use library directories specified on\n"
471 " the command line"),
473 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
474 '\0', N_("TARGET"), N_("Specify target of output file"),
475 EXACTLY_TWO_DASHES
},
476 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
477 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
478 { {"reduce-memory-overheads", no_argument
, NULL
,
479 OPTION_REDUCE_MEMORY_OVERHEADS
},
480 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
482 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
483 '\0', NULL
, N_("Reduce code size by using target specific optimizations"), TWO_DASHES
},
484 { {"no-relax", no_argument
, NULL
, OPTION_NO_RELAX
},
485 '\0', NULL
, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES
},
486 { {"retain-symbols-file", required_argument
, NULL
,
487 OPTION_RETAIN_SYMBOLS_FILE
},
488 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
489 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
490 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
491 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
492 '\0', N_("PATH"), N_("Set link time shared library search path"),
494 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
495 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
496 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
497 '\0', NULL
, NULL
, ONE_DASH
},
498 { {"pie", no_argument
, NULL
, OPTION_PIE
},
499 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
500 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
501 '\0', NULL
, NULL
, TWO_DASHES
},
502 { {"sort-common", optional_argument
, NULL
, OPTION_SORT_COMMON
},
503 '\0', N_("[=ascending|descending]"),
504 N_("Sort common symbols by alignment [in specified order]"),
506 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
507 '\0', NULL
, NULL
, NO_HELP
},
508 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
509 '\0', N_("name|alignment"),
510 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
511 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
512 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
514 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
515 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
517 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
518 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
520 { {"stats", no_argument
, NULL
, OPTION_STATS
},
521 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
522 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
523 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
524 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
525 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
526 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
527 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
528 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
529 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
531 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
532 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
533 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
534 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
535 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
536 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
537 { {"Ttext-segment", required_argument
, NULL
, OPTION_TTEXT_SEGMENT
},
538 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH
},
539 { {"unresolved-symbols=<method>", required_argument
, NULL
,
540 OPTION_UNRESOLVED_SYMBOLS
},
541 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
542 " ignore-all, report-all, ignore-in-object-files,\n"
543 " ignore-in-shared-libs"),
545 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
546 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
547 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
548 '\0', NULL
, NULL
, NO_HELP
},
549 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
550 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
551 { {"version-exports-section", required_argument
, NULL
,
552 OPTION_VERSION_EXPORTS_SECTION
},
553 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
554 " SYMBOL as the version."),
556 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
557 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
558 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
559 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
560 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
561 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
562 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
563 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
564 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
565 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
566 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
567 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
569 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
570 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
571 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
572 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
573 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
574 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
576 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
577 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
579 { {"warn-alternate-em", no_argument
, NULL
, OPTION_WARN_ALTERNATE_EM
},
580 '\0', NULL
, N_("Warn if an object has alternate ELF machine code"),
582 { {"warn-unresolved-symbols", no_argument
, NULL
,
583 OPTION_WARN_UNRESOLVED_SYMBOLS
},
584 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
585 { {"error-unresolved-symbols", no_argument
, NULL
,
586 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
587 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
588 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
589 '\0', NULL
, N_("Include all objects from following archives"),
591 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
592 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
595 #define OPTION_COUNT ARRAY_SIZE (ld_options)
598 parse_args (unsigned argc
, char **argv
)
603 char *default_dirlist
= NULL
;
605 struct option
*longopts
;
606 struct option
*really_longopts
;
608 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
610 shortopts
= (char *) xmalloc (OPTION_COUNT
* 3 + 2);
611 longopts
= (struct option
*)
612 xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
613 really_longopts
= (struct option
*)
614 malloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
616 /* Starting the short option string with '-' is for programs that
617 expect options and other ARGV-elements in any order and that care about
618 the ordering of the two. We describe each non-option ARGV-element
619 as if it were the argument of an option with character code 1. */
624 for (i
= 0; i
< OPTION_COUNT
; i
++)
626 if (ld_options
[i
].shortopt
!= '\0')
628 shortopts
[is
] = ld_options
[i
].shortopt
;
630 if (ld_options
[i
].opt
.has_arg
== required_argument
631 || ld_options
[i
].opt
.has_arg
== optional_argument
)
635 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
642 if (ld_options
[i
].opt
.name
!= NULL
)
644 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
646 really_longopts
[irl
] = ld_options
[i
].opt
;
651 longopts
[il
] = ld_options
[i
].opt
;
656 shortopts
[is
] = '\0';
657 longopts
[il
].name
= NULL
;
658 really_longopts
[irl
].name
= NULL
;
660 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
662 /* The -G option is ambiguous on different platforms. Sometimes it
663 specifies the largest data size to put into the small data
664 section. Sometimes it is equivalent to --shared. Unfortunately,
665 the first form takes an argument, while the second does not.
667 We need to permit the --shared form because on some platforms,
668 such as Solaris, gcc -shared will pass -G to the linker.
670 To permit either usage, we look through the argument list. If we
671 find -G not followed by a number, we change it into --shared.
672 This will work for most normal cases. */
673 for (i
= 1; i
< argc
; i
++)
674 if (strcmp (argv
[i
], "-G") == 0
676 || ! ISDIGIT (argv
[i
+ 1][0])))
677 argv
[i
] = (char *) "--shared";
679 /* Because we permit long options to start with a single dash, and
680 we have a --library option, and the -l option is conventionally
681 used with an immediately following argument, we can have bad
682 results if somebody tries to use -l with a library whose name
683 happens to start with "ibrary", as in -li. We avoid problems by
684 simply turning -l into --library. This means that users will
685 have to use two dashes in order to use --library, which is OK
686 since that's how it is documented.
688 FIXME: It's possible that this problem can arise for other short
689 options as well, although the user does always have the recourse
690 of adding a space between the option and the argument. */
691 for (i
= 1; i
< argc
; i
++)
693 if (argv
[i
][0] == '-'
695 && argv
[i
][2] != '\0')
699 n
= (char *) xmalloc (strlen (argv
[i
]) + 20);
700 sprintf (n
, "--library=%s", argv
[i
] + 2);
711 /* Using last_optind lets us avoid calling ldemul_parse_args
712 multiple times on a single option, which would lead to
713 confusion in the internal static variables maintained by
714 getopt. This could otherwise happen for an argument like
715 -nx, in which the -n is parsed as a single option, and we
716 loop around to pick up the -x. */
717 if (optind
!= last_optind
)
718 if (ldemul_parse_args (argc
, argv
))
721 /* getopt_long_only is like getopt_long, but '-' as well as '--'
722 can indicate a long option. */
724 last_optind
= optind
;
725 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
728 optind
= last_optind
;
729 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
732 if (ldemul_handle_option (optc
))
741 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
745 einfo (_("%P%F: use the --help option for usage information\n"));
747 case 1: /* File name. */
748 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
754 /* For HP/UX compatibility. Actually -a shared should mean
755 ``use only shared libraries'' but, then, we don't
756 currently support shared libraries on HP/UX anyhow. */
757 if (strcmp (optarg
, "archive") == 0)
758 config
.dynamic_link
= FALSE
;
759 else if (strcmp (optarg
, "shared") == 0
760 || strcmp (optarg
, "default") == 0)
761 config
.dynamic_link
= TRUE
;
763 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
766 /* FIXME: We just ignore these, but we should handle them. */
767 if (strcmp (optarg
, "definitions") == 0)
769 else if (strcmp (optarg
, "nodefinitions") == 0)
771 else if (strcmp (optarg
, "nosymbolic") == 0)
773 else if (strcmp (optarg
, "pure-text") == 0)
776 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
779 ldfile_add_arch (optarg
);
782 lang_add_target (optarg
);
785 ldfile_open_command_file (optarg
);
786 parser_input
= input_mri_script
;
789 case OPTION_CALL_SHARED
:
790 config
.dynamic_link
= TRUE
;
792 case OPTION_NON_SHARED
:
793 config
.dynamic_link
= FALSE
;
796 command_line
.cref
= TRUE
;
797 link_info
.notice_all
= TRUE
;
800 command_line
.force_common_definition
= TRUE
;
804 lex_redirect (optarg
);
805 parser_input
= input_defsym
;
811 case OPTION_DEMANGLE
:
815 enum demangling_styles style
;
817 style
= cplus_demangle_name_to_style (optarg
);
818 if (style
== unknown_demangling
)
819 einfo (_("%F%P: unknown demangling style `%s'"),
822 cplus_demangle_set_style (style
);
825 case 'I': /* Used on Solaris. */
826 case OPTION_DYNAMIC_LINKER
:
827 command_line
.interpreter
= optarg
;
830 /* Already handled in ldmain.c. */
833 command_line
.endian
= ENDIAN_BIG
;
836 command_line
.endian
= ENDIAN_LITTLE
;
838 case OPTION_EMBEDDED_RELOCS
:
839 command_line
.embedded_relocs
= TRUE
;
841 case OPTION_EXPORT_DYNAMIC
:
842 case 'E': /* HP/UX compatibility. */
843 link_info
.export_dynamic
= TRUE
;
845 case OPTION_NO_EXPORT_DYNAMIC
:
846 link_info
.export_dynamic
= FALSE
;
849 lang_add_entry (optarg
, TRUE
);
852 if (command_line
.auxiliary_filters
== NULL
)
854 command_line
.auxiliary_filters
= (char **)
855 xmalloc (2 * sizeof (char *));
856 command_line
.auxiliary_filters
[0] = optarg
;
857 command_line
.auxiliary_filters
[1] = NULL
;
865 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
867 command_line
.auxiliary_filters
= (char **)
868 xrealloc (command_line
.auxiliary_filters
,
869 (c
+ 2) * sizeof (char *));
870 command_line
.auxiliary_filters
[c
] = optarg
;
871 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
875 command_line
.filter_shlib
= optarg
;
877 case OPTION_FORCE_EXE_SUFFIX
:
878 command_line
.force_exe_suffix
= TRUE
;
883 g_switch_value
= strtoul (optarg
, &end
, 0);
885 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
891 case OPTION_GC_SECTIONS
:
892 link_info
.gc_sections
= TRUE
;
894 case OPTION_PRINT_GC_SECTIONS
:
895 link_info
.print_gc_sections
= TRUE
;
902 ldfile_add_library_path (optarg
, TRUE
);
905 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
908 config
.map_filename
= "-";
911 /* Ignore. Was handled in a pre-parse. */
914 config
.map_filename
= optarg
;
917 config
.text_read_only
= FALSE
;
918 config
.magic_demand_paged
= FALSE
;
919 config
.dynamic_link
= FALSE
;
921 case OPTION_NO_OMAGIC
:
922 config
.text_read_only
= TRUE
;
923 config
.magic_demand_paged
= TRUE
;
924 /* NB/ Does not set dynamic_link to TRUE.
925 Use --call-shared or -Bdynamic for this. */
928 config
.magic_demand_paged
= FALSE
;
929 config
.dynamic_link
= FALSE
;
931 case OPTION_NO_DEFINE_COMMON
:
932 command_line
.inhibit_common_definition
= TRUE
;
934 case OPTION_NO_DEMANGLE
:
937 case OPTION_NO_GC_SECTIONS
:
938 link_info
.gc_sections
= FALSE
;
940 case OPTION_NO_PRINT_GC_SECTIONS
:
941 link_info
.print_gc_sections
= FALSE
;
943 case OPTION_NO_KEEP_MEMORY
:
944 link_info
.keep_memory
= FALSE
;
946 case OPTION_NO_UNDEFINED
:
947 link_info
.unresolved_syms_in_objects
948 = how_to_report_unresolved_symbols
;
950 case OPTION_ALLOW_SHLIB_UNDEFINED
:
951 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
953 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
954 link_info
.unresolved_syms_in_shared_libs
955 = how_to_report_unresolved_symbols
;
957 case OPTION_UNRESOLVED_SYMBOLS
:
958 if (strcmp (optarg
, "ignore-all") == 0)
960 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
961 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
963 else if (strcmp (optarg
, "report-all") == 0)
965 link_info
.unresolved_syms_in_objects
966 = how_to_report_unresolved_symbols
;
967 link_info
.unresolved_syms_in_shared_libs
968 = how_to_report_unresolved_symbols
;
970 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
972 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
973 link_info
.unresolved_syms_in_shared_libs
974 = how_to_report_unresolved_symbols
;
976 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
978 link_info
.unresolved_syms_in_objects
979 = how_to_report_unresolved_symbols
;
980 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
983 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
985 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
986 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
987 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
988 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
989 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
990 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
993 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
994 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
995 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
996 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
997 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
998 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
1000 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
1001 link_info
.allow_multiple_definition
= TRUE
;
1003 case OPTION_NO_UNDEFINED_VERSION
:
1004 link_info
.allow_undefined_version
= FALSE
;
1006 case OPTION_DEFAULT_SYMVER
:
1007 link_info
.create_default_symver
= TRUE
;
1009 case OPTION_DEFAULT_IMPORTED_SYMVER
:
1010 link_info
.default_imported_symver
= TRUE
;
1012 case OPTION_NO_WARN_MISMATCH
:
1013 command_line
.warn_mismatch
= FALSE
;
1015 case OPTION_NO_WARN_SEARCH_MISMATCH
:
1016 command_line
.warn_search_mismatch
= FALSE
;
1018 case OPTION_NOINHIBIT_EXEC
:
1019 force_make_executable
= TRUE
;
1021 case OPTION_NOSTDLIB
:
1022 config
.only_cmd_line_lib_dirs
= TRUE
;
1024 case OPTION_NO_WHOLE_ARCHIVE
:
1025 whole_archive
= FALSE
;
1028 /* FIXME "-O<non-digits> <value>" used to set the address of
1029 section <non-digits>. Was this for compatibility with
1030 something, or can we create a new option to do that
1031 (with a syntax similar to -defsym)?
1032 getopt can't handle two args to an option without kludges. */
1034 /* Enable optimizations of output files. */
1035 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
1038 lang_add_output (optarg
, 0);
1040 case OPTION_OFORMAT
:
1041 lang_add_output_format (optarg
, NULL
, NULL
, 0);
1044 link_info
.emitrelocations
= TRUE
;
1048 if (optind
== last_optind
)
1049 /* This can happen if the user put "-rpath,a" on the command
1050 line. (Or something similar. The comma is important).
1051 Getopt becomes confused and thinks that this is a -r option
1052 but it cannot parse the text after the -r so it refuses to
1053 increment the optind counter. Detect this case and issue
1054 an error message here. We cannot just make this a warning,
1055 increment optind, and continue because getopt is too confused
1056 and will seg-fault the next time around. */
1057 einfo(_("%P%F: bad -rpath option\n"));
1059 link_info
.relocatable
= TRUE
;
1060 config
.build_constructors
= FALSE
;
1061 config
.magic_demand_paged
= FALSE
;
1062 config
.text_read_only
= FALSE
;
1063 config
.dynamic_link
= FALSE
;
1066 /* The GNU linker traditionally uses -R to mean to include
1067 only the symbols from a file. The Solaris linker uses -R
1068 to set the path used by the runtime linker to find
1069 libraries. This is the GNU linker -rpath argument. We
1070 try to support both simultaneously by checking the file
1071 named. If it is a directory, rather than a regular file,
1072 we assume -rpath was meant. */
1076 if (stat (optarg
, &s
) >= 0
1077 && ! S_ISDIR (s
.st_mode
))
1079 lang_add_input_file (optarg
,
1080 lang_input_file_is_symbols_only_enum
,
1087 if (command_line
.rpath
== NULL
)
1088 command_line
.rpath
= xstrdup (optarg
);
1091 size_t rpath_len
= strlen (command_line
.rpath
);
1092 size_t optarg_len
= strlen (optarg
);
1094 char *cp
= command_line
.rpath
;
1096 /* First see whether OPTARG is already in the path. */
1099 if (strncmp (optarg
, cp
, optarg_len
) == 0
1100 && (cp
[optarg_len
] == 0
1101 || cp
[optarg_len
] == config
.rpath_separator
))
1105 /* Not yet found. */
1106 cp
= strchr (cp
, config
.rpath_separator
);
1114 buf
= (char *) xmalloc (rpath_len
+ optarg_len
+ 2);
1115 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1116 config
.rpath_separator
, optarg
);
1117 free (command_line
.rpath
);
1118 command_line
.rpath
= buf
;
1122 case OPTION_RPATH_LINK
:
1123 if (command_line
.rpath_link
== NULL
)
1124 command_line
.rpath_link
= xstrdup (optarg
);
1129 buf
= (char *) xmalloc (strlen (command_line
.rpath_link
)
1132 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1133 config
.rpath_separator
, optarg
);
1134 free (command_line
.rpath_link
);
1135 command_line
.rpath_link
= buf
;
1138 case OPTION_NO_RELAX
:
1144 case OPTION_RETAIN_SYMBOLS_FILE
:
1145 add_keepsyms_file (optarg
);
1148 link_info
.strip
= strip_debugger
;
1151 link_info
.strip
= strip_all
;
1153 case OPTION_STRIP_DISCARDED
:
1154 link_info
.strip_discarded
= TRUE
;
1156 case OPTION_NO_STRIP_DISCARDED
:
1157 link_info
.strip_discarded
= FALSE
;
1160 if (config
.has_shared
)
1162 link_info
.shared
= TRUE
;
1163 /* When creating a shared library, the default
1164 behaviour is to ignore any unresolved references. */
1165 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1166 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1167 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1168 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1171 einfo (_("%P%F: -shared not supported\n"));
1174 if (config
.has_shared
)
1176 link_info
.shared
= TRUE
;
1177 link_info
.pie
= TRUE
;
1180 einfo (_("%P%F: -pie not supported\n"));
1182 case 'h': /* Used on Solaris. */
1184 command_line
.soname
= optarg
;
1186 case OPTION_SORT_COMMON
:
1188 || strcmp (optarg
, N_("descending")) == 0)
1189 config
.sort_common
= sort_descending
;
1190 else if (strcmp (optarg
, N_("ascending")) == 0)
1191 config
.sort_common
= sort_ascending
;
1193 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1196 case OPTION_SORT_SECTION
:
1197 if (strcmp (optarg
, N_("name")) == 0)
1198 sort_section
= by_name
;
1199 else if (strcmp (optarg
, N_("alignment")) == 0)
1200 sort_section
= by_alignment
;
1202 einfo (_("%P%F: invalid section sorting option: %s\n"),
1206 config
.stats
= TRUE
;
1208 case OPTION_SYMBOLIC
:
1209 command_line
.symbolic
= symbolic
;
1211 case OPTION_SYMBOLIC_FUNCTIONS
:
1212 command_line
.symbolic
= symbolic_functions
;
1218 previous_script_handle
= saved_script_handle
;
1219 ldfile_open_command_file (optarg
);
1220 parser_input
= input_script
;
1222 previous_script_handle
= NULL
;
1224 case OPTION_DEFAULT_SCRIPT
:
1225 command_line
.default_script
= optarg
;
1227 case OPTION_SECTION_START
:
1233 /* Check for <something>=<somthing>... */
1234 optarg2
= strchr (optarg
, '=');
1235 if (optarg2
== NULL
)
1236 einfo (_("%P%F: invalid argument to option"
1237 " \"--section-start\"\n"));
1241 /* So far so good. Are all the args present? */
1242 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1243 einfo (_("%P%F: missing argument(s) to option"
1244 " \"--section-start\"\n"));
1246 /* We must copy the section name as set_section_start
1247 doesn't do it for us. */
1248 len
= optarg2
- optarg
;
1249 sec_name
= (char *) xmalloc (len
);
1250 memcpy (sec_name
, optarg
, len
- 1);
1251 sec_name
[len
- 1] = 0;
1253 /* Then set it... */
1254 set_section_start (sec_name
, optarg2
);
1257 case OPTION_TARGET_HELP
:
1258 /* Mention any target specific options. */
1259 ldemul_list_emulation_options (stdout
);
1262 set_segment_start (".bss", optarg
);
1265 set_segment_start (".data", optarg
);
1268 set_segment_start (".text", optarg
);
1270 case OPTION_TTEXT_SEGMENT
:
1271 set_segment_start (".text-segment", optarg
);
1273 case OPTION_TRADITIONAL_FORMAT
:
1274 link_info
.traditional_format
= TRUE
;
1276 case OPTION_TASK_LINK
:
1277 link_info
.task_link
= TRUE
;
1278 /* Fall through - do an implied -r option. */
1280 link_info
.relocatable
= TRUE
;
1281 config
.build_constructors
= TRUE
;
1282 config
.magic_demand_paged
= FALSE
;
1283 config
.text_read_only
= FALSE
;
1284 config
.dynamic_link
= FALSE
;
1287 ldlang_add_undef (optarg
);
1291 lang_add_unique (optarg
);
1293 config
.unique_orphan_sections
= TRUE
;
1295 case OPTION_VERBOSE
:
1297 version_printed
= TRUE
;
1298 trace_file_tries
= TRUE
;
1299 overflow_cutoff_limit
= -2;
1303 version_printed
= TRUE
;
1307 version_printed
= TRUE
;
1309 case OPTION_VERSION
:
1313 case OPTION_VERSION_SCRIPT
:
1314 /* This option indicates a small script that only specifies
1315 version information. Read it, but don't assume that
1316 we've seen a linker script. */
1318 FILE *hold_script_handle
;
1320 hold_script_handle
= saved_script_handle
;
1321 ldfile_open_command_file (optarg
);
1322 saved_script_handle
= hold_script_handle
;
1323 parser_input
= input_version_script
;
1327 case OPTION_VERSION_EXPORTS_SECTION
:
1328 /* This option records a version symbol to be applied to the
1329 symbols listed for export to be found in the object files
1330 .exports sections. */
1331 command_line
.version_exports_section
= optarg
;
1333 case OPTION_DYNAMIC_LIST_DATA
:
1334 command_line
.dynamic_list
= dynamic_list_data
;
1335 if (command_line
.symbolic
== symbolic
)
1336 command_line
.symbolic
= symbolic_unset
;
1338 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1339 lang_append_dynamic_list_cpp_typeinfo ();
1340 if (command_line
.dynamic_list
!= dynamic_list_data
)
1341 command_line
.dynamic_list
= dynamic_list
;
1342 if (command_line
.symbolic
== symbolic
)
1343 command_line
.symbolic
= symbolic_unset
;
1345 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1346 lang_append_dynamic_list_cpp_new ();
1347 if (command_line
.dynamic_list
!= dynamic_list_data
)
1348 command_line
.dynamic_list
= dynamic_list
;
1349 if (command_line
.symbolic
== symbolic
)
1350 command_line
.symbolic
= symbolic_unset
;
1352 case OPTION_DYNAMIC_LIST
:
1353 /* This option indicates a small script that only specifies
1354 a dynamic list. Read it, but don't assume that we've
1355 seen a linker script. */
1357 FILE *hold_script_handle
;
1359 hold_script_handle
= saved_script_handle
;
1360 ldfile_open_command_file (optarg
);
1361 saved_script_handle
= hold_script_handle
;
1362 parser_input
= input_dynamic_list
;
1365 if (command_line
.dynamic_list
!= dynamic_list_data
)
1366 command_line
.dynamic_list
= dynamic_list
;
1367 if (command_line
.symbolic
== symbolic
)
1368 command_line
.symbolic
= symbolic_unset
;
1370 case OPTION_WARN_COMMON
:
1371 config
.warn_common
= TRUE
;
1373 case OPTION_WARN_CONSTRUCTORS
:
1374 config
.warn_constructors
= TRUE
;
1376 case OPTION_WARN_FATAL
:
1377 config
.fatal_warnings
= TRUE
;
1379 case OPTION_NO_WARN_FATAL
:
1380 config
.fatal_warnings
= FALSE
;
1382 case OPTION_WARN_MULTIPLE_GP
:
1383 config
.warn_multiple_gp
= TRUE
;
1385 case OPTION_WARN_ONCE
:
1386 config
.warn_once
= TRUE
;
1388 case OPTION_WARN_SECTION_ALIGN
:
1389 config
.warn_section_align
= TRUE
;
1391 case OPTION_WARN_SHARED_TEXTREL
:
1392 link_info
.warn_shared_textrel
= TRUE
;
1394 case OPTION_WARN_ALTERNATE_EM
:
1395 link_info
.warn_alternate_em
= TRUE
;
1397 case OPTION_WHOLE_ARCHIVE
:
1398 whole_archive
= TRUE
;
1400 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
:
1401 add_DT_NEEDED_for_dynamic
= TRUE
;
1403 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
:
1404 add_DT_NEEDED_for_dynamic
= FALSE
;
1406 case OPTION_ADD_DT_NEEDED_FOR_REGULAR
:
1407 add_DT_NEEDED_for_regular
= TRUE
;
1409 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
:
1410 add_DT_NEEDED_for_regular
= FALSE
;
1415 case OPTION_DISCARD_NONE
:
1416 link_info
.discard
= discard_none
;
1419 link_info
.discard
= discard_l
;
1422 link_info
.discard
= discard_all
;
1425 if (CONST_STRNEQ (optarg
, "P,"))
1427 if (default_dirlist
!= NULL
)
1428 free (default_dirlist
);
1429 default_dirlist
= xstrdup (optarg
);
1434 case OPTION_SPARE_DYNAMIC_TAGS
:
1435 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1437 case OPTION_SPLIT_BY_RELOC
:
1439 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1441 config
.split_by_reloc
= 32768;
1443 case OPTION_SPLIT_BY_FILE
:
1445 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1447 config
.split_by_file
= 1;
1449 case OPTION_CHECK_SECTIONS
:
1450 command_line
.check_section_addresses
= 1;
1452 case OPTION_NO_CHECK_SECTIONS
:
1453 command_line
.check_section_addresses
= 0;
1455 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1456 command_line
.accept_unknown_input_arch
= TRUE
;
1458 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1459 command_line
.accept_unknown_input_arch
= FALSE
;
1462 lang_enter_group ();
1467 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1469 lang_leave_group ();
1474 link_info
.init_function
= optarg
;
1478 link_info
.fini_function
= optarg
;
1481 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1482 link_info
.reduce_memory_overheads
= TRUE
;
1483 if (config
.hash_table_size
== 0)
1484 config
.hash_table_size
= 1021;
1487 case OPTION_HASH_SIZE
:
1489 bfd_size_type new_size
;
1491 new_size
= strtoul (optarg
, NULL
, 0);
1493 config
.hash_table_size
= new_size
;
1495 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1503 lang_leave_group ();
1507 if (default_dirlist
!= NULL
)
1509 set_default_dirlist (default_dirlist
);
1510 free (default_dirlist
);
1513 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1514 /* FIXME: Should we allow emulations a chance to set this ? */
1515 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1517 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1518 /* FIXME: Should we allow emulations a chance to set this ? */
1519 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1522 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1523 library search path. */
1526 set_default_dirlist (char *dirlist_ptr
)
1532 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1535 if (*dirlist_ptr
!= '\0')
1536 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1539 dirlist_ptr
= p
+ 1;
1544 set_section_start (char *sect
, char *valstr
)
1547 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1549 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1550 lang_section_start (sect
, exp_intop (val
), NULL
);
1554 set_segment_start (const char *section
, char *valstr
)
1560 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1562 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1563 /* If we already have an entry for this segment, update the existing
1566 for (seg
= segments
; seg
; seg
= seg
->next
)
1567 if (strcmp (seg
->name
, name
) == 0)
1572 /* There was no existing value so we must create a new segment
1574 seg
= (segment_type
*) stat_alloc (sizeof (*seg
));
1578 /* Add it to the linked list of segments. */
1579 seg
->next
= segments
;
1581 /* Historically, -Ttext and friends set the base address of a
1582 particular section. For backwards compatibility, we still do
1583 that. If a SEGMENT_START directive is seen, the section address
1584 assignment will be disabled. */
1585 lang_section_start (section
, exp_intop (val
), seg
);
1589 /* Print help messages for the options. */
1595 const char **targets
, **pp
;
1598 printf (_("Usage: %s [options] file...\n"), program_name
);
1600 printf (_("Options:\n"));
1601 for (i
= 0; i
< OPTION_COUNT
; i
++)
1603 if (ld_options
[i
].doc
!= NULL
)
1616 if (ld_options
[j
].shortopt
!= '\0'
1617 && ld_options
[j
].control
!= NO_HELP
)
1619 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1620 len
+= (comma
? 2 : 0) + 2;
1621 if (ld_options
[j
].arg
!= NULL
)
1623 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1628 printf ("%s", _(ld_options
[j
].arg
));
1629 len
+= strlen (_(ld_options
[j
].arg
));
1635 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1640 if (ld_options
[j
].opt
.name
!= NULL
1641 && ld_options
[j
].control
!= NO_HELP
)
1644 (ld_options
[j
].control
== TWO_DASHES
1645 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1649 two_dashes
? "-" : "",
1650 ld_options
[j
].opt
.name
);
1651 len
+= ((comma
? 2 : 0)
1653 + (two_dashes
? 1 : 0)
1654 + strlen (ld_options
[j
].opt
.name
));
1655 if (ld_options
[j
].arg
!= NULL
)
1657 printf (" %s", _(ld_options
[j
].arg
));
1658 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1664 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1672 for (; len
< 30; len
++)
1675 printf ("%s\n", _(ld_options
[i
].doc
));
1678 printf (_(" @FILE"));
1679 for (len
= strlen (" @FILE"); len
< 30; len
++)
1681 printf (_("Read options from FILE\n"));
1683 /* Note: Various tools (such as libtool) depend upon the
1684 format of the listings below - do not change them. */
1685 /* xgettext:c-format */
1686 printf (_("%s: supported targets:"), program_name
);
1687 targets
= bfd_target_list ();
1688 for (pp
= targets
; *pp
!= NULL
; pp
++)
1689 printf (" %s", *pp
);
1693 /* xgettext:c-format */
1694 printf (_("%s: supported emulations: "), program_name
);
1695 ldemul_list_emulations (stdout
);
1698 /* xgettext:c-format */
1699 printf (_("%s: emulation specific options:\n"), program_name
);
1700 ldemul_list_emulation_options (stdout
);
1703 if (REPORT_BUGS_TO
[0])
1704 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);