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
,
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
,
93 OPTION_RETAIN_SYMBOLS_FILE
,
102 OPTION_SYMBOLIC_FUNCTIONS
,
107 OPTION_TTEXT_SEGMENT
,
108 OPTION_TRADITIONAL_FORMAT
,
112 OPTION_VERSION_SCRIPT
,
113 OPTION_VERSION_EXPORTS_SECTION
,
115 OPTION_DYNAMIC_LIST_CPP_NEW
,
116 OPTION_DYNAMIC_LIST_CPP_TYPEINFO
,
117 OPTION_DYNAMIC_LIST_DATA
,
119 OPTION_WARN_CONSTRUCTORS
,
121 OPTION_NO_WARN_FATAL
,
122 OPTION_WARN_MULTIPLE_GP
,
124 OPTION_WARN_SECTION_ALIGN
,
125 OPTION_SPLIT_BY_RELOC
,
126 OPTION_SPLIT_BY_FILE
,
127 OPTION_WHOLE_ARCHIVE
,
129 OPTION_NO_ADD_NEEDED
,
133 OPTION_FORCE_EXE_SUFFIX
,
135 OPTION_NO_GC_SECTIONS
,
136 OPTION_PRINT_GC_SECTIONS
,
137 OPTION_NO_PRINT_GC_SECTIONS
,
139 OPTION_CHECK_SECTIONS
,
140 OPTION_NO_CHECK_SECTIONS
,
144 OPTION_SECTION_START
,
147 OPTION_ALLOW_SHLIB_UNDEFINED
,
148 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
149 OPTION_ALLOW_MULTIPLE_DEFINITION
,
150 OPTION_NO_UNDEFINED_VERSION
,
151 OPTION_DEFAULT_SYMVER
,
152 OPTION_DEFAULT_IMPORTED_SYMVER
,
154 OPTION_SPARE_DYNAMIC_TAGS
,
155 OPTION_NO_DEFINE_COMMON
,
158 OPTION_STRIP_DISCARDED
,
159 OPTION_NO_STRIP_DISCARDED
,
160 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
161 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
163 OPTION_UNRESOLVED_SYMBOLS
,
164 OPTION_WARN_UNRESOLVED_SYMBOLS
,
165 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
166 OPTION_WARN_SHARED_TEXTREL
,
167 OPTION_WARN_ALTERNATE_EM
,
168 OPTION_REDUCE_MEMORY_OVERHEADS
,
169 OPTION_DEFAULT_SCRIPT
172 /* The long options. This structure is used for both the option
173 parsing and the help text. */
177 /* The long option information. */
179 /* The short option with the same meaning ('\0' if none). */
181 /* The name of the argument (NULL if none). */
183 /* The documentation string. If this is NULL, this is a synonym for
184 the previous option. */
187 /* Use one dash before long option name. */
189 /* Use two dashes before long option name. */
191 /* Only accept two dashes before the long option name.
192 This is an overloading of the use of this enum, since originally it
193 was only intended to tell the --help display function how to display
194 the long option name. This feature was added in order to resolve
195 the confusion about the -omagic command line switch. Is it setting
196 the output file name to "magic" or is it setting the NMAGIC flag on
197 the output ? It has been decided that it is setting the output file
198 name, and that if you want to set the NMAGIC flag you should use -N
201 /* Don't mention this option in --help output. */
206 static const struct ld_option ld_options
[] =
208 { {NULL
, required_argument
, NULL
, '\0'},
209 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
211 { {"architecture", required_argument
, NULL
, 'A'},
212 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
213 { {"format", required_argument
, NULL
, 'b'},
214 'b', N_("TARGET"), N_("Specify target for following input files"),
216 { {"mri-script", required_argument
, NULL
, 'c'},
217 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
218 { {"dc", no_argument
, NULL
, 'd'},
219 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
220 { {"dp", no_argument
, NULL
, 'd'},
221 '\0', NULL
, NULL
, ONE_DASH
},
222 { {"entry", required_argument
, NULL
, 'e'},
223 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
224 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
225 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
226 { {"no-export-dynamic", no_argument
, NULL
, OPTION_NO_EXPORT_DYNAMIC
},
227 '\0', NULL
, N_("Undo the effect of --export-dynamic"), TWO_DASHES
},
228 { {"EB", no_argument
, NULL
, OPTION_EB
},
229 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
230 { {"EL", no_argument
, NULL
, OPTION_EL
},
231 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
232 { {"auxiliary", required_argument
, NULL
, 'f'},
233 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
235 { {"filter", required_argument
, NULL
, 'F'},
236 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
238 { {NULL
, no_argument
, NULL
, '\0'},
239 'g', NULL
, N_("Ignored"), ONE_DASH
},
240 { {"gpsize", required_argument
, NULL
, 'G'},
241 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
243 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
244 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
245 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
246 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
248 { {"library", required_argument
, NULL
, 'l'},
249 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
250 { {"library-path", required_argument
, NULL
, 'L'},
251 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
253 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
254 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
255 { {NULL
, required_argument
, NULL
, '\0'},
256 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
257 { {"print-map", no_argument
, NULL
, 'M'},
258 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
259 { {"nmagic", no_argument
, NULL
, 'n'},
260 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
261 { {"omagic", no_argument
, NULL
, 'N'},
262 'N', NULL
, N_("Do not page align data, do not make text readonly"),
263 EXACTLY_TWO_DASHES
},
264 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
265 '\0', NULL
, N_("Page align data, make text readonly"),
266 EXACTLY_TWO_DASHES
},
267 { {"output", required_argument
, NULL
, 'o'},
268 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
269 { {NULL
, required_argument
, NULL
, '\0'},
270 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
271 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
272 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
273 { {"emit-relocs", no_argument
, NULL
, 'q'},
274 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
275 { {"relocatable", no_argument
, NULL
, 'r'},
276 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
277 { {NULL
, no_argument
, NULL
, '\0'},
278 'i', NULL
, NULL
, ONE_DASH
},
279 { {"just-symbols", required_argument
, NULL
, 'R'},
280 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
282 { {"strip-all", no_argument
, NULL
, 's'},
283 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
284 { {"strip-debug", no_argument
, NULL
, 'S'},
285 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
286 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
287 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
288 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
289 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
290 { {"trace", no_argument
, NULL
, 't'},
291 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
292 { {"script", required_argument
, NULL
, 'T'},
293 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
294 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
295 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
296 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
297 '\0', NULL
, NULL
, ONE_DASH
},
298 { {"undefined", required_argument
, NULL
, 'u'},
299 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
301 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
302 '\0', N_("[=SECTION]"),
303 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
304 { {"Ur", no_argument
, NULL
, OPTION_UR
},
305 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
306 { {"version", no_argument
, NULL
, OPTION_VERSION
},
307 'v', NULL
, N_("Print version information"), TWO_DASHES
},
308 { {NULL
, no_argument
, NULL
, '\0'},
309 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
310 { {"discard-all", no_argument
, NULL
, 'x'},
311 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
312 { {"discard-locals", no_argument
, NULL
, 'X'},
313 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
314 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
315 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
316 { {"trace-symbol", required_argument
, NULL
, 'y'},
317 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
318 { {NULL
, required_argument
, NULL
, '\0'},
319 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
321 { {"start-group", no_argument
, NULL
, '('},
322 '(', NULL
, N_("Start a group"), TWO_DASHES
},
323 { {"end-group", no_argument
, NULL
, ')'},
324 ')', NULL
, N_("End a group"), TWO_DASHES
},
325 { {"accept-unknown-input-arch", no_argument
, NULL
,
326 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
328 N_("Accept input files whose architecture cannot be determined"),
330 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
331 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
332 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
334 { {"add-needed", no_argument
, NULL
, OPTION_ADD_NEEDED
},
335 '\0', NULL
, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
336 " following dynamic libs"),
338 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_NEEDED
},
339 '\0', NULL
, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
340 " in following dynamic libs"),
342 { {"as-needed", no_argument
, NULL
, OPTION_AS_NEEDED
},
343 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
345 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_AS_NEEDED
},
346 '\0', NULL
, N_("Always set DT_NEEDED for following dynamic libs"),
348 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
349 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
350 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
351 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
352 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
353 '\0', NULL
, NULL
, ONE_DASH
},
354 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
355 '\0', NULL
, NULL
, ONE_DASH
},
356 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
357 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
358 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
359 '\0', NULL
, NULL
, ONE_DASH
},
360 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
361 '\0', NULL
, NULL
, ONE_DASH
},
362 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
363 '\0', NULL
, NULL
, ONE_DASH
},
364 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
365 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
366 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
367 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
368 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
369 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
371 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
372 '\0', NULL
, N_("Do not check section addresses for overlaps"),
374 { {"cref", no_argument
, NULL
, OPTION_CREF
},
375 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
376 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
377 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
378 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
379 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
381 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
382 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
383 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
384 '\0', NULL
, N_("Treat warnings as errors"),
386 { {"no-fatal-warnings", no_argument
, NULL
, OPTION_NO_WARN_FATAL
},
387 '\0', NULL
, N_("Do not treat warnings as errors (default)"),
389 { {"fini", required_argument
, NULL
, OPTION_FINI
},
390 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
391 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
392 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
393 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
394 '\0', NULL
, N_("Remove unused sections (on some targets)"),
396 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
397 '\0', NULL
, N_("Don't remove unused sections (default)"),
399 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
400 '\0', NULL
, N_("List removed unused sections on stderr"),
402 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
403 '\0', NULL
, N_("Do not list removed unused sections"),
405 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
406 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
408 { {"help", no_argument
, NULL
, OPTION_HELP
},
409 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
410 { {"init", required_argument
, NULL
, OPTION_INIT
},
411 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
412 { {"Map", required_argument
, NULL
, OPTION_MAP
},
413 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
414 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
415 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
416 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
417 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
418 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
419 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
420 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
421 '\0', NULL
, N_("Do not allow unresolved references in object files"),
423 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
424 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
426 { {"no-allow-shlib-undefined", no_argument
, NULL
,
427 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
428 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
430 { {"allow-multiple-definition", no_argument
, NULL
,
431 OPTION_ALLOW_MULTIPLE_DEFINITION
},
432 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
433 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
434 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
435 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
436 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
437 { {"default-imported-symver", no_argument
, NULL
,
438 OPTION_DEFAULT_IMPORTED_SYMVER
},
439 '\0', NULL
, N_("Create default symbol version for imported symbols"),
441 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
442 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
443 { {"no-warn-search-mismatch", no_argument
, NULL
,
444 OPTION_NO_WARN_SEARCH_MISMATCH
},
445 '\0', NULL
, N_("Don't warn on finding an incompatible library"),
447 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
448 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
449 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
450 '\0', NULL
, N_("Create an output file even if errors occur"),
452 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
453 '\0', NULL
, NULL
, NO_HELP
},
454 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
455 '\0', NULL
, N_("Only use library directories specified on\n"
456 " the command line"),
458 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
459 '\0', N_("TARGET"), N_("Specify target of output file"),
460 EXACTLY_TWO_DASHES
},
461 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
462 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
463 { {"reduce-memory-overheads", no_argument
, NULL
,
464 OPTION_REDUCE_MEMORY_OVERHEADS
},
465 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
467 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
468 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
469 { {"retain-symbols-file", required_argument
, NULL
,
470 OPTION_RETAIN_SYMBOLS_FILE
},
471 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
472 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
473 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
474 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
475 '\0', N_("PATH"), N_("Set link time shared library search path"),
477 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
478 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
479 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
480 '\0', NULL
, NULL
, ONE_DASH
},
481 { {"pie", no_argument
, NULL
, OPTION_PIE
},
482 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
483 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
484 '\0', NULL
, NULL
, TWO_DASHES
},
485 { {"sort-common", optional_argument
, NULL
, OPTION_SORT_COMMON
},
486 '\0', N_("[=ascending|descending]"),
487 N_("Sort common symbols by alignment [in specified order]"),
489 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
490 '\0', NULL
, NULL
, NO_HELP
},
491 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
492 '\0', N_("name|alignment"),
493 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
494 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
495 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
497 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
498 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
500 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
501 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
503 { {"stats", no_argument
, NULL
, OPTION_STATS
},
504 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
505 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
506 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
507 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
508 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
509 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
510 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
511 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
512 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
514 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
515 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
516 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
517 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
518 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
519 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
520 { {"Ttext-segment", required_argument
, NULL
, OPTION_TTEXT_SEGMENT
},
521 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH
},
522 { {"unresolved-symbols=<method>", required_argument
, NULL
,
523 OPTION_UNRESOLVED_SYMBOLS
},
524 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
525 " ignore-all, report-all, ignore-in-object-files,\n"
526 " ignore-in-shared-libs"),
528 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
529 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
530 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
531 '\0', NULL
, NULL
, NO_HELP
},
532 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
533 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
534 { {"version-exports-section", required_argument
, NULL
,
535 OPTION_VERSION_EXPORTS_SECTION
},
536 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
537 " SYMBOL as the version."),
539 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
540 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
541 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
542 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
543 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
544 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
545 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
546 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
547 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
548 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
549 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
550 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
552 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
553 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
554 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
555 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
556 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
557 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
559 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
560 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
562 { {"warn-alternate-em", no_argument
, NULL
, OPTION_WARN_ALTERNATE_EM
},
563 '\0', NULL
, N_("Warn if an object has alternate ELF machine code"),
565 { {"warn-unresolved-symbols", no_argument
, NULL
,
566 OPTION_WARN_UNRESOLVED_SYMBOLS
},
567 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
568 { {"error-unresolved-symbols", no_argument
, NULL
,
569 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
570 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
571 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
572 '\0', NULL
, N_("Include all objects from following archives"),
574 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
575 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
578 #define OPTION_COUNT ARRAY_SIZE (ld_options)
581 parse_args (unsigned argc
, char **argv
)
586 char *default_dirlist
= NULL
;
588 struct option
*longopts
;
589 struct option
*really_longopts
;
591 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
593 shortopts
= xmalloc (OPTION_COUNT
* 3 + 2);
594 longopts
= xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
595 really_longopts
= xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
597 /* Starting the short option string with '-' is for programs that
598 expect options and other ARGV-elements in any order and that care about
599 the ordering of the two. We describe each non-option ARGV-element
600 as if it were the argument of an option with character code 1. */
605 for (i
= 0; i
< OPTION_COUNT
; i
++)
607 if (ld_options
[i
].shortopt
!= '\0')
609 shortopts
[is
] = ld_options
[i
].shortopt
;
611 if (ld_options
[i
].opt
.has_arg
== required_argument
612 || ld_options
[i
].opt
.has_arg
== optional_argument
)
616 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
623 if (ld_options
[i
].opt
.name
!= NULL
)
625 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
627 really_longopts
[irl
] = ld_options
[i
].opt
;
632 longopts
[il
] = ld_options
[i
].opt
;
637 shortopts
[is
] = '\0';
638 longopts
[il
].name
= NULL
;
639 really_longopts
[irl
].name
= NULL
;
641 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
643 /* The -G option is ambiguous on different platforms. Sometimes it
644 specifies the largest data size to put into the small data
645 section. Sometimes it is equivalent to --shared. Unfortunately,
646 the first form takes an argument, while the second does not.
648 We need to permit the --shared form because on some platforms,
649 such as Solaris, gcc -shared will pass -G to the linker.
651 To permit either usage, we look through the argument list. If we
652 find -G not followed by a number, we change it into --shared.
653 This will work for most normal cases. */
654 for (i
= 1; i
< argc
; i
++)
655 if (strcmp (argv
[i
], "-G") == 0
657 || ! ISDIGIT (argv
[i
+ 1][0])))
658 argv
[i
] = (char *) "--shared";
660 /* Because we permit long options to start with a single dash, and
661 we have a --library option, and the -l option is conventionally
662 used with an immediately following argument, we can have bad
663 results if somebody tries to use -l with a library whose name
664 happens to start with "ibrary", as in -li. We avoid problems by
665 simply turning -l into --library. This means that users will
666 have to use two dashes in order to use --library, which is OK
667 since that's how it is documented.
669 FIXME: It's possible that this problem can arise for other short
670 options as well, although the user does always have the recourse
671 of adding a space between the option and the argument. */
672 for (i
= 1; i
< argc
; i
++)
674 if (argv
[i
][0] == '-'
676 && argv
[i
][2] != '\0')
680 n
= xmalloc (strlen (argv
[i
]) + 20);
681 sprintf (n
, "--library=%s", argv
[i
] + 2);
692 /* Using last_optind lets us avoid calling ldemul_parse_args
693 multiple times on a single option, which would lead to
694 confusion in the internal static variables maintained by
695 getopt. This could otherwise happen for an argument like
696 -nx, in which the -n is parsed as a single option, and we
697 loop around to pick up the -x. */
698 if (optind
!= last_optind
)
699 if (ldemul_parse_args (argc
, argv
))
702 /* getopt_long_only is like getopt_long, but '-' as well as '--'
703 can indicate a long option. */
705 last_optind
= optind
;
706 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
709 optind
= last_optind
;
710 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
713 if (ldemul_handle_option (optc
))
722 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
726 einfo (_("%P%F: use the --help option for usage information\n"));
728 case 1: /* File name. */
729 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
735 /* For HP/UX compatibility. Actually -a shared should mean
736 ``use only shared libraries'' but, then, we don't
737 currently support shared libraries on HP/UX anyhow. */
738 if (strcmp (optarg
, "archive") == 0)
739 config
.dynamic_link
= FALSE
;
740 else if (strcmp (optarg
, "shared") == 0
741 || strcmp (optarg
, "default") == 0)
742 config
.dynamic_link
= TRUE
;
744 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
747 /* FIXME: We just ignore these, but we should handle them. */
748 if (strcmp (optarg
, "definitions") == 0)
750 else if (strcmp (optarg
, "nodefinitions") == 0)
752 else if (strcmp (optarg
, "nosymbolic") == 0)
754 else if (strcmp (optarg
, "pure-text") == 0)
757 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
760 ldfile_add_arch (optarg
);
763 lang_add_target (optarg
);
766 ldfile_open_command_file (optarg
);
767 parser_input
= input_mri_script
;
770 case OPTION_CALL_SHARED
:
771 config
.dynamic_link
= TRUE
;
773 case OPTION_NON_SHARED
:
774 config
.dynamic_link
= FALSE
;
777 command_line
.cref
= TRUE
;
778 link_info
.notice_all
= TRUE
;
781 command_line
.force_common_definition
= TRUE
;
785 lex_redirect (optarg
);
786 parser_input
= input_defsym
;
792 case OPTION_DEMANGLE
:
796 enum demangling_styles style
;
798 style
= cplus_demangle_name_to_style (optarg
);
799 if (style
== unknown_demangling
)
800 einfo (_("%F%P: unknown demangling style `%s'"),
803 cplus_demangle_set_style (style
);
806 case 'I': /* Used on Solaris. */
807 case OPTION_DYNAMIC_LINKER
:
808 command_line
.interpreter
= optarg
;
811 /* Already handled in ldmain.c. */
814 command_line
.endian
= ENDIAN_BIG
;
817 command_line
.endian
= ENDIAN_LITTLE
;
819 case OPTION_EMBEDDED_RELOCS
:
820 command_line
.embedded_relocs
= TRUE
;
822 case OPTION_EXPORT_DYNAMIC
:
823 case 'E': /* HP/UX compatibility. */
824 link_info
.export_dynamic
= TRUE
;
826 case OPTION_NO_EXPORT_DYNAMIC
:
827 link_info
.export_dynamic
= FALSE
;
830 lang_add_entry (optarg
, TRUE
);
831 ldlang_add_undef (optarg
);
834 if (command_line
.auxiliary_filters
== NULL
)
836 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
837 command_line
.auxiliary_filters
[0] = optarg
;
838 command_line
.auxiliary_filters
[1] = NULL
;
846 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
848 command_line
.auxiliary_filters
849 = xrealloc (command_line
.auxiliary_filters
,
850 (c
+ 2) * sizeof (char *));
851 command_line
.auxiliary_filters
[c
] = optarg
;
852 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
856 command_line
.filter_shlib
= optarg
;
858 case OPTION_FORCE_EXE_SUFFIX
:
859 command_line
.force_exe_suffix
= TRUE
;
864 g_switch_value
= strtoul (optarg
, &end
, 0);
866 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
872 case OPTION_GC_SECTIONS
:
873 link_info
.gc_sections
= TRUE
;
875 case OPTION_PRINT_GC_SECTIONS
:
876 link_info
.print_gc_sections
= TRUE
;
883 ldfile_add_library_path (optarg
, TRUE
);
886 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
889 config
.map_filename
= "-";
892 /* Ignore. Was handled in a pre-parse. */
895 config
.map_filename
= optarg
;
898 config
.text_read_only
= FALSE
;
899 config
.magic_demand_paged
= FALSE
;
900 config
.dynamic_link
= FALSE
;
902 case OPTION_NO_OMAGIC
:
903 config
.text_read_only
= TRUE
;
904 config
.magic_demand_paged
= TRUE
;
905 /* NB/ Does not set dynamic_link to TRUE.
906 Use --call-shared or -Bdynamic for this. */
909 config
.magic_demand_paged
= FALSE
;
910 config
.dynamic_link
= FALSE
;
912 case OPTION_NO_DEFINE_COMMON
:
913 command_line
.inhibit_common_definition
= TRUE
;
915 case OPTION_NO_DEMANGLE
:
918 case OPTION_NO_GC_SECTIONS
:
919 link_info
.gc_sections
= FALSE
;
921 case OPTION_NO_PRINT_GC_SECTIONS
:
922 link_info
.print_gc_sections
= FALSE
;
924 case OPTION_NO_KEEP_MEMORY
:
925 link_info
.keep_memory
= FALSE
;
927 case OPTION_NO_UNDEFINED
:
928 link_info
.unresolved_syms_in_objects
929 = how_to_report_unresolved_symbols
;
931 case OPTION_ALLOW_SHLIB_UNDEFINED
:
932 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
934 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
935 link_info
.unresolved_syms_in_shared_libs
936 = how_to_report_unresolved_symbols
;
938 case OPTION_UNRESOLVED_SYMBOLS
:
939 if (strcmp (optarg
, "ignore-all") == 0)
941 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
942 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
944 else if (strcmp (optarg
, "report-all") == 0)
946 link_info
.unresolved_syms_in_objects
947 = how_to_report_unresolved_symbols
;
948 link_info
.unresolved_syms_in_shared_libs
949 = how_to_report_unresolved_symbols
;
951 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
953 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
954 link_info
.unresolved_syms_in_shared_libs
955 = how_to_report_unresolved_symbols
;
957 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
959 link_info
.unresolved_syms_in_objects
960 = how_to_report_unresolved_symbols
;
961 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
964 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
966 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
967 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
968 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
969 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
970 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
971 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
974 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
975 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
976 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
977 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
978 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
979 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
981 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
982 link_info
.allow_multiple_definition
= TRUE
;
984 case OPTION_NO_UNDEFINED_VERSION
:
985 link_info
.allow_undefined_version
= FALSE
;
987 case OPTION_DEFAULT_SYMVER
:
988 link_info
.create_default_symver
= TRUE
;
990 case OPTION_DEFAULT_IMPORTED_SYMVER
:
991 link_info
.default_imported_symver
= TRUE
;
993 case OPTION_NO_WARN_MISMATCH
:
994 command_line
.warn_mismatch
= FALSE
;
996 case OPTION_NO_WARN_SEARCH_MISMATCH
:
997 command_line
.warn_search_mismatch
= FALSE
;
999 case OPTION_NOINHIBIT_EXEC
:
1000 force_make_executable
= TRUE
;
1002 case OPTION_NOSTDLIB
:
1003 config
.only_cmd_line_lib_dirs
= TRUE
;
1005 case OPTION_NO_WHOLE_ARCHIVE
:
1006 whole_archive
= FALSE
;
1009 /* FIXME "-O<non-digits> <value>" used to set the address of
1010 section <non-digits>. Was this for compatibility with
1011 something, or can we create a new option to do that
1012 (with a syntax similar to -defsym)?
1013 getopt can't handle two args to an option without kludges. */
1015 /* Enable optimizations of output files. */
1016 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
1019 lang_add_output (optarg
, 0);
1021 case OPTION_OFORMAT
:
1022 lang_add_output_format (optarg
, NULL
, NULL
, 0);
1025 link_info
.emitrelocations
= TRUE
;
1029 if (optind
== last_optind
)
1030 /* This can happen if the user put "-rpath,a" on the command
1031 line. (Or something similar. The comma is important).
1032 Getopt becomes confused and thinks that this is a -r option
1033 but it cannot parse the text after the -r so it refuses to
1034 increment the optind counter. Detect this case and issue
1035 an error message here. We cannot just make this a warning,
1036 increment optind, and continue because getopt is too confused
1037 and will seg-fault the next time around. */
1038 einfo(_("%P%F: bad -rpath option\n"));
1040 link_info
.relocatable
= TRUE
;
1041 config
.build_constructors
= FALSE
;
1042 config
.magic_demand_paged
= FALSE
;
1043 config
.text_read_only
= FALSE
;
1044 config
.dynamic_link
= FALSE
;
1047 /* The GNU linker traditionally uses -R to mean to include
1048 only the symbols from a file. The Solaris linker uses -R
1049 to set the path used by the runtime linker to find
1050 libraries. This is the GNU linker -rpath argument. We
1051 try to support both simultaneously by checking the file
1052 named. If it is a directory, rather than a regular file,
1053 we assume -rpath was meant. */
1057 if (stat (optarg
, &s
) >= 0
1058 && ! S_ISDIR (s
.st_mode
))
1060 lang_add_input_file (optarg
,
1061 lang_input_file_is_symbols_only_enum
,
1068 if (command_line
.rpath
== NULL
)
1069 command_line
.rpath
= xstrdup (optarg
);
1072 size_t rpath_len
= strlen (command_line
.rpath
);
1073 size_t optarg_len
= strlen (optarg
);
1075 char *cp
= command_line
.rpath
;
1077 /* First see whether OPTARG is already in the path. */
1080 if (strncmp (optarg
, cp
, optarg_len
) == 0
1081 && (cp
[optarg_len
] == 0
1082 || cp
[optarg_len
] == config
.rpath_separator
))
1086 /* Not yet found. */
1087 cp
= strchr (cp
, config
.rpath_separator
);
1095 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1096 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1097 config
.rpath_separator
, optarg
);
1098 free (command_line
.rpath
);
1099 command_line
.rpath
= buf
;
1103 case OPTION_RPATH_LINK
:
1104 if (command_line
.rpath_link
== NULL
)
1105 command_line
.rpath_link
= xstrdup (optarg
);
1110 buf
= xmalloc (strlen (command_line
.rpath_link
)
1113 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1114 config
.rpath_separator
, optarg
);
1115 free (command_line
.rpath_link
);
1116 command_line
.rpath_link
= buf
;
1120 command_line
.relax
= TRUE
;
1122 case OPTION_RETAIN_SYMBOLS_FILE
:
1123 add_keepsyms_file (optarg
);
1126 link_info
.strip
= strip_debugger
;
1129 link_info
.strip
= strip_all
;
1131 case OPTION_STRIP_DISCARDED
:
1132 link_info
.strip_discarded
= TRUE
;
1134 case OPTION_NO_STRIP_DISCARDED
:
1135 link_info
.strip_discarded
= FALSE
;
1138 if (config
.has_shared
)
1140 link_info
.shared
= TRUE
;
1141 /* When creating a shared library, the default
1142 behaviour is to ignore any unresolved references. */
1143 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1144 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1145 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1146 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1149 einfo (_("%P%F: -shared not supported\n"));
1152 if (config
.has_shared
)
1154 link_info
.shared
= TRUE
;
1155 link_info
.pie
= TRUE
;
1158 einfo (_("%P%F: -pie not supported\n"));
1160 case 'h': /* Used on Solaris. */
1162 command_line
.soname
= optarg
;
1164 case OPTION_SORT_COMMON
:
1166 || strcmp (optarg
, N_("descending")) == 0)
1167 config
.sort_common
= sort_descending
;
1168 else if (strcmp (optarg
, N_("ascending")) == 0)
1169 config
.sort_common
= sort_ascending
;
1171 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1174 case OPTION_SORT_SECTION
:
1175 if (strcmp (optarg
, N_("name")) == 0)
1176 sort_section
= by_name
;
1177 else if (strcmp (optarg
, N_("alignment")) == 0)
1178 sort_section
= by_alignment
;
1180 einfo (_("%P%F: invalid section sorting option: %s\n"),
1184 config
.stats
= TRUE
;
1186 case OPTION_SYMBOLIC
:
1187 command_line
.symbolic
= symbolic
;
1189 case OPTION_SYMBOLIC_FUNCTIONS
:
1190 command_line
.symbolic
= symbolic_functions
;
1196 previous_script_handle
= saved_script_handle
;
1197 ldfile_open_command_file (optarg
);
1198 parser_input
= input_script
;
1200 previous_script_handle
= NULL
;
1202 case OPTION_DEFAULT_SCRIPT
:
1203 command_line
.default_script
= optarg
;
1205 case OPTION_SECTION_START
:
1211 /* Check for <something>=<somthing>... */
1212 optarg2
= strchr (optarg
, '=');
1213 if (optarg2
== NULL
)
1214 einfo (_("%P%F: invalid argument to option"
1215 " \"--section-start\"\n"));
1219 /* So far so good. Are all the args present? */
1220 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1221 einfo (_("%P%F: missing argument(s) to option"
1222 " \"--section-start\"\n"));
1224 /* We must copy the section name as set_section_start
1225 doesn't do it for us. */
1226 len
= optarg2
- optarg
;
1227 sec_name
= xmalloc (len
);
1228 memcpy (sec_name
, optarg
, len
- 1);
1229 sec_name
[len
- 1] = 0;
1231 /* Then set it... */
1232 set_section_start (sec_name
, optarg2
);
1235 case OPTION_TARGET_HELP
:
1236 /* Mention any target specific options. */
1237 ldemul_list_emulation_options (stdout
);
1240 set_segment_start (".bss", optarg
);
1243 set_segment_start (".data", optarg
);
1246 set_segment_start (".text", optarg
);
1248 case OPTION_TTEXT_SEGMENT
:
1249 set_segment_start (".text-segment", optarg
);
1251 case OPTION_TRADITIONAL_FORMAT
:
1252 link_info
.traditional_format
= TRUE
;
1254 case OPTION_TASK_LINK
:
1255 link_info
.task_link
= TRUE
;
1256 /* Fall through - do an implied -r option. */
1258 link_info
.relocatable
= TRUE
;
1259 config
.build_constructors
= TRUE
;
1260 config
.magic_demand_paged
= FALSE
;
1261 config
.text_read_only
= FALSE
;
1262 config
.dynamic_link
= FALSE
;
1265 ldlang_add_undef (optarg
);
1269 lang_add_unique (optarg
);
1271 config
.unique_orphan_sections
= TRUE
;
1273 case OPTION_VERBOSE
:
1275 version_printed
= TRUE
;
1276 trace_file_tries
= TRUE
;
1277 overflow_cutoff_limit
= -2;
1281 version_printed
= TRUE
;
1285 version_printed
= TRUE
;
1287 case OPTION_VERSION
:
1291 case OPTION_VERSION_SCRIPT
:
1292 /* This option indicates a small script that only specifies
1293 version information. Read it, but don't assume that
1294 we've seen a linker script. */
1296 FILE *hold_script_handle
;
1298 hold_script_handle
= saved_script_handle
;
1299 ldfile_open_command_file (optarg
);
1300 saved_script_handle
= hold_script_handle
;
1301 parser_input
= input_version_script
;
1305 case OPTION_VERSION_EXPORTS_SECTION
:
1306 /* This option records a version symbol to be applied to the
1307 symbols listed for export to be found in the object files
1308 .exports sections. */
1309 command_line
.version_exports_section
= optarg
;
1311 case OPTION_DYNAMIC_LIST_DATA
:
1312 command_line
.dynamic_list
= dynamic_list_data
;
1313 if (command_line
.symbolic
== symbolic
)
1314 command_line
.symbolic
= symbolic_unset
;
1316 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1317 lang_append_dynamic_list_cpp_typeinfo ();
1318 if (command_line
.dynamic_list
!= dynamic_list_data
)
1319 command_line
.dynamic_list
= dynamic_list
;
1320 if (command_line
.symbolic
== symbolic
)
1321 command_line
.symbolic
= symbolic_unset
;
1323 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1324 lang_append_dynamic_list_cpp_new ();
1325 if (command_line
.dynamic_list
!= dynamic_list_data
)
1326 command_line
.dynamic_list
= dynamic_list
;
1327 if (command_line
.symbolic
== symbolic
)
1328 command_line
.symbolic
= symbolic_unset
;
1330 case OPTION_DYNAMIC_LIST
:
1331 /* This option indicates a small script that only specifies
1332 a dynamic list. Read it, but don't assume that we've
1333 seen a linker script. */
1335 FILE *hold_script_handle
;
1337 hold_script_handle
= saved_script_handle
;
1338 ldfile_open_command_file (optarg
);
1339 saved_script_handle
= hold_script_handle
;
1340 parser_input
= input_dynamic_list
;
1343 if (command_line
.dynamic_list
!= dynamic_list_data
)
1344 command_line
.dynamic_list
= dynamic_list
;
1345 if (command_line
.symbolic
== symbolic
)
1346 command_line
.symbolic
= symbolic_unset
;
1348 case OPTION_WARN_COMMON
:
1349 config
.warn_common
= TRUE
;
1351 case OPTION_WARN_CONSTRUCTORS
:
1352 config
.warn_constructors
= TRUE
;
1354 case OPTION_WARN_FATAL
:
1355 config
.fatal_warnings
= TRUE
;
1357 case OPTION_NO_WARN_FATAL
:
1358 config
.fatal_warnings
= FALSE
;
1360 case OPTION_WARN_MULTIPLE_GP
:
1361 config
.warn_multiple_gp
= TRUE
;
1363 case OPTION_WARN_ONCE
:
1364 config
.warn_once
= TRUE
;
1366 case OPTION_WARN_SECTION_ALIGN
:
1367 config
.warn_section_align
= TRUE
;
1369 case OPTION_WARN_SHARED_TEXTREL
:
1370 link_info
.warn_shared_textrel
= TRUE
;
1372 case OPTION_WARN_ALTERNATE_EM
:
1373 link_info
.warn_alternate_em
= TRUE
;
1375 case OPTION_WHOLE_ARCHIVE
:
1376 whole_archive
= TRUE
;
1378 case OPTION_ADD_NEEDED
:
1381 case OPTION_NO_ADD_NEEDED
:
1384 case OPTION_AS_NEEDED
:
1387 case OPTION_NO_AS_NEEDED
:
1393 case OPTION_DISCARD_NONE
:
1394 link_info
.discard
= discard_none
;
1397 link_info
.discard
= discard_l
;
1400 link_info
.discard
= discard_all
;
1403 if (CONST_STRNEQ (optarg
, "P,"))
1405 if (default_dirlist
!= NULL
)
1406 free (default_dirlist
);
1407 default_dirlist
= xstrdup (optarg
);
1412 case OPTION_SPARE_DYNAMIC_TAGS
:
1413 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1415 case OPTION_SPLIT_BY_RELOC
:
1417 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1419 config
.split_by_reloc
= 32768;
1421 case OPTION_SPLIT_BY_FILE
:
1423 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1425 config
.split_by_file
= 1;
1427 case OPTION_CHECK_SECTIONS
:
1428 command_line
.check_section_addresses
= 1;
1430 case OPTION_NO_CHECK_SECTIONS
:
1431 command_line
.check_section_addresses
= 0;
1433 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1434 command_line
.accept_unknown_input_arch
= TRUE
;
1436 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1437 command_line
.accept_unknown_input_arch
= FALSE
;
1441 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1443 lang_enter_group ();
1448 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1450 lang_leave_group ();
1455 link_info
.init_function
= optarg
;
1459 link_info
.fini_function
= optarg
;
1462 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1463 link_info
.reduce_memory_overheads
= TRUE
;
1464 if (config
.hash_table_size
== 0)
1465 config
.hash_table_size
= 1021;
1468 case OPTION_HASH_SIZE
:
1470 bfd_size_type new_size
;
1472 new_size
= strtoul (optarg
, NULL
, 0);
1474 config
.hash_table_size
= new_size
;
1476 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1483 lang_leave_group ();
1485 if (default_dirlist
!= NULL
)
1487 set_default_dirlist (default_dirlist
);
1488 free (default_dirlist
);
1491 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1492 /* FIXME: Should we allow emulations a chance to set this ? */
1493 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1495 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1496 /* FIXME: Should we allow emulations a chance to set this ? */
1497 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1500 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1501 library search path. */
1504 set_default_dirlist (char *dirlist_ptr
)
1510 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1513 if (*dirlist_ptr
!= '\0')
1514 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1517 dirlist_ptr
= p
+ 1;
1522 set_section_start (char *sect
, char *valstr
)
1525 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1527 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1528 lang_section_start (sect
, exp_intop (val
), NULL
);
1532 set_segment_start (const char *section
, char *valstr
)
1538 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1540 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1541 /* If we already have an entry for this segment, update the existing
1544 for (seg
= segments
; seg
; seg
= seg
->next
)
1545 if (strcmp (seg
->name
, name
) == 0)
1550 /* There was no existing value so we must create a new segment
1552 seg
= stat_alloc (sizeof (*seg
));
1556 /* Add it to the linked list of segments. */
1557 seg
->next
= segments
;
1559 /* Historically, -Ttext and friends set the base address of a
1560 particular section. For backwards compatibility, we still do
1561 that. If a SEGMENT_START directive is seen, the section address
1562 assignment will be disabled. */
1563 lang_section_start (section
, exp_intop (val
), seg
);
1567 /* Print help messages for the options. */
1573 const char **targets
, **pp
;
1576 printf (_("Usage: %s [options] file...\n"), program_name
);
1578 printf (_("Options:\n"));
1579 for (i
= 0; i
< OPTION_COUNT
; i
++)
1581 if (ld_options
[i
].doc
!= NULL
)
1594 if (ld_options
[j
].shortopt
!= '\0'
1595 && ld_options
[j
].control
!= NO_HELP
)
1597 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1598 len
+= (comma
? 2 : 0) + 2;
1599 if (ld_options
[j
].arg
!= NULL
)
1601 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1606 printf ("%s", _(ld_options
[j
].arg
));
1607 len
+= strlen (_(ld_options
[j
].arg
));
1613 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1618 if (ld_options
[j
].opt
.name
!= NULL
1619 && ld_options
[j
].control
!= NO_HELP
)
1622 (ld_options
[j
].control
== TWO_DASHES
1623 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1627 two_dashes
? "-" : "",
1628 ld_options
[j
].opt
.name
);
1629 len
+= ((comma
? 2 : 0)
1631 + (two_dashes
? 1 : 0)
1632 + strlen (ld_options
[j
].opt
.name
));
1633 if (ld_options
[j
].arg
!= NULL
)
1635 printf (" %s", _(ld_options
[j
].arg
));
1636 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1642 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1650 for (; len
< 30; len
++)
1653 printf ("%s\n", _(ld_options
[i
].doc
));
1656 printf (_(" @FILE"));
1657 for (len
= strlen (" @FILE"); len
< 30; len
++)
1659 printf (_("Read options from FILE\n"));
1661 /* Note: Various tools (such as libtool) depend upon the
1662 format of the listings below - do not change them. */
1663 /* xgettext:c-format */
1664 printf (_("%s: supported targets:"), program_name
);
1665 targets
= bfd_target_list ();
1666 for (pp
= targets
; *pp
!= NULL
; pp
++)
1667 printf (" %s", *pp
);
1671 /* xgettext:c-format */
1672 printf (_("%s: supported emulations: "), program_name
);
1673 ldemul_list_emulations (stdout
);
1676 /* xgettext:c-format */
1677 printf (_("%s: emulation specific options:\n"), program_name
);
1678 ldemul_list_emulation_options (stdout
);
1681 if (REPORT_BUGS_TO
[0])
1682 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);