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
},
501 #define OPTION_COUNT ARRAY_SIZE (ld_options)
504 parse_args (unsigned argc
, char **argv
)
509 char *default_dirlist
= NULL
;
511 struct option
*longopts
;
512 struct option
*really_longopts
;
514 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
516 shortopts
= (char *) xmalloc (OPTION_COUNT
* 3 + 2);
517 longopts
= (struct option
*)
518 xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
519 really_longopts
= (struct option
*)
520 malloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
522 /* Starting the short option string with '-' is for programs that
523 expect options and other ARGV-elements in any order and that care about
524 the ordering of the two. We describe each non-option ARGV-element
525 as if it were the argument of an option with character code 1. */
530 for (i
= 0; i
< OPTION_COUNT
; i
++)
532 if (ld_options
[i
].shortopt
!= '\0')
534 shortopts
[is
] = ld_options
[i
].shortopt
;
536 if (ld_options
[i
].opt
.has_arg
== required_argument
537 || ld_options
[i
].opt
.has_arg
== optional_argument
)
541 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
548 if (ld_options
[i
].opt
.name
!= NULL
)
550 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
552 really_longopts
[irl
] = ld_options
[i
].opt
;
557 longopts
[il
] = ld_options
[i
].opt
;
562 shortopts
[is
] = '\0';
563 longopts
[il
].name
= NULL
;
564 really_longopts
[irl
].name
= NULL
;
566 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
568 /* The -G option is ambiguous on different platforms. Sometimes it
569 specifies the largest data size to put into the small data
570 section. Sometimes it is equivalent to --shared. Unfortunately,
571 the first form takes an argument, while the second does not.
573 We need to permit the --shared form because on some platforms,
574 such as Solaris, gcc -shared will pass -G to the linker.
576 To permit either usage, we look through the argument list. If we
577 find -G not followed by a number, we change it into --shared.
578 This will work for most normal cases. */
579 for (i
= 1; i
< argc
; i
++)
580 if (strcmp (argv
[i
], "-G") == 0
582 || ! ISDIGIT (argv
[i
+ 1][0])))
583 argv
[i
] = (char *) "--shared";
585 /* Because we permit long options to start with a single dash, and
586 we have a --library option, and the -l option is conventionally
587 used with an immediately following argument, we can have bad
588 results if somebody tries to use -l with a library whose name
589 happens to start with "ibrary", as in -li. We avoid problems by
590 simply turning -l into --library. This means that users will
591 have to use two dashes in order to use --library, which is OK
592 since that's how it is documented.
594 FIXME: It's possible that this problem can arise for other short
595 options as well, although the user does always have the recourse
596 of adding a space between the option and the argument. */
597 for (i
= 1; i
< argc
; i
++)
599 if (argv
[i
][0] == '-'
601 && argv
[i
][2] != '\0')
605 n
= (char *) xmalloc (strlen (argv
[i
]) + 20);
606 sprintf (n
, "--library=%s", argv
[i
] + 2);
616 static unsigned int defsym_count
;
618 /* Using last_optind lets us avoid calling ldemul_parse_args
619 multiple times on a single option, which would lead to
620 confusion in the internal static variables maintained by
621 getopt. This could otherwise happen for an argument like
622 -nx, in which the -n is parsed as a single option, and we
623 loop around to pick up the -x. */
624 if (optind
!= last_optind
)
625 if (ldemul_parse_args (argc
, argv
))
628 /* getopt_long_only is like getopt_long, but '-' as well as '--'
629 can indicate a long option. */
631 last_optind
= optind
;
632 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
635 optind
= last_optind
;
636 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
639 if (ldemul_handle_option (optc
))
648 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
652 einfo (_("%P%F: use the --help option for usage information\n"));
654 case 1: /* File name. */
655 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
661 /* For HP/UX compatibility. Actually -a shared should mean
662 ``use only shared libraries'' but, then, we don't
663 currently support shared libraries on HP/UX anyhow. */
664 if (strcmp (optarg
, "archive") == 0)
665 input_flags
.dynamic
= FALSE
;
666 else if (strcmp (optarg
, "shared") == 0
667 || strcmp (optarg
, "default") == 0)
668 input_flags
.dynamic
= TRUE
;
670 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
673 /* FIXME: We just ignore these, but we should handle them. */
674 if (strcmp (optarg
, "definitions") == 0)
676 else if (strcmp (optarg
, "nodefinitions") == 0)
678 else if (strcmp (optarg
, "nosymbolic") == 0)
680 else if (strcmp (optarg
, "pure-text") == 0)
683 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
686 ldfile_add_arch (optarg
);
689 lang_add_target (optarg
);
692 ldfile_open_command_file (optarg
);
693 parser_input
= input_mri_script
;
696 case OPTION_CALL_SHARED
:
697 input_flags
.dynamic
= TRUE
;
699 case OPTION_NON_SHARED
:
700 input_flags
.dynamic
= FALSE
;
703 command_line
.cref
= TRUE
;
704 link_info
.notice_all
= TRUE
;
707 command_line
.force_common_definition
= TRUE
;
711 lex_redirect (optarg
, "--defsym", ++defsym_count
);
712 parser_input
= input_defsym
;
716 case OPTION_DEMANGLE
:
720 enum demangling_styles style
;
722 style
= cplus_demangle_name_to_style (optarg
);
723 if (style
== unknown_demangling
)
724 einfo (_("%F%P: unknown demangling style `%s'\n"),
727 cplus_demangle_set_style (style
);
730 case 'I': /* Used on Solaris. */
731 case OPTION_DYNAMIC_LINKER
:
732 command_line
.interpreter
= optarg
;
735 /* Already handled in ldmain.c. */
738 command_line
.endian
= ENDIAN_BIG
;
741 command_line
.endian
= ENDIAN_LITTLE
;
743 case OPTION_EMBEDDED_RELOCS
:
744 command_line
.embedded_relocs
= TRUE
;
746 case OPTION_EXPORT_DYNAMIC
:
747 case 'E': /* HP/UX compatibility. */
748 link_info
.export_dynamic
= TRUE
;
750 case OPTION_NO_EXPORT_DYNAMIC
:
751 link_info
.export_dynamic
= FALSE
;
754 lang_add_entry (optarg
, TRUE
);
757 if (command_line
.auxiliary_filters
== NULL
)
759 command_line
.auxiliary_filters
= (char **)
760 xmalloc (2 * sizeof (char *));
761 command_line
.auxiliary_filters
[0] = optarg
;
762 command_line
.auxiliary_filters
[1] = NULL
;
770 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
772 command_line
.auxiliary_filters
= (char **)
773 xrealloc (command_line
.auxiliary_filters
,
774 (c
+ 2) * sizeof (char *));
775 command_line
.auxiliary_filters
[c
] = optarg
;
776 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
780 command_line
.filter_shlib
= optarg
;
782 case OPTION_FORCE_EXE_SUFFIX
:
783 command_line
.force_exe_suffix
= TRUE
;
788 g_switch_value
= strtoul (optarg
, &end
, 0);
790 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
796 case OPTION_GC_SECTIONS
:
797 link_info
.gc_sections
= TRUE
;
799 case OPTION_PRINT_GC_SECTIONS
:
800 link_info
.print_gc_sections
= TRUE
;
807 ldfile_add_library_path (optarg
, TRUE
);
810 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
813 config
.map_filename
= "-";
816 /* Ignore. Was handled in a pre-parse. */
819 config
.map_filename
= optarg
;
822 config
.text_read_only
= FALSE
;
823 config
.magic_demand_paged
= FALSE
;
824 input_flags
.dynamic
= FALSE
;
826 case OPTION_NO_OMAGIC
:
827 config
.text_read_only
= TRUE
;
828 config
.magic_demand_paged
= TRUE
;
829 /* NB/ Does not set input_flags.dynamic to TRUE.
830 Use --call-shared or -Bdynamic for this. */
833 config
.magic_demand_paged
= FALSE
;
834 input_flags
.dynamic
= FALSE
;
836 case OPTION_NO_DEFINE_COMMON
:
837 command_line
.inhibit_common_definition
= TRUE
;
839 case OPTION_NO_DEMANGLE
:
842 case OPTION_NO_GC_SECTIONS
:
843 link_info
.gc_sections
= FALSE
;
845 case OPTION_NO_PRINT_GC_SECTIONS
:
846 link_info
.print_gc_sections
= FALSE
;
848 case OPTION_NO_KEEP_MEMORY
:
849 link_info
.keep_memory
= FALSE
;
851 case OPTION_NO_UNDEFINED
:
852 link_info
.unresolved_syms_in_objects
853 = how_to_report_unresolved_symbols
;
855 case OPTION_ALLOW_SHLIB_UNDEFINED
:
856 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
858 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
859 link_info
.unresolved_syms_in_shared_libs
860 = how_to_report_unresolved_symbols
;
862 case OPTION_UNRESOLVED_SYMBOLS
:
863 if (strcmp (optarg
, "ignore-all") == 0)
865 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
866 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
868 else if (strcmp (optarg
, "report-all") == 0)
870 link_info
.unresolved_syms_in_objects
871 = how_to_report_unresolved_symbols
;
872 link_info
.unresolved_syms_in_shared_libs
873 = how_to_report_unresolved_symbols
;
875 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
877 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
878 link_info
.unresolved_syms_in_shared_libs
879 = how_to_report_unresolved_symbols
;
881 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
883 link_info
.unresolved_syms_in_objects
884 = how_to_report_unresolved_symbols
;
885 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
888 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
890 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
891 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
892 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
893 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
894 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
895 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
898 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
899 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
900 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
901 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
902 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
903 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
905 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
906 link_info
.allow_multiple_definition
= TRUE
;
908 case OPTION_NO_UNDEFINED_VERSION
:
909 link_info
.allow_undefined_version
= FALSE
;
911 case OPTION_DEFAULT_SYMVER
:
912 link_info
.create_default_symver
= TRUE
;
914 case OPTION_DEFAULT_IMPORTED_SYMVER
:
915 link_info
.default_imported_symver
= TRUE
;
917 case OPTION_NO_WARN_MISMATCH
:
918 command_line
.warn_mismatch
= FALSE
;
920 case OPTION_NO_WARN_SEARCH_MISMATCH
:
921 command_line
.warn_search_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 input_flags
.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);
948 case OPTION_PRINT_OUTPUT_FORMAT
:
949 command_line
.print_output_format
= TRUE
;
951 #ifdef ENABLE_PLUGINS
953 if (plugin_opt_plugin (optarg
))
954 einfo (_("%P%F: %s: error loading plugin\n"),
955 plugin_error_plugin ());
957 case OPTION_PLUGIN_OPT
:
958 if (plugin_opt_plugin_arg (optarg
))
959 einfo(_("%P%F: bad -plugin-opt option\n"));
961 #endif /* ENABLE_PLUGINS */
963 link_info
.emitrelocations
= TRUE
;
967 if (optind
== last_optind
)
968 /* This can happen if the user put "-rpath,a" on the command
969 line. (Or something similar. The comma is important).
970 Getopt becomes confused and thinks that this is a -r option
971 but it cannot parse the text after the -r so it refuses to
972 increment the optind counter. Detect this case and issue
973 an error message here. We cannot just make this a warning,
974 increment optind, and continue because getopt is too confused
975 and will seg-fault the next time around. */
976 einfo(_("%P%F: bad -rpath option\n"));
978 link_info
.relocatable
= TRUE
;
979 config
.build_constructors
= FALSE
;
980 config
.magic_demand_paged
= FALSE
;
981 config
.text_read_only
= FALSE
;
982 input_flags
.dynamic
= FALSE
;
985 /* The GNU linker traditionally uses -R to mean to include
986 only the symbols from a file. The Solaris linker uses -R
987 to set the path used by the runtime linker to find
988 libraries. This is the GNU linker -rpath argument. We
989 try to support both simultaneously by checking the file
990 named. If it is a directory, rather than a regular file,
991 we assume -rpath was meant. */
995 if (stat (optarg
, &s
) >= 0
996 && ! S_ISDIR (s
.st_mode
))
998 lang_add_input_file (optarg
,
999 lang_input_file_is_symbols_only_enum
,
1006 if (command_line
.rpath
== NULL
)
1007 command_line
.rpath
= xstrdup (optarg
);
1010 size_t rpath_len
= strlen (command_line
.rpath
);
1011 size_t optarg_len
= strlen (optarg
);
1013 char *cp
= command_line
.rpath
;
1015 /* First see whether OPTARG is already in the path. */
1018 if (strncmp (optarg
, cp
, optarg_len
) == 0
1019 && (cp
[optarg_len
] == 0
1020 || cp
[optarg_len
] == config
.rpath_separator
))
1024 /* Not yet found. */
1025 cp
= strchr (cp
, config
.rpath_separator
);
1033 buf
= (char *) xmalloc (rpath_len
+ optarg_len
+ 2);
1034 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1035 config
.rpath_separator
, optarg
);
1036 free (command_line
.rpath
);
1037 command_line
.rpath
= buf
;
1041 case OPTION_RPATH_LINK
:
1042 if (command_line
.rpath_link
== NULL
)
1043 command_line
.rpath_link
= xstrdup (optarg
);
1048 buf
= (char *) xmalloc (strlen (command_line
.rpath_link
)
1051 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1052 config
.rpath_separator
, optarg
);
1053 free (command_line
.rpath_link
);
1054 command_line
.rpath_link
= buf
;
1057 case OPTION_NO_RELAX
:
1063 case OPTION_RETAIN_SYMBOLS_FILE
:
1064 add_keepsyms_file (optarg
);
1067 link_info
.strip
= strip_debugger
;
1070 link_info
.strip
= strip_all
;
1072 case OPTION_STRIP_DISCARDED
:
1073 link_info
.strip_discarded
= TRUE
;
1075 case OPTION_NO_STRIP_DISCARDED
:
1076 link_info
.strip_discarded
= FALSE
;
1079 if (config
.has_shared
)
1081 link_info
.shared
= TRUE
;
1082 /* When creating a shared library, the default
1083 behaviour is to ignore any unresolved references. */
1084 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1085 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1086 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1087 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1090 einfo (_("%P%F: -shared not supported\n"));
1093 if (config
.has_shared
)
1095 link_info
.shared
= TRUE
;
1096 link_info
.pie
= TRUE
;
1099 einfo (_("%P%F: -pie not supported\n"));
1101 case 'h': /* Used on Solaris. */
1103 command_line
.soname
= optarg
;
1105 case OPTION_SORT_COMMON
:
1107 || strcmp (optarg
, N_("descending")) == 0)
1108 config
.sort_common
= sort_descending
;
1109 else if (strcmp (optarg
, N_("ascending")) == 0)
1110 config
.sort_common
= sort_ascending
;
1112 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1115 case OPTION_SORT_SECTION
:
1116 if (strcmp (optarg
, N_("name")) == 0)
1117 sort_section
= by_name
;
1118 else if (strcmp (optarg
, N_("alignment")) == 0)
1119 sort_section
= by_alignment
;
1121 einfo (_("%P%F: invalid section sorting option: %s\n"),
1125 config
.stats
= TRUE
;
1127 case OPTION_SYMBOLIC
:
1128 command_line
.symbolic
= symbolic
;
1130 case OPTION_SYMBOLIC_FUNCTIONS
:
1131 command_line
.symbolic
= symbolic_functions
;
1137 previous_script_handle
= saved_script_handle
;
1138 ldfile_open_command_file (optarg
);
1139 parser_input
= input_script
;
1141 previous_script_handle
= NULL
;
1143 case OPTION_DEFAULT_SCRIPT
:
1144 command_line
.default_script
= optarg
;
1146 case OPTION_SECTION_START
:
1152 /* Check for <something>=<somthing>... */
1153 optarg2
= strchr (optarg
, '=');
1154 if (optarg2
== NULL
)
1155 einfo (_("%P%F: invalid argument to option"
1156 " \"--section-start\"\n"));
1160 /* So far so good. Are all the args present? */
1161 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1162 einfo (_("%P%F: missing argument(s) to option"
1163 " \"--section-start\"\n"));
1165 /* We must copy the section name as set_section_start
1166 doesn't do it for us. */
1167 len
= optarg2
- optarg
;
1168 sec_name
= (char *) xmalloc (len
);
1169 memcpy (sec_name
, optarg
, len
- 1);
1170 sec_name
[len
- 1] = 0;
1172 /* Then set it... */
1173 set_section_start (sec_name
, optarg2
);
1176 case OPTION_TARGET_HELP
:
1177 /* Mention any target specific options. */
1178 ldemul_list_emulation_options (stdout
);
1181 set_segment_start (".bss", optarg
);
1184 set_segment_start (".data", optarg
);
1187 set_segment_start (".text", optarg
);
1189 case OPTION_TTEXT_SEGMENT
:
1190 set_segment_start (".text-segment", optarg
);
1192 case OPTION_TRADITIONAL_FORMAT
:
1193 link_info
.traditional_format
= TRUE
;
1195 case OPTION_TASK_LINK
:
1196 link_info
.task_link
= TRUE
;
1197 /* Fall through - do an implied -r option. */
1199 link_info
.relocatable
= TRUE
;
1200 config
.build_constructors
= TRUE
;
1201 config
.magic_demand_paged
= FALSE
;
1202 config
.text_read_only
= FALSE
;
1203 input_flags
.dynamic
= FALSE
;
1206 ldlang_add_undef (optarg
, TRUE
);
1210 lang_add_unique (optarg
);
1212 config
.unique_orphan_sections
= TRUE
;
1214 case OPTION_VERBOSE
:
1216 version_printed
= TRUE
;
1218 overflow_cutoff_limit
= -2;
1222 int level ATTRIBUTE_UNUSED
= strtoul (optarg
, &end
, 0);
1224 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
1225 #ifdef ENABLE_PLUGINS
1226 report_plugin_symbols
= level
> 1;
1227 #endif /* ENABLE_PLUGINS */
1232 version_printed
= TRUE
;
1236 version_printed
= TRUE
;
1238 case OPTION_VERSION
:
1242 case OPTION_VERSION_SCRIPT
:
1243 /* This option indicates a small script that only specifies
1244 version information. Read it, but don't assume that
1245 we've seen a linker script. */
1247 FILE *hold_script_handle
;
1249 hold_script_handle
= saved_script_handle
;
1250 ldfile_open_command_file (optarg
);
1251 saved_script_handle
= hold_script_handle
;
1252 parser_input
= input_version_script
;
1256 case OPTION_VERSION_EXPORTS_SECTION
:
1257 /* This option records a version symbol to be applied to the
1258 symbols listed for export to be found in the object files
1259 .exports sections. */
1260 command_line
.version_exports_section
= optarg
;
1262 case OPTION_DYNAMIC_LIST_DATA
:
1263 command_line
.dynamic_list
= dynamic_list_data
;
1264 if (command_line
.symbolic
== symbolic
)
1265 command_line
.symbolic
= symbolic_unset
;
1267 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1268 lang_append_dynamic_list_cpp_typeinfo ();
1269 if (command_line
.dynamic_list
!= dynamic_list_data
)
1270 command_line
.dynamic_list
= dynamic_list
;
1271 if (command_line
.symbolic
== symbolic
)
1272 command_line
.symbolic
= symbolic_unset
;
1274 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1275 lang_append_dynamic_list_cpp_new ();
1276 if (command_line
.dynamic_list
!= dynamic_list_data
)
1277 command_line
.dynamic_list
= dynamic_list
;
1278 if (command_line
.symbolic
== symbolic
)
1279 command_line
.symbolic
= symbolic_unset
;
1281 case OPTION_DYNAMIC_LIST
:
1282 /* This option indicates a small script that only specifies
1283 a dynamic list. Read it, but don't assume that we've
1284 seen a linker script. */
1286 FILE *hold_script_handle
;
1288 hold_script_handle
= saved_script_handle
;
1289 ldfile_open_command_file (optarg
);
1290 saved_script_handle
= hold_script_handle
;
1291 parser_input
= input_dynamic_list
;
1294 if (command_line
.dynamic_list
!= dynamic_list_data
)
1295 command_line
.dynamic_list
= dynamic_list
;
1296 if (command_line
.symbolic
== symbolic
)
1297 command_line
.symbolic
= symbolic_unset
;
1299 case OPTION_WARN_COMMON
:
1300 config
.warn_common
= TRUE
;
1302 case OPTION_WARN_CONSTRUCTORS
:
1303 config
.warn_constructors
= TRUE
;
1305 case OPTION_WARN_FATAL
:
1306 config
.fatal_warnings
= TRUE
;
1308 case OPTION_NO_WARN_FATAL
:
1309 config
.fatal_warnings
= FALSE
;
1311 case OPTION_WARN_MULTIPLE_GP
:
1312 config
.warn_multiple_gp
= TRUE
;
1314 case OPTION_WARN_ONCE
:
1315 config
.warn_once
= TRUE
;
1317 case OPTION_WARN_SECTION_ALIGN
:
1318 config
.warn_section_align
= TRUE
;
1320 case OPTION_WARN_SHARED_TEXTREL
:
1321 link_info
.warn_shared_textrel
= TRUE
;
1323 case OPTION_WARN_ALTERNATE_EM
:
1324 link_info
.warn_alternate_em
= TRUE
;
1326 case OPTION_WHOLE_ARCHIVE
:
1327 input_flags
.whole_archive
= TRUE
;
1329 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
:
1330 input_flags
.add_DT_NEEDED_for_dynamic
= TRUE
;
1332 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
:
1333 input_flags
.add_DT_NEEDED_for_dynamic
= FALSE
;
1335 case OPTION_ADD_DT_NEEDED_FOR_REGULAR
:
1336 input_flags
.add_DT_NEEDED_for_regular
= TRUE
;
1338 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
:
1339 input_flags
.add_DT_NEEDED_for_regular
= FALSE
;
1344 case OPTION_DISCARD_NONE
:
1345 link_info
.discard
= discard_none
;
1348 link_info
.discard
= discard_l
;
1351 link_info
.discard
= discard_all
;
1354 if (CONST_STRNEQ (optarg
, "P,"))
1356 if (default_dirlist
!= NULL
)
1357 free (default_dirlist
);
1358 default_dirlist
= xstrdup (optarg
);
1363 case OPTION_SPARE_DYNAMIC_TAGS
:
1364 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1366 case OPTION_SPLIT_BY_RELOC
:
1368 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1370 config
.split_by_reloc
= 32768;
1372 case OPTION_SPLIT_BY_FILE
:
1374 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1376 config
.split_by_file
= 1;
1378 case OPTION_CHECK_SECTIONS
:
1379 command_line
.check_section_addresses
= 1;
1381 case OPTION_NO_CHECK_SECTIONS
:
1382 command_line
.check_section_addresses
= 0;
1384 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1385 command_line
.accept_unknown_input_arch
= TRUE
;
1387 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1388 command_line
.accept_unknown_input_arch
= FALSE
;
1391 lang_enter_group ();
1396 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1398 lang_leave_group ();
1403 link_info
.init_function
= optarg
;
1407 link_info
.fini_function
= optarg
;
1410 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1411 link_info
.reduce_memory_overheads
= TRUE
;
1412 if (config
.hash_table_size
== 0)
1413 config
.hash_table_size
= 1021;
1416 case OPTION_HASH_SIZE
:
1418 bfd_size_type new_size
;
1420 new_size
= strtoul (optarg
, NULL
, 0);
1422 config
.hash_table_size
= new_size
;
1424 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1432 lang_leave_group ();
1436 if (default_dirlist
!= NULL
)
1438 set_default_dirlist (default_dirlist
);
1439 free (default_dirlist
);
1442 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1443 /* FIXME: Should we allow emulations a chance to set this ? */
1444 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1446 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1447 /* FIXME: Should we allow emulations a chance to set this ? */
1448 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1450 if (link_info
.relocatable
)
1452 if (command_line
.check_section_addresses
< 0)
1453 command_line
.check_section_addresses
= 0;
1454 if (link_info
.shared
)
1455 einfo (_("%P%F: -r and -shared may not be used together\n"));
1458 /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data,
1459 --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and
1460 --dynamic-list FILE. -Bsymbolic and -Bsymbolic-functions are
1461 for shared libraries. -Bsymbolic overrides all others and vice
1463 switch (command_line
.symbolic
)
1465 case symbolic_unset
:
1468 /* -Bsymbolic is for shared library only. */
1469 if (link_info
.shared
)
1471 link_info
.symbolic
= TRUE
;
1472 /* Should we free the unused memory? */
1473 link_info
.dynamic_list
= NULL
;
1474 command_line
.dynamic_list
= dynamic_list_unset
;
1477 case symbolic_functions
:
1478 /* -Bsymbolic-functions is for shared library only. */
1479 if (link_info
.shared
)
1480 command_line
.dynamic_list
= dynamic_list_data
;
1484 switch (command_line
.dynamic_list
)
1486 case dynamic_list_unset
:
1488 case dynamic_list_data
:
1489 link_info
.dynamic_data
= TRUE
;
1491 link_info
.dynamic
= TRUE
;
1495 if (! link_info
.shared
)
1497 if (command_line
.filter_shlib
)
1498 einfo (_("%P%F: -F may not be used without -shared\n"));
1499 if (command_line
.auxiliary_filters
)
1500 einfo (_("%P%F: -f may not be used without -shared\n"));
1503 if (! link_info
.shared
|| link_info
.pie
)
1504 link_info
.executable
= TRUE
;
1506 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1507 don't see how else this can be handled, since in this case we
1508 must preserve all externally visible symbols. */
1509 if (link_info
.relocatable
&& link_info
.strip
== strip_all
)
1511 link_info
.strip
= strip_debugger
;
1512 if (link_info
.discard
== discard_sec_merge
)
1513 link_info
.discard
= discard_all
;
1517 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1518 library search path. */
1521 set_default_dirlist (char *dirlist_ptr
)
1527 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1530 if (*dirlist_ptr
!= '\0')
1531 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1534 dirlist_ptr
= p
+ 1;
1539 set_section_start (char *sect
, char *valstr
)
1542 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1544 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1545 lang_section_start (sect
, exp_intop (val
), NULL
);
1549 set_segment_start (const char *section
, char *valstr
)
1555 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1557 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1558 /* If we already have an entry for this segment, update the existing
1561 for (seg
= segments
; seg
; seg
= seg
->next
)
1562 if (strcmp (seg
->name
, name
) == 0)
1567 /* There was no existing value so we must create a new segment
1569 seg
= (segment_type
*) stat_alloc (sizeof (*seg
));
1573 /* Add it to the linked list of segments. */
1574 seg
->next
= segments
;
1576 /* Historically, -Ttext and friends set the base address of a
1577 particular section. For backwards compatibility, we still do
1578 that. If a SEGMENT_START directive is seen, the section address
1579 assignment will be disabled. */
1580 lang_section_start (section
, exp_intop (val
), seg
);
1584 /* Print help messages for the options. */
1590 const char **targets
, **pp
;
1593 printf (_("Usage: %s [options] file...\n"), program_name
);
1595 printf (_("Options:\n"));
1596 for (i
= 0; i
< OPTION_COUNT
; i
++)
1598 if (ld_options
[i
].doc
!= NULL
)
1611 if (ld_options
[j
].shortopt
!= '\0'
1612 && ld_options
[j
].control
!= NO_HELP
)
1614 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1615 len
+= (comma
? 2 : 0) + 2;
1616 if (ld_options
[j
].arg
!= NULL
)
1618 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1623 printf ("%s", _(ld_options
[j
].arg
));
1624 len
+= strlen (_(ld_options
[j
].arg
));
1630 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1635 if (ld_options
[j
].opt
.name
!= NULL
1636 && ld_options
[j
].control
!= NO_HELP
)
1639 (ld_options
[j
].control
== TWO_DASHES
1640 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1644 two_dashes
? "-" : "",
1645 ld_options
[j
].opt
.name
);
1646 len
+= ((comma
? 2 : 0)
1648 + (two_dashes
? 1 : 0)
1649 + strlen (ld_options
[j
].opt
.name
));
1650 if (ld_options
[j
].arg
!= NULL
)
1652 printf (" %s", _(ld_options
[j
].arg
));
1653 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1659 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1667 for (; len
< 30; len
++)
1670 printf ("%s\n", _(ld_options
[i
].doc
));
1673 printf (_(" @FILE"));
1674 for (len
= strlen (" @FILE"); len
< 30; len
++)
1676 printf (_("Read options from FILE\n"));
1678 /* Note: Various tools (such as libtool) depend upon the
1679 format of the listings below - do not change them. */
1680 /* xgettext:c-format */
1681 printf (_("%s: supported targets:"), program_name
);
1682 targets
= bfd_target_list ();
1683 for (pp
= targets
; *pp
!= NULL
; pp
++)
1684 printf (" %s", *pp
);
1688 /* xgettext:c-format */
1689 printf (_("%s: supported emulations: "), program_name
);
1690 ldemul_list_emulations (stdout
);
1693 /* xgettext:c-format */
1694 printf (_("%s: emulation specific options:\n"), program_name
);
1695 ldemul_list_emulation_options (stdout
);
1698 if (REPORT_BUGS_TO
[0])
1699 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);