1 /* Parse options for the GNU linker.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
6 This file is part of the GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
26 #include "libiberty.h"
29 #include "safe-ctype.h"
44 #ifndef PATH_SEPARATOR
45 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
46 #define PATH_SEPARATOR ';'
48 #define PATH_SEPARATOR ':'
52 /* Somewhere above, sys/stat.h got included . . . . */
53 #if !defined(S_ISDIR) && defined(S_IFDIR)
54 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
57 static void set_default_dirlist (char *);
58 static void set_section_start (char *, char *);
59 static void set_segment_start (const char *, char *);
60 static void help (void);
62 /* Non-zero if we are processing a --defsym from the command line. */
63 int parsing_defsym
= 0;
65 /* Codes used for the long options with no short synonyms. 150 isn't
66 special; it's just an arbitrary non-ASCII char value. */
74 OPTION_DYNAMIC_LINKER
,
78 OPTION_EMBEDDED_RELOCS
,
79 OPTION_EXPORT_DYNAMIC
,
84 OPTION_NO_KEEP_MEMORY
,
85 OPTION_NO_WARN_MISMATCH
,
86 OPTION_NO_WARN_SEARCH_MISMATCH
,
87 OPTION_NOINHIBIT_EXEC
,
89 OPTION_NO_WHOLE_ARCHIVE
,
92 OPTION_RETAIN_SYMBOLS_FILE
,
101 OPTION_SYMBOLIC_FUNCTIONS
,
106 OPTION_TRADITIONAL_FORMAT
,
110 OPTION_VERSION_SCRIPT
,
111 OPTION_VERSION_EXPORTS_SECTION
,
113 OPTION_DYNAMIC_LIST_CPP_NEW
,
114 OPTION_DYNAMIC_LIST_CPP_TYPEINFO
,
115 OPTION_DYNAMIC_LIST_DATA
,
117 OPTION_WARN_CONSTRUCTORS
,
119 OPTION_NO_WARN_FATAL
,
120 OPTION_WARN_MULTIPLE_GP
,
122 OPTION_WARN_SECTION_ALIGN
,
123 OPTION_SPLIT_BY_RELOC
,
124 OPTION_SPLIT_BY_FILE
,
125 OPTION_WHOLE_ARCHIVE
,
127 OPTION_NO_ADD_NEEDED
,
131 OPTION_FORCE_EXE_SUFFIX
,
133 OPTION_NO_GC_SECTIONS
,
134 OPTION_PRINT_GC_SECTIONS
,
135 OPTION_NO_PRINT_GC_SECTIONS
,
137 OPTION_CHECK_SECTIONS
,
138 OPTION_NO_CHECK_SECTIONS
,
142 OPTION_SECTION_START
,
145 OPTION_ALLOW_SHLIB_UNDEFINED
,
146 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
147 OPTION_ALLOW_MULTIPLE_DEFINITION
,
148 OPTION_NO_UNDEFINED_VERSION
,
149 OPTION_DEFAULT_SYMVER
,
150 OPTION_DEFAULT_IMPORTED_SYMVER
,
152 OPTION_SPARE_DYNAMIC_TAGS
,
153 OPTION_NO_DEFINE_COMMON
,
156 OPTION_STRIP_DISCARDED
,
157 OPTION_NO_STRIP_DISCARDED
,
158 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
159 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
161 OPTION_UNRESOLVED_SYMBOLS
,
162 OPTION_WARN_UNRESOLVED_SYMBOLS
,
163 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
164 OPTION_WARN_SHARED_TEXTREL
,
165 OPTION_REDUCE_MEMORY_OVERHEADS
,
166 OPTION_DEFAULT_SCRIPT
,
167 OPTION_IGNORE_UNRESOLVED_SYMBOL
170 /* The long options. This structure is used for both the option
171 parsing and the help text. */
175 /* The long option information. */
177 /* The short option with the same meaning ('\0' if none). */
179 /* The name of the argument (NULL if none). */
181 /* The documentation string. If this is NULL, this is a synonym for
182 the previous option. */
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. */
204 static const struct ld_option ld_options
[] =
206 { {NULL
, required_argument
, NULL
, '\0'},
207 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
209 { {"architecture", required_argument
, NULL
, 'A'},
210 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
211 { {"format", required_argument
, NULL
, 'b'},
212 'b', N_("TARGET"), N_("Specify target for following input files"),
214 { {"mri-script", required_argument
, NULL
, 'c'},
215 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
216 { {"dc", no_argument
, NULL
, 'd'},
217 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
218 { {"dp", no_argument
, NULL
, 'd'},
219 '\0', NULL
, NULL
, ONE_DASH
},
220 { {"entry", required_argument
, NULL
, 'e'},
221 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
222 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
223 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
224 { {"EB", no_argument
, NULL
, OPTION_EB
},
225 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
226 { {"EL", no_argument
, NULL
, OPTION_EL
},
227 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
228 { {"auxiliary", required_argument
, NULL
, 'f'},
229 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
231 { {"filter", required_argument
, NULL
, 'F'},
232 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
234 { {NULL
, no_argument
, NULL
, '\0'},
235 'g', NULL
, N_("Ignored"), ONE_DASH
},
236 { {"gpsize", required_argument
, NULL
, 'G'},
237 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
239 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
240 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
241 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
242 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
244 { {"library", required_argument
, NULL
, 'l'},
245 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
246 { {"library-path", required_argument
, NULL
, 'L'},
247 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
249 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
250 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
251 { {NULL
, required_argument
, NULL
, '\0'},
252 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
253 { {"print-map", no_argument
, NULL
, 'M'},
254 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
255 { {"nmagic", no_argument
, NULL
, 'n'},
256 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
257 { {"omagic", no_argument
, NULL
, 'N'},
258 'N', NULL
, N_("Do not page align data, do not make text readonly"),
259 EXACTLY_TWO_DASHES
},
260 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
261 '\0', NULL
, N_("Page align data, make text readonly"),
262 EXACTLY_TWO_DASHES
},
263 { {"output", required_argument
, NULL
, 'o'},
264 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
265 { {NULL
, required_argument
, NULL
, '\0'},
266 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
267 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
268 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
269 { {"emit-relocs", no_argument
, NULL
, 'q'},
270 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
271 { {"relocatable", no_argument
, NULL
, 'r'},
272 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
273 { {NULL
, no_argument
, NULL
, '\0'},
274 'i', NULL
, NULL
, ONE_DASH
},
275 { {"just-symbols", required_argument
, NULL
, 'R'},
276 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
278 { {"strip-all", no_argument
, NULL
, 's'},
279 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
280 { {"strip-debug", no_argument
, NULL
, 'S'},
281 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
282 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
283 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
284 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
285 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
286 { {"trace", no_argument
, NULL
, 't'},
287 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
288 { {"script", required_argument
, NULL
, 'T'},
289 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
290 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
291 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
292 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
293 '\0', NULL
, NULL
, ONE_DASH
},
294 { {"undefined", required_argument
, NULL
, 'u'},
295 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
297 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
298 '\0', N_("[=SECTION]"),
299 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
300 { {"Ur", no_argument
, NULL
, OPTION_UR
},
301 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
302 { {"version", no_argument
, NULL
, OPTION_VERSION
},
303 'v', NULL
, N_("Print version information"), TWO_DASHES
},
304 { {NULL
, no_argument
, NULL
, '\0'},
305 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
306 { {"discard-all", no_argument
, NULL
, 'x'},
307 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
308 { {"discard-locals", no_argument
, NULL
, 'X'},
309 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
310 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
311 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
312 { {"trace-symbol", required_argument
, NULL
, 'y'},
313 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
314 { {NULL
, required_argument
, NULL
, '\0'},
315 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
317 { {"start-group", no_argument
, NULL
, '('},
318 '(', NULL
, N_("Start a group"), TWO_DASHES
},
319 { {"end-group", no_argument
, NULL
, ')'},
320 ')', NULL
, N_("End a group"), TWO_DASHES
},
321 { {"accept-unknown-input-arch", no_argument
, NULL
,
322 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
324 N_("Accept input files whose architecture cannot be determined"),
326 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
327 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
328 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
330 { {"add-needed", no_argument
, NULL
, OPTION_ADD_NEEDED
},
331 '\0', NULL
, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
332 " following dynamic libs"),
334 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_NEEDED
},
335 '\0', NULL
, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
336 " in following dynamic libs"),
338 { {"as-needed", no_argument
, NULL
, OPTION_AS_NEEDED
},
339 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
341 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_AS_NEEDED
},
342 '\0', NULL
, N_("Always set DT_NEEDED for following dynamic libs"),
344 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
345 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
346 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
347 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
348 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
349 '\0', NULL
, NULL
, ONE_DASH
},
350 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
351 '\0', NULL
, NULL
, ONE_DASH
},
352 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
353 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
354 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
355 '\0', NULL
, NULL
, ONE_DASH
},
356 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
357 '\0', NULL
, NULL
, ONE_DASH
},
358 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
359 '\0', NULL
, NULL
, ONE_DASH
},
360 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
361 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
362 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
363 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
364 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
365 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
367 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
368 '\0', NULL
, N_("Do not check section addresses for overlaps"),
370 { {"cref", no_argument
, NULL
, OPTION_CREF
},
371 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
372 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
373 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
374 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
375 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
377 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
378 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
379 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
380 '\0', NULL
, N_("Treat warnings as errors"),
382 { {"no-fatal-warnings", no_argument
, NULL
, OPTION_NO_WARN_FATAL
},
383 '\0', NULL
, N_("Do not treat warnings as errors (default)"),
385 { {"fini", required_argument
, NULL
, OPTION_FINI
},
386 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
387 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
388 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
389 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
390 '\0', NULL
, N_("Remove unused sections (on some targets)"),
392 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
393 '\0', NULL
, N_("Don't remove unused sections (default)"),
395 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
396 '\0', NULL
, N_("List removed unused sections on stderr"),
398 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
399 '\0', NULL
, N_("Do not list removed unused sections"),
401 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
402 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
404 { {"help", no_argument
, NULL
, OPTION_HELP
},
405 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
406 { {"init", required_argument
, NULL
, OPTION_INIT
},
407 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
408 { {"Map", required_argument
, NULL
, OPTION_MAP
},
409 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
410 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
411 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
412 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
413 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
414 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
415 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
416 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
417 '\0', NULL
, N_("Do not allow unresolved references in object files"),
419 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
420 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
422 { {"no-allow-shlib-undefined", no_argument
, NULL
,
423 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
424 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
426 { {"allow-multiple-definition", no_argument
, NULL
,
427 OPTION_ALLOW_MULTIPLE_DEFINITION
},
428 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
429 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
430 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
431 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
432 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
433 { {"default-imported-symver", no_argument
, NULL
,
434 OPTION_DEFAULT_IMPORTED_SYMVER
},
435 '\0', NULL
, N_("Create default symbol version for imported symbols"),
437 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
438 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
439 { {"no-warn-search-mismatch", no_argument
, NULL
,
440 OPTION_NO_WARN_SEARCH_MISMATCH
},
441 '\0', NULL
, N_("Don't warn on finding an incompatible library"),
443 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
444 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
445 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
446 '\0', NULL
, N_("Create an output file even if errors occur"),
448 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
449 '\0', NULL
, NULL
, NO_HELP
},
450 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
451 '\0', NULL
, N_("Only use library directories specified on\n"
452 " the command line"),
454 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
455 '\0', N_("TARGET"), N_("Specify target of output file"),
456 EXACTLY_TWO_DASHES
},
457 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
458 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
459 { {"reduce-memory-overheads", no_argument
, NULL
,
460 OPTION_REDUCE_MEMORY_OVERHEADS
},
461 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
463 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
464 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
465 { {"retain-symbols-file", required_argument
, NULL
,
466 OPTION_RETAIN_SYMBOLS_FILE
},
467 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
468 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
469 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
470 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
471 '\0', N_("PATH"), N_("Set link time shared library search path"),
473 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
474 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
475 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD, NetBSD. */
476 '\0', NULL
, NULL
, ONE_DASH
},
477 { {"pie", no_argument
, NULL
, OPTION_PIE
},
478 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
479 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
480 '\0', NULL
, NULL
, TWO_DASHES
},
481 { {"sort-common", optional_argument
, NULL
, OPTION_SORT_COMMON
},
482 '\0', N_("[=ascending|descending]"),
483 N_("Sort common symbols by alignment [in specified order]"),
485 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
486 '\0', NULL
, NULL
, NO_HELP
},
487 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
488 '\0', N_("name|alignment"),
489 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
490 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
491 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
493 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
494 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
496 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
497 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
499 { {"stats", no_argument
, NULL
, OPTION_STATS
},
500 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
501 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
502 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
503 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
504 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
505 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
506 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
507 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
508 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
510 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
511 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
512 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
513 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
514 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
515 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
516 { {"unresolved-symbols=<method>", required_argument
, NULL
,
517 OPTION_UNRESOLVED_SYMBOLS
},
518 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
519 " ignore-all, report-all, ignore-in-object-files,\n"
520 " ignore-in-shared-libs"),
522 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
523 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
524 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
525 '\0', NULL
, NULL
, NO_HELP
},
526 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
527 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
528 { {"version-exports-section", required_argument
, NULL
,
529 OPTION_VERSION_EXPORTS_SECTION
},
530 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
531 " SYMBOL as the version."),
533 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
534 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
535 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
536 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
537 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
538 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
539 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
540 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
541 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
542 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
543 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
544 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
546 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
547 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
548 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
549 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
550 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
551 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
553 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
554 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
556 { {"warn-unresolved-symbols", no_argument
, NULL
,
557 OPTION_WARN_UNRESOLVED_SYMBOLS
},
558 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
559 { {"error-unresolved-symbols", no_argument
, NULL
,
560 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
561 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
562 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
563 '\0', NULL
, N_("Include all objects from following archives"),
565 { {"Bforcearchive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
566 '\0', NULL
, NULL
, TWO_DASHES
}, /* NetBSD. */
567 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
568 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
569 { {"ignore-unresolved-symbol", required_argument
, NULL
,
570 OPTION_IGNORE_UNRESOLVED_SYMBOL
},
572 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES
},
575 #define OPTION_COUNT ARRAY_SIZE (ld_options)
578 parse_args (unsigned argc
, char **argv
)
583 char *default_dirlist
= NULL
;
585 struct option
*longopts
;
586 struct option
*really_longopts
;
588 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
590 shortopts
= xmalloc (OPTION_COUNT
* 3 + 2);
591 longopts
= xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
592 really_longopts
= xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
594 /* Starting the short option string with '-' is for programs that
595 expect options and other ARGV-elements in any order and that care about
596 the ordering of the two. We describe each non-option ARGV-element
597 as if it were the argument of an option with character code 1. */
602 for (i
= 0; i
< OPTION_COUNT
; i
++)
604 if (ld_options
[i
].shortopt
!= '\0')
606 shortopts
[is
] = ld_options
[i
].shortopt
;
608 if (ld_options
[i
].opt
.has_arg
== required_argument
609 || ld_options
[i
].opt
.has_arg
== optional_argument
)
613 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
620 if (ld_options
[i
].opt
.name
!= NULL
)
622 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
624 really_longopts
[irl
] = ld_options
[i
].opt
;
629 longopts
[il
] = ld_options
[i
].opt
;
634 shortopts
[is
] = '\0';
635 longopts
[il
].name
= NULL
;
636 really_longopts
[irl
].name
= NULL
;
638 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
640 /* The -G option is ambiguous on different platforms. Sometimes it
641 specifies the largest data size to put into the small data
642 section. Sometimes it is equivalent to --shared. Unfortunately,
643 the first form takes an argument, while the second does not.
645 We need to permit the --shared form because on some platforms,
646 such as Solaris, gcc -shared will pass -G to the linker.
648 To permit either usage, we look through the argument list. If we
649 find -G not followed by a number, we change it into --shared.
650 This will work for most normal cases. */
651 for (i
= 1; i
< argc
; i
++)
652 if (strcmp (argv
[i
], "-G") == 0
654 || ! ISDIGIT (argv
[i
+ 1][0])))
655 argv
[i
] = (char *) "--shared";
657 /* Because we permit long options to start with a single dash, and
658 we have a --library option, and the -l option is conventionally
659 used with an immediately following argument, we can have bad
660 results if somebody tries to use -l with a library whose name
661 happens to start with "ibrary", as in -li. We avoid problems by
662 simply turning -l into --library. This means that users will
663 have to use two dashes in order to use --library, which is OK
664 since that's how it is documented.
666 FIXME: It's possible that this problem can arise for other short
667 options as well, although the user does always have the recourse
668 of adding a space between the option and the argument. */
669 for (i
= 1; i
< argc
; i
++)
671 if (argv
[i
][0] == '-'
673 && argv
[i
][2] != '\0')
677 n
= xmalloc (strlen (argv
[i
]) + 20);
678 sprintf (n
, "--library=%s", argv
[i
] + 2);
689 /* Using last_optind lets us avoid calling ldemul_parse_args
690 multiple times on a single option, which would lead to
691 confusion in the internal static variables maintained by
692 getopt. This could otherwise happen for an argument like
693 -nx, in which the -n is parsed as a single option, and we
694 loop around to pick up the -x. */
695 if (optind
!= last_optind
)
696 if (ldemul_parse_args (argc
, argv
))
699 /* getopt_long_only is like getopt_long, but '-' as well as '--'
700 can indicate a long option. */
702 last_optind
= optind
;
703 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
706 optind
= last_optind
;
707 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
710 if (ldemul_handle_option (optc
))
719 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
723 einfo (_("%P%F: use the --help option for usage information\n"));
725 case 1: /* File name. */
726 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
732 /* For HP/UX compatibility. Actually -a shared should mean
733 ``use only shared libraries'' but, then, we don't
734 currently support shared libraries on HP/UX anyhow. */
735 if (strcmp (optarg
, "archive") == 0)
736 config
.dynamic_link
= FALSE
;
737 else if (strcmp (optarg
, "shared") == 0
738 || strcmp (optarg
, "default") == 0)
739 config
.dynamic_link
= TRUE
;
741 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
744 /* FIXME: We just ignore these, but we should handle them. */
745 if (strcmp (optarg
, "definitions") == 0)
747 else if (strcmp (optarg
, "nodefinitions") == 0)
749 else if (strcmp (optarg
, "nosymbolic") == 0)
751 else if (strcmp (optarg
, "pure-text") == 0)
754 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
757 ldfile_add_arch (optarg
);
760 lang_add_target (optarg
);
763 ldfile_open_command_file (optarg
);
764 parser_input
= input_mri_script
;
767 case OPTION_CALL_SHARED
:
768 config
.dynamic_link
= TRUE
;
770 case OPTION_NON_SHARED
:
771 config
.dynamic_link
= FALSE
;
774 command_line
.cref
= TRUE
;
775 link_info
.notice_all
= TRUE
;
778 command_line
.force_common_definition
= TRUE
;
782 lex_redirect (optarg
);
783 parser_input
= input_defsym
;
789 case OPTION_DEMANGLE
:
793 enum demangling_styles style
;
795 style
= cplus_demangle_name_to_style (optarg
);
796 if (style
== unknown_demangling
)
797 einfo (_("%F%P: unknown demangling style `%s'"),
800 cplus_demangle_set_style (style
);
803 case 'I': /* Used on Solaris. */
804 case OPTION_DYNAMIC_LINKER
:
805 command_line
.interpreter
= optarg
;
808 /* Already handled in ldmain.c. */
811 command_line
.endian
= ENDIAN_BIG
;
814 command_line
.endian
= ENDIAN_LITTLE
;
816 case OPTION_EMBEDDED_RELOCS
:
817 command_line
.embedded_relocs
= TRUE
;
819 case OPTION_EXPORT_DYNAMIC
:
820 case 'E': /* HP/UX compatibility. */
821 link_info
.export_dynamic
= TRUE
;
824 lang_add_entry (optarg
, TRUE
);
827 if (command_line
.auxiliary_filters
== NULL
)
829 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
830 command_line
.auxiliary_filters
[0] = optarg
;
831 command_line
.auxiliary_filters
[1] = NULL
;
839 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
841 command_line
.auxiliary_filters
842 = xrealloc (command_line
.auxiliary_filters
,
843 (c
+ 2) * sizeof (char *));
844 command_line
.auxiliary_filters
[c
] = optarg
;
845 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
849 command_line
.filter_shlib
= optarg
;
851 case OPTION_FORCE_EXE_SUFFIX
:
852 command_line
.force_exe_suffix
= TRUE
;
857 g_switch_value
= strtoul (optarg
, &end
, 0);
859 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
865 case OPTION_GC_SECTIONS
:
866 link_info
.gc_sections
= TRUE
;
868 case OPTION_PRINT_GC_SECTIONS
:
869 link_info
.print_gc_sections
= TRUE
;
876 ldfile_add_library_path (optarg
, TRUE
);
879 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
882 config
.map_filename
= "-";
885 /* Ignore. Was handled in a pre-parse. */
888 config
.map_filename
= optarg
;
891 config
.text_read_only
= FALSE
;
892 config
.magic_demand_paged
= FALSE
;
893 config
.dynamic_link
= FALSE
;
895 case OPTION_NO_OMAGIC
:
896 config
.text_read_only
= TRUE
;
897 config
.magic_demand_paged
= TRUE
;
898 /* NB/ Does not set dynamic_link to TRUE.
899 Use --call-shared or -Bdynamic for this. */
902 config
.magic_demand_paged
= FALSE
;
903 config
.dynamic_link
= FALSE
;
905 case OPTION_NO_DEFINE_COMMON
:
906 command_line
.inhibit_common_definition
= TRUE
;
908 case OPTION_NO_DEMANGLE
:
911 case OPTION_NO_GC_SECTIONS
:
912 link_info
.gc_sections
= FALSE
;
914 case OPTION_NO_PRINT_GC_SECTIONS
:
915 link_info
.print_gc_sections
= FALSE
;
917 case OPTION_NO_KEEP_MEMORY
:
918 link_info
.keep_memory
= FALSE
;
920 case OPTION_NO_UNDEFINED
:
921 link_info
.unresolved_syms_in_objects
922 = how_to_report_unresolved_symbols
;
924 case OPTION_ALLOW_SHLIB_UNDEFINED
:
925 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
927 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
928 link_info
.unresolved_syms_in_shared_libs
929 = how_to_report_unresolved_symbols
;
931 case OPTION_UNRESOLVED_SYMBOLS
:
932 if (strcmp (optarg
, "ignore-all") == 0)
934 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
935 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
937 else if (strcmp (optarg
, "report-all") == 0)
939 link_info
.unresolved_syms_in_objects
940 = how_to_report_unresolved_symbols
;
941 link_info
.unresolved_syms_in_shared_libs
942 = how_to_report_unresolved_symbols
;
944 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
946 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
947 link_info
.unresolved_syms_in_shared_libs
948 = how_to_report_unresolved_symbols
;
950 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
952 link_info
.unresolved_syms_in_objects
953 = how_to_report_unresolved_symbols
;
954 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
957 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
959 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
960 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
961 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
962 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
963 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
964 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
967 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
968 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
969 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
970 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
971 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
972 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
974 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
975 link_info
.allow_multiple_definition
= TRUE
;
977 case OPTION_NO_UNDEFINED_VERSION
:
978 link_info
.allow_undefined_version
= FALSE
;
980 case OPTION_DEFAULT_SYMVER
:
981 link_info
.create_default_symver
= TRUE
;
983 case OPTION_DEFAULT_IMPORTED_SYMVER
:
984 link_info
.default_imported_symver
= TRUE
;
986 case OPTION_NO_WARN_MISMATCH
:
987 command_line
.warn_mismatch
= FALSE
;
989 case OPTION_NO_WARN_SEARCH_MISMATCH
:
990 command_line
.warn_search_mismatch
= FALSE
;
992 case OPTION_NOINHIBIT_EXEC
:
993 force_make_executable
= TRUE
;
995 case OPTION_NOSTDLIB
:
996 config
.only_cmd_line_lib_dirs
= TRUE
;
998 case OPTION_NO_WHOLE_ARCHIVE
:
999 whole_archive
= FALSE
;
1002 /* FIXME "-O<non-digits> <value>" used to set the address of
1003 section <non-digits>. Was this for compatibility with
1004 something, or can we create a new option to do that
1005 (with a syntax similar to -defsym)?
1006 getopt can't handle two args to an option without kludges. */
1008 /* Enable optimizations of output files. */
1009 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
1012 lang_add_output (optarg
, 0);
1014 case OPTION_OFORMAT
:
1015 lang_add_output_format (optarg
, NULL
, NULL
, 0);
1018 link_info
.emitrelocations
= TRUE
;
1022 if (optind
== last_optind
)
1023 /* This can happen if the user put "-rpath,a" on the command
1024 line. (Or something similar. The comma is important).
1025 Getopt becomes confused and thinks that this is a -r option
1026 but it cannot parse the text after the -r so it refuses to
1027 increment the optind counter. Detect this case and issue
1028 an error message here. We cannot just make this a warning,
1029 increment optind, and continue because getopt is too confused
1030 and will seg-fault the next time around. */
1031 einfo(_("%P%F: bad -rpath option\n"));
1033 link_info
.relocatable
= TRUE
;
1034 config
.build_constructors
= FALSE
;
1035 config
.magic_demand_paged
= FALSE
;
1036 config
.text_read_only
= FALSE
;
1037 config
.dynamic_link
= FALSE
;
1040 /* The GNU linker traditionally uses -R to mean to include
1041 only the symbols from a file. The Solaris linker uses -R
1042 to set the path used by the runtime linker to find
1043 libraries. This is the GNU linker -rpath argument. We
1044 try to support both simultaneously by checking the file
1045 named. If it is a directory, rather than a regular file,
1046 we assume -rpath was meant. */
1050 if (stat (optarg
, &s
) >= 0
1051 && ! S_ISDIR (s
.st_mode
))
1053 lang_add_input_file (optarg
,
1054 lang_input_file_is_symbols_only_enum
,
1061 if (command_line
.rpath
== NULL
)
1062 command_line
.rpath
= xstrdup (optarg
);
1065 size_t rpath_len
= strlen (command_line
.rpath
);
1066 size_t optarg_len
= strlen (optarg
);
1068 char *cp
= command_line
.rpath
;
1070 /* First see whether OPTARG is already in the path. */
1073 if (strncmp (optarg
, cp
, optarg_len
) == 0
1074 && (cp
[optarg_len
] == 0
1075 || cp
[optarg_len
] == config
.rpath_separator
))
1079 /* Not yet found. */
1080 cp
= strchr (cp
, config
.rpath_separator
);
1088 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1089 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1090 config
.rpath_separator
, optarg
);
1091 free (command_line
.rpath
);
1092 command_line
.rpath
= buf
;
1096 case OPTION_RPATH_LINK
:
1097 if (command_line
.rpath_link
== NULL
)
1098 command_line
.rpath_link
= xstrdup (optarg
);
1103 buf
= xmalloc (strlen (command_line
.rpath_link
)
1106 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1107 config
.rpath_separator
, optarg
);
1108 free (command_line
.rpath_link
);
1109 command_line
.rpath_link
= buf
;
1113 command_line
.relax
= TRUE
;
1115 case OPTION_RETAIN_SYMBOLS_FILE
:
1116 add_keepsyms_file (optarg
);
1119 link_info
.strip
= strip_debugger
;
1122 link_info
.strip
= strip_all
;
1124 case OPTION_STRIP_DISCARDED
:
1125 link_info
.strip_discarded
= TRUE
;
1127 case OPTION_NO_STRIP_DISCARDED
:
1128 link_info
.strip_discarded
= FALSE
;
1131 if (config
.has_shared
)
1133 link_info
.shared
= TRUE
;
1134 /* When creating a shared library, the default
1135 behaviour is to ignore any unresolved references. */
1136 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1137 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1138 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1139 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1142 einfo (_("%P%F: -shared not supported\n"));
1145 if (config
.has_shared
)
1147 link_info
.shared
= TRUE
;
1148 link_info
.pie
= TRUE
;
1151 einfo (_("%P%F: -pie not supported\n"));
1153 case 'h': /* Used on Solaris. */
1155 command_line
.soname
= optarg
;
1157 case OPTION_SORT_COMMON
:
1159 || strcmp (optarg
, N_("descending")) == 0)
1160 config
.sort_common
= sort_descending
;
1161 else if (strcmp (optarg
, N_("ascending")) == 0)
1162 config
.sort_common
= sort_ascending
;
1164 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1167 case OPTION_SORT_SECTION
:
1168 if (strcmp (optarg
, N_("name")) == 0)
1169 sort_section
= by_name
;
1170 else if (strcmp (optarg
, N_("alignment")) == 0)
1171 sort_section
= by_alignment
;
1173 einfo (_("%P%F: invalid section sorting option: %s\n"),
1177 config
.stats
= TRUE
;
1179 case OPTION_SYMBOLIC
:
1180 command_line
.symbolic
= symbolic
;
1182 case OPTION_SYMBOLIC_FUNCTIONS
:
1183 command_line
.symbolic
= symbolic_functions
;
1189 previous_script_handle
= saved_script_handle
;
1190 ldfile_open_command_file (optarg
);
1191 parser_input
= input_script
;
1193 previous_script_handle
= NULL
;
1195 case OPTION_DEFAULT_SCRIPT
:
1196 command_line
.default_script
= optarg
;
1198 case OPTION_SECTION_START
:
1204 /* Check for <something>=<somthing>... */
1205 optarg2
= strchr (optarg
, '=');
1206 if (optarg2
== NULL
)
1207 einfo (_("%P%F: invalid argument to option"
1208 " \"--section-start\"\n"));
1212 /* So far so good. Are all the args present? */
1213 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1214 einfo (_("%P%F: missing argument(s) to option"
1215 " \"--section-start\"\n"));
1217 /* We must copy the section name as set_section_start
1218 doesn't do it for us. */
1219 len
= optarg2
- optarg
;
1220 sec_name
= xmalloc (len
);
1221 memcpy (sec_name
, optarg
, len
- 1);
1222 sec_name
[len
- 1] = 0;
1224 /* Then set it... */
1225 set_section_start (sec_name
, optarg2
);
1228 case OPTION_TARGET_HELP
:
1229 /* Mention any target specific options. */
1230 ldemul_list_emulation_options (stdout
);
1233 set_segment_start (".bss", optarg
);
1236 set_segment_start (".data", optarg
);
1239 set_segment_start (".text", optarg
);
1241 case OPTION_TRADITIONAL_FORMAT
:
1242 link_info
.traditional_format
= TRUE
;
1244 case OPTION_TASK_LINK
:
1245 link_info
.task_link
= TRUE
;
1246 /* Fall through - do an implied -r option. */
1248 link_info
.relocatable
= TRUE
;
1249 config
.build_constructors
= TRUE
;
1250 config
.magic_demand_paged
= FALSE
;
1251 config
.text_read_only
= FALSE
;
1252 config
.dynamic_link
= FALSE
;
1255 ldlang_add_undef (optarg
);
1259 lang_add_unique (optarg
);
1261 config
.unique_orphan_sections
= TRUE
;
1263 case OPTION_VERBOSE
:
1265 version_printed
= TRUE
;
1266 trace_file_tries
= TRUE
;
1267 overflow_cutoff_limit
= -2;
1271 version_printed
= TRUE
;
1275 version_printed
= TRUE
;
1277 case OPTION_VERSION
:
1281 case OPTION_VERSION_SCRIPT
:
1282 /* This option indicates a small script that only specifies
1283 version information. Read it, but don't assume that
1284 we've seen a linker script. */
1286 FILE *hold_script_handle
;
1288 hold_script_handle
= saved_script_handle
;
1289 ldfile_open_command_file (optarg
);
1290 saved_script_handle
= hold_script_handle
;
1291 parser_input
= input_version_script
;
1295 case OPTION_VERSION_EXPORTS_SECTION
:
1296 /* This option records a version symbol to be applied to the
1297 symbols listed for export to be found in the object files
1298 .exports sections. */
1299 command_line
.version_exports_section
= optarg
;
1301 case OPTION_DYNAMIC_LIST_DATA
:
1302 command_line
.dynamic_list
= dynamic_list_data
;
1303 if (command_line
.symbolic
== symbolic
)
1304 command_line
.symbolic
= symbolic_unset
;
1306 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1307 lang_append_dynamic_list_cpp_typeinfo ();
1308 if (command_line
.dynamic_list
!= dynamic_list_data
)
1309 command_line
.dynamic_list
= dynamic_list
;
1310 if (command_line
.symbolic
== symbolic
)
1311 command_line
.symbolic
= symbolic_unset
;
1313 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1314 lang_append_dynamic_list_cpp_new ();
1315 if (command_line
.dynamic_list
!= dynamic_list_data
)
1316 command_line
.dynamic_list
= dynamic_list
;
1317 if (command_line
.symbolic
== symbolic
)
1318 command_line
.symbolic
= symbolic_unset
;
1320 case OPTION_DYNAMIC_LIST
:
1321 /* This option indicates a small script that only specifies
1322 a dynamic list. Read it, but don't assume that we've
1323 seen a linker script. */
1325 FILE *hold_script_handle
;
1327 hold_script_handle
= saved_script_handle
;
1328 ldfile_open_command_file (optarg
);
1329 saved_script_handle
= hold_script_handle
;
1330 parser_input
= input_dynamic_list
;
1333 if (command_line
.dynamic_list
!= dynamic_list_data
)
1334 command_line
.dynamic_list
= dynamic_list
;
1335 if (command_line
.symbolic
== symbolic
)
1336 command_line
.symbolic
= symbolic_unset
;
1338 case OPTION_WARN_COMMON
:
1339 config
.warn_common
= TRUE
;
1341 case OPTION_WARN_CONSTRUCTORS
:
1342 config
.warn_constructors
= TRUE
;
1344 case OPTION_WARN_FATAL
:
1345 config
.fatal_warnings
= TRUE
;
1347 case OPTION_NO_WARN_FATAL
:
1348 config
.fatal_warnings
= FALSE
;
1350 case OPTION_WARN_MULTIPLE_GP
:
1351 config
.warn_multiple_gp
= TRUE
;
1353 case OPTION_WARN_ONCE
:
1354 config
.warn_once
= TRUE
;
1356 case OPTION_WARN_SECTION_ALIGN
:
1357 config
.warn_section_align
= TRUE
;
1359 case OPTION_WARN_SHARED_TEXTREL
:
1360 link_info
.warn_shared_textrel
= TRUE
;
1362 case OPTION_WHOLE_ARCHIVE
:
1363 whole_archive
= TRUE
;
1365 case OPTION_ADD_NEEDED
:
1368 case OPTION_NO_ADD_NEEDED
:
1371 case OPTION_AS_NEEDED
:
1374 case OPTION_NO_AS_NEEDED
:
1380 case OPTION_IGNORE_UNRESOLVED_SYMBOL
:
1381 add_ignoresym (optarg
);
1383 case OPTION_DISCARD_NONE
:
1384 link_info
.discard
= discard_none
;
1387 link_info
.discard
= discard_l
;
1390 link_info
.discard
= discard_all
;
1393 if (CONST_STRNEQ (optarg
, "P,"))
1395 if (default_dirlist
!= NULL
)
1396 free (default_dirlist
);
1397 default_dirlist
= xstrdup (optarg
);
1402 case OPTION_SPARE_DYNAMIC_TAGS
:
1403 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1405 case OPTION_SPLIT_BY_RELOC
:
1407 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1409 config
.split_by_reloc
= 32768;
1411 case OPTION_SPLIT_BY_FILE
:
1413 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1415 config
.split_by_file
= 1;
1417 case OPTION_CHECK_SECTIONS
:
1418 command_line
.check_section_addresses
= TRUE
;
1420 case OPTION_NO_CHECK_SECTIONS
:
1421 command_line
.check_section_addresses
= FALSE
;
1423 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1424 command_line
.accept_unknown_input_arch
= TRUE
;
1426 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1427 command_line
.accept_unknown_input_arch
= FALSE
;
1431 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1433 lang_enter_group ();
1438 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1440 lang_leave_group ();
1445 link_info
.init_function
= optarg
;
1449 link_info
.fini_function
= optarg
;
1452 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1453 link_info
.reduce_memory_overheads
= TRUE
;
1454 if (config
.hash_table_size
== 0)
1455 config
.hash_table_size
= 1021;
1458 case OPTION_HASH_SIZE
:
1460 bfd_size_type new_size
;
1462 new_size
= strtoul (optarg
, NULL
, 0);
1464 config
.hash_table_size
= new_size
;
1466 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1473 lang_leave_group ();
1475 if (default_dirlist
!= NULL
)
1477 set_default_dirlist (default_dirlist
);
1478 free (default_dirlist
);
1481 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1482 /* FIXME: Should we allow emulations a chance to set this ? */
1483 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1485 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1486 /* FIXME: Should we allow emulations a chance to set this ? */
1487 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1490 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1491 library search path. */
1494 set_default_dirlist (char *dirlist_ptr
)
1500 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1503 if (*dirlist_ptr
!= '\0')
1504 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1507 dirlist_ptr
= p
+ 1;
1512 set_section_start (char *sect
, char *valstr
)
1515 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1517 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1518 lang_section_start (sect
, exp_intop (val
), NULL
);
1522 set_segment_start (const char *section
, char *valstr
)
1528 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1530 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1531 /* If we already have an entry for this segment, update the existing
1534 for (seg
= segments
; seg
; seg
= seg
->next
)
1535 if (strcmp (seg
->name
, name
) == 0)
1540 /* There was no existing value so we must create a new segment
1542 seg
= stat_alloc (sizeof (*seg
));
1546 /* Add it to the linked list of segments. */
1547 seg
->next
= segments
;
1549 /* Historically, -Ttext and friends set the base address of a
1550 particular section. For backwards compatibility, we still do
1551 that. If a SEGMENT_START directive is seen, the section address
1552 assignment will be disabled. */
1553 lang_section_start (section
, exp_intop (val
), seg
);
1557 /* Print help messages for the options. */
1563 const char **targets
, **pp
;
1566 printf (_("Usage: %s [options] file...\n"), program_name
);
1568 printf (_("Options:\n"));
1569 for (i
= 0; i
< OPTION_COUNT
; i
++)
1571 if (ld_options
[i
].doc
!= NULL
)
1584 if (ld_options
[j
].shortopt
!= '\0'
1585 && ld_options
[j
].control
!= NO_HELP
)
1587 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1588 len
+= (comma
? 2 : 0) + 2;
1589 if (ld_options
[j
].arg
!= NULL
)
1591 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1596 printf ("%s", _(ld_options
[j
].arg
));
1597 len
+= strlen (_(ld_options
[j
].arg
));
1603 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1608 if (ld_options
[j
].opt
.name
!= NULL
1609 && ld_options
[j
].control
!= NO_HELP
)
1612 (ld_options
[j
].control
== TWO_DASHES
1613 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1617 two_dashes
? "-" : "",
1618 ld_options
[j
].opt
.name
);
1619 len
+= ((comma
? 2 : 0)
1621 + (two_dashes
? 1 : 0)
1622 + strlen (ld_options
[j
].opt
.name
));
1623 if (ld_options
[j
].arg
!= NULL
)
1625 printf (" %s", _(ld_options
[j
].arg
));
1626 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1632 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1640 for (; len
< 30; len
++)
1643 printf ("%s\n", _(ld_options
[i
].doc
));
1646 printf (_(" @FILE"));
1647 for (len
= strlen (" @FILE"); len
< 30; len
++)
1649 printf (_("Read options from FILE\n"));
1651 /* Note: Various tools (such as libtool) depend upon the
1652 format of the listings below - do not change them. */
1653 /* xgettext:c-format */
1654 printf (_("%s: supported targets:"), program_name
);
1655 targets
= bfd_target_list ();
1656 for (pp
= targets
; *pp
!= NULL
; pp
++)
1657 printf (" %s", *pp
);
1661 /* xgettext:c-format */
1662 printf (_("%s: supported emulations: "), program_name
);
1663 ldemul_list_emulations (stdout
);
1666 /* xgettext:c-format */
1667 printf (_("%s: emulation specific options:\n"), program_name
);
1668 ldemul_list_emulation_options (stdout
);
1671 if (REPORT_BUGS_TO
[0])
1672 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);