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 { {"fuse-ld=", required_argument
, NULL
, OPTION_IGNORE
},
179 '\0', NULL
, N_("Ignored for GCC linker option compatibility"),
181 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
182 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
183 { {"emit-relocs", no_argument
, NULL
, 'q'},
184 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
185 { {"relocatable", no_argument
, NULL
, 'r'},
186 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
187 { {NULL
, no_argument
, NULL
, '\0'},
188 'i', NULL
, NULL
, ONE_DASH
},
189 { {"just-symbols", required_argument
, NULL
, 'R'},
190 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
192 { {"strip-all", no_argument
, NULL
, 's'},
193 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
194 { {"strip-debug", no_argument
, NULL
, 'S'},
195 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
196 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
197 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
198 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
199 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
200 { {"trace", no_argument
, NULL
, 't'},
201 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
202 { {"script", required_argument
, NULL
, 'T'},
203 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
204 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
205 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
206 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
207 '\0', NULL
, NULL
, ONE_DASH
},
208 { {"undefined", required_argument
, NULL
, 'u'},
209 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
211 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
212 '\0', N_("[=SECTION]"),
213 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
214 { {"Ur", no_argument
, NULL
, OPTION_UR
},
215 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
216 { {"version", no_argument
, NULL
, OPTION_VERSION
},
217 'v', NULL
, N_("Print version information"), TWO_DASHES
},
218 { {NULL
, no_argument
, NULL
, '\0'},
219 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
220 { {"discard-all", no_argument
, NULL
, 'x'},
221 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
222 { {"discard-locals", no_argument
, NULL
, 'X'},
223 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
224 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
225 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
226 { {"trace-symbol", required_argument
, NULL
, 'y'},
227 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
228 { {NULL
, required_argument
, NULL
, '\0'},
229 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
231 { {"start-group", no_argument
, NULL
, '('},
232 '(', NULL
, N_("Start a group"), TWO_DASHES
},
233 { {"end-group", no_argument
, NULL
, ')'},
234 ')', NULL
, N_("End a group"), TWO_DASHES
},
235 { {"accept-unknown-input-arch", no_argument
, NULL
,
236 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
238 N_("Accept input files whose architecture cannot be determined"),
240 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
241 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
242 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
245 /* The next two options are deprecated because of their similarity to
246 --as-needed and --no-as-needed. They have been replaced by
247 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
248 { {"add-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
249 '\0', NULL
, NULL
, NO_HELP
},
250 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
251 '\0', NULL
, NULL
, NO_HELP
},
253 { {"as-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_REGULAR
},
254 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
256 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
},
257 '\0', NULL
, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
258 " the command line"),
260 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
261 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
262 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
263 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
264 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
265 '\0', NULL
, NULL
, ONE_DASH
},
266 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
267 '\0', NULL
, NULL
, ONE_DASH
},
268 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
269 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
270 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
271 '\0', NULL
, NULL
, ONE_DASH
},
272 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
273 '\0', NULL
, NULL
, ONE_DASH
},
274 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
275 '\0', NULL
, NULL
, ONE_DASH
},
276 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
277 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
278 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
279 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
280 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
281 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
283 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
284 '\0', NULL
, N_("Do not check section addresses for overlaps"),
286 { {"copy-dt-needed-entries", no_argument
, NULL
,
287 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
288 '\0', NULL
, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
290 { {"no-copy-dt-needed-entries", no_argument
, NULL
,
291 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
292 '\0', NULL
, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
295 { {"cref", no_argument
, NULL
, OPTION_CREF
},
296 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
297 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
298 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
299 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
300 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
302 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
303 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
304 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
305 '\0', NULL
, N_("Treat warnings as errors"),
307 { {"no-fatal-warnings", no_argument
, NULL
, OPTION_NO_WARN_FATAL
},
308 '\0', NULL
, N_("Do not treat warnings as errors (default)"),
310 { {"fini", required_argument
, NULL
, OPTION_FINI
},
311 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
312 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
313 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
314 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
315 '\0', NULL
, N_("Remove unused sections (on some targets)"),
317 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
318 '\0', NULL
, N_("Don't remove unused sections (default)"),
320 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
321 '\0', NULL
, N_("List removed unused sections on stderr"),
323 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
324 '\0', NULL
, N_("Do not list removed unused sections"),
326 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
327 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
329 { {"help", no_argument
, NULL
, OPTION_HELP
},
330 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
331 { {"init", required_argument
, NULL
, OPTION_INIT
},
332 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
333 { {"Map", required_argument
, NULL
, OPTION_MAP
},
334 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
335 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
336 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
337 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
338 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
339 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
340 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
341 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
342 '\0', NULL
, N_("Do not allow unresolved references in object files"),
344 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
345 '\0', NULL
, N_("Allow unresolved references in shared libraries"),
347 { {"no-allow-shlib-undefined", no_argument
, NULL
,
348 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
349 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
351 { {"allow-multiple-definition", no_argument
, NULL
,
352 OPTION_ALLOW_MULTIPLE_DEFINITION
},
353 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
354 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
355 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
356 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
357 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
358 { {"default-imported-symver", no_argument
, NULL
,
359 OPTION_DEFAULT_IMPORTED_SYMVER
},
360 '\0', NULL
, N_("Create default symbol version for imported symbols"),
362 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
363 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
364 { {"no-warn-search-mismatch", no_argument
, NULL
,
365 OPTION_NO_WARN_SEARCH_MISMATCH
},
366 '\0', NULL
, N_("Don't warn on finding an incompatible library"),
368 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
369 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
370 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
371 '\0', NULL
, N_("Create an output file even if errors occur"),
373 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
374 '\0', NULL
, NULL
, NO_HELP
},
375 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
376 '\0', NULL
, N_("Only use library directories specified on\n"
377 " the command line"),
379 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
380 '\0', N_("TARGET"), N_("Specify target of output file"),
381 EXACTLY_TWO_DASHES
},
382 { {"print-output-format", no_argument
, NULL
, OPTION_PRINT_OUTPUT_FORMAT
},
383 '\0', NULL
, N_("Print default output format"), TWO_DASHES
},
384 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
385 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
386 { {"reduce-memory-overheads", no_argument
, NULL
,
387 OPTION_REDUCE_MEMORY_OVERHEADS
},
388 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
390 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
391 '\0', NULL
, N_("Reduce code size by using target specific optimizations"), TWO_DASHES
},
392 { {"no-relax", no_argument
, NULL
, OPTION_NO_RELAX
},
393 '\0', NULL
, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES
},
394 { {"retain-symbols-file", required_argument
, NULL
,
395 OPTION_RETAIN_SYMBOLS_FILE
},
396 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
397 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
398 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
399 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
400 '\0', N_("PATH"), N_("Set link time shared library search path"),
402 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
403 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
404 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
405 '\0', NULL
, NULL
, ONE_DASH
},
406 { {"pie", no_argument
, NULL
, OPTION_PIE
},
407 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
408 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
409 '\0', NULL
, NULL
, TWO_DASHES
},
410 { {"sort-common", optional_argument
, NULL
, OPTION_SORT_COMMON
},
411 '\0', N_("[=ascending|descending]"),
412 N_("Sort common symbols by alignment [in specified order]"),
414 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
415 '\0', NULL
, NULL
, NO_HELP
},
416 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
417 '\0', N_("name|alignment"),
418 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
419 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
420 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
422 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
423 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
425 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
426 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
428 { {"stats", no_argument
, NULL
, OPTION_STATS
},
429 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
430 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
431 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
432 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
433 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
434 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
435 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
436 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
437 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
439 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
440 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
441 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
442 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
443 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
444 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
445 { {"Ttext-segment", required_argument
, NULL
, OPTION_TTEXT_SEGMENT
},
446 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH
},
447 { {"Trodata-segment", required_argument
, NULL
, OPTION_TRODATA_SEGMENT
},
448 '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH
},
449 { {"Tldata-segment", required_argument
, NULL
, OPTION_TLDATA_SEGMENT
},
450 '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH
},
451 { {"unresolved-symbols=<method>", required_argument
, NULL
,
452 OPTION_UNRESOLVED_SYMBOLS
},
453 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
454 " ignore-all, report-all, ignore-in-object-files,\n"
455 " ignore-in-shared-libs"),
457 { {"verbose", optional_argument
, NULL
, OPTION_VERBOSE
},
458 '\0', N_("[=NUMBER]"),
459 N_("Output lots of information during link"), TWO_DASHES
},
460 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
461 '\0', NULL
, NULL
, NO_HELP
},
462 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
463 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
464 { {"version-exports-section", required_argument
, NULL
,
465 OPTION_VERSION_EXPORTS_SECTION
},
466 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
467 " SYMBOL as the version."),
469 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
470 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
471 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
472 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
473 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
474 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
475 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
476 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
477 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
478 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
479 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
480 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
482 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
483 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
484 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
485 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
486 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
487 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
489 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
490 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
492 { {"warn-alternate-em", no_argument
, NULL
, OPTION_WARN_ALTERNATE_EM
},
493 '\0', NULL
, N_("Warn if an object has alternate ELF machine code"),
495 { {"warn-unresolved-symbols", no_argument
, NULL
,
496 OPTION_WARN_UNRESOLVED_SYMBOLS
},
497 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
498 { {"error-unresolved-symbols", no_argument
, NULL
,
499 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
500 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
501 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
502 '\0', NULL
, N_("Include all objects from following archives"),
504 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
505 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
506 { {"ignore-unresolved-symbol", required_argument
, NULL
,
507 OPTION_IGNORE_UNRESOLVED_SYMBOL
},
509 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES
},
512 #define OPTION_COUNT ARRAY_SIZE (ld_options)
515 parse_args (unsigned argc
, char **argv
)
520 char *default_dirlist
= NULL
;
522 struct option
*longopts
;
523 struct option
*really_longopts
;
525 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
527 shortopts
= (char *) xmalloc (OPTION_COUNT
* 3 + 2);
528 longopts
= (struct option
*)
529 xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
530 really_longopts
= (struct option
*)
531 malloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
533 /* Starting the short option string with '-' is for programs that
534 expect options and other ARGV-elements in any order and that care about
535 the ordering of the two. We describe each non-option ARGV-element
536 as if it were the argument of an option with character code 1. */
541 for (i
= 0; i
< OPTION_COUNT
; i
++)
543 if (ld_options
[i
].shortopt
!= '\0')
545 shortopts
[is
] = ld_options
[i
].shortopt
;
547 if (ld_options
[i
].opt
.has_arg
== required_argument
548 || ld_options
[i
].opt
.has_arg
== optional_argument
)
552 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
559 if (ld_options
[i
].opt
.name
!= NULL
)
561 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
563 really_longopts
[irl
] = ld_options
[i
].opt
;
568 longopts
[il
] = ld_options
[i
].opt
;
573 shortopts
[is
] = '\0';
574 longopts
[il
].name
= NULL
;
575 really_longopts
[irl
].name
= NULL
;
577 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
579 /* The -G option is ambiguous on different platforms. Sometimes it
580 specifies the largest data size to put into the small data
581 section. Sometimes it is equivalent to --shared. Unfortunately,
582 the first form takes an argument, while the second does not.
584 We need to permit the --shared form because on some platforms,
585 such as Solaris, gcc -shared will pass -G to the linker.
587 To permit either usage, we look through the argument list. If we
588 find -G not followed by a number, we change it into --shared.
589 This will work for most normal cases. */
590 for (i
= 1; i
< argc
; i
++)
591 if (strcmp (argv
[i
], "-G") == 0
593 || ! ISDIGIT (argv
[i
+ 1][0])))
594 argv
[i
] = (char *) "--shared";
596 /* Because we permit long options to start with a single dash, and
597 we have a --library option, and the -l option is conventionally
598 used with an immediately following argument, we can have bad
599 results if somebody tries to use -l with a library whose name
600 happens to start with "ibrary", as in -li. We avoid problems by
601 simply turning -l into --library. This means that users will
602 have to use two dashes in order to use --library, which is OK
603 since that's how it is documented.
605 FIXME: It's possible that this problem can arise for other short
606 options as well, although the user does always have the recourse
607 of adding a space between the option and the argument. */
608 for (i
= 1; i
< argc
; i
++)
610 if (argv
[i
][0] == '-'
612 && argv
[i
][2] != '\0')
616 n
= (char *) xmalloc (strlen (argv
[i
]) + 20);
617 sprintf (n
, "--library=%s", argv
[i
] + 2);
627 static unsigned int defsym_count
;
629 /* Using last_optind lets us avoid calling ldemul_parse_args
630 multiple times on a single option, which would lead to
631 confusion in the internal static variables maintained by
632 getopt. This could otherwise happen for an argument like
633 -nx, in which the -n is parsed as a single option, and we
634 loop around to pick up the -x. */
635 if (optind
!= last_optind
)
636 if (ldemul_parse_args (argc
, argv
))
639 /* getopt_long_only is like getopt_long, but '-' as well as '--'
640 can indicate a long option. */
642 last_optind
= optind
;
643 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
646 optind
= last_optind
;
647 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
650 if (ldemul_handle_option (optc
))
659 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
663 einfo (_("%P%F: use the --help option for usage information\n"));
665 case 1: /* File name. */
666 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
672 /* For HP/UX compatibility. Actually -a shared should mean
673 ``use only shared libraries'' but, then, we don't
674 currently support shared libraries on HP/UX anyhow. */
675 if (strcmp (optarg
, "archive") == 0)
676 input_flags
.dynamic
= FALSE
;
677 else if (strcmp (optarg
, "shared") == 0
678 || strcmp (optarg
, "default") == 0)
679 input_flags
.dynamic
= TRUE
;
681 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
684 /* FIXME: We just ignore these, but we should handle them. */
685 if (strcmp (optarg
, "definitions") == 0)
687 else if (strcmp (optarg
, "nodefinitions") == 0)
689 else if (strcmp (optarg
, "nosymbolic") == 0)
691 else if (strcmp (optarg
, "pure-text") == 0)
694 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
697 ldfile_add_arch (optarg
);
700 lang_add_target (optarg
);
703 ldfile_open_command_file (optarg
);
704 parser_input
= input_mri_script
;
707 case OPTION_CALL_SHARED
:
708 input_flags
.dynamic
= TRUE
;
710 case OPTION_NON_SHARED
:
711 input_flags
.dynamic
= FALSE
;
714 command_line
.cref
= TRUE
;
715 link_info
.notice_all
= TRUE
;
718 command_line
.force_common_definition
= TRUE
;
722 lex_redirect (optarg
, "--defsym", ++defsym_count
);
723 parser_input
= input_defsym
;
727 case OPTION_DEMANGLE
:
731 enum demangling_styles style
;
733 style
= cplus_demangle_name_to_style (optarg
);
734 if (style
== unknown_demangling
)
735 einfo (_("%F%P: unknown demangling style `%s'\n"),
738 cplus_demangle_set_style (style
);
741 case 'I': /* Used on Solaris. */
742 case OPTION_DYNAMIC_LINKER
:
743 command_line
.interpreter
= optarg
;
746 /* Already handled in ldmain.c. */
749 command_line
.endian
= ENDIAN_BIG
;
752 command_line
.endian
= ENDIAN_LITTLE
;
754 case OPTION_EMBEDDED_RELOCS
:
755 command_line
.embedded_relocs
= TRUE
;
757 case OPTION_EXPORT_DYNAMIC
:
758 case 'E': /* HP/UX compatibility. */
759 link_info
.export_dynamic
= TRUE
;
761 case OPTION_NO_EXPORT_DYNAMIC
:
762 link_info
.export_dynamic
= FALSE
;
765 lang_add_entry (optarg
, TRUE
);
768 if (command_line
.auxiliary_filters
== NULL
)
770 command_line
.auxiliary_filters
= (char **)
771 xmalloc (2 * sizeof (char *));
772 command_line
.auxiliary_filters
[0] = optarg
;
773 command_line
.auxiliary_filters
[1] = NULL
;
781 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
783 command_line
.auxiliary_filters
= (char **)
784 xrealloc (command_line
.auxiliary_filters
,
785 (c
+ 2) * sizeof (char *));
786 command_line
.auxiliary_filters
[c
] = optarg
;
787 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
791 command_line
.filter_shlib
= optarg
;
793 case OPTION_FORCE_EXE_SUFFIX
:
794 command_line
.force_exe_suffix
= TRUE
;
799 g_switch_value
= strtoul (optarg
, &end
, 0);
801 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
807 case OPTION_GC_SECTIONS
:
808 link_info
.gc_sections
= TRUE
;
810 case OPTION_PRINT_GC_SECTIONS
:
811 link_info
.print_gc_sections
= TRUE
;
818 ldfile_add_library_path (optarg
, TRUE
);
821 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
824 config
.map_filename
= "-";
827 /* Ignore. Was handled in a pre-parse. */
830 config
.map_filename
= optarg
;
833 config
.text_read_only
= FALSE
;
834 config
.magic_demand_paged
= FALSE
;
835 input_flags
.dynamic
= FALSE
;
837 case OPTION_NO_OMAGIC
:
838 config
.text_read_only
= TRUE
;
839 config
.magic_demand_paged
= TRUE
;
840 /* NB/ Does not set input_flags.dynamic to TRUE.
841 Use --call-shared or -Bdynamic for this. */
844 config
.magic_demand_paged
= FALSE
;
845 input_flags
.dynamic
= FALSE
;
847 case OPTION_NO_DEFINE_COMMON
:
848 command_line
.inhibit_common_definition
= TRUE
;
850 case OPTION_NO_DEMANGLE
:
853 case OPTION_NO_GC_SECTIONS
:
854 link_info
.gc_sections
= FALSE
;
856 case OPTION_NO_PRINT_GC_SECTIONS
:
857 link_info
.print_gc_sections
= FALSE
;
859 case OPTION_NO_KEEP_MEMORY
:
860 link_info
.keep_memory
= FALSE
;
862 case OPTION_NO_UNDEFINED
:
863 link_info
.unresolved_syms_in_objects
864 = how_to_report_unresolved_symbols
;
866 case OPTION_ALLOW_SHLIB_UNDEFINED
:
867 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
869 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
870 link_info
.unresolved_syms_in_shared_libs
871 = how_to_report_unresolved_symbols
;
873 case OPTION_UNRESOLVED_SYMBOLS
:
874 if (strcmp (optarg
, "ignore-all") == 0)
876 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
877 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
879 else if (strcmp (optarg
, "report-all") == 0)
881 link_info
.unresolved_syms_in_objects
882 = how_to_report_unresolved_symbols
;
883 link_info
.unresolved_syms_in_shared_libs
884 = how_to_report_unresolved_symbols
;
886 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
888 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
889 link_info
.unresolved_syms_in_shared_libs
890 = how_to_report_unresolved_symbols
;
892 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
894 link_info
.unresolved_syms_in_objects
895 = how_to_report_unresolved_symbols
;
896 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
899 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
901 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
902 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
903 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
904 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
905 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
906 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
909 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
910 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
911 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
912 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
913 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
914 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
916 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
917 link_info
.allow_multiple_definition
= TRUE
;
919 case OPTION_NO_UNDEFINED_VERSION
:
920 link_info
.allow_undefined_version
= FALSE
;
922 case OPTION_DEFAULT_SYMVER
:
923 link_info
.create_default_symver
= TRUE
;
925 case OPTION_DEFAULT_IMPORTED_SYMVER
:
926 link_info
.default_imported_symver
= TRUE
;
928 case OPTION_NO_WARN_MISMATCH
:
929 command_line
.warn_mismatch
= FALSE
;
931 case OPTION_NO_WARN_SEARCH_MISMATCH
:
932 command_line
.warn_search_mismatch
= FALSE
;
934 case OPTION_NOINHIBIT_EXEC
:
935 force_make_executable
= TRUE
;
937 case OPTION_NOSTDLIB
:
938 config
.only_cmd_line_lib_dirs
= TRUE
;
940 case OPTION_NO_WHOLE_ARCHIVE
:
941 input_flags
.whole_archive
= FALSE
;
944 /* FIXME "-O<non-digits> <value>" used to set the address of
945 section <non-digits>. Was this for compatibility with
946 something, or can we create a new option to do that
947 (with a syntax similar to -defsym)?
948 getopt can't handle two args to an option without kludges. */
950 /* Enable optimizations of output files. */
951 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
954 lang_add_output (optarg
, 0);
957 lang_add_output_format (optarg
, NULL
, NULL
, 0);
959 case OPTION_PRINT_OUTPUT_FORMAT
:
960 command_line
.print_output_format
= TRUE
;
962 #ifdef ENABLE_PLUGINS
964 plugin_opt_plugin (optarg
);
966 case OPTION_PLUGIN_OPT
:
967 if (plugin_opt_plugin_arg (optarg
))
968 einfo(_("%P%F: bad -plugin-opt option\n"));
970 #endif /* ENABLE_PLUGINS */
972 link_info
.emitrelocations
= TRUE
;
976 if (optind
== last_optind
)
977 /* This can happen if the user put "-rpath,a" on the command
978 line. (Or something similar. The comma is important).
979 Getopt becomes confused and thinks that this is a -r option
980 but it cannot parse the text after the -r so it refuses to
981 increment the optind counter. Detect this case and issue
982 an error message here. We cannot just make this a warning,
983 increment optind, and continue because getopt is too confused
984 and will seg-fault the next time around. */
985 einfo(_("%P%F: bad -rpath option\n"));
987 link_info
.relocatable
= TRUE
;
988 config
.build_constructors
= FALSE
;
989 config
.magic_demand_paged
= FALSE
;
990 config
.text_read_only
= FALSE
;
991 input_flags
.dynamic
= FALSE
;
994 /* The GNU linker traditionally uses -R to mean to include
995 only the symbols from a file. The Solaris linker uses -R
996 to set the path used by the runtime linker to find
997 libraries. This is the GNU linker -rpath argument. We
998 try to support both simultaneously by checking the file
999 named. If it is a directory, rather than a regular file,
1000 we assume -rpath was meant. */
1004 if (stat (optarg
, &s
) >= 0
1005 && ! S_ISDIR (s
.st_mode
))
1007 lang_add_input_file (optarg
,
1008 lang_input_file_is_symbols_only_enum
,
1015 if (command_line
.rpath
== NULL
)
1016 command_line
.rpath
= xstrdup (optarg
);
1019 size_t rpath_len
= strlen (command_line
.rpath
);
1020 size_t optarg_len
= strlen (optarg
);
1022 char *cp
= command_line
.rpath
;
1024 /* First see whether OPTARG is already in the path. */
1027 if (strncmp (optarg
, cp
, optarg_len
) == 0
1028 && (cp
[optarg_len
] == 0
1029 || cp
[optarg_len
] == config
.rpath_separator
))
1033 /* Not yet found. */
1034 cp
= strchr (cp
, config
.rpath_separator
);
1042 buf
= (char *) xmalloc (rpath_len
+ optarg_len
+ 2);
1043 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1044 config
.rpath_separator
, optarg
);
1045 free (command_line
.rpath
);
1046 command_line
.rpath
= buf
;
1050 case OPTION_RPATH_LINK
:
1051 if (command_line
.rpath_link
== NULL
)
1052 command_line
.rpath_link
= xstrdup (optarg
);
1057 buf
= (char *) xmalloc (strlen (command_line
.rpath_link
)
1060 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1061 config
.rpath_separator
, optarg
);
1062 free (command_line
.rpath_link
);
1063 command_line
.rpath_link
= buf
;
1066 case OPTION_NO_RELAX
:
1072 case OPTION_RETAIN_SYMBOLS_FILE
:
1073 add_keepsyms_file (optarg
);
1076 link_info
.strip
= strip_debugger
;
1079 link_info
.strip
= strip_all
;
1081 case OPTION_STRIP_DISCARDED
:
1082 link_info
.strip_discarded
= TRUE
;
1084 case OPTION_NO_STRIP_DISCARDED
:
1085 link_info
.strip_discarded
= FALSE
;
1088 if (config
.has_shared
)
1090 link_info
.shared
= TRUE
;
1091 /* When creating a shared library, the default
1092 behaviour is to ignore any unresolved references. */
1093 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1094 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1095 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1096 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1099 einfo (_("%P%F: -shared not supported\n"));
1102 if (config
.has_shared
)
1104 link_info
.shared
= TRUE
;
1105 link_info
.pie
= TRUE
;
1108 einfo (_("%P%F: -pie not supported\n"));
1110 case 'h': /* Used on Solaris. */
1112 command_line
.soname
= optarg
;
1114 case OPTION_SORT_COMMON
:
1116 || strcmp (optarg
, N_("descending")) == 0)
1117 config
.sort_common
= sort_descending
;
1118 else if (strcmp (optarg
, N_("ascending")) == 0)
1119 config
.sort_common
= sort_ascending
;
1121 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1124 case OPTION_SORT_SECTION
:
1125 if (strcmp (optarg
, N_("name")) == 0)
1126 sort_section
= by_name
;
1127 else if (strcmp (optarg
, N_("alignment")) == 0)
1128 sort_section
= by_alignment
;
1130 einfo (_("%P%F: invalid section sorting option: %s\n"),
1134 config
.stats
= TRUE
;
1136 case OPTION_SYMBOLIC
:
1137 command_line
.symbolic
= symbolic
;
1139 case OPTION_SYMBOLIC_FUNCTIONS
:
1140 command_line
.symbolic
= symbolic_functions
;
1146 previous_script_handle
= saved_script_handle
;
1147 ldfile_open_command_file (optarg
);
1148 parser_input
= input_script
;
1150 previous_script_handle
= NULL
;
1152 case OPTION_DEFAULT_SCRIPT
:
1153 command_line
.default_script
= optarg
;
1155 case OPTION_SECTION_START
:
1161 /* Check for <something>=<somthing>... */
1162 optarg2
= strchr (optarg
, '=');
1163 if (optarg2
== NULL
)
1164 einfo (_("%P%F: invalid argument to option"
1165 " \"--section-start\"\n"));
1169 /* So far so good. Are all the args present? */
1170 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1171 einfo (_("%P%F: missing argument(s) to option"
1172 " \"--section-start\"\n"));
1174 /* We must copy the section name as set_section_start
1175 doesn't do it for us. */
1176 len
= optarg2
- optarg
;
1177 sec_name
= (char *) xmalloc (len
);
1178 memcpy (sec_name
, optarg
, len
- 1);
1179 sec_name
[len
- 1] = 0;
1181 /* Then set it... */
1182 set_section_start (sec_name
, optarg2
);
1185 case OPTION_TARGET_HELP
:
1186 /* Mention any target specific options. */
1187 ldemul_list_emulation_options (stdout
);
1190 set_segment_start (".bss", optarg
);
1193 set_segment_start (".data", optarg
);
1196 set_segment_start (".text", optarg
);
1198 case OPTION_TTEXT_SEGMENT
:
1199 set_segment_start (".text-segment", optarg
);
1201 case OPTION_TRODATA_SEGMENT
:
1202 set_segment_start (".rodata-segment", optarg
);
1204 case OPTION_TLDATA_SEGMENT
:
1205 set_segment_start (".ldata-segment", optarg
);
1207 case OPTION_TRADITIONAL_FORMAT
:
1208 link_info
.traditional_format
= TRUE
;
1210 case OPTION_TASK_LINK
:
1211 link_info
.task_link
= TRUE
;
1212 /* Fall through - do an implied -r option. */
1214 link_info
.relocatable
= TRUE
;
1215 config
.build_constructors
= TRUE
;
1216 config
.magic_demand_paged
= FALSE
;
1217 config
.text_read_only
= FALSE
;
1218 input_flags
.dynamic
= FALSE
;
1221 ldlang_add_undef (optarg
, TRUE
);
1225 lang_add_unique (optarg
);
1227 config
.unique_orphan_sections
= TRUE
;
1229 case OPTION_VERBOSE
:
1231 version_printed
= TRUE
;
1233 overflow_cutoff_limit
= -2;
1237 int level ATTRIBUTE_UNUSED
= strtoul (optarg
, &end
, 0);
1239 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
1240 #ifdef ENABLE_PLUGINS
1241 report_plugin_symbols
= level
> 1;
1242 #endif /* ENABLE_PLUGINS */
1247 version_printed
= TRUE
;
1251 version_printed
= TRUE
;
1253 case OPTION_VERSION
:
1257 case OPTION_VERSION_SCRIPT
:
1258 /* This option indicates a small script that only specifies
1259 version information. Read it, but don't assume that
1260 we've seen a linker script. */
1262 FILE *hold_script_handle
;
1264 hold_script_handle
= saved_script_handle
;
1265 ldfile_open_command_file (optarg
);
1266 saved_script_handle
= hold_script_handle
;
1267 parser_input
= input_version_script
;
1271 case OPTION_VERSION_EXPORTS_SECTION
:
1272 /* This option records a version symbol to be applied to the
1273 symbols listed for export to be found in the object files
1274 .exports sections. */
1275 command_line
.version_exports_section
= optarg
;
1277 case OPTION_DYNAMIC_LIST_DATA
:
1278 command_line
.dynamic_list
= dynamic_list_data
;
1279 if (command_line
.symbolic
== symbolic
)
1280 command_line
.symbolic
= symbolic_unset
;
1282 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1283 lang_append_dynamic_list_cpp_typeinfo ();
1284 if (command_line
.dynamic_list
!= dynamic_list_data
)
1285 command_line
.dynamic_list
= dynamic_list
;
1286 if (command_line
.symbolic
== symbolic
)
1287 command_line
.symbolic
= symbolic_unset
;
1289 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1290 lang_append_dynamic_list_cpp_new ();
1291 if (command_line
.dynamic_list
!= dynamic_list_data
)
1292 command_line
.dynamic_list
= dynamic_list
;
1293 if (command_line
.symbolic
== symbolic
)
1294 command_line
.symbolic
= symbolic_unset
;
1296 case OPTION_DYNAMIC_LIST
:
1297 /* This option indicates a small script that only specifies
1298 a dynamic list. Read it, but don't assume that we've
1299 seen a linker script. */
1301 FILE *hold_script_handle
;
1303 hold_script_handle
= saved_script_handle
;
1304 ldfile_open_command_file (optarg
);
1305 saved_script_handle
= hold_script_handle
;
1306 parser_input
= input_dynamic_list
;
1309 if (command_line
.dynamic_list
!= dynamic_list_data
)
1310 command_line
.dynamic_list
= dynamic_list
;
1311 if (command_line
.symbolic
== symbolic
)
1312 command_line
.symbolic
= symbolic_unset
;
1314 case OPTION_WARN_COMMON
:
1315 config
.warn_common
= TRUE
;
1317 case OPTION_WARN_CONSTRUCTORS
:
1318 config
.warn_constructors
= TRUE
;
1320 case OPTION_WARN_FATAL
:
1321 config
.fatal_warnings
= TRUE
;
1323 case OPTION_NO_WARN_FATAL
:
1324 config
.fatal_warnings
= FALSE
;
1326 case OPTION_WARN_MULTIPLE_GP
:
1327 config
.warn_multiple_gp
= TRUE
;
1329 case OPTION_WARN_ONCE
:
1330 config
.warn_once
= TRUE
;
1332 case OPTION_WARN_SECTION_ALIGN
:
1333 config
.warn_section_align
= TRUE
;
1335 case OPTION_WARN_SHARED_TEXTREL
:
1336 link_info
.warn_shared_textrel
= TRUE
;
1338 case OPTION_WARN_ALTERNATE_EM
:
1339 link_info
.warn_alternate_em
= TRUE
;
1341 case OPTION_WHOLE_ARCHIVE
:
1342 input_flags
.whole_archive
= TRUE
;
1344 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
:
1345 input_flags
.add_DT_NEEDED_for_dynamic
= TRUE
;
1347 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
:
1348 input_flags
.add_DT_NEEDED_for_dynamic
= FALSE
;
1350 case OPTION_ADD_DT_NEEDED_FOR_REGULAR
:
1351 input_flags
.add_DT_NEEDED_for_regular
= TRUE
;
1353 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
:
1354 input_flags
.add_DT_NEEDED_for_regular
= FALSE
;
1359 case OPTION_IGNORE_UNRESOLVED_SYMBOL
:
1360 add_ignoresym (&link_info
, optarg
);
1362 case OPTION_DISCARD_NONE
:
1363 link_info
.discard
= discard_none
;
1366 link_info
.discard
= discard_l
;
1369 link_info
.discard
= discard_all
;
1372 if (CONST_STRNEQ (optarg
, "P,"))
1374 if (default_dirlist
!= NULL
)
1375 free (default_dirlist
);
1376 default_dirlist
= xstrdup (optarg
);
1381 case OPTION_SPARE_DYNAMIC_TAGS
:
1382 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1384 case OPTION_SPLIT_BY_RELOC
:
1386 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1388 config
.split_by_reloc
= 32768;
1390 case OPTION_SPLIT_BY_FILE
:
1392 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1394 config
.split_by_file
= 1;
1396 case OPTION_CHECK_SECTIONS
:
1397 command_line
.check_section_addresses
= 1;
1399 case OPTION_NO_CHECK_SECTIONS
:
1400 command_line
.check_section_addresses
= 0;
1402 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1403 command_line
.accept_unknown_input_arch
= TRUE
;
1405 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1406 command_line
.accept_unknown_input_arch
= FALSE
;
1409 lang_enter_group ();
1414 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1416 lang_leave_group ();
1421 link_info
.init_function
= optarg
;
1425 link_info
.fini_function
= optarg
;
1428 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1429 link_info
.reduce_memory_overheads
= TRUE
;
1430 if (config
.hash_table_size
== 0)
1431 config
.hash_table_size
= 1021;
1434 case OPTION_HASH_SIZE
:
1436 bfd_size_type new_size
;
1438 new_size
= strtoul (optarg
, NULL
, 0);
1440 config
.hash_table_size
= new_size
;
1442 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1450 lang_leave_group ();
1454 if (default_dirlist
!= NULL
)
1456 set_default_dirlist (default_dirlist
);
1457 free (default_dirlist
);
1460 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1461 /* FIXME: Should we allow emulations a chance to set this ? */
1462 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1464 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1465 /* FIXME: Should we allow emulations a chance to set this ? */
1466 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1468 if (link_info
.relocatable
)
1470 if (command_line
.check_section_addresses
< 0)
1471 command_line
.check_section_addresses
= 0;
1472 if (link_info
.shared
)
1473 einfo (_("%P%F: -r and -shared may not be used together\n"));
1476 /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data,
1477 --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and
1478 --dynamic-list FILE. -Bsymbolic and -Bsymbolic-functions are
1479 for shared libraries. -Bsymbolic overrides all others and vice
1481 switch (command_line
.symbolic
)
1483 case symbolic_unset
:
1486 /* -Bsymbolic is for shared library only. */
1487 if (link_info
.shared
)
1489 link_info
.symbolic
= TRUE
;
1490 /* Should we free the unused memory? */
1491 link_info
.dynamic_list
= NULL
;
1492 command_line
.dynamic_list
= dynamic_list_unset
;
1495 case symbolic_functions
:
1496 /* -Bsymbolic-functions is for shared library only. */
1497 if (link_info
.shared
)
1498 command_line
.dynamic_list
= dynamic_list_data
;
1502 switch (command_line
.dynamic_list
)
1504 case dynamic_list_unset
:
1506 case dynamic_list_data
:
1507 link_info
.dynamic_data
= TRUE
;
1509 link_info
.dynamic
= TRUE
;
1513 if (! link_info
.shared
)
1515 if (command_line
.filter_shlib
)
1516 einfo (_("%P%F: -F may not be used without -shared\n"));
1517 if (command_line
.auxiliary_filters
)
1518 einfo (_("%P%F: -f may not be used without -shared\n"));
1521 if (! link_info
.shared
|| link_info
.pie
)
1522 link_info
.executable
= TRUE
;
1524 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1525 don't see how else this can be handled, since in this case we
1526 must preserve all externally visible symbols. */
1527 if (link_info
.relocatable
&& link_info
.strip
== strip_all
)
1529 link_info
.strip
= strip_debugger
;
1530 if (link_info
.discard
== discard_sec_merge
)
1531 link_info
.discard
= discard_all
;
1535 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1536 library search path. */
1539 set_default_dirlist (char *dirlist_ptr
)
1545 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1548 if (*dirlist_ptr
!= '\0')
1549 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1552 dirlist_ptr
= p
+ 1;
1557 set_section_start (char *sect
, char *valstr
)
1560 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1562 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1563 lang_section_start (sect
, exp_intop (val
), NULL
);
1567 set_segment_start (const char *section
, char *valstr
)
1573 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1575 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1576 /* If we already have an entry for this segment, update the existing
1579 for (seg
= segments
; seg
; seg
= seg
->next
)
1580 if (strcmp (seg
->name
, name
) == 0)
1585 /* There was no existing value so we must create a new segment
1587 seg
= (segment_type
*) stat_alloc (sizeof (*seg
));
1591 /* Add it to the linked list of segments. */
1592 seg
->next
= segments
;
1594 /* Historically, -Ttext and friends set the base address of a
1595 particular section. For backwards compatibility, we still do
1596 that. If a SEGMENT_START directive is seen, the section address
1597 assignment will be disabled. */
1598 lang_section_start (section
, exp_intop (val
), seg
);
1602 /* Print help messages for the options. */
1608 const char **targets
, **pp
;
1611 printf (_("Usage: %s [options] file...\n"), program_name
);
1613 printf (_("Options:\n"));
1614 for (i
= 0; i
< OPTION_COUNT
; i
++)
1616 if (ld_options
[i
].doc
!= NULL
)
1629 if (ld_options
[j
].shortopt
!= '\0'
1630 && ld_options
[j
].control
!= NO_HELP
)
1632 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1633 len
+= (comma
? 2 : 0) + 2;
1634 if (ld_options
[j
].arg
!= NULL
)
1636 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1641 printf ("%s", _(ld_options
[j
].arg
));
1642 len
+= strlen (_(ld_options
[j
].arg
));
1648 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1653 if (ld_options
[j
].opt
.name
!= NULL
1654 && ld_options
[j
].control
!= NO_HELP
)
1657 (ld_options
[j
].control
== TWO_DASHES
1658 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1662 two_dashes
? "-" : "",
1663 ld_options
[j
].opt
.name
);
1664 len
+= ((comma
? 2 : 0)
1666 + (two_dashes
? 1 : 0)
1667 + strlen (ld_options
[j
].opt
.name
));
1668 if (ld_options
[j
].arg
!= NULL
)
1670 printf (" %s", _(ld_options
[j
].arg
));
1671 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1677 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1685 for (; len
< 30; len
++)
1688 printf ("%s\n", _(ld_options
[i
].doc
));
1691 printf (_(" @FILE"));
1692 for (len
= strlen (" @FILE"); len
< 30; len
++)
1694 printf (_("Read options from FILE\n"));
1696 /* Note: Various tools (such as libtool) depend upon the
1697 format of the listings below - do not change them. */
1698 /* xgettext:c-format */
1699 printf (_("%s: supported targets:"), program_name
);
1700 targets
= bfd_target_list ();
1701 for (pp
= targets
; *pp
!= NULL
; pp
++)
1702 printf (" %s", *pp
);
1706 /* xgettext:c-format */
1707 printf (_("%s: supported emulations: "), program_name
);
1708 ldemul_list_emulations (stdout
);
1711 /* xgettext:c-format */
1712 printf (_("%s: emulation specific options:\n"), program_name
);
1713 ldemul_list_emulation_options (stdout
);
1716 if (REPORT_BUGS_TO
[0])
1717 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);