1 /* Parse options for the GNU linker.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
6 This file is part of GLD, the Gnu Linker.
8 GLD 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 2, or (at your option)
13 GLD 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 GLD; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "libiberty.h"
28 #include "safe-ctype.h"
43 #ifndef PATH_SEPARATOR
44 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
45 #define PATH_SEPARATOR ';'
47 #define PATH_SEPARATOR ':'
51 /* Somewhere above, sys/stat.h got included . . . . */
52 #if !defined(S_ISDIR) && defined(S_IFDIR)
53 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
56 static void set_default_dirlist (char *);
57 static void set_section_start (char *, char *);
58 static void set_segment_start (const char *, char *);
59 static void help (void);
61 /* Non-zero if we are processing a --defsym from the command line. */
62 int parsing_defsym
= 0;
64 /* Codes used for the long options with no short synonyms. 150 isn't
65 special; it's just an arbitrary non-ASCII char value. */
73 OPTION_DYNAMIC_LINKER
,
76 OPTION_EMBEDDED_RELOCS
,
77 OPTION_EXPORT_DYNAMIC
,
82 OPTION_NO_KEEP_MEMORY
,
83 OPTION_NO_WARN_MISMATCH
,
84 OPTION_NOINHIBIT_EXEC
,
86 OPTION_NO_WHOLE_ARCHIVE
,
89 OPTION_RETAIN_SYMBOLS_FILE
,
102 OPTION_TRADITIONAL_FORMAT
,
106 OPTION_VERSION_SCRIPT
,
107 OPTION_VERSION_EXPORTS_SECTION
,
109 OPTION_WARN_CONSTRUCTORS
,
111 OPTION_WARN_MULTIPLE_GP
,
113 OPTION_WARN_SECTION_ALIGN
,
114 OPTION_SPLIT_BY_RELOC
,
115 OPTION_SPLIT_BY_FILE
,
116 OPTION_WHOLE_ARCHIVE
,
118 OPTION_NO_ADD_NEEDED
,
122 OPTION_FORCE_EXE_SUFFIX
,
124 OPTION_NO_GC_SECTIONS
,
126 OPTION_CHECK_SECTIONS
,
127 OPTION_NO_CHECK_SECTIONS
,
131 OPTION_SECTION_START
,
134 OPTION_ALLOW_SHLIB_UNDEFINED
,
135 OPTION_NO_ALLOW_SHLIB_UNDEFINED
,
136 OPTION_ALLOW_MULTIPLE_DEFINITION
,
137 OPTION_NO_UNDEFINED_VERSION
,
138 OPTION_DEFAULT_SYMVER
,
139 OPTION_DEFAULT_IMPORTED_SYMVER
,
141 OPTION_SPARE_DYNAMIC_TAGS
,
142 OPTION_NO_DEFINE_COMMON
,
145 OPTION_STRIP_DISCARDED
,
146 OPTION_NO_STRIP_DISCARDED
,
147 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
,
148 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
,
150 OPTION_UNRESOLVED_SYMBOLS
,
151 OPTION_WARN_UNRESOLVED_SYMBOLS
,
152 OPTION_ERROR_UNRESOLVED_SYMBOLS
,
153 OPTION_WARN_SHARED_TEXTREL
,
154 OPTION_REDUCE_MEMORY_OVERHEADS
157 /* The long options. This structure is used for both the option
158 parsing and the help text. */
162 /* The long option information. */
164 /* The short option with the same meaning ('\0' if none). */
166 /* The name of the argument (NULL if none). */
168 /* The documentation string. If this is NULL, this is a synonym for
169 the previous option. */
172 /* Use one dash before long option name. */
174 /* Use two dashes before long option name. */
176 /* Only accept two dashes before the long option name.
177 This is an overloading of the use of this enum, since originally it
178 was only intended to tell the --help display function how to display
179 the long option name. This feature was added in order to resolve
180 the confusion about the -omagic command line switch. Is it setting
181 the output file name to "magic" or is it setting the NMAGIC flag on
182 the output ? It has been decided that it is setting the output file
183 name, and that if you want to set the NMAGIC flag you should use -N
186 /* Don't mention this option in --help output. */
191 static const struct ld_option ld_options
[] =
193 { {NULL
, required_argument
, NULL
, '\0'},
194 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
196 { {"architecture", required_argument
, NULL
, 'A'},
197 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
198 { {"format", required_argument
, NULL
, 'b'},
199 'b', N_("TARGET"), N_("Specify target for following input files"),
201 { {"mri-script", required_argument
, NULL
, 'c'},
202 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
203 { {"dc", no_argument
, NULL
, 'd'},
204 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
205 { {"dp", no_argument
, NULL
, 'd'},
206 '\0', NULL
, NULL
, ONE_DASH
},
207 { {"entry", required_argument
, NULL
, 'e'},
208 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
209 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
210 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
211 { {"EB", no_argument
, NULL
, OPTION_EB
},
212 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
213 { {"EL", no_argument
, NULL
, OPTION_EL
},
214 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
215 { {"auxiliary", required_argument
, NULL
, 'f'},
216 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
218 { {"filter", required_argument
, NULL
, 'F'},
219 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
221 { {NULL
, no_argument
, NULL
, '\0'},
222 'g', NULL
, N_("Ignored"), ONE_DASH
},
223 { {"gpsize", required_argument
, NULL
, 'G'},
224 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
226 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
227 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
228 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
229 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
231 { {"library", required_argument
, NULL
, 'l'},
232 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
233 { {"library-path", required_argument
, NULL
, 'L'},
234 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
236 { {NULL
, required_argument
, NULL
, '\0'},
237 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
238 { {"print-map", no_argument
, NULL
, 'M'},
239 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
240 { {"nmagic", no_argument
, NULL
, 'n'},
241 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
242 { {"omagic", no_argument
, NULL
, 'N'},
243 'N', NULL
, N_("Do not page align data, do not make text readonly"),
244 EXACTLY_TWO_DASHES
},
245 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
246 '\0', NULL
, N_("Page align data, make text readonly"),
247 EXACTLY_TWO_DASHES
},
248 { {"output", required_argument
, NULL
, 'o'},
249 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
250 { {NULL
, required_argument
, NULL
, '\0'},
251 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
252 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
253 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
254 { {"emit-relocs", no_argument
, NULL
, 'q'},
255 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
256 { {"relocatable", no_argument
, NULL
, 'r'},
257 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
258 { {NULL
, no_argument
, NULL
, '\0'},
259 'i', NULL
, NULL
, ONE_DASH
},
260 { {"just-symbols", required_argument
, NULL
, 'R'},
261 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
263 { {"strip-all", no_argument
, NULL
, 's'},
264 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
265 { {"strip-debug", no_argument
, NULL
, 'S'},
266 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
267 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
268 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
269 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
270 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
271 { {"trace", no_argument
, NULL
, 't'},
272 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
273 { {"script", required_argument
, NULL
, 'T'},
274 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
275 { {"undefined", required_argument
, NULL
, 'u'},
276 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
278 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
279 '\0', N_("[=SECTION]"),
280 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
281 { {"Ur", no_argument
, NULL
, OPTION_UR
},
282 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
283 { {"version", no_argument
, NULL
, OPTION_VERSION
},
284 'v', NULL
, N_("Print version information"), TWO_DASHES
},
285 { {NULL
, no_argument
, NULL
, '\0'},
286 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
287 { {"discard-all", no_argument
, NULL
, 'x'},
288 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
289 { {"discard-locals", no_argument
, NULL
, 'X'},
290 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
291 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
292 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
293 { {"trace-symbol", required_argument
, NULL
, 'y'},
294 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
295 { {NULL
, required_argument
, NULL
, '\0'},
296 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
298 { {"start-group", no_argument
, NULL
, '('},
299 '(', NULL
, N_("Start a group"), TWO_DASHES
},
300 { {"end-group", no_argument
, NULL
, ')'},
301 ')', NULL
, N_("End a group"), TWO_DASHES
},
302 { {"accept-unknown-input-arch", no_argument
, NULL
,
303 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
305 N_("Accept input files whose architecture cannot be determined"),
307 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
308 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
309 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
311 { {"add-needed", no_argument
, NULL
, OPTION_ADD_NEEDED
},
312 '\0', NULL
, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
313 "\t\t\t\tfollowing dynamic libs"), TWO_DASHES
},
314 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_NEEDED
},
315 '\0', NULL
, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
316 "\t\t\t\tin following dynamic libs"), TWO_DASHES
},
317 { {"as-needed", no_argument
, NULL
, OPTION_AS_NEEDED
},
318 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
320 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_AS_NEEDED
},
321 '\0', NULL
, N_("Always set DT_NEEDED for following dynamic libs"),
323 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
324 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
325 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
326 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
327 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
328 '\0', NULL
, NULL
, ONE_DASH
},
329 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
330 '\0', NULL
, NULL
, ONE_DASH
},
331 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
332 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
333 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
334 '\0', NULL
, NULL
, ONE_DASH
},
335 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
336 '\0', NULL
, NULL
, ONE_DASH
},
337 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
338 '\0', NULL
, NULL
, ONE_DASH
},
339 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
340 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
341 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
342 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
344 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
345 '\0', NULL
, N_("Do not check section addresses for overlaps"),
347 { {"cref", no_argument
, NULL
, OPTION_CREF
},
348 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
349 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
350 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
351 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
352 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
354 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
355 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
356 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
357 '\0', NULL
, N_("Treat warnings as errors"),
359 { {"fini", required_argument
, NULL
, OPTION_FINI
},
360 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
361 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
362 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
363 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
364 '\0', NULL
, N_("Remove unused sections (on some targets)"),
366 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
367 '\0', NULL
, N_("Don't remove unused sections (default)"),
369 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
370 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
372 { {"help", no_argument
, NULL
, OPTION_HELP
},
373 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
374 { {"init", required_argument
, NULL
, OPTION_INIT
},
375 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
376 { {"Map", required_argument
, NULL
, OPTION_MAP
},
377 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
378 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
379 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
380 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
381 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
382 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
383 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
384 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
385 '\0', NULL
, N_("Do not allow unresolved references in object files"),
387 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
388 '\0', NULL
, N_("Allow unresolved references in shared libaries"),
390 { {"no-allow-shlib-undefined", no_argument
, NULL
,
391 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
392 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
394 { {"allow-multiple-definition", no_argument
, NULL
,
395 OPTION_ALLOW_MULTIPLE_DEFINITION
},
396 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
397 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
398 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
399 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
400 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
401 { {"default-imported-symver", no_argument
, NULL
,
402 OPTION_DEFAULT_IMPORTED_SYMVER
},
403 '\0', NULL
, N_("Create default symbol version for imported symbols"),
405 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
406 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
407 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
408 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
409 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
410 '\0', NULL
, N_("Create an output file even if errors occur"),
412 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
413 '\0', NULL
, NULL
, NO_HELP
},
414 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
415 '\0', NULL
, N_("Only use library directories specified on\n"
416 "\t\t\t\tthe command line"), ONE_DASH
},
417 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
418 '\0', N_("TARGET"), N_("Specify target of output file"),
419 EXACTLY_TWO_DASHES
},
420 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
421 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
422 { {"reduce-memory-overheads", no_argument
, NULL
,
423 OPTION_REDUCE_MEMORY_OVERHEADS
},
424 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
426 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
427 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
428 { {"retain-symbols-file", required_argument
, NULL
,
429 OPTION_RETAIN_SYMBOLS_FILE
},
430 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
431 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
432 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
433 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
434 '\0', N_("PATH"), N_("Set link time shared library search path"),
436 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
437 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
438 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
439 '\0', NULL
, NULL
, ONE_DASH
},
440 { {"pie", no_argument
, NULL
, OPTION_PIE
},
441 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
442 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
443 '\0', NULL
, NULL
, TWO_DASHES
},
444 { {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
445 '\0', NULL
, N_("Sort common symbols by size"), TWO_DASHES
},
446 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
447 '\0', NULL
, NULL
, NO_HELP
},
448 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
449 '\0', N_("name|alignment"),
450 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
451 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
452 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
454 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
455 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
457 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
458 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
460 { {"stats", no_argument
, NULL
, OPTION_STATS
},
461 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
462 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
463 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
464 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
465 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
466 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
467 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
468 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
469 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
471 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
472 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
473 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
474 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
475 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
476 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
477 { {"unresolved-symbols=<method>", required_argument
, NULL
,
478 OPTION_UNRESOLVED_SYMBOLS
},
479 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
480 "\t\t\t\tignore-all, report-all, ignore-in-object-files,\n"
481 "\t\t\t\tignore-in-shared-libs"), TWO_DASHES
},
482 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
483 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
484 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
485 '\0', NULL
, NULL
, NO_HELP
},
486 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
487 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
488 { {"version-exports-section", required_argument
, NULL
,
489 OPTION_VERSION_EXPORTS_SECTION
},
490 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
491 "\t\t\t\tSYMBOL as the version."), TWO_DASHES
},
492 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
493 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
494 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
495 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
497 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
498 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
499 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
500 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
501 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
502 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
504 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
505 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
507 { {"warn-unresolved-symbols", no_argument
, NULL
,
508 OPTION_WARN_UNRESOLVED_SYMBOLS
},
509 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
510 { {"error-unresolved-symbols", no_argument
, NULL
,
511 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
512 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
513 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
514 '\0', NULL
, N_("Include all objects from following archives"),
516 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
517 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
520 #define OPTION_COUNT ARRAY_SIZE (ld_options)
523 parse_args (unsigned argc
, char **argv
)
528 char *default_dirlist
= NULL
;
530 struct option
*longopts
;
531 struct option
*really_longopts
;
533 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
535 shortopts
= xmalloc (OPTION_COUNT
* 3 + 2);
536 longopts
= xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
537 really_longopts
= xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
539 /* Starting the short option string with '-' is for programs that
540 expect options and other ARGV-elements in any order and that care about
541 the ordering of the two. We describe each non-option ARGV-element
542 as if it were the argument of an option with character code 1. */
547 for (i
= 0; i
< OPTION_COUNT
; i
++)
549 if (ld_options
[i
].shortopt
!= '\0')
551 shortopts
[is
] = ld_options
[i
].shortopt
;
553 if (ld_options
[i
].opt
.has_arg
== required_argument
554 || ld_options
[i
].opt
.has_arg
== optional_argument
)
558 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
565 if (ld_options
[i
].opt
.name
!= NULL
)
567 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
569 really_longopts
[irl
] = ld_options
[i
].opt
;
574 longopts
[il
] = ld_options
[i
].opt
;
579 shortopts
[is
] = '\0';
580 longopts
[il
].name
= NULL
;
581 really_longopts
[irl
].name
= NULL
;
583 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
585 /* The -G option is ambiguous on different platforms. Sometimes it
586 specifies the largest data size to put into the small data
587 section. Sometimes it is equivalent to --shared. Unfortunately,
588 the first form takes an argument, while the second does not.
590 We need to permit the --shared form because on some platforms,
591 such as Solaris, gcc -shared will pass -G to the linker.
593 To permit either usage, we look through the argument list. If we
594 find -G not followed by a number, we change it into --shared.
595 This will work for most normal cases. */
596 for (i
= 1; i
< argc
; i
++)
597 if (strcmp (argv
[i
], "-G") == 0
599 || ! ISDIGIT (argv
[i
+ 1][0])))
600 argv
[i
] = (char *) "--shared";
602 /* Because we permit long options to start with a single dash, and
603 we have a --library option, and the -l option is conventionally
604 used with an immediately following argument, we can have bad
605 results if somebody tries to use -l with a library whose name
606 happens to start with "ibrary", as in -li. We avoid problems by
607 simply turning -l into --library. This means that users will
608 have to use two dashes in order to use --library, which is OK
609 since that's how it is documented.
611 FIXME: It's possible that this problem can arise for other short
612 options as well, although the user does always have the recourse
613 of adding a space between the option and the argument. */
614 for (i
= 1; i
< argc
; i
++)
616 if (argv
[i
][0] == '-'
618 && argv
[i
][2] != '\0')
622 n
= xmalloc (strlen (argv
[i
]) + 20);
623 sprintf (n
, "--library=%s", argv
[i
] + 2);
634 /* Using last_optind lets us avoid calling ldemul_parse_args
635 multiple times on a single option, which would lead to
636 confusion in the internal static variables maintained by
637 getopt. This could otherwise happen for an argument like
638 -nx, in which the -n is parsed as a single option, and we
639 loop around to pick up the -x. */
640 if (optind
!= last_optind
)
641 if (ldemul_parse_args (argc
, argv
))
644 /* getopt_long_only is like getopt_long, but '-' as well as '--'
645 can indicate a long option. */
647 last_optind
= optind
;
648 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
651 optind
= last_optind
;
652 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
655 if (ldemul_handle_option (optc
))
664 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
666 einfo (_("%P%F: use the --help option for usage information\n"));
668 case 1: /* File name. */
669 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
675 /* For HP/UX compatibility. Actually -a shared should mean
676 ``use only shared libraries'' but, then, we don't
677 currently support shared libraries on HP/UX anyhow. */
678 if (strcmp (optarg
, "archive") == 0)
679 config
.dynamic_link
= FALSE
;
680 else if (strcmp (optarg
, "shared") == 0
681 || strcmp (optarg
, "default") == 0)
682 config
.dynamic_link
= TRUE
;
684 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
687 /* FIXME: We just ignore these, but we should handle them. */
688 if (strcmp (optarg
, "definitions") == 0)
690 else if (strcmp (optarg
, "nodefinitions") == 0)
692 else if (strcmp (optarg
, "nosymbolic") == 0)
694 else if (strcmp (optarg
, "pure-text") == 0)
697 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
700 ldfile_add_arch (optarg
);
703 lang_add_target (optarg
);
706 ldfile_open_command_file (optarg
);
707 parser_input
= input_mri_script
;
710 case OPTION_CALL_SHARED
:
711 config
.dynamic_link
= TRUE
;
713 case OPTION_NON_SHARED
:
714 config
.dynamic_link
= FALSE
;
717 command_line
.cref
= TRUE
;
718 link_info
.notice_all
= TRUE
;
721 command_line
.force_common_definition
= TRUE
;
725 lex_redirect (optarg
);
726 parser_input
= input_defsym
;
732 case OPTION_DEMANGLE
:
736 enum demangling_styles style
;
738 style
= cplus_demangle_name_to_style (optarg
);
739 if (style
== unknown_demangling
)
740 einfo (_("%F%P: unknown demangling style `%s'"),
743 cplus_demangle_set_style (style
);
746 case 'I': /* Used on Solaris. */
747 case OPTION_DYNAMIC_LINKER
:
748 command_line
.interpreter
= optarg
;
751 command_line
.endian
= ENDIAN_BIG
;
754 command_line
.endian
= ENDIAN_LITTLE
;
756 case OPTION_EMBEDDED_RELOCS
:
757 command_line
.embedded_relocs
= TRUE
;
759 case OPTION_EXPORT_DYNAMIC
:
760 case 'E': /* HP/UX compatibility. */
761 link_info
.export_dynamic
= TRUE
;
764 lang_add_entry (optarg
, TRUE
);
767 if (command_line
.auxiliary_filters
== NULL
)
769 command_line
.auxiliary_filters
= xmalloc (2 * sizeof (char *));
770 command_line
.auxiliary_filters
[0] = optarg
;
771 command_line
.auxiliary_filters
[1] = NULL
;
779 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
781 command_line
.auxiliary_filters
782 = xrealloc (command_line
.auxiliary_filters
,
783 (c
+ 2) * sizeof (char *));
784 command_line
.auxiliary_filters
[c
] = optarg
;
785 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
789 command_line
.filter_shlib
= optarg
;
791 case OPTION_FORCE_EXE_SUFFIX
:
792 command_line
.force_exe_suffix
= TRUE
;
797 g_switch_value
= strtoul (optarg
, &end
, 0);
799 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
805 case OPTION_GC_SECTIONS
:
806 command_line
.gc_sections
= TRUE
;
813 ldfile_add_library_path (optarg
, TRUE
);
816 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
819 config
.map_filename
= "-";
822 /* Ignore. Was handled in a pre-parse. */
825 config
.map_filename
= optarg
;
828 config
.text_read_only
= FALSE
;
829 config
.magic_demand_paged
= FALSE
;
830 config
.dynamic_link
= FALSE
;
832 case OPTION_NO_OMAGIC
:
833 config
.text_read_only
= TRUE
;
834 config
.magic_demand_paged
= TRUE
;
835 /* NB/ Does not set dynamic_link to TRUE.
836 Use --call-shared or -Bdynamic for this. */
839 config
.magic_demand_paged
= FALSE
;
840 config
.dynamic_link
= FALSE
;
842 case OPTION_NO_DEFINE_COMMON
:
843 command_line
.inhibit_common_definition
= TRUE
;
845 case OPTION_NO_DEMANGLE
:
848 case OPTION_NO_GC_SECTIONS
:
849 command_line
.gc_sections
= FALSE
;
851 case OPTION_NO_KEEP_MEMORY
:
852 link_info
.keep_memory
= FALSE
;
854 case OPTION_NO_UNDEFINED
:
855 link_info
.unresolved_syms_in_objects
856 = how_to_report_unresolved_symbols
;
858 case OPTION_ALLOW_SHLIB_UNDEFINED
:
859 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
861 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
862 link_info
.unresolved_syms_in_shared_libs
863 = how_to_report_unresolved_symbols
;
865 case OPTION_UNRESOLVED_SYMBOLS
:
866 if (strcmp (optarg
, "ignore-all") == 0)
868 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
869 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
871 else if (strcmp (optarg
, "report-all") == 0)
873 link_info
.unresolved_syms_in_objects
874 = how_to_report_unresolved_symbols
;
875 link_info
.unresolved_syms_in_shared_libs
876 = how_to_report_unresolved_symbols
;
878 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
880 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
881 link_info
.unresolved_syms_in_shared_libs
882 = how_to_report_unresolved_symbols
;
884 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
886 link_info
.unresolved_syms_in_objects
887 = how_to_report_unresolved_symbols
;
888 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
891 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
893 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
894 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
895 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
896 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
897 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
898 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
901 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
902 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
903 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
904 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
905 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
906 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
908 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
909 link_info
.allow_multiple_definition
= TRUE
;
911 case OPTION_NO_UNDEFINED_VERSION
:
912 link_info
.allow_undefined_version
= FALSE
;
914 case OPTION_DEFAULT_SYMVER
:
915 link_info
.create_default_symver
= TRUE
;
917 case OPTION_DEFAULT_IMPORTED_SYMVER
:
918 link_info
.default_imported_symver
= TRUE
;
920 case OPTION_NO_WARN_MISMATCH
:
921 command_line
.warn_mismatch
= FALSE
;
923 case OPTION_NOINHIBIT_EXEC
:
924 force_make_executable
= TRUE
;
926 case OPTION_NOSTDLIB
:
927 config
.only_cmd_line_lib_dirs
= TRUE
;
929 case OPTION_NO_WHOLE_ARCHIVE
:
930 whole_archive
= FALSE
;
933 /* FIXME "-O<non-digits> <value>" used to set the address of
934 section <non-digits>. Was this for compatibility with
935 something, or can we create a new option to do that
936 (with a syntax similar to -defsym)?
937 getopt can't handle two args to an option without kludges. */
939 /* Enable optimizations of output files. */
940 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
943 lang_add_output (optarg
, 0);
946 lang_add_output_format (optarg
, NULL
, NULL
, 0);
949 link_info
.emitrelocations
= TRUE
;
953 if (optind
== last_optind
)
954 /* This can happen if the user put "-rpath,a" on the command
955 line. (Or something similar. The comma is important).
956 Getopt becomes confused and thinks that this is a -r option
957 but it cannot parse the text after the -r so it refuses to
958 increment the optind counter. Detect this case and issue
959 an error message here. We cannot just make this a warning,
960 increment optind, and continue because getopt is too confused
961 and will seg-fault the next time around. */
962 einfo(_("%P%F: bad -rpath option\n"));
964 link_info
.relocatable
= TRUE
;
965 config
.build_constructors
= FALSE
;
966 config
.magic_demand_paged
= FALSE
;
967 config
.text_read_only
= FALSE
;
968 config
.dynamic_link
= FALSE
;
971 /* The GNU linker traditionally uses -R to mean to include
972 only the symbols from a file. The Solaris linker uses -R
973 to set the path used by the runtime linker to find
974 libraries. This is the GNU linker -rpath argument. We
975 try to support both simultaneously by checking the file
976 named. If it is a directory, rather than a regular file,
977 we assume -rpath was meant. */
981 if (stat (optarg
, &s
) >= 0
982 && ! S_ISDIR (s
.st_mode
))
984 lang_add_input_file (optarg
,
985 lang_input_file_is_symbols_only_enum
,
992 if (command_line
.rpath
== NULL
)
993 command_line
.rpath
= xstrdup (optarg
);
996 size_t rpath_len
= strlen (command_line
.rpath
);
997 size_t optarg_len
= strlen (optarg
);
999 char *cp
= command_line
.rpath
;
1001 /* First see whether OPTARG is already in the path. */
1006 while (optarg
[idx
] != '\0' && optarg
[idx
] == cp
[idx
])
1008 if (optarg
[idx
] == '\0'
1009 && (cp
[idx
] == '\0' || cp
[idx
] == ':'))
1013 /* Not yet found. */
1014 cp
= strchr (cp
, ':');
1022 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
1023 sprintf (buf
, "%s:%s", command_line
.rpath
, optarg
);
1024 free (command_line
.rpath
);
1025 command_line
.rpath
= buf
;
1029 case OPTION_RPATH_LINK
:
1030 if (command_line
.rpath_link
== NULL
)
1031 command_line
.rpath_link
= xstrdup (optarg
);
1036 buf
= xmalloc (strlen (command_line
.rpath_link
)
1039 sprintf (buf
, "%s:%s", command_line
.rpath_link
, optarg
);
1040 free (command_line
.rpath_link
);
1041 command_line
.rpath_link
= buf
;
1045 command_line
.relax
= TRUE
;
1047 case OPTION_RETAIN_SYMBOLS_FILE
:
1048 add_keepsyms_file (optarg
);
1051 link_info
.strip
= strip_debugger
;
1054 link_info
.strip
= strip_all
;
1056 case OPTION_STRIP_DISCARDED
:
1057 link_info
.strip_discarded
= TRUE
;
1059 case OPTION_NO_STRIP_DISCARDED
:
1060 link_info
.strip_discarded
= FALSE
;
1063 if (config
.has_shared
)
1065 link_info
.shared
= TRUE
;
1066 /* When creating a shared library, the default
1067 behaviour is to ignore any unresolved references. */
1068 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1069 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1070 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1071 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1074 einfo (_("%P%F: -shared not supported\n"));
1077 if (config
.has_shared
)
1079 link_info
.shared
= TRUE
;
1080 link_info
.pie
= TRUE
;
1083 einfo (_("%P%F: -pie not supported\n"));
1085 case 'h': /* Used on Solaris. */
1087 command_line
.soname
= optarg
;
1089 case OPTION_SORT_COMMON
:
1090 config
.sort_common
= TRUE
;
1092 case OPTION_SORT_SECTION
:
1093 if (strcmp (optarg
, N_("name")) == 0)
1094 sort_section
= by_name
;
1095 else if (strcmp (optarg
, N_("alignment")) == 0)
1096 sort_section
= by_alignment
;
1098 einfo (_("%P%F: invalid section sorting option: %s\n"),
1102 config
.stats
= TRUE
;
1104 case OPTION_SYMBOLIC
:
1105 link_info
.symbolic
= TRUE
;
1111 ldfile_open_command_file (optarg
);
1112 parser_input
= input_script
;
1115 case OPTION_SECTION_START
:
1121 /* Check for <something>=<somthing>... */
1122 optarg2
= strchr (optarg
, '=');
1123 if (optarg2
== NULL
)
1124 einfo (_("%P%F: invalid argument to option"
1125 " \"--section-start\"\n"));
1129 /* So far so good. Are all the args present? */
1130 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1131 einfo (_("%P%F: missing argument(s) to option"
1132 " \"--section-start\"\n"));
1134 /* We must copy the section name as set_section_start
1135 doesn't do it for us. */
1136 len
= optarg2
- optarg
;
1137 sec_name
= xmalloc (len
);
1138 memcpy (sec_name
, optarg
, len
- 1);
1139 sec_name
[len
- 1] = 0;
1141 /* Then set it... */
1142 set_section_start (sec_name
, optarg2
);
1145 case OPTION_TARGET_HELP
:
1146 /* Mention any target specific options. */
1147 ldemul_list_emulation_options (stdout
);
1150 set_segment_start (".bss", optarg
);
1153 set_segment_start (".data", optarg
);
1156 set_segment_start (".text", optarg
);
1158 case OPTION_TRADITIONAL_FORMAT
:
1159 link_info
.traditional_format
= TRUE
;
1161 case OPTION_TASK_LINK
:
1162 link_info
.task_link
= TRUE
;
1163 /* Fall through - do an implied -r option. */
1165 link_info
.relocatable
= TRUE
;
1166 config
.build_constructors
= TRUE
;
1167 config
.magic_demand_paged
= FALSE
;
1168 config
.text_read_only
= FALSE
;
1169 config
.dynamic_link
= FALSE
;
1172 ldlang_add_undef (optarg
);
1176 lang_add_unique (optarg
);
1178 config
.unique_orphan_sections
= TRUE
;
1180 case OPTION_VERBOSE
:
1182 version_printed
= TRUE
;
1183 trace_file_tries
= TRUE
;
1184 overflow_cutoff_limit
= -2;
1188 version_printed
= TRUE
;
1192 version_printed
= TRUE
;
1194 case OPTION_VERSION
:
1198 case OPTION_VERSION_SCRIPT
:
1199 /* This option indicates a small script that only specifies
1200 version information. Read it, but don't assume that
1201 we've seen a linker script. */
1203 FILE *hold_script_handle
;
1205 hold_script_handle
= saved_script_handle
;
1206 ldfile_open_command_file (optarg
);
1207 saved_script_handle
= hold_script_handle
;
1208 parser_input
= input_version_script
;
1212 case OPTION_VERSION_EXPORTS_SECTION
:
1213 /* This option records a version symbol to be applied to the
1214 symbols listed for export to be found in the object files
1215 .exports sections. */
1216 command_line
.version_exports_section
= optarg
;
1218 case OPTION_WARN_COMMON
:
1219 config
.warn_common
= TRUE
;
1221 case OPTION_WARN_CONSTRUCTORS
:
1222 config
.warn_constructors
= TRUE
;
1224 case OPTION_WARN_FATAL
:
1225 config
.fatal_warnings
= TRUE
;
1227 case OPTION_WARN_MULTIPLE_GP
:
1228 config
.warn_multiple_gp
= TRUE
;
1230 case OPTION_WARN_ONCE
:
1231 config
.warn_once
= TRUE
;
1233 case OPTION_WARN_SECTION_ALIGN
:
1234 config
.warn_section_align
= TRUE
;
1236 case OPTION_WARN_SHARED_TEXTREL
:
1237 link_info
.warn_shared_textrel
= TRUE
;
1239 case OPTION_WHOLE_ARCHIVE
:
1240 whole_archive
= TRUE
;
1242 case OPTION_ADD_NEEDED
:
1245 case OPTION_NO_ADD_NEEDED
:
1248 case OPTION_AS_NEEDED
:
1251 case OPTION_NO_AS_NEEDED
:
1257 case OPTION_DISCARD_NONE
:
1258 link_info
.discard
= discard_none
;
1261 link_info
.discard
= discard_l
;
1264 link_info
.discard
= discard_all
;
1267 if (strncmp (optarg
, "P,", 2) == 0)
1269 if (default_dirlist
!= NULL
)
1270 free (default_dirlist
);
1271 default_dirlist
= xstrdup (optarg
);
1276 case OPTION_SPARE_DYNAMIC_TAGS
:
1277 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1279 case OPTION_SPLIT_BY_RELOC
:
1281 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1283 config
.split_by_reloc
= 32768;
1285 case OPTION_SPLIT_BY_FILE
:
1287 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1289 config
.split_by_file
= 1;
1291 case OPTION_CHECK_SECTIONS
:
1292 command_line
.check_section_addresses
= TRUE
;
1294 case OPTION_NO_CHECK_SECTIONS
:
1295 command_line
.check_section_addresses
= FALSE
;
1297 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1298 command_line
.accept_unknown_input_arch
= TRUE
;
1300 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1301 command_line
.accept_unknown_input_arch
= FALSE
;
1305 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1307 lang_enter_group ();
1312 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1314 lang_leave_group ();
1319 link_info
.init_function
= optarg
;
1323 link_info
.fini_function
= optarg
;
1326 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1327 command_line
.reduce_memory_overheads
= TRUE
;
1328 if (config
.hash_table_size
== 0)
1329 config
.hash_table_size
= 1021;
1332 case OPTION_HASH_SIZE
:
1334 bfd_size_type new_size
;
1336 new_size
= strtoul (optarg
, NULL
, 0);
1338 config
.hash_table_size
= new_size
;
1340 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1347 lang_leave_group ();
1349 if (default_dirlist
!= NULL
)
1351 set_default_dirlist (default_dirlist
);
1352 free (default_dirlist
);
1355 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1356 /* FIXME: Should we allow emulations a chance to set this ? */
1357 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1359 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1360 /* FIXME: Should we allow emulations a chance to set this ? */
1361 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1364 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1365 library search path. */
1368 set_default_dirlist (char *dirlist_ptr
)
1374 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1377 if (*dirlist_ptr
!= '\0')
1378 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1381 dirlist_ptr
= p
+ 1;
1386 set_section_start (char *sect
, char *valstr
)
1389 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1391 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1392 lang_section_start (sect
, exp_intop (val
), NULL
);
1396 set_segment_start (const char *section
, char *valstr
)
1402 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1404 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1405 /* If we already have an entry for this segment, update the existing
1408 for (seg
= segments
; seg
; seg
= seg
->next
)
1409 if (strcmp (seg
->name
, name
) == 0)
1414 /* There was no existing value so we must create a new segment
1416 seg
= stat_alloc (sizeof (*seg
));
1420 /* Add it to the linked list of segments. */
1421 seg
->next
= segments
;
1423 /* Historically, -Ttext and friends set the base address of a
1424 particular section. For backwards compatibility, we still do
1425 that. If a SEGMENT_START directive is seen, the section address
1426 assignment will be disabled. */
1427 lang_section_start (section
, exp_intop (val
), seg
);
1431 /* Print help messages for the options. */
1437 const char **targets
, **pp
;
1439 printf (_("Usage: %s [options] file...\n"), program_name
);
1441 printf (_("Options:\n"));
1442 for (i
= 0; i
< OPTION_COUNT
; i
++)
1444 if (ld_options
[i
].doc
!= NULL
)
1458 if (ld_options
[j
].shortopt
!= '\0'
1459 && ld_options
[j
].control
!= NO_HELP
)
1461 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1462 len
+= (comma
? 2 : 0) + 2;
1463 if (ld_options
[j
].arg
!= NULL
)
1465 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1470 printf ("%s", _(ld_options
[j
].arg
));
1471 len
+= strlen (_(ld_options
[j
].arg
));
1477 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1482 if (ld_options
[j
].opt
.name
!= NULL
1483 && ld_options
[j
].control
!= NO_HELP
)
1486 (ld_options
[j
].control
== TWO_DASHES
1487 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1491 two_dashes
? "-" : "",
1492 ld_options
[j
].opt
.name
);
1493 len
+= ((comma
? 2 : 0)
1495 + (two_dashes
? 1 : 0)
1496 + strlen (ld_options
[j
].opt
.name
));
1497 if (ld_options
[j
].arg
!= NULL
)
1499 printf (" %s", _(ld_options
[j
].arg
));
1500 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1506 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1514 for (; len
< 30; len
++)
1517 printf ("%s\n", _(ld_options
[i
].doc
));
1521 /* Note: Various tools (such as libtool) depend upon the
1522 format of the listings below - do not change them. */
1523 /* xgettext:c-format */
1524 printf (_("%s: supported targets:"), program_name
);
1525 targets
= bfd_target_list ();
1526 for (pp
= targets
; *pp
!= NULL
; pp
++)
1527 printf (" %s", *pp
);
1531 /* xgettext:c-format */
1532 printf (_("%s: supported emulations: "), program_name
);
1533 ldemul_list_emulations (stdout
);
1536 /* xgettext:c-format */
1537 printf (_("%s: emulation specific options:\n"), program_name
);
1538 ldemul_list_emulation_options (stdout
);
1541 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);