1 /* Parse options for the GNU linker.
2 Copyright (C) 1991-2021 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"
25 #include "filenames.h"
29 #include "safe-ctype.h"
44 #if BFD_SUPPORTS_PLUGINS
46 #endif /* BFD_SUPPORTS_PLUGINS */
48 #ifndef PATH_SEPARATOR
49 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
50 #define PATH_SEPARATOR ';'
52 #define PATH_SEPARATOR ':'
56 /* Somewhere above, sys/stat.h got included . . . . */
57 #if !defined(S_ISDIR) && defined(S_IFDIR)
58 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
61 static void set_default_dirlist (char *);
62 static void set_section_start (char *, char *);
63 static void set_segment_start (const char *, char *);
64 static void help (void);
66 /* The long options. This structure is used for both the option
67 parsing and the help text. */
70 /* Use one dash before long option name. */
72 /* Use two dashes before long option name. */
74 /* Only accept two dashes before the long option name.
75 This is an overloading of the use of this enum, since originally it
76 was only intended to tell the --help display function how to display
77 the long option name. This feature was added in order to resolve
78 the confusion about the -omagic command line switch. Is it setting
79 the output file name to "magic" or is it setting the NMAGIC flag on
80 the output ? It has been decided that it is setting the output file
81 name, and that if you want to set the NMAGIC flag you should use -N
84 /* Don't mention this option in --help output. */
90 /* The long option information. */
92 /* The short option with the same meaning ('\0' if none). */
94 /* The name of the argument (NULL if none). */
96 /* The documentation string. If this is NULL, this is a synonym for
97 the previous option. */
99 enum control_enum control
;
102 static const struct ld_option ld_options
[] =
104 { {NULL
, required_argument
, NULL
, '\0'},
105 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
107 { {"architecture", required_argument
, NULL
, 'A'},
108 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
109 { {"format", required_argument
, NULL
, 'b'},
110 'b', N_("TARGET"), N_("Specify target for following input files"),
112 { {"mri-script", required_argument
, NULL
, 'c'},
113 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
114 { {"dc", no_argument
, NULL
, 'd'},
115 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
116 { {"dp", no_argument
, NULL
, 'd'},
117 '\0', NULL
, NULL
, ONE_DASH
},
118 { {"dependency-file", required_argument
, NULL
, OPTION_DEPENDENCY_FILE
},
119 '\0', N_("FILE"), N_("Write dependency file"), TWO_DASHES
},
120 { {"force-group-allocation", no_argument
, NULL
,
121 OPTION_FORCE_GROUP_ALLOCATION
},
122 '\0', NULL
, N_("Force group members out of groups"), TWO_DASHES
},
123 { {"entry", required_argument
, NULL
, 'e'},
124 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
125 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
126 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
127 { {"no-export-dynamic", no_argument
, NULL
, OPTION_NO_EXPORT_DYNAMIC
},
128 '\0', NULL
, N_("Undo the effect of --export-dynamic"), TWO_DASHES
},
129 { {"enable-non-contiguous-regions", no_argument
, NULL
, OPTION_NON_CONTIGUOUS_REGIONS
},
130 '\0', NULL
, N_("Enable support of non-contiguous memory regions"), TWO_DASHES
},
131 { {"enable-non-contiguous-regions-warnings", no_argument
, NULL
, OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS
},
132 '\0', NULL
, N_("Enable warnings when --enable-non-contiguous-regions may cause unexpected behaviour"), TWO_DASHES
},
133 { {"EB", no_argument
, NULL
, OPTION_EB
},
134 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
135 { {"EL", no_argument
, NULL
, OPTION_EL
},
136 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
137 { {"auxiliary", required_argument
, NULL
, 'f'},
138 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
140 { {"filter", required_argument
, NULL
, 'F'},
141 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
143 { {NULL
, no_argument
, NULL
, '\0'},
144 'g', NULL
, N_("Ignored"), ONE_DASH
},
145 { {"gpsize", required_argument
, NULL
, 'G'},
146 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
148 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
149 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
150 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
151 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
153 { {"no-dynamic-linker", no_argument
, NULL
, OPTION_NO_DYNAMIC_LINKER
},
154 '\0', NULL
, N_("Produce an executable with no program interpreter header"),
156 { {"library", required_argument
, NULL
, 'l'},
157 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
158 { {"library-path", required_argument
, NULL
, 'L'},
159 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
161 { {"sysroot=<DIRECTORY>", required_argument
, NULL
, OPTION_SYSROOT
},
162 '\0', NULL
, N_("Override the default sysroot location"), TWO_DASHES
},
163 { {NULL
, required_argument
, NULL
, '\0'},
164 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
165 { {"print-map", no_argument
, NULL
, 'M'},
166 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
167 { {"nmagic", no_argument
, NULL
, 'n'},
168 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
169 { {"omagic", no_argument
, NULL
, 'N'},
170 'N', NULL
, N_("Do not page align data, do not make text readonly"),
171 EXACTLY_TWO_DASHES
},
172 { {"no-omagic", no_argument
, NULL
, OPTION_NO_OMAGIC
},
173 '\0', NULL
, N_("Page align data, make text readonly"),
174 EXACTLY_TWO_DASHES
},
175 { {"output", required_argument
, NULL
, 'o'},
176 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES
},
177 { {NULL
, required_argument
, NULL
, '\0'},
178 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
179 { {"out-implib", required_argument
, NULL
, OPTION_OUT_IMPLIB
},
180 '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES
},
181 #if BFD_SUPPORTS_PLUGINS
182 { {"plugin", required_argument
, NULL
, OPTION_PLUGIN
},
183 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH
},
184 { {"plugin-opt", required_argument
, NULL
, OPTION_PLUGIN_OPT
},
185 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH
},
186 { {"flto", optional_argument
, NULL
, OPTION_IGNORE
},
187 '\0', NULL
, N_("Ignored for GCC LTO option compatibility"),
189 { {"flto-partition=", required_argument
, NULL
, OPTION_IGNORE
},
190 '\0', NULL
, N_("Ignored for GCC LTO option compatibility"),
193 { {"plugin", required_argument
, NULL
, OPTION_IGNORE
},
194 '\0', N_("PLUGIN"), N_("Load named plugin (ignored)"), ONE_DASH
},
195 { {"plugin-opt", required_argument
, NULL
, OPTION_IGNORE
},
196 '\0', N_("ARG"), N_("Send arg to last-loaded plugin (ignored)"), ONE_DASH
},
197 #endif /* BFD_SUPPORTS_PLUGINS */
198 { {"fuse-ld=", required_argument
, NULL
, OPTION_IGNORE
},
199 '\0', NULL
, N_("Ignored for GCC linker option compatibility"),
201 { {"map-whole-files", optional_argument
, NULL
, OPTION_IGNORE
},
202 '\0', NULL
, N_("Ignored for gold option compatibility"),
204 { {"no-map-whole-files", optional_argument
, NULL
, OPTION_IGNORE
},
205 '\0', NULL
, N_("Ignored for gold option compatibility"),
207 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
208 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
209 { {"emit-relocs", no_argument
, NULL
, 'q'},
210 'q', NULL
, "Generate relocations in final output", TWO_DASHES
},
211 { {"relocatable", no_argument
, NULL
, 'r'},
212 'r', NULL
, N_("Generate relocatable output"), TWO_DASHES
},
213 { {NULL
, no_argument
, NULL
, '\0'},
214 'i', NULL
, NULL
, ONE_DASH
},
215 { {"just-symbols", required_argument
, NULL
, 'R'},
216 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
218 { {"strip-all", no_argument
, NULL
, 's'},
219 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
220 { {"strip-debug", no_argument
, NULL
, 'S'},
221 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
222 { {"strip-discarded", no_argument
, NULL
, OPTION_STRIP_DISCARDED
},
223 '\0', NULL
, N_("Strip symbols in discarded sections"), TWO_DASHES
},
224 { {"no-strip-discarded", no_argument
, NULL
, OPTION_NO_STRIP_DISCARDED
},
225 '\0', NULL
, N_("Do not strip symbols in discarded sections"), TWO_DASHES
},
226 { {"trace", no_argument
, NULL
, 't'},
227 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
228 { {"script", required_argument
, NULL
, 'T'},
229 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
230 { {"default-script", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
231 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES
},
232 { {"dT", required_argument
, NULL
, OPTION_DEFAULT_SCRIPT
},
233 '\0', NULL
, NULL
, ONE_DASH
},
234 { {"undefined", required_argument
, NULL
, 'u'},
235 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
237 { {"require-defined", required_argument
, NULL
, OPTION_REQUIRE_DEFINED_SYMBOL
},
238 '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"),
240 { {"unique", optional_argument
, NULL
, OPTION_UNIQUE
},
241 '\0', N_("[=SECTION]"),
242 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES
},
243 { {"Ur", no_argument
, NULL
, OPTION_UR
},
244 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
245 { {"version", no_argument
, NULL
, OPTION_VERSION
},
246 'v', NULL
, N_("Print version information"), TWO_DASHES
},
247 { {NULL
, no_argument
, NULL
, '\0'},
248 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
249 { {"discard-all", no_argument
, NULL
, 'x'},
250 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
251 { {"discard-locals", no_argument
, NULL
, 'X'},
252 'X', NULL
, N_("Discard temporary local symbols (default)"), TWO_DASHES
},
253 { {"discard-none", no_argument
, NULL
, OPTION_DISCARD_NONE
},
254 '\0', NULL
, N_("Don't discard any local symbols"), TWO_DASHES
},
255 { {"trace-symbol", required_argument
, NULL
, 'y'},
256 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
257 { {NULL
, required_argument
, NULL
, '\0'},
258 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
260 { {"start-group", no_argument
, NULL
, '('},
261 '(', NULL
, N_("Start a group"), TWO_DASHES
},
262 { {"end-group", no_argument
, NULL
, ')'},
263 ')', NULL
, N_("End a group"), TWO_DASHES
},
264 { {"accept-unknown-input-arch", no_argument
, NULL
,
265 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
},
267 N_("Accept input files whose architecture cannot be determined"),
269 { {"no-accept-unknown-input-arch", no_argument
, NULL
,
270 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
},
271 '\0', NULL
, N_("Reject input files whose architecture is unknown"),
274 /* The next two options are deprecated because of their similarity to
275 --as-needed and --no-as-needed. They have been replaced by
276 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
277 { {"add-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
278 '\0', NULL
, NULL
, NO_HELP
},
279 { {"no-add-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
280 '\0', NULL
, NULL
, NO_HELP
},
282 { {"as-needed", no_argument
, NULL
, OPTION_ADD_DT_NEEDED_FOR_REGULAR
},
283 '\0', NULL
, N_("Only set DT_NEEDED for following dynamic libs if used"),
285 { {"no-as-needed", no_argument
, NULL
, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
},
286 '\0', NULL
, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
287 " the command line"),
289 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
290 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
291 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
292 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
293 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
294 '\0', NULL
, NULL
, ONE_DASH
},
295 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
296 '\0', NULL
, NULL
, ONE_DASH
},
297 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
298 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
299 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
300 '\0', NULL
, NULL
, ONE_DASH
},
301 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
302 '\0', NULL
, NULL
, ONE_DASH
},
303 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
304 '\0', NULL
, NULL
, ONE_DASH
},
305 { {"Bno-symbolic", no_argument
, NULL
, OPTION_NO_SYMBOLIC
},
306 '\0', NULL
, N_("Don't bind global references locally"), ONE_DASH
},
307 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
308 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
309 { {"Bsymbolic-functions", no_argument
, NULL
, OPTION_SYMBOLIC_FUNCTIONS
},
310 '\0', NULL
, N_("Bind global function references locally"), ONE_DASH
},
311 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
312 '\0', NULL
, N_("Check section addresses for overlaps (default)"),
314 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
315 '\0', NULL
, N_("Do not check section addresses for overlaps"),
317 { {"copy-dt-needed-entries", no_argument
, NULL
,
318 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
},
319 '\0', NULL
, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
321 { {"no-copy-dt-needed-entries", no_argument
, NULL
,
322 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
},
323 '\0', NULL
, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
326 { {"cref", no_argument
, NULL
, OPTION_CREF
},
327 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
328 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
329 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
330 { {"demangle", optional_argument
, NULL
, OPTION_DEMANGLE
},
331 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
333 { {"disable-multiple-abs-defs", no_argument
, NULL
,
334 OPTION_DISABLE_MULTIPLE_DEFS_ABS
},
335 '\0', NULL
, N_("Do not allow multiple definitions with symbols included\n"
336 " in filename invoked by -R or --just-symbols"),
338 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
339 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
340 { {"fatal-warnings", no_argument
, NULL
, OPTION_WARN_FATAL
},
341 '\0', NULL
, N_("Treat warnings as errors"),
343 { {"no-fatal-warnings", no_argument
, NULL
, OPTION_NO_WARN_FATAL
},
344 '\0', NULL
, N_("Do not treat warnings as errors (default)"),
346 { {"fini", required_argument
, NULL
, OPTION_FINI
},
347 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH
},
348 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
349 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
350 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
351 '\0', NULL
, N_("Remove unused sections (on some targets)"),
353 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
354 '\0', NULL
, N_("Don't remove unused sections (default)"),
356 { {"print-gc-sections", no_argument
, NULL
, OPTION_PRINT_GC_SECTIONS
},
357 '\0', NULL
, N_("List removed unused sections on stderr"),
359 { {"no-print-gc-sections", no_argument
, NULL
, OPTION_NO_PRINT_GC_SECTIONS
},
360 '\0', NULL
, N_("Do not list removed unused sections"),
362 { {"gc-keep-exported", no_argument
, NULL
, OPTION_GC_KEEP_EXPORTED
},
363 '\0', NULL
, N_("Keep exported symbols when removing unused sections"),
365 { {"hash-size=<NUMBER>", required_argument
, NULL
, OPTION_HASH_SIZE
},
366 '\0', NULL
, N_("Set default hash table size close to <NUMBER>"),
368 { {"help", no_argument
, NULL
, OPTION_HELP
},
369 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
370 { {"init", required_argument
, NULL
, OPTION_INIT
},
371 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH
},
372 { {"Map", required_argument
, NULL
, OPTION_MAP
},
373 '\0', N_("FILE/DIR"), N_("Write a linker map to FILE or DIR/<outputname>.map"), ONE_DASH
},
374 { {"no-define-common", no_argument
, NULL
, OPTION_NO_DEFINE_COMMON
},
375 '\0', NULL
, N_("Do not define Common storage"), TWO_DASHES
},
376 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
377 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
378 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
379 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
380 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
381 '\0', NULL
, N_("Do not allow unresolved references in object files"),
383 { {"allow-shlib-undefined", no_argument
, NULL
, OPTION_ALLOW_SHLIB_UNDEFINED
},
384 '\0', NULL
, N_("Allow unresolved references in shared libraries"),
386 { {"no-allow-shlib-undefined", no_argument
, NULL
,
387 OPTION_NO_ALLOW_SHLIB_UNDEFINED
},
388 '\0', NULL
, N_("Do not allow unresolved references in shared libs"),
390 { {"allow-multiple-definition", no_argument
, NULL
,
391 OPTION_ALLOW_MULTIPLE_DEFINITION
},
392 '\0', NULL
, N_("Allow multiple definitions"), TWO_DASHES
},
393 #if SUPPORT_ERROR_HANDLING_SCRIPT
394 { {"error-handling-script", required_argument
, NULL
,
395 OPTION_ERROR_HANDLING_SCRIPT
},
396 '\0', N_("SCRIPT"), N_("Provide a script to help with undefined symbol errors"), TWO_DASHES
},
398 { {"no-undefined-version", no_argument
, NULL
, OPTION_NO_UNDEFINED_VERSION
},
399 '\0', NULL
, N_("Disallow undefined version"), TWO_DASHES
},
400 { {"default-symver", no_argument
, NULL
, OPTION_DEFAULT_SYMVER
},
401 '\0', NULL
, N_("Create default symbol version"), TWO_DASHES
},
402 { {"default-imported-symver", no_argument
, NULL
,
403 OPTION_DEFAULT_IMPORTED_SYMVER
},
404 '\0', NULL
, N_("Create default symbol version for imported symbols"),
406 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
407 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
408 { {"no-warn-search-mismatch", no_argument
, NULL
,
409 OPTION_NO_WARN_SEARCH_MISMATCH
},
410 '\0', NULL
, N_("Don't warn on finding an incompatible library"),
412 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
413 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
414 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
415 '\0', NULL
, N_("Create an output file even if errors occur"),
417 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
418 '\0', NULL
, NULL
, NO_HELP
},
419 { {"nostdlib", no_argument
, NULL
, OPTION_NOSTDLIB
},
420 '\0', NULL
, N_("Only use library directories specified on\n"
421 " the command line"),
423 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
424 '\0', N_("TARGET"), N_("Specify target of output file"),
425 EXACTLY_TWO_DASHES
},
426 { {"print-output-format", no_argument
, NULL
, OPTION_PRINT_OUTPUT_FORMAT
},
427 '\0', NULL
, N_("Print default output format"), TWO_DASHES
},
428 { {"print-sysroot", no_argument
, NULL
, OPTION_PRINT_SYSROOT
},
429 '\0', NULL
, N_("Print current sysroot"), TWO_DASHES
},
430 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
431 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
432 { {"reduce-memory-overheads", no_argument
, NULL
,
433 OPTION_REDUCE_MEMORY_OVERHEADS
},
434 '\0', NULL
, N_("Reduce memory overheads, possibly taking much longer"),
436 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
437 '\0', NULL
, N_("Reduce code size by using target specific optimizations"), TWO_DASHES
},
438 { {"no-relax", no_argument
, NULL
, OPTION_NO_RELAX
},
439 '\0', NULL
, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES
},
440 { {"retain-symbols-file", required_argument
, NULL
,
441 OPTION_RETAIN_SYMBOLS_FILE
},
442 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
443 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
444 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
445 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
446 '\0', N_("PATH"), N_("Set link time shared library search path"),
448 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
449 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
450 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
451 '\0', NULL
, NULL
, ONE_DASH
},
452 { {"pie", no_argument
, NULL
, OPTION_PIE
},
453 '\0', NULL
, N_("Create a position independent executable"), ONE_DASH
},
454 { {"pic-executable", no_argument
, NULL
, OPTION_PIE
},
455 '\0', NULL
, NULL
, TWO_DASHES
},
456 { {"no-pie", no_argument
, NULL
, OPTION_NO_PIE
},
457 '\0', NULL
, N_("Create a position dependent executable (default)"), ONE_DASH
},
458 { {"sort-common", optional_argument
, NULL
, OPTION_SORT_COMMON
},
459 '\0', N_("[=ascending|descending]"),
460 N_("Sort common symbols by alignment [in specified order]"),
462 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
463 '\0', NULL
, NULL
, NO_HELP
},
464 { {"sort-section", required_argument
, NULL
, OPTION_SORT_SECTION
},
465 '\0', N_("name|alignment"),
466 N_("Sort sections by name or maximum alignment"), TWO_DASHES
},
467 { {"spare-dynamic-tags", required_argument
, NULL
, OPTION_SPARE_DYNAMIC_TAGS
},
468 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
470 { {"split-by-file", optional_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
471 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
473 { {"split-by-reloc", optional_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
474 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
476 { {"stats", no_argument
, NULL
, OPTION_STATS
},
477 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
478 { {"target-help", no_argument
, NULL
, OPTION_TARGET_HELP
},
479 '\0', NULL
, N_("Display target specific options"), TWO_DASHES
},
480 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
481 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
482 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
483 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
484 { {"section-start", required_argument
, NULL
, OPTION_SECTION_START
},
485 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
487 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
488 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
489 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
490 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
491 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
492 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
493 { {"Ttext-segment", required_argument
, NULL
, OPTION_TTEXT_SEGMENT
},
494 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH
},
495 { {"Trodata-segment", required_argument
, NULL
, OPTION_TRODATA_SEGMENT
},
496 '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH
},
497 { {"Tldata-segment", required_argument
, NULL
, OPTION_TLDATA_SEGMENT
},
498 '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH
},
499 { {"unresolved-symbols=<method>", required_argument
, NULL
,
500 OPTION_UNRESOLVED_SYMBOLS
},
501 '\0', NULL
, N_("How to handle unresolved symbols. <method> is:\n"
502 " ignore-all, report-all, ignore-in-object-files,\n"
503 " ignore-in-shared-libs"),
505 { {"verbose", optional_argument
, NULL
, OPTION_VERBOSE
},
506 '\0', N_("[=NUMBER]"),
507 N_("Output lots of information during link"), TWO_DASHES
},
508 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
509 '\0', NULL
, NULL
, NO_HELP
},
510 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
511 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
512 { {"version-exports-section", required_argument
, NULL
,
513 OPTION_VERSION_EXPORTS_SECTION
},
514 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
515 " SYMBOL as the version."),
517 { {"dynamic-list-data", no_argument
, NULL
, OPTION_DYNAMIC_LIST_DATA
},
518 '\0', NULL
, N_("Add data symbols to dynamic list"), TWO_DASHES
},
519 { {"dynamic-list-cpp-new", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_NEW
},
520 '\0', NULL
, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES
},
521 { {"dynamic-list-cpp-typeinfo", no_argument
, NULL
, OPTION_DYNAMIC_LIST_CPP_TYPEINFO
},
522 '\0', NULL
, N_("Use C++ typeinfo dynamic list"), TWO_DASHES
},
523 { {"dynamic-list", required_argument
, NULL
, OPTION_DYNAMIC_LIST
},
524 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES
},
525 { {"export-dynamic-symbol", required_argument
, NULL
, OPTION_EXPORT_DYNAMIC_SYMBOL
},
526 '\0', N_("SYMBOL"), N_("Export the specified symbol"), EXACTLY_TWO_DASHES
},
527 { {"export-dynamic-symbol-list", required_argument
, NULL
, OPTION_EXPORT_DYNAMIC_SYMBOL_LIST
},
528 '\0', N_("FILE"), N_("Read export dynamic symbol list"), EXACTLY_TWO_DASHES
},
529 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
530 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
531 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
532 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
534 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
535 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
536 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
537 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
538 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
539 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
541 { {"warn-textrel", no_argument
, NULL
, OPTION_WARN_TEXTREL
},
543 #if DEFAULT_LD_TEXTREL_CHECK_WARNING
544 N_("Warn if output has DT_TEXTREL (default)"),
546 N_("Warn if output has DT_TEXTREL"),
549 { {"warn-shared-textrel", no_argument
, NULL
, OPTION_WARN_TEXTREL
},
550 '\0', NULL
, NULL
, NO_HELP
},
551 { {"warn-alternate-em", no_argument
, NULL
, OPTION_WARN_ALTERNATE_EM
},
552 '\0', NULL
, N_("Warn if an object has alternate ELF machine code"),
554 { {"warn-unresolved-symbols", no_argument
, NULL
,
555 OPTION_WARN_UNRESOLVED_SYMBOLS
},
556 '\0', NULL
, N_("Report unresolved symbols as warnings"), TWO_DASHES
},
557 { {"error-unresolved-symbols", no_argument
, NULL
,
558 OPTION_ERROR_UNRESOLVED_SYMBOLS
},
559 '\0', NULL
, N_("Report unresolved symbols as errors"), TWO_DASHES
},
560 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
561 '\0', NULL
, N_("Include all objects from following archives"),
563 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
564 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
565 { {"ignore-unresolved-symbol", required_argument
, NULL
,
566 OPTION_IGNORE_UNRESOLVED_SYMBOL
},
568 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES
},
569 { {"push-state", no_argument
, NULL
, OPTION_PUSH_STATE
},
570 '\0', NULL
, N_("Push state of flags governing input file handling"),
572 { {"pop-state", no_argument
, NULL
, OPTION_POP_STATE
},
573 '\0', NULL
, N_("Pop state of flags governing input file handling"),
575 { {"print-memory-usage", no_argument
, NULL
, OPTION_PRINT_MEMORY_USAGE
},
576 '\0', NULL
, N_("Report target memory usage"), TWO_DASHES
},
577 { {"orphan-handling", required_argument
, NULL
, OPTION_ORPHAN_HANDLING
},
578 '\0', N_("=MODE"), N_("Control how orphan sections are handled."),
580 { {"print-map-discarded", no_argument
, NULL
, OPTION_PRINT_MAP_DISCARDED
},
581 '\0', NULL
, N_("Show discarded sections in map file output (default)"),
583 { {"no-print-map-discarded", no_argument
, NULL
, OPTION_NO_PRINT_MAP_DISCARDED
},
584 '\0', NULL
, N_("Do not show discarded sections in map file output"),
586 { {"ctf-variables", no_argument
, NULL
, OPTION_CTF_VARIABLES
},
587 '\0', NULL
, N_("Emit names and types of static variables in CTF"),
589 { {"no-ctf-variables", no_argument
, NULL
, OPTION_NO_CTF_VARIABLES
},
590 '\0', NULL
, N_("Do not emit names and types of static variables in CTF"),
592 { {"ctf-share-types=<method>", required_argument
, NULL
,
593 OPTION_CTF_SHARE_TYPES
},
594 '\0', NULL
, N_("How to share CTF types between translation units.\n"
595 " <method> is: share-unconflicted (default),\n"
596 " share-duplicated"),
600 #define OPTION_COUNT ARRAY_SIZE (ld_options)
603 parse_args (unsigned argc
, char **argv
)
608 char *default_dirlist
= NULL
;
610 struct option
*longopts
;
611 struct option
*really_longopts
;
618 } opt_symbolic
= symbolic_unset
;
619 enum dynamic_list_enum
621 dynamic_list_unset
= 0,
624 } opt_dynamic_list
= dynamic_list_unset
;
625 struct bfd_elf_dynamic_list
*export_list
= NULL
;
627 shortopts
= (char *) xmalloc (OPTION_COUNT
* 3 + 2);
628 longopts
= (struct option
*)
629 xmalloc (sizeof (*longopts
) * (OPTION_COUNT
+ 1));
630 really_longopts
= (struct option
*)
631 xmalloc (sizeof (*really_longopts
) * (OPTION_COUNT
+ 1));
633 /* Starting the short option string with '-' is for programs that
634 expect options and other ARGV-elements in any order and that care about
635 the ordering of the two. We describe each non-option ARGV-element
636 as if it were the argument of an option with character code 1. */
641 for (i
= 0; i
< OPTION_COUNT
; i
++)
643 if (ld_options
[i
].shortopt
!= '\0')
645 shortopts
[is
] = ld_options
[i
].shortopt
;
647 if (ld_options
[i
].opt
.has_arg
== required_argument
648 || ld_options
[i
].opt
.has_arg
== optional_argument
)
652 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
659 if (ld_options
[i
].opt
.name
!= NULL
)
661 if (ld_options
[i
].control
== EXACTLY_TWO_DASHES
)
663 really_longopts
[irl
] = ld_options
[i
].opt
;
668 longopts
[il
] = ld_options
[i
].opt
;
673 shortopts
[is
] = '\0';
674 longopts
[il
].name
= NULL
;
675 really_longopts
[irl
].name
= NULL
;
677 ldemul_add_options (is
, &shortopts
, il
, &longopts
, irl
, &really_longopts
);
679 /* The -G option is ambiguous on different platforms. Sometimes it
680 specifies the largest data size to put into the small data
681 section. Sometimes it is equivalent to --shared. Unfortunately,
682 the first form takes an argument, while the second does not.
684 We need to permit the --shared form because on some platforms,
685 such as Solaris, gcc -shared will pass -G to the linker.
687 To permit either usage, we look through the argument list. If we
688 find -G not followed by a number, we change it into --shared.
689 This will work for most normal cases. */
690 for (i
= 1; i
< argc
; i
++)
691 if (strcmp (argv
[i
], "-G") == 0
693 || ! ISDIGIT (argv
[i
+ 1][0])))
694 argv
[i
] = (char *) "--shared";
696 /* Because we permit long options to start with a single dash, and
697 we have a --library option, and the -l option is conventionally
698 used with an immediately following argument, we can have bad
699 results if somebody tries to use -l with a library whose name
700 happens to start with "ibrary", as in -li. We avoid problems by
701 simply turning -l into --library. This means that users will
702 have to use two dashes in order to use --library, which is OK
703 since that's how it is documented.
705 FIXME: It's possible that this problem can arise for other short
706 options as well, although the user does always have the recourse
707 of adding a space between the option and the argument. */
708 for (i
= 1; i
< argc
; i
++)
710 if (argv
[i
][0] == '-'
712 && argv
[i
][2] != '\0')
716 n
= (char *) xmalloc (strlen (argv
[i
]) + 20);
717 sprintf (n
, "--library=%s", argv
[i
] + 2);
727 static unsigned int defsym_count
;
729 /* Using last_optind lets us avoid calling ldemul_parse_args
730 multiple times on a single option, which would lead to
731 confusion in the internal static variables maintained by
732 getopt. This could otherwise happen for an argument like
733 -nx, in which the -n is parsed as a single option, and we
734 loop around to pick up the -x. */
735 if (optind
!= last_optind
)
736 if (ldemul_parse_args (argc
, argv
))
739 /* getopt_long_only is like getopt_long, but '-' as well as '--'
740 can indicate a long option. */
742 last_optind
= optind
;
743 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
746 optind
= last_optind
;
747 optc
= getopt_long (argc
, argv
, "-", really_longopts
, &longind
);
749 /* Attempt to detect grouped short options, eg: "-non-start".
750 Accepting such options is error prone as it is not clear if the user
751 intended "-n -o n-start" or "--non-start". */
752 else if (longind
== 0 /* This is a short option. */
753 && optc
> 32 /* It is a valid option. */
754 /* The character is not the second character of argv[last_optind]. */
755 && optc
!= argv
[last_optind
][1])
758 einfo (_("%F%P: Error: unable to disambiguate: %s (did you mean -%s ?)\n"),
759 argv
[last_optind
], argv
[last_optind
]);
761 einfo (_("%P: Warning: grouped short command line options are deprecated: %s\n"), argv
[last_optind
]);
764 if (ldemul_handle_option (optc
))
774 /* If the last word on the command line is an option that
775 requires an argument, getopt will refuse to recognise it.
776 Try to catch such options here and issue a more helpful
777 error message than just "unrecognized option". */
780 for (opt
= ARRAY_SIZE (ld_options
); opt
--;)
781 if (ld_options
[opt
].opt
.has_arg
== required_argument
782 /* FIXME: There are a few short options that do not
783 have long equivalents, but which require arguments.
784 We should handle them too. */
785 && ld_options
[opt
].opt
.name
!= NULL
786 && strcmp (argv
[last_optind
] + ld_options
[opt
].control
, ld_options
[opt
].opt
.name
) == 0)
788 einfo (_("%P: %s: missing argument\n"), argv
[last_optind
]);
793 einfo (_("%P: unrecognized option '%s'\n"), argv
[last_optind
]);
798 einfo (_("%F%P: use the --help option for usage information\n"));
801 case 1: /* File name. */
802 lang_add_input_file (optarg
, lang_input_file_is_file_enum
, NULL
);
808 /* For HP/UX compatibility. Actually -a shared should mean
809 ``use only shared libraries'' but, then, we don't
810 currently support shared libraries on HP/UX anyhow. */
811 if (strcmp (optarg
, "archive") == 0)
812 input_flags
.dynamic
= false;
813 else if (strcmp (optarg
, "shared") == 0
814 || strcmp (optarg
, "default") == 0)
815 input_flags
.dynamic
= true;
817 einfo (_("%F%P: unrecognized -a option `%s'\n"), optarg
);
820 /* FIXME: We just ignore these, but we should handle them. */
821 if (strcmp (optarg
, "definitions") == 0)
823 else if (strcmp (optarg
, "nodefinitions") == 0)
825 else if (strcmp (optarg
, "nosymbolic") == 0)
827 else if (strcmp (optarg
, "pure-text") == 0)
830 einfo (_("%F%P: unrecognized -assert option `%s'\n"), optarg
);
833 ldfile_add_arch (optarg
);
836 lang_add_target (optarg
);
839 ldfile_open_command_file (optarg
);
840 parser_input
= input_mri_script
;
843 case OPTION_CALL_SHARED
:
844 input_flags
.dynamic
= true;
846 case OPTION_NON_SHARED
:
847 input_flags
.dynamic
= false;
850 command_line
.cref
= true;
851 link_info
.notice_all
= true;
854 command_line
.force_common_definition
= true;
856 case OPTION_FORCE_GROUP_ALLOCATION
:
857 command_line
.force_group_allocation
= true;
861 lex_redirect (optarg
, "--defsym", ++defsym_count
);
862 parser_input
= input_defsym
;
866 case OPTION_DEMANGLE
:
870 enum demangling_styles style
;
872 style
= cplus_demangle_name_to_style (optarg
);
873 if (style
== unknown_demangling
)
874 einfo (_("%F%P: unknown demangling style `%s'\n"),
877 cplus_demangle_set_style (style
);
880 case 'I': /* Used on Solaris. */
881 case OPTION_DYNAMIC_LINKER
:
882 command_line
.interpreter
= optarg
;
883 link_info
.nointerp
= 0;
885 case OPTION_NO_DYNAMIC_LINKER
:
886 link_info
.nointerp
= 1;
889 /* Already handled in ldmain.c. */
892 command_line
.endian
= ENDIAN_BIG
;
895 command_line
.endian
= ENDIAN_LITTLE
;
897 case OPTION_EMBEDDED_RELOCS
:
898 command_line
.embedded_relocs
= true;
900 case OPTION_EXPORT_DYNAMIC
:
901 case 'E': /* HP/UX compatibility. */
902 link_info
.export_dynamic
= true;
904 case OPTION_NO_EXPORT_DYNAMIC
:
905 link_info
.export_dynamic
= false;
907 case OPTION_NON_CONTIGUOUS_REGIONS
:
908 link_info
.non_contiguous_regions
= true;
910 case OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS
:
911 link_info
.non_contiguous_regions_warnings
= true;
914 lang_add_entry (optarg
, true);
917 if (command_line
.auxiliary_filters
== NULL
)
919 command_line
.auxiliary_filters
= (char **)
920 xmalloc (2 * sizeof (char *));
921 command_line
.auxiliary_filters
[0] = optarg
;
922 command_line
.auxiliary_filters
[1] = NULL
;
930 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
932 command_line
.auxiliary_filters
= (char **)
933 xrealloc (command_line
.auxiliary_filters
,
934 (c
+ 2) * sizeof (char *));
935 command_line
.auxiliary_filters
[c
] = optarg
;
936 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
940 command_line
.filter_shlib
= optarg
;
942 case OPTION_FORCE_EXE_SUFFIX
:
943 command_line
.force_exe_suffix
= true;
948 g_switch_value
= strtoul (optarg
, &end
, 0);
950 einfo (_("%F%P: invalid number `%s'\n"), optarg
);
956 case OPTION_GC_SECTIONS
:
957 link_info
.gc_sections
= true;
959 case OPTION_PRINT_GC_SECTIONS
:
960 link_info
.print_gc_sections
= true;
962 case OPTION_GC_KEEP_EXPORTED
:
963 link_info
.gc_keep_exported
= true;
970 ldfile_add_library_path (optarg
, true);
973 lang_add_input_file (optarg
, lang_input_file_is_l_enum
, NULL
);
976 config
.map_filename
= "-";
979 /* Ignore. Was handled in a pre-parse. */
982 config
.map_filename
= optarg
;
985 config
.text_read_only
= false;
986 config
.magic_demand_paged
= false;
987 input_flags
.dynamic
= false;
989 case OPTION_NO_OMAGIC
:
990 config
.text_read_only
= true;
991 config
.magic_demand_paged
= true;
992 /* NB/ Does not set input_flags.dynamic to TRUE.
993 Use --call-shared or -Bdynamic for this. */
996 config
.text_read_only
= true;
997 config
.magic_demand_paged
= false;
998 input_flags
.dynamic
= false;
1000 case OPTION_NO_DEFINE_COMMON
:
1001 link_info
.inhibit_common_definition
= true;
1003 case OPTION_NO_DEMANGLE
:
1006 case OPTION_NO_GC_SECTIONS
:
1007 link_info
.gc_sections
= false;
1009 case OPTION_NO_PRINT_GC_SECTIONS
:
1010 link_info
.print_gc_sections
= false;
1012 case OPTION_NO_KEEP_MEMORY
:
1013 link_info
.keep_memory
= false;
1015 case OPTION_NO_UNDEFINED
:
1016 link_info
.unresolved_syms_in_objects
= RM_DIAGNOSE
;
1018 case OPTION_ALLOW_SHLIB_UNDEFINED
:
1019 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1021 case OPTION_NO_ALLOW_SHLIB_UNDEFINED
:
1022 link_info
.unresolved_syms_in_shared_libs
= RM_DIAGNOSE
;
1024 case OPTION_UNRESOLVED_SYMBOLS
:
1025 if (strcmp (optarg
, "ignore-all") == 0)
1027 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1028 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1030 else if (strcmp (optarg
, "report-all") == 0)
1032 link_info
.unresolved_syms_in_objects
= RM_DIAGNOSE
;
1033 link_info
.unresolved_syms_in_shared_libs
= RM_DIAGNOSE
;
1035 else if (strcmp (optarg
, "ignore-in-object-files") == 0)
1037 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1038 link_info
.unresolved_syms_in_shared_libs
= RM_DIAGNOSE
;
1040 else if (strcmp (optarg
, "ignore-in-shared-libs") == 0)
1042 link_info
.unresolved_syms_in_objects
= RM_DIAGNOSE
;
1043 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1046 einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg
);
1048 case OPTION_WARN_UNRESOLVED_SYMBOLS
:
1049 link_info
.warn_unresolved_syms
= true;
1051 case OPTION_ERROR_UNRESOLVED_SYMBOLS
:
1052 link_info
.warn_unresolved_syms
= false;
1054 case OPTION_ALLOW_MULTIPLE_DEFINITION
:
1055 link_info
.allow_multiple_definition
= true;
1058 #if SUPPORT_ERROR_HANDLING_SCRIPT
1059 case OPTION_ERROR_HANDLING_SCRIPT
:
1060 /* FIXME: Should we warn if the script is being overridden by another ?
1061 Or maybe they should be chained together ? */
1062 error_handling_script
= optarg
;
1066 case OPTION_NO_UNDEFINED_VERSION
:
1067 link_info
.allow_undefined_version
= false;
1069 case OPTION_DEFAULT_SYMVER
:
1070 link_info
.create_default_symver
= true;
1072 case OPTION_DEFAULT_IMPORTED_SYMVER
:
1073 link_info
.default_imported_symver
= true;
1075 case OPTION_NO_WARN_MISMATCH
:
1076 command_line
.warn_mismatch
= false;
1078 case OPTION_NO_WARN_SEARCH_MISMATCH
:
1079 command_line
.warn_search_mismatch
= false;
1081 case OPTION_NOINHIBIT_EXEC
:
1082 force_make_executable
= true;
1084 case OPTION_NOSTDLIB
:
1085 config
.only_cmd_line_lib_dirs
= true;
1087 case OPTION_NO_WHOLE_ARCHIVE
:
1088 input_flags
.whole_archive
= false;
1091 /* FIXME "-O<non-digits> <value>" used to set the address of
1092 section <non-digits>. Was this for compatibility with
1093 something, or can we create a new option to do that
1094 (with a syntax similar to -defsym)?
1095 getopt can't handle two args to an option without kludges. */
1097 /* Enable optimizations of output files. */
1098 link_info
.optimize
= strtoul (optarg
, NULL
, 0) != 0;
1101 lang_add_output (optarg
, 0);
1103 case OPTION_OFORMAT
:
1104 lang_add_output_format (optarg
, NULL
, NULL
, 0);
1106 case OPTION_OUT_IMPLIB
:
1107 command_line
.out_implib_filename
= xstrdup (optarg
);
1109 case OPTION_PRINT_SYSROOT
:
1114 case OPTION_PRINT_OUTPUT_FORMAT
:
1115 command_line
.print_output_format
= true;
1117 #if BFD_SUPPORTS_PLUGINS
1119 plugin_opt_plugin (optarg
);
1121 case OPTION_PLUGIN_OPT
:
1122 if (plugin_opt_plugin_arg (optarg
))
1123 einfo (_("%F%P: bad -plugin-opt option\n"));
1125 #endif /* BFD_SUPPORTS_PLUGINS */
1127 link_info
.emitrelocations
= true;
1131 if (optind
== last_optind
)
1132 /* This can happen if the user put "-rpath,a" on the command
1133 line. (Or something similar. The comma is important).
1134 Getopt becomes confused and thinks that this is a -r option
1135 but it cannot parse the text after the -r so it refuses to
1136 increment the optind counter. Detect this case and issue
1137 an error message here. We cannot just make this a warning,
1138 increment optind, and continue because getopt is too confused
1139 and will seg-fault the next time around. */
1140 einfo(_("%F%P: unrecognised option: %s\n"), argv
[optind
]);
1142 if (bfd_link_pic (&link_info
))
1143 einfo (_("%F%P: -r and %s may not be used together\n"),
1144 bfd_link_dll (&link_info
) ? "-shared" : "-pie");
1146 link_info
.type
= type_relocatable
;
1147 config
.build_constructors
= false;
1148 config
.magic_demand_paged
= false;
1149 config
.text_read_only
= false;
1150 input_flags
.dynamic
= false;
1153 /* The GNU linker traditionally uses -R to mean to include
1154 only the symbols from a file. The Solaris linker uses -R
1155 to set the path used by the runtime linker to find
1156 libraries. This is the GNU linker -rpath argument. We
1157 try to support both simultaneously by checking the file
1158 named. If it is a directory, rather than a regular file,
1159 we assume -rpath was meant. */
1163 if (stat (optarg
, &s
) >= 0
1164 && ! S_ISDIR (s
.st_mode
))
1166 lang_add_input_file (optarg
,
1167 lang_input_file_is_symbols_only_enum
,
1174 if (command_line
.rpath
== NULL
)
1175 command_line
.rpath
= xstrdup (optarg
);
1178 size_t rpath_len
= strlen (command_line
.rpath
);
1179 size_t optarg_len
= strlen (optarg
);
1181 char *cp
= command_line
.rpath
;
1183 /* First see whether OPTARG is already in the path. */
1186 if (strncmp (optarg
, cp
, optarg_len
) == 0
1187 && (cp
[optarg_len
] == 0
1188 || cp
[optarg_len
] == config
.rpath_separator
))
1192 /* Not yet found. */
1193 cp
= strchr (cp
, config
.rpath_separator
);
1201 buf
= (char *) xmalloc (rpath_len
+ optarg_len
+ 2);
1202 sprintf (buf
, "%s%c%s", command_line
.rpath
,
1203 config
.rpath_separator
, optarg
);
1204 free (command_line
.rpath
);
1205 command_line
.rpath
= buf
;
1209 case OPTION_RPATH_LINK
:
1210 if (command_line
.rpath_link
== NULL
)
1211 command_line
.rpath_link
= xstrdup (optarg
);
1216 buf
= (char *) xmalloc (strlen (command_line
.rpath_link
)
1219 sprintf (buf
, "%s%c%s", command_line
.rpath_link
,
1220 config
.rpath_separator
, optarg
);
1221 free (command_line
.rpath_link
);
1222 command_line
.rpath_link
= buf
;
1225 case OPTION_NO_RELAX
:
1231 case OPTION_RETAIN_SYMBOLS_FILE
:
1232 add_keepsyms_file (optarg
);
1235 link_info
.strip
= strip_debugger
;
1238 link_info
.strip
= strip_all
;
1240 case OPTION_STRIP_DISCARDED
:
1241 link_info
.strip_discarded
= true;
1243 case OPTION_NO_STRIP_DISCARDED
:
1244 link_info
.strip_discarded
= false;
1246 case OPTION_DISABLE_MULTIPLE_DEFS_ABS
:
1247 link_info
.prohibit_multiple_definition_absolute
= true;
1250 if (config
.has_shared
)
1252 if (bfd_link_relocatable (&link_info
))
1253 einfo (_("%F%P: -r and %s may not be used together\n"),
1256 link_info
.type
= type_dll
;
1257 /* When creating a shared library, the default
1258 behaviour is to ignore any unresolved references. */
1259 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1260 link_info
.unresolved_syms_in_objects
= RM_IGNORE
;
1261 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1262 link_info
.unresolved_syms_in_shared_libs
= RM_IGNORE
;
1265 einfo (_("%F%P: -shared not supported\n"));
1268 link_info
.type
= type_pde
;
1271 if (config
.has_shared
)
1273 if (bfd_link_relocatable (&link_info
))
1274 einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
1276 link_info
.type
= type_pie
;
1279 einfo (_("%F%P: -pie not supported\n"));
1281 case 'h': /* Used on Solaris. */
1283 if (optarg
[0] == '\0' && command_line
.soname
1284 && command_line
.soname
[0])
1285 einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
1287 command_line
.soname
= optarg
;
1289 case OPTION_SORT_COMMON
:
1291 || strcmp (optarg
, N_("descending")) == 0)
1292 config
.sort_common
= sort_descending
;
1293 else if (strcmp (optarg
, N_("ascending")) == 0)
1294 config
.sort_common
= sort_ascending
;
1296 einfo (_("%F%P: invalid common section sorting option: %s\n"),
1299 case OPTION_SORT_SECTION
:
1300 if (strcmp (optarg
, N_("name")) == 0)
1301 sort_section
= by_name
;
1302 else if (strcmp (optarg
, N_("alignment")) == 0)
1303 sort_section
= by_alignment
;
1305 einfo (_("%F%P: invalid section sorting option: %s\n"),
1309 config
.stats
= true;
1311 case OPTION_NO_SYMBOLIC
:
1312 opt_symbolic
= symbolic_unset
;
1314 case OPTION_SYMBOLIC
:
1315 opt_symbolic
= symbolic
;
1317 case OPTION_SYMBOLIC_FUNCTIONS
:
1318 opt_symbolic
= symbolic_functions
;
1324 previous_script_handle
= saved_script_handle
;
1325 ldfile_open_script_file (optarg
);
1326 parser_input
= input_script
;
1328 previous_script_handle
= NULL
;
1330 case OPTION_DEFAULT_SCRIPT
:
1331 command_line
.default_script
= optarg
;
1333 case OPTION_SECTION_START
:
1339 /* Check for <something>=<somthing>... */
1340 optarg2
= strchr (optarg
, '=');
1341 if (optarg2
== NULL
)
1342 einfo (_("%F%P: invalid argument to option"
1343 " \"--section-start\"\n"));
1347 /* So far so good. Are all the args present? */
1348 if ((*optarg
== '\0') || (*optarg2
== '\0'))
1349 einfo (_("%F%P: missing argument(s) to option"
1350 " \"--section-start\"\n"));
1352 /* We must copy the section name as set_section_start
1353 doesn't do it for us. */
1354 len
= optarg2
- optarg
;
1355 sec_name
= (char *) xmalloc (len
);
1356 memcpy (sec_name
, optarg
, len
- 1);
1357 sec_name
[len
- 1] = 0;
1359 /* Then set it... */
1360 set_section_start (sec_name
, optarg2
);
1363 case OPTION_TARGET_HELP
:
1364 /* Mention any target specific options. */
1365 ldemul_list_emulation_options (stdout
);
1368 set_segment_start (".bss", optarg
);
1371 set_segment_start (".data", optarg
);
1374 set_segment_start (".text", optarg
);
1376 case OPTION_TTEXT_SEGMENT
:
1377 set_segment_start (".text-segment", optarg
);
1379 case OPTION_TRODATA_SEGMENT
:
1380 set_segment_start (".rodata-segment", optarg
);
1382 case OPTION_TLDATA_SEGMENT
:
1383 set_segment_start (".ldata-segment", optarg
);
1385 case OPTION_TRADITIONAL_FORMAT
:
1386 link_info
.traditional_format
= true;
1388 case OPTION_TASK_LINK
:
1389 link_info
.task_link
= true;
1392 if (bfd_link_pic (&link_info
))
1393 einfo (_("%F%P: -r and %s may not be used together\n"),
1394 bfd_link_dll (&link_info
) ? "-shared" : "-pie");
1396 link_info
.type
= type_relocatable
;
1397 config
.build_constructors
= true;
1398 config
.magic_demand_paged
= false;
1399 config
.text_read_only
= false;
1400 input_flags
.dynamic
= false;
1403 ldlang_add_undef (optarg
, true);
1405 case OPTION_REQUIRE_DEFINED_SYMBOL
:
1406 ldlang_add_require_defined (optarg
);
1410 lang_add_unique (optarg
);
1412 config
.unique_orphan_sections
= true;
1414 case OPTION_VERBOSE
:
1416 version_printed
= true;
1418 overflow_cutoff_limit
= -2;
1422 int level ATTRIBUTE_UNUSED
= strtoul (optarg
, &end
, 0);
1424 einfo (_("%F%P: invalid number `%s'\n"), optarg
);
1425 #if BFD_SUPPORTS_PLUGINS
1426 report_plugin_symbols
= level
> 1;
1427 #endif /* BFD_SUPPORTS_PLUGINS */
1432 version_printed
= true;
1436 version_printed
= true;
1438 case OPTION_VERSION
:
1442 case OPTION_VERSION_SCRIPT
:
1443 /* This option indicates a small script that only specifies
1444 version information. Read it, but don't assume that
1445 we've seen a linker script. */
1447 FILE *hold_script_handle
;
1449 hold_script_handle
= saved_script_handle
;
1450 ldfile_open_command_file (optarg
);
1451 saved_script_handle
= hold_script_handle
;
1452 parser_input
= input_version_script
;
1456 case OPTION_VERSION_EXPORTS_SECTION
:
1457 /* This option records a version symbol to be applied to the
1458 symbols listed for export to be found in the object files
1459 .exports sections. */
1460 command_line
.version_exports_section
= optarg
;
1462 case OPTION_DYNAMIC_LIST_DATA
:
1463 opt_dynamic_list
= dynamic_list_data
;
1465 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO
:
1466 lang_append_dynamic_list_cpp_typeinfo ();
1467 if (opt_dynamic_list
!= dynamic_list_data
)
1468 opt_dynamic_list
= dynamic_list
;
1470 case OPTION_DYNAMIC_LIST_CPP_NEW
:
1471 lang_append_dynamic_list_cpp_new ();
1472 if (opt_dynamic_list
!= dynamic_list_data
)
1473 opt_dynamic_list
= dynamic_list
;
1475 case OPTION_DYNAMIC_LIST
:
1476 /* This option indicates a small script that only specifies
1477 a dynamic list. Read it, but don't assume that we've
1478 seen a linker script. */
1480 FILE *hold_script_handle
;
1482 hold_script_handle
= saved_script_handle
;
1483 ldfile_open_command_file (optarg
);
1484 saved_script_handle
= hold_script_handle
;
1485 parser_input
= input_dynamic_list
;
1486 current_dynamic_list_p
= &link_info
.dynamic_list
;
1489 if (opt_dynamic_list
!= dynamic_list_data
)
1490 opt_dynamic_list
= dynamic_list
;
1492 case OPTION_EXPORT_DYNAMIC_SYMBOL
:
1494 struct bfd_elf_version_expr
*expr
1495 = lang_new_vers_pattern (NULL
, xstrdup (optarg
), NULL
,
1497 lang_append_dynamic_list (&export_list
, expr
);
1500 case OPTION_EXPORT_DYNAMIC_SYMBOL_LIST
:
1501 /* This option indicates a small script that only specifies
1502 an export list. Read it, but don't assume that we've
1503 seen a linker script. */
1505 FILE *hold_script_handle
;
1507 hold_script_handle
= saved_script_handle
;
1508 ldfile_open_command_file (optarg
);
1509 saved_script_handle
= hold_script_handle
;
1510 parser_input
= input_dynamic_list
;
1511 current_dynamic_list_p
= &export_list
;
1515 case OPTION_WARN_COMMON
:
1516 config
.warn_common
= true;
1518 case OPTION_WARN_CONSTRUCTORS
:
1519 config
.warn_constructors
= true;
1521 case OPTION_WARN_FATAL
:
1522 config
.fatal_warnings
= true;
1524 case OPTION_NO_WARN_FATAL
:
1525 config
.fatal_warnings
= false;
1527 case OPTION_WARN_MULTIPLE_GP
:
1528 config
.warn_multiple_gp
= true;
1530 case OPTION_WARN_ONCE
:
1531 config
.warn_once
= true;
1533 case OPTION_WARN_SECTION_ALIGN
:
1534 config
.warn_section_align
= true;
1536 case OPTION_WARN_TEXTREL
:
1537 link_info
.textrel_check
= textrel_check_warning
;
1539 case OPTION_WARN_ALTERNATE_EM
:
1540 link_info
.warn_alternate_em
= true;
1542 case OPTION_WHOLE_ARCHIVE
:
1543 input_flags
.whole_archive
= true;
1545 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC
:
1546 input_flags
.add_DT_NEEDED_for_dynamic
= true;
1548 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC
:
1549 input_flags
.add_DT_NEEDED_for_dynamic
= false;
1551 case OPTION_ADD_DT_NEEDED_FOR_REGULAR
:
1552 input_flags
.add_DT_NEEDED_for_regular
= true;
1554 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR
:
1555 input_flags
.add_DT_NEEDED_for_regular
= false;
1560 case OPTION_IGNORE_UNRESOLVED_SYMBOL
:
1561 add_ignoresym (&link_info
, optarg
);
1563 case OPTION_DISCARD_NONE
:
1564 link_info
.discard
= discard_none
;
1567 link_info
.discard
= discard_l
;
1570 link_info
.discard
= discard_all
;
1573 if (startswith (optarg
, "P,"))
1575 free (default_dirlist
);
1576 default_dirlist
= xstrdup (optarg
);
1581 case OPTION_SPARE_DYNAMIC_TAGS
:
1582 link_info
.spare_dynamic_tags
= strtoul (optarg
, NULL
, 0);
1584 case OPTION_SPLIT_BY_RELOC
:
1586 config
.split_by_reloc
= strtoul (optarg
, NULL
, 0);
1588 config
.split_by_reloc
= 32768;
1590 case OPTION_SPLIT_BY_FILE
:
1592 config
.split_by_file
= bfd_scan_vma (optarg
, NULL
, 0);
1594 config
.split_by_file
= 1;
1596 case OPTION_CHECK_SECTIONS
:
1597 command_line
.check_section_addresses
= 1;
1599 case OPTION_NO_CHECK_SECTIONS
:
1600 command_line
.check_section_addresses
= 0;
1602 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH
:
1603 command_line
.accept_unknown_input_arch
= true;
1605 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH
:
1606 command_line
.accept_unknown_input_arch
= false;
1609 lang_enter_group ();
1614 einfo (_("%F%P: group ended before it began (--help for usage)\n"));
1616 lang_leave_group ();
1621 link_info
.init_function
= optarg
;
1625 link_info
.fini_function
= optarg
;
1628 case OPTION_REDUCE_MEMORY_OVERHEADS
:
1629 link_info
.reduce_memory_overheads
= true;
1630 if (config
.hash_table_size
== 0)
1631 config
.hash_table_size
= 1021;
1634 case OPTION_HASH_SIZE
:
1636 bfd_size_type new_size
;
1638 new_size
= strtoul (optarg
, NULL
, 0);
1640 config
.hash_table_size
= new_size
;
1642 einfo (_("%X%P: --hash-size needs a numeric argument\n"));
1646 case OPTION_PUSH_STATE
:
1647 input_flags
.pushed
= xmemdup (&input_flags
,
1648 sizeof (input_flags
),
1649 sizeof (input_flags
));
1652 case OPTION_POP_STATE
:
1653 if (input_flags
.pushed
== NULL
)
1654 einfo (_("%F%P: no state pushed before popping\n"));
1657 struct lang_input_statement_flags
*oldp
= input_flags
.pushed
;
1658 memcpy (&input_flags
, oldp
, sizeof (input_flags
));
1663 case OPTION_PRINT_MEMORY_USAGE
:
1664 command_line
.print_memory_usage
= true;
1667 case OPTION_ORPHAN_HANDLING
:
1668 if (strcasecmp (optarg
, "place") == 0)
1669 config
.orphan_handling
= orphan_handling_place
;
1670 else if (strcasecmp (optarg
, "warn") == 0)
1671 config
.orphan_handling
= orphan_handling_warn
;
1672 else if (strcasecmp (optarg
, "error") == 0)
1673 config
.orphan_handling
= orphan_handling_error
;
1674 else if (strcasecmp (optarg
, "discard") == 0)
1675 config
.orphan_handling
= orphan_handling_discard
;
1677 einfo (_("%F%P: invalid argument to option"
1678 " \"--orphan-handling\"\n"));
1681 case OPTION_NO_PRINT_MAP_DISCARDED
:
1682 config
.print_map_discarded
= false;
1685 case OPTION_PRINT_MAP_DISCARDED
:
1686 config
.print_map_discarded
= true;
1689 case OPTION_DEPENDENCY_FILE
:
1690 config
.dependency_file
= optarg
;
1693 case OPTION_CTF_VARIABLES
:
1694 config
.ctf_variables
= true;
1697 case OPTION_NO_CTF_VARIABLES
:
1698 config
.ctf_variables
= false;
1701 case OPTION_CTF_SHARE_TYPES
:
1702 if (strcmp (optarg
, "share-unconflicted") == 0)
1703 config
.ctf_share_duplicated
= false;
1704 else if (strcmp (optarg
, "share-duplicated") == 0)
1705 config
.ctf_share_duplicated
= true;
1707 einfo (_("%F%P: bad --ctf-share-types option: %s\n"), optarg
);
1712 free (really_longopts
);
1716 /* Run a couple of checks on the map filename. */
1717 if (config
.map_filename
)
1719 char * new_name
= NULL
;
1723 if (config
.map_filename
[0] == 0)
1725 einfo (_("%P: no file/directory name provided for map output; ignored\n"));
1726 config
.map_filename
= NULL
;
1728 else if (strcmp (config
.map_filename
, "-") == 0)
1729 ; /* Write to stdout. Handled in main(). */
1730 else if ((percent
= strchr (config
.map_filename
, '%')) != NULL
)
1732 /* FIXME: Check for a second % character and issue an error ? */
1734 /* Construct a map file by replacing the % character with the (full)
1735 output filename. If the % character was the last character in
1736 the original map filename then add a .map extension. */
1738 res
= asprintf (&new_name
, "%s%s%s", config
.map_filename
,
1740 percent
[1] ? percent
+ 1 : ".map");
1742 /* FIXME: Should we ensure that any directory components in new_name exist ? */
1748 /* If the map filename is actually a directory then create
1749 a file inside it, based upon the output filename. */
1750 if (stat (config
.map_filename
, &s
) < 0)
1752 if (errno
!= ENOENT
)
1753 einfo (_("%P: cannot stat linker map file: %E\n"));
1755 else if (S_ISDIR (s
.st_mode
))
1757 char lastc
= config
.map_filename
[strlen (config
.map_filename
) - 1];
1758 res
= asprintf (&new_name
, "%s%s%s.map",
1759 config
.map_filename
,
1760 IS_DIR_SEPARATOR (lastc
) ? "" : "/",
1761 lbasename (output_filename
));
1763 else if (! S_ISREG (s
.st_mode
))
1765 einfo (_("%P: linker map file is not a regular file\n"));
1766 config
.map_filename
= NULL
;
1768 /* else FIXME: Check write permission ? */
1773 /* If the asprintf failed then something is probably very
1774 wrong. Better to halt now rather than continue on
1775 into more problems. */
1776 einfo (_("%P%F: cannot create name for linker map file: %E\n"));
1778 else if (new_name
!= NULL
)
1780 /* This is a trivial memory leak. */
1781 config
.map_filename
= new_name
;
1785 if (command_line
.soname
&& command_line
.soname
[0] == '\0')
1787 einfo (_("%P: SONAME must not be empty string; ignored\n"));
1788 command_line
.soname
= NULL
;
1793 einfo (_("%P: missing --end-group; added as last command line option\n"));
1794 lang_leave_group ();
1798 if (default_dirlist
!= NULL
)
1800 set_default_dirlist (default_dirlist
);
1801 free (default_dirlist
);
1804 if (link_info
.unresolved_syms_in_objects
== RM_NOT_YET_SET
)
1805 /* FIXME: Should we allow emulations a chance to set this ? */
1806 link_info
.unresolved_syms_in_objects
= RM_DIAGNOSE
;
1808 if (link_info
.unresolved_syms_in_shared_libs
== RM_NOT_YET_SET
)
1809 /* FIXME: Should we allow emulations a chance to set this ? */
1810 link_info
.unresolved_syms_in_shared_libs
= RM_DIAGNOSE
;
1812 if (bfd_link_relocatable (&link_info
)
1813 && command_line
.check_section_addresses
< 0)
1814 command_line
.check_section_addresses
= 0;
1818 struct bfd_elf_version_expr
*head
= export_list
->head
.list
;
1819 struct bfd_elf_version_expr
*next
;
1821 /* For --export-dynamic-symbol[-list]:
1822 1. When building executable, treat like --dynamic-list.
1823 2. When building shared object:
1824 a. If -Bsymbolic or --dynamic-list are used, treat like
1826 b. Otherwise, ignored.
1828 if (!bfd_link_relocatable (&link_info
)
1829 && (bfd_link_executable (&link_info
)
1830 || opt_symbolic
!= symbolic_unset
1831 || opt_dynamic_list
!= dynamic_list_unset
))
1833 /* Append the export list to link_info.dynamic_list. */
1834 if (link_info
.dynamic_list
)
1836 for (next
= head
; next
->next
!= NULL
; next
= next
->next
)
1838 next
->next
= link_info
.dynamic_list
->head
.list
;
1839 link_info
.dynamic_list
->head
.list
= head
;
1842 link_info
.dynamic_list
= export_list
;
1844 if (opt_dynamic_list
!= dynamic_list_data
)
1845 opt_dynamic_list
= dynamic_list
;
1849 /* Free the export list. */
1850 for (; head
->next
!= NULL
; head
= next
)
1859 switch (opt_dynamic_list
)
1861 case dynamic_list_unset
:
1863 case dynamic_list_data
:
1864 link_info
.dynamic_data
= true;
1867 link_info
.dynamic
= true;
1868 opt_symbolic
= symbolic_unset
;
1872 /* -Bsymbolic and -Bsymbols-functions are for shared library output. */
1873 if (bfd_link_dll (&link_info
))
1874 switch (opt_symbolic
)
1876 case symbolic_unset
:
1879 link_info
.symbolic
= true;
1880 if (link_info
.dynamic_list
)
1882 struct bfd_elf_version_expr
*ent
, *next
;
1883 for (ent
= link_info
.dynamic_list
->head
.list
; ent
; ent
= next
)
1888 free (link_info
.dynamic_list
);
1889 link_info
.dynamic_list
= NULL
;
1892 case symbolic_functions
:
1893 link_info
.dynamic
= true;
1894 link_info
.dynamic_data
= true;
1898 if (!bfd_link_dll (&link_info
))
1900 if (command_line
.filter_shlib
)
1901 einfo (_("%F%P: -F may not be used without -shared\n"));
1902 if (command_line
.auxiliary_filters
)
1903 einfo (_("%F%P: -f may not be used without -shared\n"));
1906 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1907 don't see how else this can be handled, since in this case we
1908 must preserve all externally visible symbols. */
1909 if (bfd_link_relocatable (&link_info
) && link_info
.strip
== strip_all
)
1911 link_info
.strip
= strip_debugger
;
1912 if (link_info
.discard
== discard_sec_merge
)
1913 link_info
.discard
= discard_all
;
1917 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1918 library search path. */
1921 set_default_dirlist (char *dirlist_ptr
)
1927 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1930 if (*dirlist_ptr
!= '\0')
1931 ldfile_add_library_path (dirlist_ptr
, true);
1934 dirlist_ptr
= p
+ 1;
1939 set_section_start (char *sect
, char *valstr
)
1942 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1944 einfo (_("%F%P: invalid hex number `%s'\n"), valstr
);
1945 lang_section_start (sect
, exp_intop (val
), NULL
);
1949 set_segment_start (const char *section
, char *valstr
)
1955 bfd_vma val
= bfd_scan_vma (valstr
, &end
, 16);
1957 einfo (_("%F%P: invalid hex number `%s'\n"), valstr
);
1958 /* If we already have an entry for this segment, update the existing
1961 for (seg
= segments
; seg
; seg
= seg
->next
)
1962 if (strcmp (seg
->name
, name
) == 0)
1965 lang_section_start (section
, exp_intop (val
), seg
);
1968 /* There was no existing value so we must create a new segment
1970 seg
= stat_alloc (sizeof (*seg
));
1974 /* Add it to the linked list of segments. */
1975 seg
->next
= segments
;
1977 /* Historically, -Ttext and friends set the base address of a
1978 particular section. For backwards compatibility, we still do
1979 that. If a SEGMENT_START directive is seen, the section address
1980 assignment will be disabled. */
1981 lang_section_start (section
, exp_intop (val
), seg
);
1985 elf_shlib_list_options (FILE *file
)
1988 --audit=AUDITLIB Specify a library to use for auditing\n"));
1990 -Bgroup Selects group name lookup rules for DSO\n"));
1992 --disable-new-dtags Disable new dynamic tags\n"));
1994 --enable-new-dtags Enable new dynamic tags\n"));
1996 --eh-frame-hdr Create .eh_frame_hdr section\n"));
1998 --no-eh-frame-hdr Do not create .eh_frame_hdr section\n"));
2000 --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
2002 --hash-style=STYLE Set hash style to sysv/gnu/both. Default: "));
2003 if (DEFAULT_EMIT_SYSV_HASH
)
2005 /* Note - these strings are not translated as
2006 they are keywords not descriptive text. */
2007 if (DEFAULT_EMIT_GNU_HASH
)
2008 fprintf (file
, "both\n");
2010 fprintf (file
, "sysv\n");
2014 if (DEFAULT_EMIT_GNU_HASH
)
2015 fprintf (file
, "gnu\n");
2017 /* FIXME: Can this happen ? */
2018 fprintf (file
, "none\n");
2021 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
2022 Specify a library to use for auditing dependencies\n"));
2024 -z combreloc Merge dynamic relocs into one section and sort\n"));
2026 -z nocombreloc Don't merge dynamic relocs into one section\n"));
2028 -z global Make symbols in DSO available for subsequently\n\
2029 loaded objects\n"));
2031 -z initfirst Mark DSO to be initialized first at runtime\n"));
2033 -z interpose Mark object to interpose all DSOs but executable\n"));
2035 -z unique Mark DSO to be loaded at most once by default, and only in the main namespace\n"));
2037 -z nounique Don't mark DSO as a loadable at most once\n"));
2039 -z lazy Mark object lazy runtime binding (default)\n"));
2041 -z loadfltr Mark object requiring immediate process\n"));
2043 -z nocopyreloc Don't create copy relocs\n"));
2045 -z nodefaultlib Mark object not to use default search paths\n"));
2047 -z nodelete Mark DSO non-deletable at runtime\n"));
2049 -z nodlopen Mark DSO not available to dlopen\n"));
2051 -z nodump Mark DSO not available to dldump\n"));
2053 -z now Mark object non-lazy runtime binding\n"));
2055 -z origin Mark object requiring immediate $ORIGIN\n\
2056 processing at runtime\n"));
2057 #if DEFAULT_LD_Z_RELRO
2059 -z relro Create RELRO program header (default)\n"));
2061 -z norelro Don't create RELRO program header\n"));
2064 -z relro Create RELRO program header\n"));
2066 -z norelro Don't create RELRO program header (default)\n"));
2068 #if DEFAULT_LD_Z_SEPARATE_CODE
2070 -z separate-code Create separate code program header (default)\n"));
2072 -z noseparate-code Don't create separate code program header\n"));
2075 -z separate-code Create separate code program header\n"));
2077 -z noseparate-code Don't create separate code program header (default)\n"));
2080 -z common Generate common symbols with STT_COMMON type\n"));
2082 -z nocommon Generate common symbols with STT_OBJECT type\n"));
2083 if (link_info
.textrel_check
== textrel_check_error
)
2085 -z text Treat DT_TEXTREL in output as error (default)\n"));
2088 -z text Treat DT_TEXTREL in output as error\n"));
2089 if (link_info
.textrel_check
== textrel_check_none
)
2092 -z notext Don't treat DT_TEXTREL in output as error (default)\n"));
2094 -z textoff Don't treat DT_TEXTREL in output as error (default)\n"));
2099 -z notext Don't treat DT_TEXTREL in output as error\n"));
2101 -z textoff Don't treat DT_TEXTREL in output as error\n"));
2106 elf_static_list_options (FILE *file
)
2109 --build-id[=STYLE] Generate build ID note\n"));
2111 --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\
2112 Compress DWARF debug sections using zlib\n"));
2113 #ifdef DEFAULT_FLAG_COMPRESS_DEBUG
2115 Default: zlib-gabi\n"));
2121 -z common-page-size=SIZE Set common page size to SIZE\n"));
2123 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
2125 -z defs Report unresolved symbols in object files\n"));
2127 -z undefs Ignore unresolved symbols in object files\n"));
2129 -z muldefs Allow multiple definitions\n"));
2131 -z stack-size=SIZE Set size of stack segment\n"));
2133 -z execstack Mark executable as requiring executable stack\n"));
2135 -z noexecstack Mark executable as not requiring executable stack\n"));
2137 -z unique-symbol Avoid duplicated local symbol names\n"));
2139 -z nounique-symbol Keep duplicated local symbol names (default)\n"));
2141 -z globalaudit Mark executable requiring global auditing\n"));
2143 -z start-stop-gc Enable garbage collection on __start/__stop\n"));
2145 -z nostart-stop-gc Don't garbage collect __start/__stop (default)\n"));
2147 -z start-stop-visibility=V Set visibility of built-in __start/__stop symbols\n\
2148 to DEFAULT, PROTECTED, HIDDEN or INTERNAL\n"));
2152 elf_plt_unwind_list_options (FILE *file
)
2155 --ld-generated-unwind-info Generate exception handling info for PLT\n"));
2157 --no-ld-generated-unwind-info\n\
2158 Don't generate exception handling info for PLT\n"));
2162 ld_list_options (FILE *file
, bool elf
, bool shlib
, bool plt_unwind
)
2166 printf (_("ELF emulations:\n"));
2168 elf_plt_unwind_list_options (file
);
2169 elf_static_list_options (file
);
2171 elf_shlib_list_options (file
);
2175 /* Print help messages for the options. */
2181 const char **targets
, **pp
;
2184 printf (_("Usage: %s [options] file...\n"), program_name
);
2186 printf (_("Options:\n"));
2187 for (i
= 0; i
< OPTION_COUNT
; i
++)
2189 if (ld_options
[i
].doc
!= NULL
)
2202 if (ld_options
[j
].shortopt
!= '\0'
2203 && ld_options
[j
].control
!= NO_HELP
)
2205 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
2206 len
+= (comma
? 2 : 0) + 2;
2207 if (ld_options
[j
].arg
!= NULL
)
2209 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
2214 printf ("%s", _(ld_options
[j
].arg
));
2215 len
+= strlen (_(ld_options
[j
].arg
));
2221 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
2226 if (ld_options
[j
].opt
.name
!= NULL
2227 && ld_options
[j
].control
!= NO_HELP
)
2230 (ld_options
[j
].control
== TWO_DASHES
2231 || ld_options
[j
].control
== EXACTLY_TWO_DASHES
);
2235 two_dashes
? "-" : "",
2236 ld_options
[j
].opt
.name
);
2237 len
+= ((comma
? 2 : 0)
2239 + (two_dashes
? 1 : 0)
2240 + strlen (ld_options
[j
].opt
.name
));
2241 if (ld_options
[j
].arg
!= NULL
)
2243 printf (" %s", _(ld_options
[j
].arg
));
2244 len
+= 1 + strlen (_(ld_options
[j
].arg
));
2250 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
2258 for (; len
< 30; len
++)
2261 printf ("%s\n", _(ld_options
[i
].doc
));
2264 printf (_(" @FILE"));
2265 for (len
= strlen (" @FILE"); len
< 30; len
++)
2267 printf (_("Read options from FILE\n"));
2269 /* Note: Various tools (such as libtool) depend upon the
2270 format of the listings below - do not change them. */
2271 /* xgettext:c-format */
2272 printf (_("%s: supported targets:"), program_name
);
2273 targets
= bfd_target_list ();
2274 for (pp
= targets
; *pp
!= NULL
; pp
++)
2275 printf (" %s", *pp
);
2279 /* xgettext:c-format */
2280 printf (_("%s: supported emulations: "), program_name
);
2281 ldemul_list_emulations (stdout
);
2284 /* xgettext:c-format */
2285 printf (_("%s: emulation specific options:\n"), program_name
);
2286 ld_list_options (stdout
, ELF_LIST_OPTIONS
, ELF_SHLIB_LIST_OPTIONS
,
2287 ELF_PLT_UNWIND_LIST_OPTIONS
);
2288 ldemul_list_emulation_options (stdout
);
2291 if (REPORT_BUGS_TO
[0])
2292 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO
);