1 /* Parse options for the GNU linker.
2 Copyright (C) 1991-2015 Free Software Foundation, Inc.
4 This file is part of the GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
24 #include "libiberty.h"
27 #include "safe-ctype.h"
43 #endif /* ENABLE_PLUGINS */
45 #ifndef PATH_SEPARATOR
46 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
47 #define PATH_SEPARATOR ';'
49 #define PATH_SEPARATOR ':'
53 /* Somewhere above, sys/stat.h got included . . . . */
54 #if !defined(S_ISDIR) && defined(S_IFDIR)
55 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
58 static void set_default_dirlist (char *);
59 static void set_section_start (char *, char *);
60 static void set_segment_start (const char *, char *);
61 static void help (void);
63 /* The long options. This structure is used for both the option
64 parsing and the help text. */
67 /* Use one dash before long option name. */
69 /* Use two dashes before long option name. */
71 /* Only accept two dashes before the long option name.
72 This is an overloading of the use of this enum, since originally it
73 was only intended to tell the --help display function how to display
74 the long option name. This feature was added in order to resolve
75 the confusion about the -omagic command line switch. Is it setting
76 the output file name to "magic" or is it setting the NMAGIC flag on
77 the output ? It has been decided that it is setting the output file
78 name, and that if you want to set the NMAGIC flag you should use -N
81 /* Don't mention this option in --help output. */
87 /* The long option information. */
89 /* The short option with the same meaning ('\0' if none). */
91 /* The name of the argument (NULL if none). */
93 /* The documentation string. If this is NULL, this is a synonym for
94 the previous option. */
96 enum control_enum control
;
99 static const struct ld_option ld_options
[] =
101 { {NULL
, required_argument
, NULL
, '\0'},
102 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
104 { {"architecture", required_argument
, NULL
, 'A'},
105 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
106 { {"format", required_argument
, NULL
, 'b'},
107 'b', N_("TARGET"), N_("Specify target for following input files"),
109 { {"mri-script", required_argument
, NULL
, 'c'},
110 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
111 { {"dc", no_argument
, NULL
, 'd'},
112 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
113 { {"dp", no_argument
, NULL
, 'd'},
114 '\0', NULL
, NULL
, ONE_DASH
},
115 { {"entry", required_argument
, NULL
, 'e'},
116 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
117 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
118 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
119 { {"no-export-dynamic", no_argument
, NULL
, OPTION_NO_EXPORT_DYNAMIC
},
120 '\0', NULL
, N_("Undo the effect of --export-dynamic"), TWO_DASHES
},
121 { {"EB", no_argument
, NULL
, OPTION_EB
},
122 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
123 { {"EL", no_argument
, NULL
, OPTION_EL
},
124 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
125 { {"auxiliary", required_argument
, NULL
, 'f'},
126 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
128 { {"filter", required_argument
, NULL
, 'F'},
129 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
131 { {NULL
, no_argument
, NULL
, '\0'},
132 'g', NULL
, N_("Ignored"), ONE_DASH
},
133 { {"gpsize", required_argument
, NULL
, 'G'},
134 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
136 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
137 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
138 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
139 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
141 { {"library", required_argument
, NULL
, 'l'},
142 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
143 { {"library-path", required_argument
, NULL
, 'L'},
144 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
146 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
147 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
148 { {NULL
, required_argument
, NULL
, '\0'},
149 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
150 { {"print-map", no_argument
, NULL
, 'M'},
151 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
152 { {"nmagic", no_argument
, NULL
, 'n'},
153 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
154 { {"omagic", no_argument
, NULL
, 'N'},
155 'N', NULL
, N_("Do not page align data, do not make text readonly"),
156 EXACTLY_TWO_DASHES
},
157 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
158 '\0', NULL
, N_("Page align data, make text readonly"),
159 EXACTLY_TWO_DASHES
},
160 { {"output", required_argument
, NULL
, 'o'},
161 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
162 { {NULL
, required_argument
, NULL
, '\0'},
163 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
164 #ifdef ENABLE_PLUGINS
165 { {"plugin", required_argument
, NULL
, OPTION_PLUGIN
},
166 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH
},
167 { {"plugin-opt", required_argument
, NULL
, OPTION_PLUGIN_OPT
},
168 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH
},
169 { {"flto", optional_argument
, NULL
, OPTION_IGNORE
},
170 '\0', NULL
, N_("Ignored for GCC LTO option compatibility"),
172 { {"flto-partition=", required_argument
, NULL
, OPTION_IGNORE
},
173 '\0', NULL
, N_("Ignored for GCC LTO option compatibility"),
175 #endif /* ENABLE_PLUGINS */
176 { {"fuse-ld=", required_argument
, NULL
, OPTION_IGNORE
},
177 '\0', NULL
, N_("Ignored for GCC linker option compatibility"),
179 { {"map-whole-files", optional_argument
, NULL
, OPTION_IGNORE
},
180 '\0', NULL
, N_("Ignored for gold option compatibility"),
182 { {"no-map-whole-files", optional_argument
, NULL
, OPTION_IGNORE
},
183 '\0', NULL
, N_("Ignored for gold option compatibility"),
185 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
186 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
187 { {"emit-relocs", no_argument
, NULL
, 'q'},
188 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
189 { {"relocatable", no_argument
, NULL
, 'r'},
190 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
191 { {NULL
, no_argument
, NULL
, '\0'},
192 'i', NULL
, NULL
, ONE_DASH
},
193 { {"just-symbols", required_argument
, NULL
, 'R'},
194 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
196 { {"strip-all", no_argument
, NULL
, 's'},
197 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
198 { {"strip-debug", no_argument
, NULL
, 'S'},
199 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
200 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
201 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
202 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
203 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
204 { {"trace", no_argument
, NULL
, 't'},
205 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
206 { {"script", required_argument
, NULL
, 'T'},
207 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
208 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
209 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
210 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
211 '\0', NULL
, NULL
, ONE_DASH
},
212 { {"undefined", required_argument
, NULL
, 'u'},
213 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
215 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
216 '\0', N_("[=SECTION]"),
217 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
218 { {"Ur", no_argument
, NULL
, OPTION_UR
},
219 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
220 { {"version", no_argument
, NULL
, OPTION_VERSION
},
221 'v', NULL
, N_("Print version information"), TWO_DASHES
},
222 { {NULL
, no_argument
, NULL
, '\0'},
223 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
224 { {"discard-all", no_argument
, NULL
, 'x'},
225 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
226 { {"discard-locals", no_argument
, NULL
, 'X'},
227 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
228 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
229 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
230 { {"trace-symbol", required_argument
, NULL
, 'y'},
231 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
232 { {NULL
, required_argument
, NULL
, '\0'},
233 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
235 { {"start-group", no_argument
, NULL
, '('},
236 '(', NULL
, N_("Start a group"), TWO_DASHES
},
237 { {"end-group", no_argument
, NULL
, ')'},
238 ')', NULL
, N_("End a group"), TWO_DASHES
},
239 { {"accept-unknown-input-arch", no_argument
, NULL
,
240 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
242 N_("Accept input files whose architecture cannot be determined"),
244 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
245 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
246 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
249 /* The next two options are deprecated because of their similarity to
250 --as-needed and --no-as-needed. They have been replaced by
251 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
252 { {"add-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
253 '\0', NULL
, NULL
, NO_HELP
},
254 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
255 '\0', NULL
, NULL
, NO_HELP
},
257 { {"as-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_REGULAR
},
258 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
260 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
},
261 '\0', NULL
, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
262 " the command line"),
264 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
265 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
266 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
267 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
268 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
269 '\0', NULL
, NULL
, ONE_DASH
},
270 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
271 '\0', NULL
, NULL
, ONE_DASH
},
272 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
273 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
274 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
275 '\0', NULL
, NULL
, ONE_DASH
},
276 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
277 '\0', NULL
, NULL
, ONE_DASH
},
278 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
279 '\0', NULL
, NULL
, ONE_DASH
},
280 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
281 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
282 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
283 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
284 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
285 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
287 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
288 '\0', NULL
, N_("Do not check section addresses for overlaps"),
290 { {"copy-dt-needed-entries", no_argument
, NULL
,
291 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
292 '\0', NULL
, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
294 { {"no-copy-dt-needed-entries", no_argument
, NULL
,
295 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
296 '\0', NULL
, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
299 { {"cref", no_argument
, NULL
, OPTION_CREF
},
300 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
301 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
302 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
303 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
304 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
306 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
307 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
308 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
309 '\0', NULL
, N_("Treat warnings as errors"),
311 { {"no-fatal-warnings", no_argument
, NULL
, OPTION_NO_WARN_FATAL
},
312 '\0', NULL
, N_("Do not treat warnings as errors (default)"),
314 { {"fini", required_argument
, NULL
, OPTION_FINI
},
315 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
316 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
317 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
318 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
319 '\0', NULL
, N_("Remove unused sections (on some targets)"),
321 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
322 '\0', NULL
, N_("Don't remove unused sections (default)"),
324 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
325 '\0', NULL
, N_("List removed unused sections on stderr"),
327 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
328 '\0', NULL
, N_("Do not list removed unused sections"),
330 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
331 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
333 { {"help", no_argument
, NULL
, OPTION_HELP
},
334 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
335 { {"init", required_argument
, NULL
, OPTION_INIT
},
336 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
337 { {"Map", required_argument
, NULL
, OPTION_MAP
},
338 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
339 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
340 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
341 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
342 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
343 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
344 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
345 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
346 '\0', NULL
, N_("Do not allow unresolved references in object files"),
348 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
349 '\0', NULL
, N_("Allow unresolved references in shared libraries"),
351 { {"no-allow-shlib-undefined", no_argument
, NULL
,
352 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
353 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
355 { {"allow-multiple-definition", no_argument
, NULL
,
356 OPTION_ALLOW_MULTIPLE_DEFINITION
},
357 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
358 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
359 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
360 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
361 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
362 { {"default-imported-symver", no_argument
, NULL
,
363 OPTION_DEFAULT_IMPORTED_SYMVER
},
364 '\0', NULL
, N_("Create default symbol version for imported symbols"),
366 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
367 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
368 { {"no-warn-search-mismatch", no_argument
, NULL
,
369 OPTION_NO_WARN_SEARCH_MISMATCH
},
370 '\0', NULL
, N_("Don't warn on finding an incompatible library"),
372 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
373 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
374 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
375 '\0', NULL
, N_("Create an output file even if errors occur"),
377 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
378 '\0', NULL
, NULL
, NO_HELP
},
379 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
380 '\0', NULL
, N_("Only use library directories specified on\n"
381 " the command line"),
383 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
384 '\0', N_("TARGET"), N_("Specify target of output file"),
385 EXACTLY_TWO_DASHES
},
386 { {"print-output-format", no_argument
, NULL
, OPTION_PRINT_OUTPUT_FORMAT
},
387 '\0', NULL
, N_("Print default output format"), TWO_DASHES
},
388 { {"print-sysroot", no_argument
, NULL
, OPTION_PRINT_SYSROOT
},
389 '\0', NULL
, N_("Print current sysroot"), TWO_DASHES
},
390 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
391 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
392 { {"reduce-memory-overheads", no_argument
, NULL
,
393 OPTION_REDUCE_MEMORY_OVERHEADS
},
394 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
396 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
397 '\0', NULL
, N_("Reduce code size by using target specific optimizations"), TWO_DASHES
},
398 { {"no-relax", no_argument
, NULL
, OPTION_NO_RELAX
},
399 '\0', NULL
, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES
},
400 { {"retain-symbols-file", required_argument
, NULL
,
401 OPTION_RETAIN_SYMBOLS_FILE
},
402 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
403 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
404 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
405 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
406 '\0', N_("PATH"), N_("Set link time shared library search path"),
408 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
409 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
410 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
411 '\0', NULL
, NULL
, ONE_DASH
},
412 { {"pie", no_argument
, NULL
, OPTION_PIE
},
413 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
414 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
415 '\0', NULL
, NULL
, TWO_DASHES
},
416 { {"sort-common", optional_argument
, NULL
, OPTION_SORT_COMMON
},
417 '\0', N_("[=ascending|descending]"),
418 N_("Sort common symbols by alignment [in specified order]"),
420 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
421 '\0', NULL
, NULL
, NO_HELP
},
422 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
423 '\0', N_("name|alignment"),
424 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
425 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
426 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
428 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
429 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
431 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
432 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
434 { {"stats", no_argument
, NULL
, OPTION_STATS
},
435 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
436 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
437 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
438 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
439 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
440 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
441 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
442 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
443 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
445 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
446 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
447 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
448 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
449 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
450 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
451 { {"Ttext-segment", required_argument
, NULL
, OPTION_TTEXT_SEGMENT
},
452 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH
},
453 { {"Trodata-segment", required_argument
, NULL
, OPTION_TRODATA_SEGMENT
},
454 '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH
},
455 { {"Tldata-segment", required_argument
, NULL
, OPTION_TLDATA_SEGMENT
},
456 '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH
},
457 { {"unresolved-symbols=<method>", required_argument
, NULL
,
458 OPTION_UNRESOLVED_SYMBOLS
},
459 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
460 " ignore-all, report-all, ignore-in-object-files,\n"
461 " ignore-in-shared-libs"),
463 { {"verbose", optional_argument
, NULL
, OPTION_VERBOSE
},
464 '\0', N_("[=NUMBER]"),
465 N_("Output lots of information during link"), TWO_DASHES
},
466 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
467 '\0', NULL
, NULL
, NO_HELP
},
468 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
469 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
470 { {"version-exports-section", required_argument
, NULL
,
471 OPTION_VERSION_EXPORTS_SECTION
},
472 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
473 " SYMBOL as the version."),
475 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
476 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
477 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
478 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
479 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
480 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
481 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
482 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
483 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
484 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
485 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
486 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
488 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
489 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
490 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
491 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
492 { {"warn-orphan", no_argument
, NULL
, OPTION_WARN_ORPHAN
},
493 '\0', NULL
, N_("Warn if any orphan sections are encountered"), TWO_DASHES
},
494 { {"no-warn-orphan", no_argument
, NULL
, OPTION_NO_WARN_ORPHAN
},
495 '\0', NULL
, N_("Do not warn if orphan sections are encountered (default)"), TWO_DASHES
},
496 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
497 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
499 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_SHARED_TEXTREL
},
500 '\0', NULL
, N_("Warn if shared object has DT_TEXTREL"),
502 { {"warn-alternate-em", no_argument
, NULL
, OPTION_WARN_ALTERNATE_EM
},
503 '\0', NULL
, N_("Warn if an object has alternate ELF machine code"),
505 { {"warn-unresolved-symbols", no_argument
, NULL
,
506 OPTION_WARN_UNRESOLVED_SYMBOLS
},
507 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
508 { {"error-unresolved-symbols", no_argument
, NULL
,
509 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
510 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
511 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
512 '\0', NULL
, N_("Include all objects from following archives"),
514 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
515 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
516 { {"ignore-unresolved-symbol", required_argument
, NULL
,
517 OPTION_IGNORE_UNRESOLVED_SYMBOL
},
519 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES
},
520 { {"push-state", no_argument
, NULL
, OPTION_PUSH_STATE
},
521 '\0', NULL
, N_("Push state of flags governing input file handling"),
523 { {"pop-state", no_argument
, NULL
, OPTION_POP_STATE
},
524 '\0', NULL
, N_("Pop state of flags governing input file handling"),
526 { {"print-memory-usage", no_argument
, NULL
, OPTION_PRINT_MEMORY_USAGE
},
527 '\0', NULL
, N_("Report target memory usage"), TWO_DASHES
},
530 #define OPTION_COUNT ARRAY_SIZE (ld_options)
533 parse_args (unsigned argc
, char **argv
)
538 char *default_dirlist
= NULL
;
540 struct option
*longopts
;
541 struct option
*really_longopts
;
543 enum report_method how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
545 shortopts
= (char *) xmalloc (OPTION_COUNT
* 3 + 2);
546 longopts
= (struct option
*)
547 xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
548 really_longopts
= (struct option
*)
549 malloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
551 /* Starting the short option string with '-' is for programs that
552 expect options and other ARGV-elements in any order and that care about
553 the ordering of the two. We describe each non-option ARGV-element
554 as if it were the argument of an option with character code 1. */
559 for (i
= 0; i
< OPTION_COUNT
; i
++)
561 if (ld_options
[i
].shortopt
!= '\0')
563 shortopts
[is
] = ld_options
[i
].shortopt
;
565 if (ld_options
[i
].opt
.has_arg
== required_argument
566 || ld_options
[i
].opt
.has_arg
== optional_argument
)
570 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
577 if (ld_options
[i
].opt
.name
!= NULL
)
579 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
581 really_longopts
[irl
] = ld_options
[i
].opt
;
586 longopts
[il
] = ld_options
[i
].opt
;
591 shortopts
[is
] = '\0';
592 longopts
[il
].name
= NULL
;
593 really_longopts
[irl
].name
= NULL
;
595 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
597 /* The -G option is ambiguous on different platforms. Sometimes it
598 specifies the largest data size to put into the small data
599 section. Sometimes it is equivalent to --shared. Unfortunately,
600 the first form takes an argument, while the second does not.
602 We need to permit the --shared form because on some platforms,
603 such as Solaris, gcc -shared will pass -G to the linker.
605 To permit either usage, we look through the argument list. If we
606 find -G not followed by a number, we change it into --shared.
607 This will work for most normal cases. */
608 for (i
= 1; i
< argc
; i
++)
609 if (strcmp (argv
[i
], "-G") == 0
611 || ! ISDIGIT (argv
[i
+ 1][0])))
612 argv
[i
] = (char *) "--shared";
614 /* Because we permit long options to start with a single dash, and
615 we have a --library option, and the -l option is conventionally
616 used with an immediately following argument, we can have bad
617 results if somebody tries to use -l with a library whose name
618 happens to start with "ibrary", as in -li. We avoid problems by
619 simply turning -l into --library. This means that users will
620 have to use two dashes in order to use --library, which is OK
621 since that's how it is documented.
623 FIXME: It's possible that this problem can arise for other short
624 options as well, although the user does always have the recourse
625 of adding a space between the option and the argument. */
626 for (i
= 1; i
< argc
; i
++)
628 if (argv
[i
][0] == '-'
630 && argv
[i
][2] != '\0')
634 n
= (char *) xmalloc (strlen (argv
[i
]) + 20);
635 sprintf (n
, "--library=%s", argv
[i
] + 2);
645 static unsigned int defsym_count
;
647 /* Using last_optind lets us avoid calling ldemul_parse_args
648 multiple times on a single option, which would lead to
649 confusion in the internal static variables maintained by
650 getopt. This could otherwise happen for an argument like
651 -nx, in which the -n is parsed as a single option, and we
652 loop around to pick up the -x. */
653 if (optind
!= last_optind
)
654 if (ldemul_parse_args (argc
, argv
))
657 /* getopt_long_only is like getopt_long, but '-' as well as '--'
658 can indicate a long option. */
660 last_optind
= optind
;
661 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
664 optind
= last_optind
;
665 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
668 if (ldemul_handle_option (optc
))
677 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
681 einfo (_("%P%F: use the --help option for usage information\n"));
683 case 1: /* File name. */
684 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
690 /* For HP/UX compatibility. Actually -a shared should mean
691 ``use only shared libraries'' but, then, we don't
692 currently support shared libraries on HP/UX anyhow. */
693 if (strcmp (optarg
, "archive") == 0)
694 input_flags
.dynamic
= FALSE
;
695 else if (strcmp (optarg
, "shared") == 0
696 || strcmp (optarg
, "default") == 0)
697 input_flags
.dynamic
= TRUE
;
699 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
702 /* FIXME: We just ignore these, but we should handle them. */
703 if (strcmp (optarg
, "definitions") == 0)
705 else if (strcmp (optarg
, "nodefinitions") == 0)
707 else if (strcmp (optarg
, "nosymbolic") == 0)
709 else if (strcmp (optarg
, "pure-text") == 0)
712 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
715 ldfile_add_arch (optarg
);
718 lang_add_target (optarg
);
721 ldfile_open_command_file (optarg
);
722 parser_input
= input_mri_script
;
725 case OPTION_CALL_SHARED
:
726 input_flags
.dynamic
= TRUE
;
728 case OPTION_NON_SHARED
:
729 input_flags
.dynamic
= FALSE
;
732 command_line
.cref
= TRUE
;
733 link_info
.notice_all
= TRUE
;
736 command_line
.force_common_definition
= TRUE
;
740 lex_redirect (optarg
, "--defsym", ++defsym_count
);
741 parser_input
= input_defsym
;
745 case OPTION_DEMANGLE
:
749 enum demangling_styles style
;
751 style
= cplus_demangle_name_to_style (optarg
);
752 if (style
== unknown_demangling
)
753 einfo (_("%F%P: unknown demangling style `%s'\n"),
756 cplus_demangle_set_style (style
);
759 case 'I': /* Used on Solaris. */
760 case OPTION_DYNAMIC_LINKER
:
761 command_line
.interpreter
= optarg
;
764 /* Already handled in ldmain.c. */
767 command_line
.endian
= ENDIAN_BIG
;
770 command_line
.endian
= ENDIAN_LITTLE
;
772 case OPTION_EMBEDDED_RELOCS
:
773 command_line
.embedded_relocs
= TRUE
;
775 case OPTION_EXPORT_DYNAMIC
:
776 case 'E': /* HP/UX compatibility. */
777 link_info
.export_dynamic
= TRUE
;
779 case OPTION_NO_EXPORT_DYNAMIC
:
780 link_info
.export_dynamic
= FALSE
;
783 lang_add_entry (optarg
, TRUE
);
786 if (command_line
.auxiliary_filters
== NULL
)
788 command_line
.auxiliary_filters
= (char **)
789 xmalloc (2 * sizeof (char *));
790 command_line
.auxiliary_filters
[0] = optarg
;
791 command_line
.auxiliary_filters
[1] = NULL
;
799 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
801 command_line
.auxiliary_filters
= (char **)
802 xrealloc (command_line
.auxiliary_filters
,
803 (c
+ 2) * sizeof (char *));
804 command_line
.auxiliary_filters
[c
] = optarg
;
805 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
809 command_line
.filter_shlib
= optarg
;
811 case OPTION_FORCE_EXE_SUFFIX
:
812 command_line
.force_exe_suffix
= TRUE
;
817 g_switch_value
= strtoul (optarg
, &end
, 0);
819 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
825 case OPTION_GC_SECTIONS
:
826 link_info
.gc_sections
= TRUE
;
828 case OPTION_PRINT_GC_SECTIONS
:
829 link_info
.print_gc_sections
= TRUE
;
836 ldfile_add_library_path (optarg
, TRUE
);
839 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
842 config
.map_filename
= "-";
845 /* Ignore. Was handled in a pre-parse. */
848 config
.map_filename
= optarg
;
851 config
.text_read_only
= FALSE
;
852 config
.magic_demand_paged
= FALSE
;
853 input_flags
.dynamic
= FALSE
;
855 case OPTION_NO_OMAGIC
:
856 config
.text_read_only
= TRUE
;
857 config
.magic_demand_paged
= TRUE
;
858 /* NB/ Does not set input_flags.dynamic to TRUE.
859 Use --call-shared or -Bdynamic for this. */
862 config
.magic_demand_paged
= FALSE
;
863 input_flags
.dynamic
= FALSE
;
865 case OPTION_NO_DEFINE_COMMON
:
866 command_line
.inhibit_common_definition
= TRUE
;
868 case OPTION_NO_DEMANGLE
:
871 case OPTION_NO_GC_SECTIONS
:
872 link_info
.gc_sections
= FALSE
;
874 case OPTION_NO_PRINT_GC_SECTIONS
:
875 link_info
.print_gc_sections
= FALSE
;
877 case OPTION_NO_KEEP_MEMORY
:
878 link_info
.keep_memory
= FALSE
;
880 case OPTION_NO_UNDEFINED
:
881 link_info
.unresolved_syms_in_objects
882 = how_to_report_unresolved_symbols
;
884 case OPTION_ALLOW_SHLIB_UNDEFINED
:
885 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
887 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
888 link_info
.unresolved_syms_in_shared_libs
889 = how_to_report_unresolved_symbols
;
891 case OPTION_UNRESOLVED_SYMBOLS
:
892 if (strcmp (optarg
, "ignore-all") == 0)
894 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
895 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
897 else if (strcmp (optarg
, "report-all") == 0)
899 link_info
.unresolved_syms_in_objects
900 = how_to_report_unresolved_symbols
;
901 link_info
.unresolved_syms_in_shared_libs
902 = how_to_report_unresolved_symbols
;
904 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
906 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
907 link_info
.unresolved_syms_in_shared_libs
908 = how_to_report_unresolved_symbols
;
910 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
912 link_info
.unresolved_syms_in_objects
913 = how_to_report_unresolved_symbols
;
914 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
917 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg
);
919 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
920 how_to_report_unresolved_symbols
= RM_GENERATE_WARNING
;
921 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
922 link_info
.unresolved_syms_in_objects
= RM_GENERATE_WARNING
;
923 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
924 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_WARNING
;
927 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
928 how_to_report_unresolved_symbols
= RM_GENERATE_ERROR
;
929 if (link_info
.unresolved_syms_in_objects
== RM_GENERATE_WARNING
)
930 link_info
.unresolved_syms_in_objects
= RM_GENERATE_ERROR
;
931 if (link_info
.unresolved_syms_in_shared_libs
== RM_GENERATE_WARNING
)
932 link_info
.unresolved_syms_in_shared_libs
= RM_GENERATE_ERROR
;
934 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
935 link_info
.allow_multiple_definition
= TRUE
;
937 case OPTION_NO_UNDEFINED_VERSION
:
938 link_info
.allow_undefined_version
= FALSE
;
940 case OPTION_DEFAULT_SYMVER
:
941 link_info
.create_default_symver
= TRUE
;
943 case OPTION_DEFAULT_IMPORTED_SYMVER
:
944 link_info
.default_imported_symver
= TRUE
;
946 case OPTION_NO_WARN_MISMATCH
:
947 command_line
.warn_mismatch
= FALSE
;
949 case OPTION_NO_WARN_SEARCH_MISMATCH
:
950 command_line
.warn_search_mismatch
= FALSE
;
952 case OPTION_NOINHIBIT_EXEC
:
953 force_make_executable
= TRUE
;
955 case OPTION_NOSTDLIB
:
956 config
.only_cmd_line_lib_dirs
= TRUE
;
958 case OPTION_NO_WHOLE_ARCHIVE
:
959 input_flags
.whole_archive
= FALSE
;
962 /* FIXME "-O<non-digits> <value>" used to set the address of
963 section <non-digits>. Was this for compatibility with
964 something, or can we create a new option to do that
965 (with a syntax similar to -defsym)?
966 getopt can't handle two args to an option without kludges. */
968 /* Enable optimizations of output files. */
969 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? TRUE
: FALSE
;
972 lang_add_output (optarg
, 0);
975 lang_add_output_format (optarg
, NULL
, NULL
, 0);
977 case OPTION_PRINT_SYSROOT
:
982 case OPTION_PRINT_OUTPUT_FORMAT
:
983 command_line
.print_output_format
= TRUE
;
985 #ifdef ENABLE_PLUGINS
987 plugin_opt_plugin (optarg
);
989 case OPTION_PLUGIN_OPT
:
990 if (plugin_opt_plugin_arg (optarg
))
991 einfo(_("%P%F: bad -plugin-opt option\n"));
993 #endif /* ENABLE_PLUGINS */
995 link_info
.emitrelocations
= TRUE
;
999 if (optind
== last_optind
)
1000 /* This can happen if the user put "-rpath,a" on the command
1001 line. (Or something similar. The comma is important).
1002 Getopt becomes confused and thinks that this is a -r option
1003 but it cannot parse the text after the -r so it refuses to
1004 increment the optind counter. Detect this case and issue
1005 an error message here. We cannot just make this a warning,
1006 increment optind, and continue because getopt is too confused
1007 and will seg-fault the next time around. */
1008 einfo(_("%P%F: unrecognised option: %s\n"), argv
[optind
]);
1010 link_info
.relocatable
= TRUE
;
1011 config
.build_constructors
= FALSE
;
1012 config
.magic_demand_paged
= FALSE
;
1013 config
.text_read_only
= FALSE
;
1014 input_flags
.dynamic
= FALSE
;
1017 /* The GNU linker traditionally uses -R to mean to include
1018 only the symbols from a file. The Solaris linker uses -R
1019 to set the path used by the runtime linker to find
1020 libraries. This is the GNU linker -rpath argument. We
1021 try to support both simultaneously by checking the file
1022 named. If it is a directory, rather than a regular file,
1023 we assume -rpath was meant. */
1027 if (stat (optarg
, &s
) >= 0
1028 && ! S_ISDIR (s
.st_mode
))
1030 lang_add_input_file (optarg
,
1031 lang_input_file_is_symbols_only_enum
,
1038 if (command_line
.rpath
== NULL
)
1039 command_line
.rpath
= xstrdup (optarg
);
1042 size_t rpath_len
= strlen (command_line
.rpath
);
1043 size_t optarg_len
= strlen (optarg
);
1045 char *cp
= command_line
.rpath
;
1047 /* First see whether OPTARG is already in the path. */
1050 if (strncmp (optarg
, cp
, optarg_len
) == 0
1051 && (cp
[optarg_len
] == 0
1052 || cp
[optarg_len
] == config
.rpath_separator
))
1056 /* Not yet found. */
1057 cp
= strchr (cp
, config
.rpath_separator
);
1065 buf
= (char *) xmalloc (rpath_len
+ optarg_len
+ 2);
1066 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1067 config
.rpath_separator
, optarg
);
1068 free (command_line
.rpath
);
1069 command_line
.rpath
= buf
;
1073 case OPTION_RPATH_LINK
:
1074 if (command_line
.rpath_link
== NULL
)
1075 command_line
.rpath_link
= xstrdup (optarg
);
1080 buf
= (char *) xmalloc (strlen (command_line
.rpath_link
)
1083 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1084 config
.rpath_separator
, optarg
);
1085 free (command_line
.rpath_link
);
1086 command_line
.rpath_link
= buf
;
1089 case OPTION_NO_RELAX
:
1095 case OPTION_RETAIN_SYMBOLS_FILE
:
1096 add_keepsyms_file (optarg
);
1099 link_info
.strip
= strip_debugger
;
1102 link_info
.strip
= strip_all
;
1104 case OPTION_STRIP_DISCARDED
:
1105 link_info
.strip_discarded
= TRUE
;
1107 case OPTION_NO_STRIP_DISCARDED
:
1108 link_info
.strip_discarded
= FALSE
;
1111 if (config
.has_shared
)
1113 link_info
.shared
= TRUE
;
1114 /* When creating a shared library, the default
1115 behaviour is to ignore any unresolved references. */
1116 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1117 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1118 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1119 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1122 einfo (_("%P%F: -shared not supported\n"));
1125 if (config
.has_shared
)
1127 link_info
.shared
= TRUE
;
1128 link_info
.pie
= TRUE
;
1131 einfo (_("%P%F: -pie not supported\n"));
1133 case 'h': /* Used on Solaris. */
1135 if (optarg
[0] == '\0' && command_line
.soname
1136 && command_line
.soname
[0])
1137 einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
1139 command_line
.soname
= optarg
;
1141 case OPTION_SORT_COMMON
:
1143 || strcmp (optarg
, N_("descending")) == 0)
1144 config
.sort_common
= sort_descending
;
1145 else if (strcmp (optarg
, N_("ascending")) == 0)
1146 config
.sort_common
= sort_ascending
;
1148 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1151 case OPTION_SORT_SECTION
:
1152 if (strcmp (optarg
, N_("name")) == 0)
1153 sort_section
= by_name
;
1154 else if (strcmp (optarg
, N_("alignment")) == 0)
1155 sort_section
= by_alignment
;
1157 einfo (_("%P%F: invalid section sorting option: %s\n"),
1161 config
.stats
= TRUE
;
1163 case OPTION_SYMBOLIC
:
1164 command_line
.symbolic
= symbolic
;
1166 case OPTION_SYMBOLIC_FUNCTIONS
:
1167 command_line
.symbolic
= symbolic_functions
;
1173 previous_script_handle
= saved_script_handle
;
1174 ldfile_open_command_file (optarg
);
1175 parser_input
= input_script
;
1177 previous_script_handle
= NULL
;
1179 case OPTION_DEFAULT_SCRIPT
:
1180 command_line
.default_script
= optarg
;
1182 case OPTION_SECTION_START
:
1188 /* Check for <something>=<somthing>... */
1189 optarg2
= strchr (optarg
, '=');
1190 if (optarg2
== NULL
)
1191 einfo (_("%P%F: invalid argument to option"
1192 " \"--section-start\"\n"));
1196 /* So far so good. Are all the args present? */
1197 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1198 einfo (_("%P%F: missing argument(s) to option"
1199 " \"--section-start\"\n"));
1201 /* We must copy the section name as set_section_start
1202 doesn't do it for us. */
1203 len
= optarg2
- optarg
;
1204 sec_name
= (char *) xmalloc (len
);
1205 memcpy (sec_name
, optarg
, len
- 1);
1206 sec_name
[len
- 1] = 0;
1208 /* Then set it... */
1209 set_section_start (sec_name
, optarg2
);
1212 case OPTION_TARGET_HELP
:
1213 /* Mention any target specific options. */
1214 ldemul_list_emulation_options (stdout
);
1217 set_segment_start (".bss", optarg
);
1220 set_segment_start (".data", optarg
);
1223 set_segment_start (".text", optarg
);
1225 case OPTION_TTEXT_SEGMENT
:
1226 set_segment_start (".text-segment", optarg
);
1228 case OPTION_TRODATA_SEGMENT
:
1229 set_segment_start (".rodata-segment", optarg
);
1231 case OPTION_TLDATA_SEGMENT
:
1232 set_segment_start (".ldata-segment", optarg
);
1234 case OPTION_TRADITIONAL_FORMAT
:
1235 link_info
.traditional_format
= TRUE
;
1237 case OPTION_TASK_LINK
:
1238 link_info
.task_link
= TRUE
;
1239 /* Fall through - do an implied -r option. */
1241 link_info
.relocatable
= TRUE
;
1242 config
.build_constructors
= TRUE
;
1243 config
.magic_demand_paged
= FALSE
;
1244 config
.text_read_only
= FALSE
;
1245 input_flags
.dynamic
= FALSE
;
1248 ldlang_add_undef (optarg
, TRUE
);
1252 lang_add_unique (optarg
);
1254 config
.unique_orphan_sections
= TRUE
;
1256 case OPTION_VERBOSE
:
1258 version_printed
= TRUE
;
1260 overflow_cutoff_limit
= -2;
1264 int level ATTRIBUTE_UNUSED
= strtoul (optarg
, &end
, 0);
1266 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
1267 #ifdef ENABLE_PLUGINS
1268 report_plugin_symbols
= level
> 1;
1269 #endif /* ENABLE_PLUGINS */
1274 version_printed
= TRUE
;
1278 version_printed
= TRUE
;
1280 case OPTION_VERSION
:
1284 case OPTION_VERSION_SCRIPT
:
1285 /* This option indicates a small script that only specifies
1286 version information. Read it, but don't assume that
1287 we've seen a linker script. */
1289 FILE *hold_script_handle
;
1291 hold_script_handle
= saved_script_handle
;
1292 ldfile_open_command_file (optarg
);
1293 saved_script_handle
= hold_script_handle
;
1294 parser_input
= input_version_script
;
1298 case OPTION_VERSION_EXPORTS_SECTION
:
1299 /* This option records a version symbol to be applied to the
1300 symbols listed for export to be found in the object files
1301 .exports sections. */
1302 command_line
.version_exports_section
= optarg
;
1304 case OPTION_DYNAMIC_LIST_DATA
:
1305 command_line
.dynamic_list
= dynamic_list_data
;
1306 if (command_line
.symbolic
== symbolic
)
1307 command_line
.symbolic
= symbolic_unset
;
1309 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1310 lang_append_dynamic_list_cpp_typeinfo ();
1311 if (command_line
.dynamic_list
!= dynamic_list_data
)
1312 command_line
.dynamic_list
= dynamic_list
;
1313 if (command_line
.symbolic
== symbolic
)
1314 command_line
.symbolic
= symbolic_unset
;
1316 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1317 lang_append_dynamic_list_cpp_new ();
1318 if (command_line
.dynamic_list
!= dynamic_list_data
)
1319 command_line
.dynamic_list
= dynamic_list
;
1320 if (command_line
.symbolic
== symbolic
)
1321 command_line
.symbolic
= symbolic_unset
;
1323 case OPTION_DYNAMIC_LIST
:
1324 /* This option indicates a small script that only specifies
1325 a dynamic list. Read it, but don't assume that we've
1326 seen a linker script. */
1328 FILE *hold_script_handle
;
1330 hold_script_handle
= saved_script_handle
;
1331 ldfile_open_command_file (optarg
);
1332 saved_script_handle
= hold_script_handle
;
1333 parser_input
= input_dynamic_list
;
1336 if (command_line
.dynamic_list
!= dynamic_list_data
)
1337 command_line
.dynamic_list
= dynamic_list
;
1338 if (command_line
.symbolic
== symbolic
)
1339 command_line
.symbolic
= symbolic_unset
;
1341 case OPTION_WARN_COMMON
:
1342 config
.warn_common
= TRUE
;
1344 case OPTION_WARN_CONSTRUCTORS
:
1345 config
.warn_constructors
= TRUE
;
1347 case OPTION_WARN_FATAL
:
1348 config
.fatal_warnings
= TRUE
;
1350 case OPTION_NO_WARN_FATAL
:
1351 config
.fatal_warnings
= FALSE
;
1353 case OPTION_WARN_MULTIPLE_GP
:
1354 config
.warn_multiple_gp
= TRUE
;
1356 case OPTION_WARN_ONCE
:
1357 config
.warn_once
= TRUE
;
1359 case OPTION_WARN_ORPHAN
:
1360 config
.warn_orphan
= TRUE
;
1362 case OPTION_NO_WARN_ORPHAN
:
1363 config
.warn_orphan
= FALSE
;
1365 case OPTION_WARN_SECTION_ALIGN
:
1366 config
.warn_section_align
= TRUE
;
1368 case OPTION_WARN_SHARED_TEXTREL
:
1369 link_info
.warn_shared_textrel
= TRUE
;
1371 case OPTION_WARN_ALTERNATE_EM
:
1372 link_info
.warn_alternate_em
= TRUE
;
1374 case OPTION_WHOLE_ARCHIVE
:
1375 input_flags
.whole_archive
= TRUE
;
1377 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
:
1378 input_flags
.add_DT_NEEDED_for_dynamic
= TRUE
;
1380 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
:
1381 input_flags
.add_DT_NEEDED_for_dynamic
= FALSE
;
1383 case OPTION_ADD_DT_NEEDED_FOR_REGULAR
:
1384 input_flags
.add_DT_NEEDED_for_regular
= TRUE
;
1386 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
:
1387 input_flags
.add_DT_NEEDED_for_regular
= FALSE
;
1392 case OPTION_IGNORE_UNRESOLVED_SYMBOL
:
1393 add_ignoresym (&link_info
, optarg
);
1395 case OPTION_DISCARD_NONE
:
1396 link_info
.discard
= discard_none
;
1399 link_info
.discard
= discard_l
;
1402 link_info
.discard
= discard_all
;
1405 if (CONST_STRNEQ (optarg
, "P,"))
1407 if (default_dirlist
!= NULL
)
1408 free (default_dirlist
);
1409 default_dirlist
= xstrdup (optarg
);
1414 case OPTION_SPARE_DYNAMIC_TAGS
:
1415 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1417 case OPTION_SPLIT_BY_RELOC
:
1419 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1421 config
.split_by_reloc
= 32768;
1423 case OPTION_SPLIT_BY_FILE
:
1425 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1427 config
.split_by_file
= 1;
1429 case OPTION_CHECK_SECTIONS
:
1430 command_line
.check_section_addresses
= 1;
1432 case OPTION_NO_CHECK_SECTIONS
:
1433 command_line
.check_section_addresses
= 0;
1435 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1436 command_line
.accept_unknown_input_arch
= TRUE
;
1438 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1439 command_line
.accept_unknown_input_arch
= FALSE
;
1442 lang_enter_group ();
1447 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1449 lang_leave_group ();
1454 link_info
.init_function
= optarg
;
1458 link_info
.fini_function
= optarg
;
1461 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1462 link_info
.reduce_memory_overheads
= TRUE
;
1463 if (config
.hash_table_size
== 0)
1464 config
.hash_table_size
= 1021;
1467 case OPTION_HASH_SIZE
:
1469 bfd_size_type new_size
;
1471 new_size
= strtoul (optarg
, NULL
, 0);
1473 config
.hash_table_size
= new_size
;
1475 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1479 case OPTION_PUSH_STATE
:
1480 input_flags
.pushed
= xmemdup (&input_flags
,
1481 sizeof (input_flags
),
1482 sizeof (input_flags
));
1485 case OPTION_POP_STATE
:
1486 if (input_flags
.pushed
== NULL
)
1487 einfo (_("%P%F: no state pushed before popping\n"));
1490 struct lang_input_statement_flags
*oldp
= input_flags
.pushed
;
1491 memcpy (&input_flags
, oldp
, sizeof (input_flags
));
1496 case OPTION_PRINT_MEMORY_USAGE
:
1497 command_line
.print_memory_usage
= TRUE
;
1502 if (command_line
.soname
&& command_line
.soname
[0] == '\0')
1504 einfo (_("%P: SONAME must not be empty string; ignored\n"));
1505 command_line
.soname
= NULL
;
1510 lang_leave_group ();
1514 if (default_dirlist
!= NULL
)
1516 set_default_dirlist (default_dirlist
);
1517 free (default_dirlist
);
1520 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1521 /* FIXME: Should we allow emulations a chance to set this ? */
1522 link_info
.unresolved_syms_in_objects
= how_to_report_unresolved_symbols
;
1524 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1525 /* FIXME: Should we allow emulations a chance to set this ? */
1526 link_info
.unresolved_syms_in_shared_libs
= how_to_report_unresolved_symbols
;
1528 if (link_info
.relocatable
)
1530 if (command_line
.check_section_addresses
< 0)
1531 command_line
.check_section_addresses
= 0;
1532 if (link_info
.shared
)
1533 einfo (_("%P%F: -r and -shared may not be used together\n"));
1536 /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data,
1537 --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and
1538 --dynamic-list FILE. -Bsymbolic and -Bsymbolic-functions are
1539 for shared libraries. -Bsymbolic overrides all others and vice
1541 switch (command_line
.symbolic
)
1543 case symbolic_unset
:
1546 /* -Bsymbolic is for shared library only. */
1547 if (link_info
.shared
)
1549 link_info
.symbolic
= TRUE
;
1550 /* Should we free the unused memory? */
1551 link_info
.dynamic_list
= NULL
;
1552 command_line
.dynamic_list
= dynamic_list_unset
;
1555 case symbolic_functions
:
1556 /* -Bsymbolic-functions is for shared library only. */
1557 if (link_info
.shared
)
1558 command_line
.dynamic_list
= dynamic_list_data
;
1562 switch (command_line
.dynamic_list
)
1564 case dynamic_list_unset
:
1566 case dynamic_list_data
:
1567 link_info
.dynamic_data
= TRUE
;
1569 link_info
.dynamic
= TRUE
;
1573 if (! link_info
.shared
)
1575 if (command_line
.filter_shlib
)
1576 einfo (_("%P%F: -F may not be used without -shared\n"));
1577 if (command_line
.auxiliary_filters
)
1578 einfo (_("%P%F: -f may not be used without -shared\n"));
1581 if (! link_info
.shared
|| link_info
.pie
)
1582 link_info
.executable
= TRUE
;
1584 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1585 don't see how else this can be handled, since in this case we
1586 must preserve all externally visible symbols. */
1587 if (link_info
.relocatable
&& link_info
.strip
== strip_all
)
1589 link_info
.strip
= strip_debugger
;
1590 if (link_info
.discard
== discard_sec_merge
)
1591 link_info
.discard
= discard_all
;
1595 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1596 library search path. */
1599 set_default_dirlist (char *dirlist_ptr
)
1605 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1608 if (*dirlist_ptr
!= '\0')
1609 ldfile_add_library_path (dirlist_ptr
, TRUE
);
1612 dirlist_ptr
= p
+ 1;
1617 set_section_start (char *sect
, char *valstr
)
1620 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1622 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1623 lang_section_start (sect
, exp_intop (val
), NULL
);
1627 set_segment_start (const char *section
, char *valstr
)
1633 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1635 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1636 /* If we already have an entry for this segment, update the existing
1639 for (seg
= segments
; seg
; seg
= seg
->next
)
1640 if (strcmp (seg
->name
, name
) == 0)
1645 /* There was no existing value so we must create a new segment
1647 seg
= (segment_type
*) stat_alloc (sizeof (*seg
));
1651 /* Add it to the linked list of segments. */
1652 seg
->next
= segments
;
1654 /* Historically, -Ttext and friends set the base address of a
1655 particular section. For backwards compatibility, we still do
1656 that. If a SEGMENT_START directive is seen, the section address
1657 assignment will be disabled. */
1658 lang_section_start (section
, exp_intop (val
), seg
);
1662 elf_shlib_list_options (FILE *file
)
1665 --audit=AUDITLIB Specify a library to use for auditing\n"));
1667 -Bgroup Selects group name lookup rules for DSO\n"));
1669 --disable-new-dtags Disable new dynamic tags\n"));
1671 --enable-new-dtags Enable new dynamic tags\n"));
1673 --eh-frame-hdr Create .eh_frame_hdr section\n"));
1675 --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
1677 --hash-style=STYLE Set hash style to sysv, gnu or both\n"));
1679 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
1680 Specify a library to use for auditing dependencies\n"));
1682 -z combreloc Merge dynamic relocs into one section and sort\n"));
1684 -z nocombreloc Don't merge dynamic relocs into one section\n"));
1686 -z global Make symbols in DSO available for subsequently\n\
1687 loaded objects\n"));
1689 -z initfirst Mark DSO to be initialized first at runtime\n"));
1691 -z interpose Mark object to interpose all DSOs but executable\n"));
1693 -z lazy Mark object lazy runtime binding (default)\n"));
1695 -z loadfltr Mark object requiring immediate process\n"));
1697 -z nocopyreloc Don't create copy relocs\n"));
1699 -z nodefaultlib Mark object not to use default search paths\n"));
1701 -z nodelete Mark DSO non-deletable at runtime\n"));
1703 -z nodlopen Mark DSO not available to dlopen\n"));
1705 -z nodump Mark DSO not available to dldump\n"));
1707 -z now Mark object non-lazy runtime binding\n"));
1709 -z origin Mark object requiring immediate $ORIGIN\n\
1710 processing at runtime\n"));
1712 -z relro Create RELRO program header\n"));
1714 -z norelro Don't create RELRO program header\n"));
1716 -z stacksize=SIZE Set size of stack segment\n"));
1718 -z text Treat DT_TEXTREL in shared object as error\n"));
1720 -z notext Don't treat DT_TEXTREL in shared object as error\n"));
1722 -z textoff Don't treat DT_TEXTREL in shared object as error\n"));
1726 elf_static_list_options (FILE *file
)
1729 --build-id[=STYLE] Generate build ID note\n"));
1731 --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\
1732 Compress DWARF debug sections using zlib\n"));
1734 -z common-page-size=SIZE Set common page size to SIZE\n"));
1736 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
1738 -z defs Report unresolved symbols in object files.\n"));
1740 -z muldefs Allow multiple definitions\n"));
1742 -z execstack Mark executable as requiring executable stack\n"));
1744 -z noexecstack Mark executable as not requiring executable stack\n"));
1748 elf_plt_unwind_list_options (FILE *file
)
1751 --ld-generated-unwind-info Generate exception handling info for PLT\n\
1752 --no-ld-generated-unwind-info\n\
1753 Don't generate exception handling info for PLT\n"));
1757 ld_list_options (FILE *file
, bfd_boolean elf
, bfd_boolean shlib
,
1758 bfd_boolean plt_unwind
)
1762 printf (_("ELF emulations:\n"));
1764 elf_plt_unwind_list_options (file
);
1765 elf_static_list_options (file
);
1767 elf_shlib_list_options (file
);
1771 /* Print help messages for the options. */
1777 const char **targets
, **pp
;
1780 printf (_("Usage: %s [options] file...\n"), program_name
);
1782 printf (_("Options:\n"));
1783 for (i
= 0; i
< OPTION_COUNT
; i
++)
1785 if (ld_options
[i
].doc
!= NULL
)
1798 if (ld_options
[j
].shortopt
!= '\0'
1799 && ld_options
[j
].control
!= NO_HELP
)
1801 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1802 len
+= (comma
? 2 : 0) + 2;
1803 if (ld_options
[j
].arg
!= NULL
)
1805 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1810 printf ("%s", _(ld_options
[j
].arg
));
1811 len
+= strlen (_(ld_options
[j
].arg
));
1817 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1822 if (ld_options
[j
].opt
.name
!= NULL
1823 && ld_options
[j
].control
!= NO_HELP
)
1826 (ld_options
[j
].control
== TWO_DASHES
1827 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
1831 two_dashes
? "-" : "",
1832 ld_options
[j
].opt
.name
);
1833 len
+= ((comma
? 2 : 0)
1835 + (two_dashes
? 1 : 0)
1836 + strlen (ld_options
[j
].opt
.name
));
1837 if (ld_options
[j
].arg
!= NULL
)
1839 printf (" %s", _(ld_options
[j
].arg
));
1840 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1846 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1854 for (; len
< 30; len
++)
1857 printf ("%s\n", _(ld_options
[i
].doc
));
1860 printf (_(" @FILE"));
1861 for (len
= strlen (" @FILE"); len
< 30; len
++)
1863 printf (_("Read options from FILE\n"));
1865 /* Note: Various tools (such as libtool) depend upon the
1866 format of the listings below - do not change them. */
1867 /* xgettext:c-format */
1868 printf (_("%s: supported targets:"), program_name
);
1869 targets
= bfd_target_list ();
1870 for (pp
= targets
; *pp
!= NULL
; pp
++)
1871 printf (" %s", *pp
);
1875 /* xgettext:c-format */
1876 printf (_("%s: supported emulations: "), program_name
);
1877 ldemul_list_emulations (stdout
);
1880 /* xgettext:c-format */
1881 printf (_("%s: emulation specific options:\n"), program_name
);
1882 ld_list_options (stdout
, ELF_LIST_OPTIONS
, ELF_SHLIB_LIST_OPTIONS
,
1883 ELF_PLT_UNWIND_LIST_OPTIONS
);
1884 ldemul_list_emulation_options (stdout
);
1887 if (REPORT_BUGS_TO
[0])
1888 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);