1 /* Parse options for the GNU linker.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012
4 Free Software Foundation, Inc.
6 This file is part of the GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
26 #include "libiberty.h"
29 #include "safe-ctype.h"
45 #endif /* ENABLE_PLUGINS */
47 #ifndef PATH_SEPARATOR
48 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
49 #define PATH_SEPARATOR ';'
51 #define PATH_SEPARATOR ':'
55 /* Somewhere above, sys/stat.h got included . . . . */
56 #if !defined(S_ISDIR) && defined(S_IFDIR)
57 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
60 static void set_default_dirlist (char *);
61 static void set_section_start (char *, char *);
62 static void set_segment_start (const char *, char *);
63 static void help (void);
65 /* The long options. This structure is used for both the option
66 parsing and the help text. */
69 /* Use one dash before long option name. */
71 /* Use two dashes before long option name. */
73 /* Only accept two dashes before the long option name.
74 This is an overloading of the use of this enum, since originally it
75 was only intended to tell the --help display function how to display
76 the long option name. This feature was added in order to resolve
77 the confusion about the -omagic command line switch. Is it setting
78 the output file name to "magic" or is it setting the NMAGIC flag on
79 the output ? It has been decided that it is setting the output file
80 name, and that if you want to set the NMAGIC flag you should use -N
83 /* Don't mention this option in --help output. */
89 /* The long option information. */
91 /* The short option with the same meaning ('\0' if none). */
93 /* The name of the argument (NULL if none). */
95 /* The documentation string. If this is NULL, this is a synonym for
96 the previous option. */
98 enum control_enum control;
101 static const struct ld_option ld_options[] =
103 { {NULL, required_argument, NULL, '\0'},
104 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
106 { {"architecture", required_argument, NULL, 'A'},
107 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
108 { {"format", required_argument, NULL, 'b'},
109 'b', N_("TARGET"), N_("Specify target for following input files"),
111 { {"mri-script", required_argument, NULL, 'c'},
112 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
113 { {"dc", no_argument, NULL, 'd'},
114 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
115 { {"dp", no_argument, NULL, 'd'},
116 '\0', NULL, NULL, ONE_DASH },
117 { {"entry", required_argument, NULL, 'e'},
118 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
119 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
120 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
121 { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC},
122 '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES },
123 { {"EB", no_argument, NULL, OPTION_EB},
124 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
125 { {"EL", no_argument, NULL, OPTION_EL},
126 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
127 { {"auxiliary", required_argument, NULL, 'f'},
128 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
130 { {"filter", required_argument, NULL, 'F'},
131 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
133 { {NULL, no_argument, NULL, '\0'},
134 'g', NULL, N_("Ignored"), ONE_DASH },
135 { {"gpsize", required_argument, NULL, 'G'},
136 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
138 { {"soname", required_argument, NULL, OPTION_SONAME},
139 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
140 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
141 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
143 { {"library", required_argument, NULL, 'l'},
144 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
145 { {"library-path", required_argument, NULL, 'L'},
146 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
148 { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
149 '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
150 { {NULL, required_argument, NULL, '\0'},
151 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
152 { {"print-map", no_argument, NULL, 'M'},
153 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
154 { {"nmagic", no_argument, NULL, 'n'},
155 'n', NULL, N_("Do not page align data"), TWO_DASHES },
156 { {"omagic", no_argument, NULL, 'N'},
157 'N', NULL, N_("Do not page align data, do not make text readonly"),
158 EXACTLY_TWO_DASHES },
159 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
160 '\0', NULL, N_("Page align data, make text readonly"),
161 EXACTLY_TWO_DASHES },
162 { {"output", required_argument, NULL, 'o'},
163 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
164 { {NULL, required_argument, NULL, '\0'},
165 'O', NULL, N_("Optimize output file"), ONE_DASH },
166 #ifdef ENABLE_PLUGINS
167 { {"plugin", required_argument, NULL, OPTION_PLUGIN},
168 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
169 { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
170 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
171 { {"flto", optional_argument, NULL, OPTION_IGNORE},
172 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
174 { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
175 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
177 #endif /* ENABLE_PLUGINS */
178 { {"Qy", no_argument, NULL, OPTION_IGNORE},
179 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
180 { {"emit-relocs", no_argument, NULL, 'q'},
181 'q', NULL, "Generate relocations in final output", TWO_DASHES },
182 { {"relocatable", no_argument, NULL, 'r'},
183 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
184 { {NULL, no_argument, NULL, '\0'},
185 'i', NULL, NULL, ONE_DASH },
186 { {"just-symbols", required_argument, NULL, 'R'},
187 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
189 { {"strip-all", no_argument, NULL, 's'},
190 's', NULL, N_("Strip all symbols"), TWO_DASHES },
191 { {"strip-debug", no_argument, NULL, 'S'},
192 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
193 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
194 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
195 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
196 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
197 { {"trace", no_argument, NULL, 't'},
198 't', NULL, N_("Trace file opens"), TWO_DASHES },
199 { {"script", required_argument, NULL, 'T'},
200 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
201 { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
202 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
203 { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
204 '\0', NULL, NULL, ONE_DASH },
205 { {"undefined", required_argument, NULL, 'u'},
206 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
208 { {"unique", optional_argument, NULL, OPTION_UNIQUE},
209 '\0', N_("[=SECTION]"),
210 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
211 { {"Ur", no_argument, NULL, OPTION_UR},
212 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
213 { {"version", no_argument, NULL, OPTION_VERSION},
214 'v', NULL, N_("Print version information"), TWO_DASHES },
215 { {NULL, no_argument, NULL, '\0'},
216 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
217 { {"discard-all", no_argument, NULL, 'x'},
218 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
219 { {"discard-locals", no_argument, NULL, 'X'},
220 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
221 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
222 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
223 { {"trace-symbol", required_argument, NULL, 'y'},
224 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
225 { {NULL, required_argument, NULL, '\0'},
226 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
228 { {"start-group", no_argument, NULL, '('},
229 '(', NULL, N_("Start a group"), TWO_DASHES },
230 { {"end-group", no_argument, NULL, ')'},
231 ')', NULL, N_("End a group"), TWO_DASHES },
232 { {"accept-unknown-input-arch", no_argument, NULL,
233 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
235 N_("Accept input files whose architecture cannot be determined"),
237 { {"no-accept-unknown-input-arch", no_argument, NULL,
238 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
239 '\0', NULL, N_("Reject input files whose architecture is unknown"),
242 /* The next two options are deprecated because of their similarity to
243 --as-needed and --no-as-needed. They have been replaced by
244 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
245 { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
246 '\0', NULL, NULL, NO_HELP },
247 { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
248 '\0', NULL, NULL, NO_HELP },
250 { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
251 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
253 { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
254 '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
255 " the command line"),
257 { {"assert", required_argument, NULL, OPTION_ASSERT},
258 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
259 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
260 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
261 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
262 '\0', NULL, NULL, ONE_DASH },
263 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
264 '\0', NULL, NULL, ONE_DASH },
265 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
266 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
267 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
268 '\0', NULL, NULL, ONE_DASH },
269 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
270 '\0', NULL, NULL, ONE_DASH },
271 { {"static", no_argument, NULL, OPTION_NON_SHARED},
272 '\0', NULL, NULL, ONE_DASH },
273 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
274 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
275 { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
276 '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
277 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
278 '\0', NULL, N_("Check section addresses for overlaps (default)"),
280 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
281 '\0', NULL, N_("Do not check section addresses for overlaps"),
283 { {"copy-dt-needed-entries", no_argument, NULL,
284 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
285 '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
287 { {"no-copy-dt-needed-entries", no_argument, NULL,
288 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
289 '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
292 { {"cref", no_argument, NULL, OPTION_CREF},
293 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
294 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
295 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
296 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
297 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
299 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
300 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
301 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
302 '\0', NULL, N_("Treat warnings as errors"),
304 { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL},
305 '\0', NULL, N_("Do not treat warnings as errors (default)"),
307 { {"fini", required_argument, NULL, OPTION_FINI},
308 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
309 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
310 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
311 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
312 '\0', NULL, N_("Remove unused sections (on some targets)"),
314 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
315 '\0', NULL, N_("Don't remove unused sections (default)"),
317 { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
318 '\0', NULL, N_("List removed unused sections on stderr"),
320 { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
321 '\0', NULL, N_("Do not list removed unused sections"),
323 { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
324 '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
326 { {"help", no_argument, NULL, OPTION_HELP},
327 '\0', NULL, N_("Print option help"), TWO_DASHES },
328 { {"init", required_argument, NULL, OPTION_INIT},
329 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
330 { {"Map", required_argument, NULL, OPTION_MAP},
331 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH },
332 { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
333 '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
334 { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
335 '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
336 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
337 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
338 { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
339 '\0', NULL, N_("Do not allow unresolved references in object files"),
341 { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
342 '\0', NULL, N_("Allow unresolved references in shared libraries"),
344 { {"no-allow-shlib-undefined", no_argument, NULL,
345 OPTION_NO_ALLOW_SHLIB_UNDEFINED},
346 '\0', NULL, N_("Do not allow unresolved references in shared libs"),
348 { {"allow-multiple-definition", no_argument, NULL,
349 OPTION_ALLOW_MULTIPLE_DEFINITION},
350 '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
351 { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
352 '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
353 { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
354 '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
355 { {"default-imported-symver", no_argument, NULL,
356 OPTION_DEFAULT_IMPORTED_SYMVER},
357 '\0', NULL, N_("Create default symbol version for imported symbols"),
359 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
360 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
361 { {"no-warn-search-mismatch", no_argument, NULL,
362 OPTION_NO_WARN_SEARCH_MISMATCH},
363 '\0', NULL, N_("Don't warn on finding an incompatible library"),
365 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
366 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
367 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
368 '\0', NULL, N_("Create an output file even if errors occur"),
370 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
371 '\0', NULL, NULL, NO_HELP },
372 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
373 '\0', NULL, N_("Only use library directories specified on\n"
374 " the command line"),
376 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
377 '\0', N_("TARGET"), N_("Specify target of output file"),
378 EXACTLY_TWO_DASHES },
379 { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
380 '\0', NULL, N_("Print default output format"), TWO_DASHES },
381 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
382 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
383 { {"reduce-memory-overheads", no_argument, NULL,
384 OPTION_REDUCE_MEMORY_OVERHEADS},
385 '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
387 { {"relax", no_argument, NULL, OPTION_RELAX},
388 '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
389 { {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
390 '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES },
391 { {"retain-symbols-file", required_argument, NULL,
392 OPTION_RETAIN_SYMBOLS_FILE},
393 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
394 { {"rpath", required_argument, NULL, OPTION_RPATH},
395 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
396 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
397 '\0', N_("PATH"), N_("Set link time shared library search path"),
399 { {"shared", no_argument, NULL, OPTION_SHARED},
400 '\0', NULL, N_("Create a shared library"), ONE_DASH },
401 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
402 '\0', NULL, NULL, ONE_DASH },
403 { {"pie", no_argument, NULL, OPTION_PIE},
404 '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
405 { {"pic-executable", no_argument, NULL, OPTION_PIE},
406 '\0', NULL, NULL, TWO_DASHES },
407 { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
408 '\0', N_("[=ascending|descending]"),
409 N_("Sort common symbols by alignment [in specified order]"),
411 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
412 '\0', NULL, NULL, NO_HELP },
413 { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
414 '\0', N_("name|alignment"),
415 N_("Sort sections by name or maximum alignment"), TWO_DASHES },
416 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
417 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
419 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
420 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
422 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
423 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
425 { {"stats", no_argument, NULL, OPTION_STATS},
426 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
427 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
428 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
429 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
430 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
431 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
432 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
433 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
434 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
436 { {"Tbss", required_argument, NULL, OPTION_TBSS},
437 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
438 { {"Tdata", required_argument, NULL, OPTION_TDATA},
439 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
440 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
441 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
442 { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT},
443 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH },
444 { {"unresolved-symbols=<method>", required_argument, NULL,
445 OPTION_UNRESOLVED_SYMBOLS},
446 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n"
447 " ignore-all, report-all, ignore-in-object-files,\n"
448 " ignore-in-shared-libs"),
450 { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
451 '\0', N_("[=NUMBER]"),
452 N_("Output lots of information during link"), TWO_DASHES },
453 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
454 '\0', NULL, NULL, NO_HELP },
455 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
456 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
457 { {"version-exports-section", required_argument, NULL,
458 OPTION_VERSION_EXPORTS_SECTION },
459 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
460 " SYMBOL as the version."),
462 { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
463 '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
464 { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
465 '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
466 { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
467 '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
468 { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
469 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
470 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
471 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
472 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
473 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
475 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
476 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
477 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
478 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
479 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
480 '\0', NULL, N_("Warn if start of section changes due to alignment"),
482 { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
483 '\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
485 { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
486 '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
488 { {"warn-unresolved-symbols", no_argument, NULL,
489 OPTION_WARN_UNRESOLVED_SYMBOLS},
490 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
491 { {"error-unresolved-symbols", no_argument, NULL,
492 OPTION_ERROR_UNRESOLVED_SYMBOLS},
493 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
494 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
495 '\0', NULL, N_("Include all objects from following archives"),
497 { {"wrap", required_argument, NULL, OPTION_WRAP},
498 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
499 { {"ignore-unresolved-symbol", required_argument, NULL,
500 OPTION_IGNORE_UNRESOLVED_SYMBOL},
502 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
505 #define OPTION_COUNT ARRAY_SIZE (ld_options)
508 parse_args (unsigned argc, char **argv)
513 char *default_dirlist = NULL;
515 struct option *longopts;
516 struct option *really_longopts;
518 enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
520 shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
521 longopts = (struct option *)
522 xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
523 really_longopts = (struct option *)
524 malloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
526 /* Starting the short option string with '-' is for programs that
527 expect options and other ARGV-elements in any order and that care about
528 the ordering of the two. We describe each non-option ARGV-element
529 as if it were the argument of an option with character code 1. */
534 for (i = 0; i < OPTION_COUNT; i++)
536 if (ld_options[i].shortopt != '\0')
538 shortopts[is] = ld_options[i].shortopt;
540 if (ld_options[i].opt.has_arg == required_argument
541 || ld_options[i].opt.has_arg == optional_argument)
545 if (ld_options[i].opt.has_arg == optional_argument)
552 if (ld_options[i].opt.name != NULL)
554 if (ld_options[i].control == EXACTLY_TWO_DASHES)
556 really_longopts[irl] = ld_options[i].opt;
561 longopts[il] = ld_options[i].opt;
566 shortopts[is] = '\0';
567 longopts[il].name = NULL;
568 really_longopts[irl].name = NULL;
570 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
572 /* The -G option is ambiguous on different platforms. Sometimes it
573 specifies the largest data size to put into the small data
574 section. Sometimes it is equivalent to --shared. Unfortunately,
575 the first form takes an argument, while the second does not.
577 We need to permit the --shared form because on some platforms,
578 such as Solaris, gcc -shared will pass -G to the linker.
580 To permit either usage, we look through the argument list. If we
581 find -G not followed by a number, we change it into --shared.
582 This will work for most normal cases. */
583 for (i = 1; i < argc; i++)
584 if (strcmp (argv[i], "-G") == 0
586 || ! ISDIGIT (argv[i + 1][0])))
587 argv[i] = (char *) "--shared";
589 /* Because we permit long options to start with a single dash, and
590 we have a --library option, and the -l option is conventionally
591 used with an immediately following argument, we can have bad
592 results if somebody tries to use -l with a library whose name
593 happens to start with "ibrary", as in -li. We avoid problems by
594 simply turning -l into --library. This means that users will
595 have to use two dashes in order to use --library, which is OK
596 since that's how it is documented.
598 FIXME: It's possible that this problem can arise for other short
599 options as well, although the user does always have the recourse
600 of adding a space between the option and the argument. */
601 for (i = 1; i < argc; i++)
603 if (argv[i][0] == '-'
605 && argv[i][2] != '\0')
609 n = (char *) xmalloc (strlen (argv[i]) + 20);
610 sprintf (n, "--library=%s", argv[i] + 2);
620 static unsigned int defsym_count;
622 /* Using last_optind lets us avoid calling ldemul_parse_args
623 multiple times on a single option, which would lead to
624 confusion in the internal static variables maintained by
625 getopt. This could otherwise happen for an argument like
626 -nx, in which the -n is parsed as a single option, and we
627 loop around to pick up the -x. */
628 if (optind != last_optind)
629 if (ldemul_parse_args (argc, argv))
632 /* getopt_long_only is like getopt_long, but '-' as well as '--'
633 can indicate a long option. */
635 last_optind = optind;
636 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
639 optind = last_optind;
640 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
643 if (ldemul_handle_option (optc))
652 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
656 einfo (_("%P%F: use the --help option for usage information\n"));
658 case 1: /* File name. */
659 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
665 /* For HP/UX compatibility. Actually -a shared should mean
666 ``use only shared libraries'' but, then, we don't
667 currently support shared libraries on HP/UX anyhow. */
668 if (strcmp (optarg, "archive") == 0)
669 input_flags.dynamic = FALSE;
670 else if (strcmp (optarg, "shared") == 0
671 || strcmp (optarg, "default") == 0)
672 input_flags.dynamic = TRUE;
674 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
677 /* FIXME: We just ignore these, but we should handle them. */
678 if (strcmp (optarg, "definitions") == 0)
680 else if (strcmp (optarg, "nodefinitions") == 0)
682 else if (strcmp (optarg, "nosymbolic") == 0)
684 else if (strcmp (optarg, "pure-text") == 0)
687 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
690 ldfile_add_arch (optarg);
693 lang_add_target (optarg);
696 ldfile_open_command_file (optarg);
697 parser_input = input_mri_script;
700 case OPTION_CALL_SHARED:
701 input_flags.dynamic = TRUE;
703 case OPTION_NON_SHARED:
704 input_flags.dynamic = FALSE;
707 command_line.cref = TRUE;
708 link_info.notice_all = TRUE;
711 command_line.force_common_definition = TRUE;
715 lex_redirect (optarg, "--defsym", ++defsym_count);
716 parser_input = input_defsym;
720 case OPTION_DEMANGLE:
724 enum demangling_styles style;
726 style = cplus_demangle_name_to_style (optarg);
727 if (style == unknown_demangling)
728 einfo (_("%F%P: unknown demangling style `%s'\n"),
731 cplus_demangle_set_style (style);
734 case 'I': /* Used on Solaris. */
735 case OPTION_DYNAMIC_LINKER:
736 command_line.interpreter = optarg;
739 /* Already handled in ldmain.c. */
742 command_line.endian = ENDIAN_BIG;
745 command_line.endian = ENDIAN_LITTLE;
747 case OPTION_EMBEDDED_RELOCS:
748 command_line.embedded_relocs = TRUE;
750 case OPTION_EXPORT_DYNAMIC:
751 case 'E': /* HP/UX compatibility. */
752 link_info.export_dynamic = TRUE;
754 case OPTION_NO_EXPORT_DYNAMIC:
755 link_info.export_dynamic = FALSE;
758 lang_add_entry (optarg, TRUE);
761 if (command_line.auxiliary_filters == NULL)
763 command_line.auxiliary_filters = (char **)
764 xmalloc (2 * sizeof (char *));
765 command_line.auxiliary_filters[0] = optarg;
766 command_line.auxiliary_filters[1] = NULL;
774 for (p = command_line.auxiliary_filters; *p != NULL; p++)
776 command_line.auxiliary_filters = (char **)
777 xrealloc (command_line.auxiliary_filters,
778 (c + 2) * sizeof (char *));
779 command_line.auxiliary_filters[c] = optarg;
780 command_line.auxiliary_filters[c + 1] = NULL;
784 command_line.filter_shlib = optarg;
786 case OPTION_FORCE_EXE_SUFFIX:
787 command_line.force_exe_suffix = TRUE;
792 g_switch_value = strtoul (optarg, &end, 0);
794 einfo (_("%P%F: invalid number `%s'\n"), optarg);
800 case OPTION_GC_SECTIONS:
801 link_info.gc_sections = TRUE;
803 case OPTION_PRINT_GC_SECTIONS:
804 link_info.print_gc_sections = TRUE;
811 ldfile_add_library_path (optarg, TRUE);
814 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
817 config.map_filename = "-";
820 /* Ignore. Was handled in a pre-parse. */
823 config.map_filename = optarg;
826 config.text_read_only = FALSE;
827 config.magic_demand_paged = FALSE;
828 input_flags.dynamic = FALSE;
830 case OPTION_NO_OMAGIC:
831 config.text_read_only = TRUE;
832 config.magic_demand_paged = TRUE;
833 /* NB/ Does not set input_flags.dynamic to TRUE.
834 Use --call-shared or -Bdynamic for this. */
837 config.magic_demand_paged = FALSE;
838 input_flags.dynamic = FALSE;
840 case OPTION_NO_DEFINE_COMMON:
841 command_line.inhibit_common_definition = TRUE;
843 case OPTION_NO_DEMANGLE:
846 case OPTION_NO_GC_SECTIONS:
847 link_info.gc_sections = FALSE;
849 case OPTION_NO_PRINT_GC_SECTIONS:
850 link_info.print_gc_sections = FALSE;
852 case OPTION_NO_KEEP_MEMORY:
853 link_info.keep_memory = FALSE;
855 case OPTION_NO_UNDEFINED:
856 link_info.unresolved_syms_in_objects
857 = how_to_report_unresolved_symbols;
859 case OPTION_ALLOW_SHLIB_UNDEFINED:
860 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
862 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
863 link_info.unresolved_syms_in_shared_libs
864 = how_to_report_unresolved_symbols;
866 case OPTION_UNRESOLVED_SYMBOLS:
867 if (strcmp (optarg, "ignore-all") == 0)
869 link_info.unresolved_syms_in_objects = RM_IGNORE;
870 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
872 else if (strcmp (optarg, "report-all") == 0)
874 link_info.unresolved_syms_in_objects
875 = how_to_report_unresolved_symbols;
876 link_info.unresolved_syms_in_shared_libs
877 = how_to_report_unresolved_symbols;
879 else if (strcmp (optarg, "ignore-in-object-files") == 0)
881 link_info.unresolved_syms_in_objects = RM_IGNORE;
882 link_info.unresolved_syms_in_shared_libs
883 = how_to_report_unresolved_symbols;
885 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
887 link_info.unresolved_syms_in_objects
888 = how_to_report_unresolved_symbols;
889 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
892 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg);
894 case OPTION_WARN_UNRESOLVED_SYMBOLS:
895 how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
896 if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
897 link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
898 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
899 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
902 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
903 how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
904 if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
905 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
906 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
907 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
909 case OPTION_ALLOW_MULTIPLE_DEFINITION:
910 link_info.allow_multiple_definition = TRUE;
912 case OPTION_NO_UNDEFINED_VERSION:
913 link_info.allow_undefined_version = FALSE;
915 case OPTION_DEFAULT_SYMVER:
916 link_info.create_default_symver = TRUE;
918 case OPTION_DEFAULT_IMPORTED_SYMVER:
919 link_info.default_imported_symver = TRUE;
921 case OPTION_NO_WARN_MISMATCH:
922 command_line.warn_mismatch = FALSE;
924 case OPTION_NO_WARN_SEARCH_MISMATCH:
925 command_line.warn_search_mismatch = FALSE;
927 case OPTION_NOINHIBIT_EXEC:
928 force_make_executable = TRUE;
930 case OPTION_NOSTDLIB:
931 config.only_cmd_line_lib_dirs = TRUE;
933 case OPTION_NO_WHOLE_ARCHIVE:
934 input_flags.whole_archive = FALSE;
937 /* FIXME "-O<non-digits> <value>" used to set the address of
938 section <non-digits>. Was this for compatibility with
939 something, or can we create a new option to do that
940 (with a syntax similar to -defsym)?
941 getopt can't handle two args to an option without kludges. */
943 /* Enable optimizations of output files. */
944 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
947 lang_add_output (optarg, 0);
950 lang_add_output_format (optarg, NULL, NULL, 0);
952 case OPTION_PRINT_OUTPUT_FORMAT:
953 command_line.print_output_format = TRUE;
955 #ifdef ENABLE_PLUGINS
957 plugin_opt_plugin (optarg);
959 case OPTION_PLUGIN_OPT:
960 if (plugin_opt_plugin_arg (optarg))
961 einfo(_("%P%F: bad -plugin-opt option\n"));
963 #endif /* ENABLE_PLUGINS */
965 link_info.emitrelocations = TRUE;
969 if (optind == last_optind)
970 /* This can happen if the user put "-rpath,a" on the command
971 line. (Or something similar. The comma is important).
972 Getopt becomes confused and thinks that this is a -r option
973 but it cannot parse the text after the -r so it refuses to
974 increment the optind counter. Detect this case and issue
975 an error message here. We cannot just make this a warning,
976 increment optind, and continue because getopt is too confused
977 and will seg-fault the next time around. */
978 einfo(_("%P%F: bad -rpath option\n"));
980 link_info.relocatable = TRUE;
981 config.build_constructors = FALSE;
982 config.magic_demand_paged = FALSE;
983 config.text_read_only = FALSE;
984 input_flags.dynamic = FALSE;
987 /* The GNU linker traditionally uses -R to mean to include
988 only the symbols from a file. The Solaris linker uses -R
989 to set the path used by the runtime linker to find
990 libraries. This is the GNU linker -rpath argument. We
991 try to support both simultaneously by checking the file
992 named. If it is a directory, rather than a regular file,
993 we assume -rpath was meant. */
997 if (stat (optarg, &s) >= 0
998 && ! S_ISDIR (s.st_mode))
1000 lang_add_input_file (optarg,
1001 lang_input_file_is_symbols_only_enum,
1008 if (command_line.rpath == NULL)
1009 command_line.rpath = xstrdup (optarg);
1012 size_t rpath_len = strlen (command_line.rpath);
1013 size_t optarg_len = strlen (optarg);
1015 char *cp = command_line.rpath;
1017 /* First see whether OPTARG is already in the path. */
1020 if (strncmp (optarg, cp, optarg_len) == 0
1021 && (cp[optarg_len] == 0
1022 || cp[optarg_len] == config.rpath_separator))
1026 /* Not yet found. */
1027 cp = strchr (cp, config.rpath_separator);
1035 buf = (char *) xmalloc (rpath_len + optarg_len + 2);
1036 sprintf (buf, "%s%c%s", command_line.rpath,
1037 config.rpath_separator, optarg);
1038 free (command_line.rpath);
1039 command_line.rpath = buf;
1043 case OPTION_RPATH_LINK:
1044 if (command_line.rpath_link == NULL)
1045 command_line.rpath_link = xstrdup (optarg);
1050 buf = (char *) xmalloc (strlen (command_line.rpath_link)
1053 sprintf (buf, "%s%c%s", command_line.rpath_link,
1054 config.rpath_separator, optarg);
1055 free (command_line.rpath_link);
1056 command_line.rpath_link = buf;
1059 case OPTION_NO_RELAX:
1065 case OPTION_RETAIN_SYMBOLS_FILE:
1066 add_keepsyms_file (optarg);
1069 link_info.strip = strip_debugger;
1072 link_info.strip = strip_all;
1074 case OPTION_STRIP_DISCARDED:
1075 link_info.strip_discarded = TRUE;
1077 case OPTION_NO_STRIP_DISCARDED:
1078 link_info.strip_discarded = FALSE;
1081 if (config.has_shared)
1083 link_info.shared = TRUE;
1084 /* When creating a shared library, the default
1085 behaviour is to ignore any unresolved references. */
1086 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1087 link_info.unresolved_syms_in_objects = RM_IGNORE;
1088 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1089 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1092 einfo (_("%P%F: -shared not supported\n"));
1095 if (config.has_shared)
1097 link_info.shared = TRUE;
1098 link_info.pie = TRUE;
1101 einfo (_("%P%F: -pie not supported\n"));
1103 case 'h': /* Used on Solaris. */
1105 command_line.soname = optarg;
1107 case OPTION_SORT_COMMON:
1109 || strcmp (optarg, N_("descending")) == 0)
1110 config.sort_common = sort_descending;
1111 else if (strcmp (optarg, N_("ascending")) == 0)
1112 config.sort_common = sort_ascending;
1114 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1117 case OPTION_SORT_SECTION:
1118 if (strcmp (optarg, N_("name")) == 0)
1119 sort_section = by_name;
1120 else if (strcmp (optarg, N_("alignment")) == 0)
1121 sort_section = by_alignment;
1123 einfo (_("%P%F: invalid section sorting option: %s\n"),
1127 config.stats = TRUE;
1129 case OPTION_SYMBOLIC:
1130 command_line.symbolic = symbolic;
1132 case OPTION_SYMBOLIC_FUNCTIONS:
1133 command_line.symbolic = symbolic_functions;
1139 previous_script_handle = saved_script_handle;
1140 ldfile_open_command_file (optarg);
1141 parser_input = input_script;
1143 previous_script_handle = NULL;
1145 case OPTION_DEFAULT_SCRIPT:
1146 command_line.default_script = optarg;
1148 case OPTION_SECTION_START:
1154 /* Check for <something>=<somthing>... */
1155 optarg2 = strchr (optarg, '=');
1156 if (optarg2 == NULL)
1157 einfo (_("%P%F: invalid argument to option"
1158 " \"--section-start\"\n"));
1162 /* So far so good. Are all the args present? */
1163 if ((*optarg == '\0') || (*optarg2 == '\0'))
1164 einfo (_("%P%F: missing argument(s) to option"
1165 " \"--section-start\"\n"));
1167 /* We must copy the section name as set_section_start
1168 doesn't do it for us. */
1169 len = optarg2 - optarg;
1170 sec_name = (char *) xmalloc (len);
1171 memcpy (sec_name, optarg, len - 1);
1172 sec_name[len - 1] = 0;
1174 /* Then set it... */
1175 set_section_start (sec_name, optarg2);
1178 case OPTION_TARGET_HELP:
1179 /* Mention any target specific options. */
1180 ldemul_list_emulation_options (stdout);
1183 set_segment_start (".bss", optarg);
1186 set_segment_start (".data", optarg);
1189 set_segment_start (".text", optarg);
1191 case OPTION_TTEXT_SEGMENT:
1192 set_segment_start (".text-segment", optarg);
1194 case OPTION_TRADITIONAL_FORMAT:
1195 link_info.traditional_format = TRUE;
1197 case OPTION_TASK_LINK:
1198 link_info.task_link = TRUE;
1199 /* Fall through - do an implied -r option. */
1201 link_info.relocatable = TRUE;
1202 config.build_constructors = TRUE;
1203 config.magic_demand_paged = FALSE;
1204 config.text_read_only = FALSE;
1205 input_flags.dynamic = FALSE;
1208 ldlang_add_undef (optarg, TRUE);
1212 lang_add_unique (optarg);
1214 config.unique_orphan_sections = TRUE;
1216 case OPTION_VERBOSE:
1218 version_printed = TRUE;
1220 overflow_cutoff_limit = -2;
1224 int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
1226 einfo (_("%P%F: invalid number `%s'\n"), optarg);
1227 #ifdef ENABLE_PLUGINS
1228 report_plugin_symbols = level > 1;
1229 #endif /* ENABLE_PLUGINS */
1234 version_printed = TRUE;
1238 version_printed = TRUE;
1240 case OPTION_VERSION:
1244 case OPTION_VERSION_SCRIPT:
1245 /* This option indicates a small script that only specifies
1246 version information. Read it, but don't assume that
1247 we've seen a linker script. */
1249 FILE *hold_script_handle;
1251 hold_script_handle = saved_script_handle;
1252 ldfile_open_command_file (optarg);
1253 saved_script_handle = hold_script_handle;
1254 parser_input = input_version_script;
1258 case OPTION_VERSION_EXPORTS_SECTION:
1259 /* This option records a version symbol to be applied to the
1260 symbols listed for export to be found in the object files
1261 .exports sections. */
1262 command_line.version_exports_section = optarg;
1264 case OPTION_DYNAMIC_LIST_DATA:
1265 command_line.dynamic_list = dynamic_list_data;
1266 if (command_line.symbolic == symbolic)
1267 command_line.symbolic = symbolic_unset;
1269 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1270 lang_append_dynamic_list_cpp_typeinfo ();
1271 if (command_line.dynamic_list != dynamic_list_data)
1272 command_line.dynamic_list = dynamic_list;
1273 if (command_line.symbolic == symbolic)
1274 command_line.symbolic = symbolic_unset;
1276 case OPTION_DYNAMIC_LIST_CPP_NEW:
1277 lang_append_dynamic_list_cpp_new ();
1278 if (command_line.dynamic_list != dynamic_list_data)
1279 command_line.dynamic_list = dynamic_list;
1280 if (command_line.symbolic == symbolic)
1281 command_line.symbolic = symbolic_unset;
1283 case OPTION_DYNAMIC_LIST:
1284 /* This option indicates a small script that only specifies
1285 a dynamic list. Read it, but don't assume that we've
1286 seen a linker script. */
1288 FILE *hold_script_handle;
1290 hold_script_handle = saved_script_handle;
1291 ldfile_open_command_file (optarg);
1292 saved_script_handle = hold_script_handle;
1293 parser_input = input_dynamic_list;
1296 if (command_line.dynamic_list != dynamic_list_data)
1297 command_line.dynamic_list = dynamic_list;
1298 if (command_line.symbolic == symbolic)
1299 command_line.symbolic = symbolic_unset;
1301 case OPTION_WARN_COMMON:
1302 config.warn_common = TRUE;
1304 case OPTION_WARN_CONSTRUCTORS:
1305 config.warn_constructors = TRUE;
1307 case OPTION_WARN_FATAL:
1308 config.fatal_warnings = TRUE;
1310 case OPTION_NO_WARN_FATAL:
1311 config.fatal_warnings = FALSE;
1313 case OPTION_WARN_MULTIPLE_GP:
1314 config.warn_multiple_gp = TRUE;
1316 case OPTION_WARN_ONCE:
1317 config.warn_once = TRUE;
1319 case OPTION_WARN_SECTION_ALIGN:
1320 config.warn_section_align = TRUE;
1322 case OPTION_WARN_SHARED_TEXTREL:
1323 link_info.warn_shared_textrel = TRUE;
1325 case OPTION_WARN_ALTERNATE_EM:
1326 link_info.warn_alternate_em = TRUE;
1328 case OPTION_WHOLE_ARCHIVE:
1329 input_flags.whole_archive = TRUE;
1331 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
1332 input_flags.add_DT_NEEDED_for_dynamic = TRUE;
1334 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
1335 input_flags.add_DT_NEEDED_for_dynamic = FALSE;
1337 case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
1338 input_flags.add_DT_NEEDED_for_regular = TRUE;
1340 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
1341 input_flags.add_DT_NEEDED_for_regular = FALSE;
1346 case OPTION_IGNORE_UNRESOLVED_SYMBOL:
1347 add_ignoresym (&link_info, optarg);
1349 case OPTION_DISCARD_NONE:
1350 link_info.discard = discard_none;
1353 link_info.discard = discard_l;
1356 link_info.discard = discard_all;
1359 if (CONST_STRNEQ (optarg, "P,"))
1361 if (default_dirlist != NULL)
1362 free (default_dirlist);
1363 default_dirlist = xstrdup (optarg);
1368 case OPTION_SPARE_DYNAMIC_TAGS:
1369 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1371 case OPTION_SPLIT_BY_RELOC:
1373 config.split_by_reloc = strtoul (optarg, NULL, 0);
1375 config.split_by_reloc = 32768;
1377 case OPTION_SPLIT_BY_FILE:
1379 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1381 config.split_by_file = 1;
1383 case OPTION_CHECK_SECTIONS:
1384 command_line.check_section_addresses = 1;
1386 case OPTION_NO_CHECK_SECTIONS:
1387 command_line.check_section_addresses = 0;
1389 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1390 command_line.accept_unknown_input_arch = TRUE;
1392 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1393 command_line.accept_unknown_input_arch = FALSE;
1396 lang_enter_group ();
1401 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1403 lang_leave_group ();
1408 link_info.init_function = optarg;
1412 link_info.fini_function = optarg;
1415 case OPTION_REDUCE_MEMORY_OVERHEADS:
1416 link_info.reduce_memory_overheads = TRUE;
1417 if (config.hash_table_size == 0)
1418 config.hash_table_size = 1021;
1421 case OPTION_HASH_SIZE:
1423 bfd_size_type new_size;
1425 new_size = strtoul (optarg, NULL, 0);
1427 config.hash_table_size = new_size;
1429 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1437 lang_leave_group ();
1441 if (default_dirlist != NULL)
1443 set_default_dirlist (default_dirlist);
1444 free (default_dirlist);
1447 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1448 /* FIXME: Should we allow emulations a chance to set this ? */
1449 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
1451 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1452 /* FIXME: Should we allow emulations a chance to set this ? */
1453 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
1455 if (link_info.relocatable)
1457 if (command_line.check_section_addresses < 0)
1458 command_line.check_section_addresses = 0;
1459 if (link_info.shared)
1460 einfo (_("%P%F: -r and -shared may not be used together\n"));
1463 /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data,
1464 --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and
1465 --dynamic-list FILE. -Bsymbolic and -Bsymbolic-functions are
1466 for shared libraries. -Bsymbolic overrides all others and vice
1468 switch (command_line.symbolic)
1470 case symbolic_unset:
1473 /* -Bsymbolic is for shared library only. */
1474 if (link_info.shared)
1476 link_info.symbolic = TRUE;
1477 /* Should we free the unused memory? */
1478 link_info.dynamic_list = NULL;
1479 command_line.dynamic_list = dynamic_list_unset;
1482 case symbolic_functions:
1483 /* -Bsymbolic-functions is for shared library only. */
1484 if (link_info.shared)
1485 command_line.dynamic_list = dynamic_list_data;
1489 switch (command_line.dynamic_list)
1491 case dynamic_list_unset:
1493 case dynamic_list_data:
1494 link_info.dynamic_data = TRUE;
1496 link_info.dynamic = TRUE;
1500 if (! link_info.shared)
1502 if (command_line.filter_shlib)
1503 einfo (_("%P%F: -F may not be used without -shared\n"));
1504 if (command_line.auxiliary_filters)
1505 einfo (_("%P%F: -f may not be used without -shared\n"));
1508 if (! link_info.shared || link_info.pie)
1509 link_info.executable = TRUE;
1511 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1512 don't see how else this can be handled, since in this case we
1513 must preserve all externally visible symbols. */
1514 if (link_info.relocatable && link_info.strip == strip_all)
1516 link_info.strip = strip_debugger;
1517 if (link_info.discard == discard_sec_merge)
1518 link_info.discard = discard_all;
1522 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1523 library search path. */
1526 set_default_dirlist (char *dirlist_ptr)
1532 p = strchr (dirlist_ptr, PATH_SEPARATOR);
1535 if (*dirlist_ptr != '\0')
1536 ldfile_add_library_path (dirlist_ptr, TRUE);
1539 dirlist_ptr = p + 1;
1544 set_section_start (char *sect, char *valstr)
1547 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1549 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1550 lang_section_start (sect, exp_intop (val), NULL);
1554 set_segment_start (const char *section, char *valstr)
1560 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1562 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1563 /* If we already have an entry for this segment, update the existing
1566 for (seg = segments; seg; seg = seg->next)
1567 if (strcmp (seg->name, name) == 0)
1572 /* There was no existing value so we must create a new segment
1574 seg = (segment_type *) stat_alloc (sizeof (*seg));
1578 /* Add it to the linked list of segments. */
1579 seg->next = segments;
1581 /* Historically, -Ttext and friends set the base address of a
1582 particular section. For backwards compatibility, we still do
1583 that. If a SEGMENT_START directive is seen, the section address
1584 assignment will be disabled. */
1585 lang_section_start (section, exp_intop (val), seg);
1589 /* Print help messages for the options. */
1595 const char **targets, **pp;
1598 printf (_("Usage: %s [options] file...\n"), program_name);
1600 printf (_("Options:\n"));
1601 for (i = 0; i < OPTION_COUNT; i++)
1603 if (ld_options[i].doc != NULL)
1616 if (ld_options[j].shortopt != '\0'
1617 && ld_options[j].control != NO_HELP)
1619 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1620 len += (comma ? 2 : 0) + 2;
1621 if (ld_options[j].arg != NULL)
1623 if (ld_options[j].opt.has_arg != optional_argument)
1628 printf ("%s", _(ld_options[j].arg));
1629 len += strlen (_(ld_options[j].arg));
1635 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1640 if (ld_options[j].opt.name != NULL
1641 && ld_options[j].control != NO_HELP)
1644 (ld_options[j].control == TWO_DASHES
1645 || ld_options[j].control == EXACTLY_TWO_DASHES);
1649 two_dashes ? "-" : "",
1650 ld_options[j].opt.name);
1651 len += ((comma ? 2 : 0)
1653 + (two_dashes ? 1 : 0)
1654 + strlen (ld_options[j].opt.name));
1655 if (ld_options[j].arg != NULL)
1657 printf (" %s", _(ld_options[j].arg));
1658 len += 1 + strlen (_(ld_options[j].arg));
1664 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1672 for (; len < 30; len++)
1675 printf ("%s\n", _(ld_options[i].doc));
1678 printf (_(" @FILE"));
1679 for (len = strlen (" @FILE"); len < 30; len++)
1681 printf (_("Read options from FILE\n"));
1683 /* Note: Various tools (such as libtool) depend upon the
1684 format of the listings below - do not change them. */
1685 /* xgettext:c-format */
1686 printf (_("%s: supported targets:"), program_name);
1687 targets = bfd_target_list ();
1688 for (pp = targets; *pp != NULL; pp++)
1689 printf (" %s", *pp);
1693 /* xgettext:c-format */
1694 printf (_("%s: supported emulations: "), program_name);
1695 ldemul_list_emulations (stdout);
1698 /* xgettext:c-format */
1699 printf (_("%s: emulation specific options:\n"), program_name);
1700 ldemul_list_emulation_options (stdout);
1703 if (REPORT_BUGS_TO[0])
1704 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);