gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / ld / lexsup.c
1 /* Parse options for the GNU linker.
2 Copyright (C) 1991-2020 Free Software Foundation, Inc.
3
4 This file is part of the GNU Binutils.
5
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.
10
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.
15
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. */
20
21 #include "sysdep.h"
22 #include "bfd.h"
23 #include "bfdver.h"
24 #include "libiberty.h"
25 #include <stdio.h>
26 #include <string.h>
27 #include "safe-ctype.h"
28 #include "getopt.h"
29 #include "bfdlink.h"
30 #include "ctf-api.h"
31 #include "ld.h"
32 #include "ldmain.h"
33 #include "ldmisc.h"
34 #include "ldexp.h"
35 #include "ldlang.h"
36 #include <ldgram.h>
37 #include "ldlex.h"
38 #include "ldfile.h"
39 #include "ldver.h"
40 #include "ldemul.h"
41 #include "demangle.h"
42 #ifdef ENABLE_PLUGINS
43 #include "plugin.h"
44 #endif /* ENABLE_PLUGINS */
45
46 #ifndef PATH_SEPARATOR
47 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
48 #define PATH_SEPARATOR ';'
49 #else
50 #define PATH_SEPARATOR ':'
51 #endif
52 #endif
53
54 /* Somewhere above, sys/stat.h got included . . . . */
55 #if !defined(S_ISDIR) && defined(S_IFDIR)
56 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
57 #endif
58
59 static void set_default_dirlist (char *);
60 static void set_section_start (char *, char *);
61 static void set_segment_start (const char *, char *);
62 static void help (void);
63
64 /* The long options. This structure is used for both the option
65 parsing and the help text. */
66
67 enum control_enum {
68 /* Use one dash before long option name. */
69 ONE_DASH = 1,
70 /* Use two dashes before long option name. */
71 TWO_DASHES = 2,
72 /* Only accept two dashes before the long option name.
73 This is an overloading of the use of this enum, since originally it
74 was only intended to tell the --help display function how to display
75 the long option name. This feature was added in order to resolve
76 the confusion about the -omagic command line switch. Is it setting
77 the output file name to "magic" or is it setting the NMAGIC flag on
78 the output ? It has been decided that it is setting the output file
79 name, and that if you want to set the NMAGIC flag you should use -N
80 or --omagic. */
81 EXACTLY_TWO_DASHES,
82 /* Don't mention this option in --help output. */
83 NO_HELP
84 };
85
86 struct ld_option
87 {
88 /* The long option information. */
89 struct option opt;
90 /* The short option with the same meaning ('\0' if none). */
91 char shortopt;
92 /* The name of the argument (NULL if none). */
93 const char *arg;
94 /* The documentation string. If this is NULL, this is a synonym for
95 the previous option. */
96 const char *doc;
97 enum control_enum control;
98 };
99
100 static const struct ld_option ld_options[] =
101 {
102 { {NULL, required_argument, NULL, '\0'},
103 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
104 ONE_DASH },
105 { {"architecture", required_argument, NULL, 'A'},
106 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
107 { {"format", required_argument, NULL, 'b'},
108 'b', N_("TARGET"), N_("Specify target for following input files"),
109 TWO_DASHES },
110 { {"mri-script", required_argument, NULL, 'c'},
111 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
112 { {"dc", no_argument, NULL, 'd'},
113 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
114 { {"dp", no_argument, NULL, 'd'},
115 '\0', NULL, NULL, ONE_DASH },
116 { {"force-group-allocation", no_argument, NULL,
117 OPTION_FORCE_GROUP_ALLOCATION},
118 '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
119 { {"entry", required_argument, NULL, 'e'},
120 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
121 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
122 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
123 { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC},
124 '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES },
125 { {"enable-non-contiguous-regions", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS},
126 '\0', NULL, N_("Enable support of non-contiguous memory regions"), TWO_DASHES },
127 { {"enable-non-contiguous-regions-warnings", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS},
128 '\0', NULL, N_("Enable warnings when --enable-non-contiguous-regions may cause unexpected behaviour"), TWO_DASHES },
129 { {"EB", no_argument, NULL, OPTION_EB},
130 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
131 { {"EL", no_argument, NULL, OPTION_EL},
132 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
133 { {"auxiliary", required_argument, NULL, 'f'},
134 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
135 TWO_DASHES },
136 { {"filter", required_argument, NULL, 'F'},
137 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
138 TWO_DASHES },
139 { {NULL, no_argument, NULL, '\0'},
140 'g', NULL, N_("Ignored"), ONE_DASH },
141 { {"gpsize", required_argument, NULL, 'G'},
142 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
143 TWO_DASHES },
144 { {"soname", required_argument, NULL, OPTION_SONAME},
145 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
146 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
147 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
148 TWO_DASHES },
149 { {"no-dynamic-linker", no_argument, NULL, OPTION_NO_DYNAMIC_LINKER},
150 '\0', NULL, N_("Produce an executable with no program interpreter header"),
151 TWO_DASHES },
152 { {"library", required_argument, NULL, 'l'},
153 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
154 { {"library-path", required_argument, NULL, 'L'},
155 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
156 TWO_DASHES },
157 { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
158 '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
159 { {NULL, required_argument, NULL, '\0'},
160 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
161 { {"print-map", no_argument, NULL, 'M'},
162 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
163 { {"nmagic", no_argument, NULL, 'n'},
164 'n', NULL, N_("Do not page align data"), TWO_DASHES },
165 { {"omagic", no_argument, NULL, 'N'},
166 'N', NULL, N_("Do not page align data, do not make text readonly"),
167 EXACTLY_TWO_DASHES },
168 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
169 '\0', NULL, N_("Page align data, make text readonly"),
170 EXACTLY_TWO_DASHES },
171 { {"output", required_argument, NULL, 'o'},
172 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
173 { {NULL, required_argument, NULL, '\0'},
174 'O', NULL, N_("Optimize output file"), ONE_DASH },
175 { {"out-implib", required_argument, NULL, OPTION_OUT_IMPLIB},
176 '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES },
177 #ifdef ENABLE_PLUGINS
178 { {"plugin", required_argument, NULL, OPTION_PLUGIN},
179 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
180 { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
181 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
182 { {"flto", optional_argument, NULL, OPTION_IGNORE},
183 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
184 ONE_DASH },
185 { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
186 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
187 ONE_DASH },
188 #endif /* ENABLE_PLUGINS */
189 { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE},
190 '\0', NULL, N_("Ignored for GCC linker option compatibility"),
191 ONE_DASH },
192 { {"map-whole-files", optional_argument, NULL, OPTION_IGNORE},
193 '\0', NULL, N_("Ignored for gold option compatibility"),
194 TWO_DASHES },
195 { {"no-map-whole-files", optional_argument, NULL, OPTION_IGNORE},
196 '\0', NULL, N_("Ignored for gold option compatibility"),
197 TWO_DASHES },
198 { {"Qy", no_argument, NULL, OPTION_IGNORE},
199 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
200 { {"emit-relocs", no_argument, NULL, 'q'},
201 'q', NULL, "Generate relocations in final output", TWO_DASHES },
202 { {"relocatable", no_argument, NULL, 'r'},
203 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
204 { {NULL, no_argument, NULL, '\0'},
205 'i', NULL, NULL, ONE_DASH },
206 { {"just-symbols", required_argument, NULL, 'R'},
207 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
208 TWO_DASHES },
209 { {"strip-all", no_argument, NULL, 's'},
210 's', NULL, N_("Strip all symbols"), TWO_DASHES },
211 { {"strip-debug", no_argument, NULL, 'S'},
212 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
213 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
214 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
215 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
216 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
217 { {"trace", no_argument, NULL, 't'},
218 't', NULL, N_("Trace file opens"), TWO_DASHES },
219 { {"script", required_argument, NULL, 'T'},
220 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
221 { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
222 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
223 { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
224 '\0', NULL, NULL, ONE_DASH },
225 { {"undefined", required_argument, NULL, 'u'},
226 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
227 TWO_DASHES },
228 { {"require-defined", required_argument, NULL, OPTION_REQUIRE_DEFINED_SYMBOL},
229 '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"),
230 TWO_DASHES },
231 { {"unique", optional_argument, NULL, OPTION_UNIQUE},
232 '\0', N_("[=SECTION]"),
233 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
234 { {"Ur", no_argument, NULL, OPTION_UR},
235 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
236 { {"version", no_argument, NULL, OPTION_VERSION},
237 'v', NULL, N_("Print version information"), TWO_DASHES },
238 { {NULL, no_argument, NULL, '\0'},
239 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
240 { {"discard-all", no_argument, NULL, 'x'},
241 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
242 { {"discard-locals", no_argument, NULL, 'X'},
243 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
244 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
245 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
246 { {"trace-symbol", required_argument, NULL, 'y'},
247 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
248 { {NULL, required_argument, NULL, '\0'},
249 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
250 ONE_DASH },
251 { {"start-group", no_argument, NULL, '('},
252 '(', NULL, N_("Start a group"), TWO_DASHES },
253 { {"end-group", no_argument, NULL, ')'},
254 ')', NULL, N_("End a group"), TWO_DASHES },
255 { {"accept-unknown-input-arch", no_argument, NULL,
256 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
257 '\0', NULL,
258 N_("Accept input files whose architecture cannot be determined"),
259 TWO_DASHES },
260 { {"no-accept-unknown-input-arch", no_argument, NULL,
261 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
262 '\0', NULL, N_("Reject input files whose architecture is unknown"),
263 TWO_DASHES },
264
265 /* The next two options are deprecated because of their similarity to
266 --as-needed and --no-as-needed. They have been replaced by
267 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
268 { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
269 '\0', NULL, NULL, NO_HELP },
270 { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
271 '\0', NULL, NULL, NO_HELP },
272
273 { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
274 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
275 TWO_DASHES },
276 { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
277 '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
278 " the command line"),
279 TWO_DASHES },
280 { {"assert", required_argument, NULL, OPTION_ASSERT},
281 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
282 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
283 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
284 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
285 '\0', NULL, NULL, ONE_DASH },
286 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
287 '\0', NULL, NULL, ONE_DASH },
288 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
289 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
290 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
291 '\0', NULL, NULL, ONE_DASH },
292 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
293 '\0', NULL, NULL, ONE_DASH },
294 { {"static", no_argument, NULL, OPTION_NON_SHARED},
295 '\0', NULL, NULL, ONE_DASH },
296 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
297 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
298 { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
299 '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
300 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
301 '\0', NULL, N_("Check section addresses for overlaps (default)"),
302 TWO_DASHES },
303 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
304 '\0', NULL, N_("Do not check section addresses for overlaps"),
305 TWO_DASHES },
306 { {"copy-dt-needed-entries", no_argument, NULL,
307 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
308 '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
309 TWO_DASHES },
310 { {"no-copy-dt-needed-entries", no_argument, NULL,
311 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
312 '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
313 TWO_DASHES },
314
315 { {"cref", no_argument, NULL, OPTION_CREF},
316 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
317 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
318 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
319 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
320 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
321 TWO_DASHES },
322 { {"disable-multiple-abs-defs", no_argument, NULL,
323 OPTION_DISABLE_MULTIPLE_DEFS_ABS},
324 '\0', NULL, N_("Do not allow multiple definitions with symbols included\n"
325 " in filename invoked by -R or --just-symbols"),
326 TWO_DASHES},
327 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
328 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
329 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
330 '\0', NULL, N_("Treat warnings as errors"),
331 TWO_DASHES },
332 { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL},
333 '\0', NULL, N_("Do not treat warnings as errors (default)"),
334 TWO_DASHES },
335 { {"fini", required_argument, NULL, OPTION_FINI},
336 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
337 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
338 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
339 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
340 '\0', NULL, N_("Remove unused sections (on some targets)"),
341 TWO_DASHES },
342 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
343 '\0', NULL, N_("Don't remove unused sections (default)"),
344 TWO_DASHES },
345 { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
346 '\0', NULL, N_("List removed unused sections on stderr"),
347 TWO_DASHES },
348 { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
349 '\0', NULL, N_("Do not list removed unused sections"),
350 TWO_DASHES },
351 { {"gc-keep-exported", no_argument, NULL, OPTION_GC_KEEP_EXPORTED},
352 '\0', NULL, N_("Keep exported symbols when removing unused sections"),
353 TWO_DASHES },
354 { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
355 '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
356 TWO_DASHES },
357 { {"help", no_argument, NULL, OPTION_HELP},
358 '\0', NULL, N_("Print option help"), TWO_DASHES },
359 { {"init", required_argument, NULL, OPTION_INIT},
360 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
361 { {"Map", required_argument, NULL, OPTION_MAP},
362 '\0', N_("FILE/DIR"), N_("Write a linker map to FILE or DIR/<outputname>.map"), ONE_DASH },
363 { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
364 '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
365 { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
366 '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
367 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
368 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
369 { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
370 '\0', NULL, N_("Do not allow unresolved references in object files"),
371 TWO_DASHES },
372 { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
373 '\0', NULL, N_("Allow unresolved references in shared libraries"),
374 TWO_DASHES },
375 { {"no-allow-shlib-undefined", no_argument, NULL,
376 OPTION_NO_ALLOW_SHLIB_UNDEFINED},
377 '\0', NULL, N_("Do not allow unresolved references in shared libs"),
378 TWO_DASHES },
379 { {"allow-multiple-definition", no_argument, NULL,
380 OPTION_ALLOW_MULTIPLE_DEFINITION},
381 '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
382 { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
383 '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
384 { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
385 '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
386 { {"default-imported-symver", no_argument, NULL,
387 OPTION_DEFAULT_IMPORTED_SYMVER},
388 '\0', NULL, N_("Create default symbol version for imported symbols"),
389 TWO_DASHES },
390 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
391 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
392 { {"no-warn-search-mismatch", no_argument, NULL,
393 OPTION_NO_WARN_SEARCH_MISMATCH},
394 '\0', NULL, N_("Don't warn on finding an incompatible library"),
395 TWO_DASHES},
396 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
397 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
398 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
399 '\0', NULL, N_("Create an output file even if errors occur"),
400 TWO_DASHES },
401 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
402 '\0', NULL, NULL, NO_HELP },
403 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
404 '\0', NULL, N_("Only use library directories specified on\n"
405 " the command line"),
406 ONE_DASH },
407 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
408 '\0', N_("TARGET"), N_("Specify target of output file"),
409 EXACTLY_TWO_DASHES },
410 { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
411 '\0', NULL, N_("Print default output format"), TWO_DASHES },
412 { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT},
413 '\0', NULL, N_("Print current sysroot"), TWO_DASHES },
414 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
415 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
416 { {"reduce-memory-overheads", no_argument, NULL,
417 OPTION_REDUCE_MEMORY_OVERHEADS},
418 '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
419 TWO_DASHES },
420 { {"relax", no_argument, NULL, OPTION_RELAX},
421 '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
422 { {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
423 '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES },
424 { {"retain-symbols-file", required_argument, NULL,
425 OPTION_RETAIN_SYMBOLS_FILE},
426 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
427 { {"rpath", required_argument, NULL, OPTION_RPATH},
428 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
429 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
430 '\0', N_("PATH"), N_("Set link time shared library search path"),
431 ONE_DASH },
432 { {"shared", no_argument, NULL, OPTION_SHARED},
433 '\0', NULL, N_("Create a shared library"), ONE_DASH },
434 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
435 '\0', NULL, NULL, ONE_DASH },
436 { {"pie", no_argument, NULL, OPTION_PIE},
437 '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
438 { {"pic-executable", no_argument, NULL, OPTION_PIE},
439 '\0', NULL, NULL, TWO_DASHES },
440 { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
441 '\0', N_("[=ascending|descending]"),
442 N_("Sort common symbols by alignment [in specified order]"),
443 TWO_DASHES },
444 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
445 '\0', NULL, NULL, NO_HELP },
446 { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
447 '\0', N_("name|alignment"),
448 N_("Sort sections by name or maximum alignment"), TWO_DASHES },
449 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
450 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
451 TWO_DASHES },
452 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
453 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
454 TWO_DASHES },
455 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
456 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
457 TWO_DASHES },
458 { {"stats", no_argument, NULL, OPTION_STATS},
459 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
460 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
461 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
462 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
463 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
464 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
465 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
466 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
467 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
468 TWO_DASHES },
469 { {"Tbss", required_argument, NULL, OPTION_TBSS},
470 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
471 { {"Tdata", required_argument, NULL, OPTION_TDATA},
472 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
473 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
474 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
475 { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT},
476 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH },
477 { {"Trodata-segment", required_argument, NULL, OPTION_TRODATA_SEGMENT},
478 '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH },
479 { {"Tldata-segment", required_argument, NULL, OPTION_TLDATA_SEGMENT},
480 '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH },
481 { {"unresolved-symbols=<method>", required_argument, NULL,
482 OPTION_UNRESOLVED_SYMBOLS},
483 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n"
484 " ignore-all, report-all, ignore-in-object-files,\n"
485 " ignore-in-shared-libs"),
486 TWO_DASHES },
487 { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
488 '\0', N_("[=NUMBER]"),
489 N_("Output lots of information during link"), TWO_DASHES },
490 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
491 '\0', NULL, NULL, NO_HELP },
492 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
493 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
494 { {"version-exports-section", required_argument, NULL,
495 OPTION_VERSION_EXPORTS_SECTION },
496 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
497 " SYMBOL as the version."),
498 TWO_DASHES },
499 { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
500 '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
501 { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
502 '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
503 { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
504 '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
505 { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
506 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
507 { {"export-dynamic-symbol", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL},
508 '\0', N_("SYMBOL"), N_("Export the specified symbol"), EXACTLY_TWO_DASHES },
509 { {"export-dynamic-symbol-list", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL_LIST},
510 '\0', N_("FILE"), N_("Read export dynamic symbol list"), EXACTLY_TWO_DASHES },
511 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
512 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
513 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
514 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
515 TWO_DASHES },
516 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
517 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
518 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
519 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
520 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
521 '\0', NULL, N_("Warn if start of section changes due to alignment"),
522 TWO_DASHES },
523 { {"warn-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
524 '\0', NULL,
525 #if DEFAULT_LD_TEXTREL_CHECK_WARNING
526 N_("Warn if outpout has DT_TEXTREL (default)"),
527 #else
528 N_("Warn if outpout has DT_TEXTREL"),
529 #endif
530 TWO_DASHES },
531 { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
532 '\0', NULL, NULL, NO_HELP },
533 { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
534 '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
535 TWO_DASHES },
536 { {"warn-unresolved-symbols", no_argument, NULL,
537 OPTION_WARN_UNRESOLVED_SYMBOLS},
538 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
539 { {"error-unresolved-symbols", no_argument, NULL,
540 OPTION_ERROR_UNRESOLVED_SYMBOLS},
541 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
542 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
543 '\0', NULL, N_("Include all objects from following archives"),
544 TWO_DASHES },
545 { {"wrap", required_argument, NULL, OPTION_WRAP},
546 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
547 { {"ignore-unresolved-symbol", required_argument, NULL,
548 OPTION_IGNORE_UNRESOLVED_SYMBOL},
549 '\0', N_("SYMBOL"),
550 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
551 { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
552 '\0', NULL, N_("Push state of flags governing input file handling"),
553 TWO_DASHES },
554 { {"pop-state", no_argument, NULL, OPTION_POP_STATE},
555 '\0', NULL, N_("Pop state of flags governing input file handling"),
556 TWO_DASHES },
557 { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE},
558 '\0', NULL, N_("Report target memory usage"), TWO_DASHES },
559 { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING},
560 '\0', N_("=MODE"), N_("Control how orphan sections are handled."),
561 TWO_DASHES },
562 { {"print-map-discarded", no_argument, NULL, OPTION_PRINT_MAP_DISCARDED},
563 '\0', NULL, N_("Show discarded sections in map file output (default)"),
564 TWO_DASHES },
565 { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISCARDED},
566 '\0', NULL, N_("Do not show discarded sections in map file output"),
567 TWO_DASHES },
568 };
569
570 #define OPTION_COUNT ARRAY_SIZE (ld_options)
571
572 void
573 parse_args (unsigned argc, char **argv)
574 {
575 unsigned i;
576 int is, il, irl;
577 int ingroup = 0;
578 char *default_dirlist = NULL;
579 char *shortopts;
580 struct option *longopts;
581 struct option *really_longopts;
582 int last_optind;
583 enum symbolic_enum
584 {
585 symbolic_unset = 0,
586 symbolic,
587 symbolic_functions,
588 } opt_symbolic = symbolic_unset;
589 enum dynamic_list_enum
590 {
591 dynamic_list_unset = 0,
592 dynamic_list_data,
593 dynamic_list
594 } opt_dynamic_list = dynamic_list_unset;
595 struct bfd_elf_dynamic_list *export_list = NULL;
596
597 shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
598 longopts = (struct option *)
599 xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
600 really_longopts = (struct option *)
601 malloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
602
603 /* Starting the short option string with '-' is for programs that
604 expect options and other ARGV-elements in any order and that care about
605 the ordering of the two. We describe each non-option ARGV-element
606 as if it were the argument of an option with character code 1. */
607 shortopts[0] = '-';
608 is = 1;
609 il = 0;
610 irl = 0;
611 for (i = 0; i < OPTION_COUNT; i++)
612 {
613 if (ld_options[i].shortopt != '\0')
614 {
615 shortopts[is] = ld_options[i].shortopt;
616 ++is;
617 if (ld_options[i].opt.has_arg == required_argument
618 || ld_options[i].opt.has_arg == optional_argument)
619 {
620 shortopts[is] = ':';
621 ++is;
622 if (ld_options[i].opt.has_arg == optional_argument)
623 {
624 shortopts[is] = ':';
625 ++is;
626 }
627 }
628 }
629 if (ld_options[i].opt.name != NULL)
630 {
631 if (ld_options[i].control == EXACTLY_TWO_DASHES)
632 {
633 really_longopts[irl] = ld_options[i].opt;
634 ++irl;
635 }
636 else
637 {
638 longopts[il] = ld_options[i].opt;
639 ++il;
640 }
641 }
642 }
643 shortopts[is] = '\0';
644 longopts[il].name = NULL;
645 really_longopts[irl].name = NULL;
646
647 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
648
649 /* The -G option is ambiguous on different platforms. Sometimes it
650 specifies the largest data size to put into the small data
651 section. Sometimes it is equivalent to --shared. Unfortunately,
652 the first form takes an argument, while the second does not.
653
654 We need to permit the --shared form because on some platforms,
655 such as Solaris, gcc -shared will pass -G to the linker.
656
657 To permit either usage, we look through the argument list. If we
658 find -G not followed by a number, we change it into --shared.
659 This will work for most normal cases. */
660 for (i = 1; i < argc; i++)
661 if (strcmp (argv[i], "-G") == 0
662 && (i + 1 >= argc
663 || ! ISDIGIT (argv[i + 1][0])))
664 argv[i] = (char *) "--shared";
665
666 /* Because we permit long options to start with a single dash, and
667 we have a --library option, and the -l option is conventionally
668 used with an immediately following argument, we can have bad
669 results if somebody tries to use -l with a library whose name
670 happens to start with "ibrary", as in -li. We avoid problems by
671 simply turning -l into --library. This means that users will
672 have to use two dashes in order to use --library, which is OK
673 since that's how it is documented.
674
675 FIXME: It's possible that this problem can arise for other short
676 options as well, although the user does always have the recourse
677 of adding a space between the option and the argument. */
678 for (i = 1; i < argc; i++)
679 {
680 if (argv[i][0] == '-'
681 && argv[i][1] == 'l'
682 && argv[i][2] != '\0')
683 {
684 char *n;
685
686 n = (char *) xmalloc (strlen (argv[i]) + 20);
687 sprintf (n, "--library=%s", argv[i] + 2);
688 argv[i] = n;
689 }
690 }
691
692 last_optind = -1;
693 while (1)
694 {
695 int longind;
696 int optc;
697 static unsigned int defsym_count;
698
699 /* Using last_optind lets us avoid calling ldemul_parse_args
700 multiple times on a single option, which would lead to
701 confusion in the internal static variables maintained by
702 getopt. This could otherwise happen for an argument like
703 -nx, in which the -n is parsed as a single option, and we
704 loop around to pick up the -x. */
705 if (optind != last_optind)
706 if (ldemul_parse_args (argc, argv))
707 continue;
708
709 /* getopt_long_only is like getopt_long, but '-' as well as '--'
710 can indicate a long option. */
711 opterr = 0;
712 last_optind = optind;
713 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
714 if (optc == '?')
715 {
716 optind = last_optind;
717 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
718 }
719
720 if (ldemul_handle_option (optc))
721 continue;
722
723 if (optc == -1)
724 break;
725
726 switch (optc)
727 {
728 case '?':
729 {
730 /* If the last word on the command line is an option that
731 requires an argument, getopt will refuse to recognise it.
732 Try to catch such options here and issue a more helpful
733 error message than just "unrecognized option". */
734 int opt;
735
736 for (opt = ARRAY_SIZE (ld_options); opt--;)
737 if (ld_options[opt].opt.has_arg == required_argument
738 /* FIXME: There are a few short options that do not
739 have long equivalents, but which require arguments.
740 We should handle them too. */
741 && ld_options[opt].opt.name != NULL
742 && strcmp (argv[last_optind] + ld_options[opt].control, ld_options[opt].opt.name) == 0)
743 {
744 einfo (_("%P: %s: missing argument\n"), argv[last_optind]);
745 break;
746 }
747
748 if (opt == -1)
749 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
750 }
751 /* Fall through. */
752
753 default:
754 einfo (_("%F%P: use the --help option for usage information\n"));
755 break;
756
757 case 1: /* File name. */
758 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
759 break;
760
761 case OPTION_IGNORE:
762 break;
763 case 'a':
764 /* For HP/UX compatibility. Actually -a shared should mean
765 ``use only shared libraries'' but, then, we don't
766 currently support shared libraries on HP/UX anyhow. */
767 if (strcmp (optarg, "archive") == 0)
768 input_flags.dynamic = FALSE;
769 else if (strcmp (optarg, "shared") == 0
770 || strcmp (optarg, "default") == 0)
771 input_flags.dynamic = TRUE;
772 else
773 einfo (_("%F%P: unrecognized -a option `%s'\n"), optarg);
774 break;
775 case OPTION_ASSERT:
776 /* FIXME: We just ignore these, but we should handle them. */
777 if (strcmp (optarg, "definitions") == 0)
778 ;
779 else if (strcmp (optarg, "nodefinitions") == 0)
780 ;
781 else if (strcmp (optarg, "nosymbolic") == 0)
782 ;
783 else if (strcmp (optarg, "pure-text") == 0)
784 ;
785 else
786 einfo (_("%F%P: unrecognized -assert option `%s'\n"), optarg);
787 break;
788 case 'A':
789 ldfile_add_arch (optarg);
790 break;
791 case 'b':
792 lang_add_target (optarg);
793 break;
794 case 'c':
795 ldfile_open_command_file (optarg);
796 parser_input = input_mri_script;
797 yyparse ();
798 break;
799 case OPTION_CALL_SHARED:
800 input_flags.dynamic = TRUE;
801 break;
802 case OPTION_NON_SHARED:
803 input_flags.dynamic = FALSE;
804 break;
805 case OPTION_CREF:
806 command_line.cref = TRUE;
807 link_info.notice_all = TRUE;
808 break;
809 case 'd':
810 command_line.force_common_definition = TRUE;
811 break;
812 case OPTION_FORCE_GROUP_ALLOCATION:
813 command_line.force_group_allocation = TRUE;
814 break;
815 case OPTION_DEFSYM:
816 lex_string = optarg;
817 lex_redirect (optarg, "--defsym", ++defsym_count);
818 parser_input = input_defsym;
819 yyparse ();
820 lex_string = NULL;
821 break;
822 case OPTION_DEMANGLE:
823 demangling = TRUE;
824 if (optarg != NULL)
825 {
826 enum demangling_styles style;
827
828 style = cplus_demangle_name_to_style (optarg);
829 if (style == unknown_demangling)
830 einfo (_("%F%P: unknown demangling style `%s'\n"),
831 optarg);
832
833 cplus_demangle_set_style (style);
834 }
835 break;
836 case 'I': /* Used on Solaris. */
837 case OPTION_DYNAMIC_LINKER:
838 command_line.interpreter = optarg;
839 link_info.nointerp = 0;
840 break;
841 case OPTION_NO_DYNAMIC_LINKER:
842 link_info.nointerp = 1;
843 break;
844 case OPTION_SYSROOT:
845 /* Already handled in ldmain.c. */
846 break;
847 case OPTION_EB:
848 command_line.endian = ENDIAN_BIG;
849 break;
850 case OPTION_EL:
851 command_line.endian = ENDIAN_LITTLE;
852 break;
853 case OPTION_EMBEDDED_RELOCS:
854 command_line.embedded_relocs = TRUE;
855 break;
856 case OPTION_EXPORT_DYNAMIC:
857 case 'E': /* HP/UX compatibility. */
858 link_info.export_dynamic = TRUE;
859 break;
860 case OPTION_NO_EXPORT_DYNAMIC:
861 link_info.export_dynamic = FALSE;
862 break;
863 case OPTION_NON_CONTIGUOUS_REGIONS:
864 link_info.non_contiguous_regions = TRUE;
865 break;
866 case OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS:
867 link_info.non_contiguous_regions_warnings = TRUE;
868 break;
869 case 'e':
870 lang_add_entry (optarg, TRUE);
871 break;
872 case 'f':
873 if (command_line.auxiliary_filters == NULL)
874 {
875 command_line.auxiliary_filters = (char **)
876 xmalloc (2 * sizeof (char *));
877 command_line.auxiliary_filters[0] = optarg;
878 command_line.auxiliary_filters[1] = NULL;
879 }
880 else
881 {
882 int c;
883 char **p;
884
885 c = 0;
886 for (p = command_line.auxiliary_filters; *p != NULL; p++)
887 ++c;
888 command_line.auxiliary_filters = (char **)
889 xrealloc (command_line.auxiliary_filters,
890 (c + 2) * sizeof (char *));
891 command_line.auxiliary_filters[c] = optarg;
892 command_line.auxiliary_filters[c + 1] = NULL;
893 }
894 break;
895 case 'F':
896 command_line.filter_shlib = optarg;
897 break;
898 case OPTION_FORCE_EXE_SUFFIX:
899 command_line.force_exe_suffix = TRUE;
900 break;
901 case 'G':
902 {
903 char *end;
904 g_switch_value = strtoul (optarg, &end, 0);
905 if (*end)
906 einfo (_("%F%P: invalid number `%s'\n"), optarg);
907 }
908 break;
909 case 'g':
910 /* Ignore. */
911 break;
912 case OPTION_GC_SECTIONS:
913 link_info.gc_sections = TRUE;
914 break;
915 case OPTION_PRINT_GC_SECTIONS:
916 link_info.print_gc_sections = TRUE;
917 break;
918 case OPTION_GC_KEEP_EXPORTED:
919 link_info.gc_keep_exported = TRUE;
920 break;
921 case OPTION_HELP:
922 help ();
923 xexit (0);
924 break;
925 case 'L':
926 ldfile_add_library_path (optarg, TRUE);
927 break;
928 case 'l':
929 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
930 break;
931 case 'M':
932 config.map_filename = "-";
933 break;
934 case 'm':
935 /* Ignore. Was handled in a pre-parse. */
936 break;
937 case OPTION_MAP:
938 config.map_filename = optarg;
939 break;
940 case 'N':
941 config.text_read_only = FALSE;
942 config.magic_demand_paged = FALSE;
943 input_flags.dynamic = FALSE;
944 break;
945 case OPTION_NO_OMAGIC:
946 config.text_read_only = TRUE;
947 config.magic_demand_paged = TRUE;
948 /* NB/ Does not set input_flags.dynamic to TRUE.
949 Use --call-shared or -Bdynamic for this. */
950 break;
951 case 'n':
952 config.text_read_only = TRUE;
953 config.magic_demand_paged = FALSE;
954 input_flags.dynamic = FALSE;
955 break;
956 case OPTION_NO_DEFINE_COMMON:
957 link_info.inhibit_common_definition = TRUE;
958 break;
959 case OPTION_NO_DEMANGLE:
960 demangling = FALSE;
961 break;
962 case OPTION_NO_GC_SECTIONS:
963 link_info.gc_sections = FALSE;
964 break;
965 case OPTION_NO_PRINT_GC_SECTIONS:
966 link_info.print_gc_sections = FALSE;
967 break;
968 case OPTION_NO_KEEP_MEMORY:
969 link_info.keep_memory = FALSE;
970 break;
971 case OPTION_NO_UNDEFINED:
972 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
973 break;
974 case OPTION_ALLOW_SHLIB_UNDEFINED:
975 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
976 break;
977 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
978 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
979 break;
980 case OPTION_UNRESOLVED_SYMBOLS:
981 if (strcmp (optarg, "ignore-all") == 0)
982 {
983 link_info.unresolved_syms_in_objects = RM_IGNORE;
984 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
985 }
986 else if (strcmp (optarg, "report-all") == 0)
987 {
988 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
989 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
990 }
991 else if (strcmp (optarg, "ignore-in-object-files") == 0)
992 {
993 link_info.unresolved_syms_in_objects = RM_IGNORE;
994 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
995 }
996 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
997 {
998 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
999 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1000 }
1001 else
1002 einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg);
1003 break;
1004 case OPTION_WARN_UNRESOLVED_SYMBOLS:
1005 link_info.warn_unresolved_syms = TRUE;
1006 break;
1007 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
1008 link_info.warn_unresolved_syms = FALSE;
1009 break;
1010 case OPTION_ALLOW_MULTIPLE_DEFINITION:
1011 link_info.allow_multiple_definition = TRUE;
1012 break;
1013 case OPTION_NO_UNDEFINED_VERSION:
1014 link_info.allow_undefined_version = FALSE;
1015 break;
1016 case OPTION_DEFAULT_SYMVER:
1017 link_info.create_default_symver = TRUE;
1018 break;
1019 case OPTION_DEFAULT_IMPORTED_SYMVER:
1020 link_info.default_imported_symver = TRUE;
1021 break;
1022 case OPTION_NO_WARN_MISMATCH:
1023 command_line.warn_mismatch = FALSE;
1024 break;
1025 case OPTION_NO_WARN_SEARCH_MISMATCH:
1026 command_line.warn_search_mismatch = FALSE;
1027 break;
1028 case OPTION_NOINHIBIT_EXEC:
1029 force_make_executable = TRUE;
1030 break;
1031 case OPTION_NOSTDLIB:
1032 config.only_cmd_line_lib_dirs = TRUE;
1033 break;
1034 case OPTION_NO_WHOLE_ARCHIVE:
1035 input_flags.whole_archive = FALSE;
1036 break;
1037 case 'O':
1038 /* FIXME "-O<non-digits> <value>" used to set the address of
1039 section <non-digits>. Was this for compatibility with
1040 something, or can we create a new option to do that
1041 (with a syntax similar to -defsym)?
1042 getopt can't handle two args to an option without kludges. */
1043
1044 /* Enable optimizations of output files. */
1045 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
1046 break;
1047 case 'o':
1048 lang_add_output (optarg, 0);
1049 break;
1050 case OPTION_OFORMAT:
1051 lang_add_output_format (optarg, NULL, NULL, 0);
1052 break;
1053 case OPTION_OUT_IMPLIB:
1054 command_line.out_implib_filename = xstrdup (optarg);
1055 break;
1056 case OPTION_PRINT_SYSROOT:
1057 if (*ld_sysroot)
1058 puts (ld_sysroot);
1059 xexit (0);
1060 break;
1061 case OPTION_PRINT_OUTPUT_FORMAT:
1062 command_line.print_output_format = TRUE;
1063 break;
1064 #ifdef ENABLE_PLUGINS
1065 case OPTION_PLUGIN:
1066 plugin_opt_plugin (optarg);
1067 break;
1068 case OPTION_PLUGIN_OPT:
1069 if (plugin_opt_plugin_arg (optarg))
1070 einfo (_("%F%P: bad -plugin-opt option\n"));
1071 break;
1072 #endif /* ENABLE_PLUGINS */
1073 case 'q':
1074 link_info.emitrelocations = TRUE;
1075 break;
1076 case 'i':
1077 case 'r':
1078 if (optind == last_optind)
1079 /* This can happen if the user put "-rpath,a" on the command
1080 line. (Or something similar. The comma is important).
1081 Getopt becomes confused and thinks that this is a -r option
1082 but it cannot parse the text after the -r so it refuses to
1083 increment the optind counter. Detect this case and issue
1084 an error message here. We cannot just make this a warning,
1085 increment optind, and continue because getopt is too confused
1086 and will seg-fault the next time around. */
1087 einfo(_("%F%P: unrecognised option: %s\n"), argv[optind]);
1088
1089 if (bfd_link_pic (&link_info))
1090 einfo (_("%F%P: -r and %s may not be used together\n"),
1091 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1092
1093 link_info.type = type_relocatable;
1094 config.build_constructors = FALSE;
1095 config.magic_demand_paged = FALSE;
1096 config.text_read_only = FALSE;
1097 input_flags.dynamic = FALSE;
1098 break;
1099 case 'R':
1100 /* The GNU linker traditionally uses -R to mean to include
1101 only the symbols from a file. The Solaris linker uses -R
1102 to set the path used by the runtime linker to find
1103 libraries. This is the GNU linker -rpath argument. We
1104 try to support both simultaneously by checking the file
1105 named. If it is a directory, rather than a regular file,
1106 we assume -rpath was meant. */
1107 {
1108 struct stat s;
1109
1110 if (stat (optarg, &s) >= 0
1111 && ! S_ISDIR (s.st_mode))
1112 {
1113 lang_add_input_file (optarg,
1114 lang_input_file_is_symbols_only_enum,
1115 NULL);
1116 break;
1117 }
1118 }
1119 /* Fall through. */
1120 case OPTION_RPATH:
1121 if (command_line.rpath == NULL)
1122 command_line.rpath = xstrdup (optarg);
1123 else
1124 {
1125 size_t rpath_len = strlen (command_line.rpath);
1126 size_t optarg_len = strlen (optarg);
1127 char *buf;
1128 char *cp = command_line.rpath;
1129
1130 /* First see whether OPTARG is already in the path. */
1131 do
1132 {
1133 if (strncmp (optarg, cp, optarg_len) == 0
1134 && (cp[optarg_len] == 0
1135 || cp[optarg_len] == config.rpath_separator))
1136 /* We found it. */
1137 break;
1138
1139 /* Not yet found. */
1140 cp = strchr (cp, config.rpath_separator);
1141 if (cp != NULL)
1142 ++cp;
1143 }
1144 while (cp != NULL);
1145
1146 if (cp == NULL)
1147 {
1148 buf = (char *) xmalloc (rpath_len + optarg_len + 2);
1149 sprintf (buf, "%s%c%s", command_line.rpath,
1150 config.rpath_separator, optarg);
1151 free (command_line.rpath);
1152 command_line.rpath = buf;
1153 }
1154 }
1155 break;
1156 case OPTION_RPATH_LINK:
1157 if (command_line.rpath_link == NULL)
1158 command_line.rpath_link = xstrdup (optarg);
1159 else
1160 {
1161 char *buf;
1162
1163 buf = (char *) xmalloc (strlen (command_line.rpath_link)
1164 + strlen (optarg)
1165 + 2);
1166 sprintf (buf, "%s%c%s", command_line.rpath_link,
1167 config.rpath_separator, optarg);
1168 free (command_line.rpath_link);
1169 command_line.rpath_link = buf;
1170 }
1171 break;
1172 case OPTION_NO_RELAX:
1173 DISABLE_RELAXATION;
1174 break;
1175 case OPTION_RELAX:
1176 ENABLE_RELAXATION;
1177 break;
1178 case OPTION_RETAIN_SYMBOLS_FILE:
1179 add_keepsyms_file (optarg);
1180 break;
1181 case 'S':
1182 link_info.strip = strip_debugger;
1183 break;
1184 case 's':
1185 link_info.strip = strip_all;
1186 break;
1187 case OPTION_STRIP_DISCARDED:
1188 link_info.strip_discarded = TRUE;
1189 break;
1190 case OPTION_NO_STRIP_DISCARDED:
1191 link_info.strip_discarded = FALSE;
1192 break;
1193 case OPTION_DISABLE_MULTIPLE_DEFS_ABS:
1194 link_info.prohibit_multiple_definition_absolute = TRUE;
1195 break;
1196 case OPTION_SHARED:
1197 if (config.has_shared)
1198 {
1199 if (bfd_link_relocatable (&link_info))
1200 einfo (_("%F%P: -r and %s may not be used together\n"),
1201 "-shared");
1202
1203 link_info.type = type_dll;
1204 /* When creating a shared library, the default
1205 behaviour is to ignore any unresolved references. */
1206 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1207 link_info.unresolved_syms_in_objects = RM_IGNORE;
1208 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1209 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1210 }
1211 else
1212 einfo (_("%F%P: -shared not supported\n"));
1213 break;
1214 case OPTION_PIE:
1215 if (config.has_shared)
1216 {
1217 if (bfd_link_relocatable (&link_info))
1218 einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
1219
1220 link_info.type = type_pie;
1221 }
1222 else
1223 einfo (_("%F%P: -pie not supported\n"));
1224 break;
1225 case 'h': /* Used on Solaris. */
1226 case OPTION_SONAME:
1227 if (optarg[0] == '\0' && command_line.soname
1228 && command_line.soname[0])
1229 einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
1230 else
1231 command_line.soname = optarg;
1232 break;
1233 case OPTION_SORT_COMMON:
1234 if (optarg == NULL
1235 || strcmp (optarg, N_("descending")) == 0)
1236 config.sort_common = sort_descending;
1237 else if (strcmp (optarg, N_("ascending")) == 0)
1238 config.sort_common = sort_ascending;
1239 else
1240 einfo (_("%F%P: invalid common section sorting option: %s\n"),
1241 optarg);
1242 break;
1243 case OPTION_SORT_SECTION:
1244 if (strcmp (optarg, N_("name")) == 0)
1245 sort_section = by_name;
1246 else if (strcmp (optarg, N_("alignment")) == 0)
1247 sort_section = by_alignment;
1248 else
1249 einfo (_("%F%P: invalid section sorting option: %s\n"),
1250 optarg);
1251 break;
1252 case OPTION_STATS:
1253 config.stats = TRUE;
1254 break;
1255 case OPTION_SYMBOLIC:
1256 opt_symbolic = symbolic;
1257 break;
1258 case OPTION_SYMBOLIC_FUNCTIONS:
1259 opt_symbolic = symbolic_functions;
1260 break;
1261 case 't':
1262 ++trace_files;
1263 break;
1264 case 'T':
1265 previous_script_handle = saved_script_handle;
1266 ldfile_open_script_file (optarg);
1267 parser_input = input_script;
1268 yyparse ();
1269 previous_script_handle = NULL;
1270 break;
1271 case OPTION_DEFAULT_SCRIPT:
1272 command_line.default_script = optarg;
1273 break;
1274 case OPTION_SECTION_START:
1275 {
1276 char *optarg2;
1277 char *sec_name;
1278 int len;
1279
1280 /* Check for <something>=<somthing>... */
1281 optarg2 = strchr (optarg, '=');
1282 if (optarg2 == NULL)
1283 einfo (_("%F%P: invalid argument to option"
1284 " \"--section-start\"\n"));
1285
1286 optarg2++;
1287
1288 /* So far so good. Are all the args present? */
1289 if ((*optarg == '\0') || (*optarg2 == '\0'))
1290 einfo (_("%F%P: missing argument(s) to option"
1291 " \"--section-start\"\n"));
1292
1293 /* We must copy the section name as set_section_start
1294 doesn't do it for us. */
1295 len = optarg2 - optarg;
1296 sec_name = (char *) xmalloc (len);
1297 memcpy (sec_name, optarg, len - 1);
1298 sec_name[len - 1] = 0;
1299
1300 /* Then set it... */
1301 set_section_start (sec_name, optarg2);
1302 }
1303 break;
1304 case OPTION_TARGET_HELP:
1305 /* Mention any target specific options. */
1306 ldemul_list_emulation_options (stdout);
1307 exit (0);
1308 case OPTION_TBSS:
1309 set_segment_start (".bss", optarg);
1310 break;
1311 case OPTION_TDATA:
1312 set_segment_start (".data", optarg);
1313 break;
1314 case OPTION_TTEXT:
1315 set_segment_start (".text", optarg);
1316 break;
1317 case OPTION_TTEXT_SEGMENT:
1318 set_segment_start (".text-segment", optarg);
1319 break;
1320 case OPTION_TRODATA_SEGMENT:
1321 set_segment_start (".rodata-segment", optarg);
1322 break;
1323 case OPTION_TLDATA_SEGMENT:
1324 set_segment_start (".ldata-segment", optarg);
1325 break;
1326 case OPTION_TRADITIONAL_FORMAT:
1327 link_info.traditional_format = TRUE;
1328 break;
1329 case OPTION_TASK_LINK:
1330 link_info.task_link = TRUE;
1331 /* Fall through. */
1332 case OPTION_UR:
1333 if (bfd_link_pic (&link_info))
1334 einfo (_("%F%P: -r and %s may not be used together\n"),
1335 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1336
1337 link_info.type = type_relocatable;
1338 config.build_constructors = TRUE;
1339 config.magic_demand_paged = FALSE;
1340 config.text_read_only = FALSE;
1341 input_flags.dynamic = FALSE;
1342 break;
1343 case 'u':
1344 ldlang_add_undef (optarg, TRUE);
1345 break;
1346 case OPTION_REQUIRE_DEFINED_SYMBOL:
1347 ldlang_add_require_defined (optarg);
1348 break;
1349 case OPTION_UNIQUE:
1350 if (optarg != NULL)
1351 lang_add_unique (optarg);
1352 else
1353 config.unique_orphan_sections = TRUE;
1354 break;
1355 case OPTION_VERBOSE:
1356 ldversion (1);
1357 version_printed = TRUE;
1358 verbose = TRUE;
1359 overflow_cutoff_limit = -2;
1360 if (optarg != NULL)
1361 {
1362 char *end;
1363 int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
1364 if (*end)
1365 einfo (_("%F%P: invalid number `%s'\n"), optarg);
1366 #ifdef ENABLE_PLUGINS
1367 report_plugin_symbols = level > 1;
1368 #endif /* ENABLE_PLUGINS */
1369 }
1370 break;
1371 case 'v':
1372 ldversion (0);
1373 version_printed = TRUE;
1374 break;
1375 case 'V':
1376 ldversion (1);
1377 version_printed = TRUE;
1378 break;
1379 case OPTION_VERSION:
1380 ldversion (2);
1381 xexit (0);
1382 break;
1383 case OPTION_VERSION_SCRIPT:
1384 /* This option indicates a small script that only specifies
1385 version information. Read it, but don't assume that
1386 we've seen a linker script. */
1387 {
1388 FILE *hold_script_handle;
1389
1390 hold_script_handle = saved_script_handle;
1391 ldfile_open_command_file (optarg);
1392 saved_script_handle = hold_script_handle;
1393 parser_input = input_version_script;
1394 yyparse ();
1395 }
1396 break;
1397 case OPTION_VERSION_EXPORTS_SECTION:
1398 /* This option records a version symbol to be applied to the
1399 symbols listed for export to be found in the object files
1400 .exports sections. */
1401 command_line.version_exports_section = optarg;
1402 break;
1403 case OPTION_DYNAMIC_LIST_DATA:
1404 opt_dynamic_list = dynamic_list_data;
1405 break;
1406 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1407 lang_append_dynamic_list_cpp_typeinfo ();
1408 if (opt_dynamic_list != dynamic_list_data)
1409 opt_dynamic_list = dynamic_list;
1410 break;
1411 case OPTION_DYNAMIC_LIST_CPP_NEW:
1412 lang_append_dynamic_list_cpp_new ();
1413 if (opt_dynamic_list != dynamic_list_data)
1414 opt_dynamic_list = dynamic_list;
1415 break;
1416 case OPTION_DYNAMIC_LIST:
1417 /* This option indicates a small script that only specifies
1418 a dynamic list. Read it, but don't assume that we've
1419 seen a linker script. */
1420 {
1421 FILE *hold_script_handle;
1422
1423 hold_script_handle = saved_script_handle;
1424 ldfile_open_command_file (optarg);
1425 saved_script_handle = hold_script_handle;
1426 parser_input = input_dynamic_list;
1427 current_dynamic_list_p = &link_info.dynamic_list;
1428 yyparse ();
1429 }
1430 if (opt_dynamic_list != dynamic_list_data)
1431 opt_dynamic_list = dynamic_list;
1432 break;
1433 case OPTION_EXPORT_DYNAMIC_SYMBOL:
1434 {
1435 struct bfd_elf_version_expr *expr
1436 = lang_new_vers_pattern (NULL, xstrdup (optarg), NULL,
1437 FALSE);
1438 lang_append_dynamic_list (&export_list, expr);
1439 }
1440 break;
1441 case OPTION_EXPORT_DYNAMIC_SYMBOL_LIST:
1442 /* This option indicates a small script that only specifies
1443 an export list. Read it, but don't assume that we've
1444 seen a linker script. */
1445 {
1446 FILE *hold_script_handle;
1447
1448 hold_script_handle = saved_script_handle;
1449 ldfile_open_command_file (optarg);
1450 saved_script_handle = hold_script_handle;
1451 parser_input = input_dynamic_list;
1452 current_dynamic_list_p = &export_list;
1453 yyparse ();
1454 }
1455 break;
1456 case OPTION_WARN_COMMON:
1457 config.warn_common = TRUE;
1458 break;
1459 case OPTION_WARN_CONSTRUCTORS:
1460 config.warn_constructors = TRUE;
1461 break;
1462 case OPTION_WARN_FATAL:
1463 config.fatal_warnings = TRUE;
1464 break;
1465 case OPTION_NO_WARN_FATAL:
1466 config.fatal_warnings = FALSE;
1467 break;
1468 case OPTION_WARN_MULTIPLE_GP:
1469 config.warn_multiple_gp = TRUE;
1470 break;
1471 case OPTION_WARN_ONCE:
1472 config.warn_once = TRUE;
1473 break;
1474 case OPTION_WARN_SECTION_ALIGN:
1475 config.warn_section_align = TRUE;
1476 break;
1477 case OPTION_WARN_TEXTREL:
1478 link_info.textrel_check = textrel_check_warning;
1479 break;
1480 case OPTION_WARN_ALTERNATE_EM:
1481 link_info.warn_alternate_em = TRUE;
1482 break;
1483 case OPTION_WHOLE_ARCHIVE:
1484 input_flags.whole_archive = TRUE;
1485 break;
1486 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
1487 input_flags.add_DT_NEEDED_for_dynamic = TRUE;
1488 break;
1489 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
1490 input_flags.add_DT_NEEDED_for_dynamic = FALSE;
1491 break;
1492 case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
1493 input_flags.add_DT_NEEDED_for_regular = TRUE;
1494 break;
1495 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
1496 input_flags.add_DT_NEEDED_for_regular = FALSE;
1497 break;
1498 case OPTION_WRAP:
1499 add_wrap (optarg);
1500 break;
1501 case OPTION_IGNORE_UNRESOLVED_SYMBOL:
1502 add_ignoresym (&link_info, optarg);
1503 break;
1504 case OPTION_DISCARD_NONE:
1505 link_info.discard = discard_none;
1506 break;
1507 case 'X':
1508 link_info.discard = discard_l;
1509 break;
1510 case 'x':
1511 link_info.discard = discard_all;
1512 break;
1513 case 'Y':
1514 if (CONST_STRNEQ (optarg, "P,"))
1515 optarg += 2;
1516 free (default_dirlist);
1517 default_dirlist = xstrdup (optarg);
1518 break;
1519 case 'y':
1520 add_ysym (optarg);
1521 break;
1522 case OPTION_SPARE_DYNAMIC_TAGS:
1523 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1524 break;
1525 case OPTION_SPLIT_BY_RELOC:
1526 if (optarg != NULL)
1527 config.split_by_reloc = strtoul (optarg, NULL, 0);
1528 else
1529 config.split_by_reloc = 32768;
1530 break;
1531 case OPTION_SPLIT_BY_FILE:
1532 if (optarg != NULL)
1533 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1534 else
1535 config.split_by_file = 1;
1536 break;
1537 case OPTION_CHECK_SECTIONS:
1538 command_line.check_section_addresses = 1;
1539 break;
1540 case OPTION_NO_CHECK_SECTIONS:
1541 command_line.check_section_addresses = 0;
1542 break;
1543 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1544 command_line.accept_unknown_input_arch = TRUE;
1545 break;
1546 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1547 command_line.accept_unknown_input_arch = FALSE;
1548 break;
1549 case '(':
1550 lang_enter_group ();
1551 ingroup++;
1552 break;
1553 case ')':
1554 if (! ingroup)
1555 einfo (_("%F%P: group ended before it began (--help for usage)\n"));
1556
1557 lang_leave_group ();
1558 ingroup--;
1559 break;
1560
1561 case OPTION_INIT:
1562 link_info.init_function = optarg;
1563 break;
1564
1565 case OPTION_FINI:
1566 link_info.fini_function = optarg;
1567 break;
1568
1569 case OPTION_REDUCE_MEMORY_OVERHEADS:
1570 link_info.reduce_memory_overheads = TRUE;
1571 if (config.hash_table_size == 0)
1572 config.hash_table_size = 1021;
1573 break;
1574
1575 case OPTION_HASH_SIZE:
1576 {
1577 bfd_size_type new_size;
1578
1579 new_size = strtoul (optarg, NULL, 0);
1580 if (new_size)
1581 config.hash_table_size = new_size;
1582 else
1583 einfo (_("%X%P: --hash-size needs a numeric argument\n"));
1584 }
1585 break;
1586
1587 case OPTION_PUSH_STATE:
1588 input_flags.pushed = xmemdup (&input_flags,
1589 sizeof (input_flags),
1590 sizeof (input_flags));
1591 break;
1592
1593 case OPTION_POP_STATE:
1594 if (input_flags.pushed == NULL)
1595 einfo (_("%F%P: no state pushed before popping\n"));
1596 else
1597 {
1598 struct lang_input_statement_flags *oldp = input_flags.pushed;
1599 memcpy (&input_flags, oldp, sizeof (input_flags));
1600 free (oldp);
1601 }
1602 break;
1603
1604 case OPTION_PRINT_MEMORY_USAGE:
1605 command_line.print_memory_usage = TRUE;
1606 break;
1607
1608 case OPTION_ORPHAN_HANDLING:
1609 if (strcasecmp (optarg, "place") == 0)
1610 config.orphan_handling = orphan_handling_place;
1611 else if (strcasecmp (optarg, "warn") == 0)
1612 config.orphan_handling = orphan_handling_warn;
1613 else if (strcasecmp (optarg, "error") == 0)
1614 config.orphan_handling = orphan_handling_error;
1615 else if (strcasecmp (optarg, "discard") == 0)
1616 config.orphan_handling = orphan_handling_discard;
1617 else
1618 einfo (_("%F%P: invalid argument to option"
1619 " \"--orphan-handling\"\n"));
1620 break;
1621
1622 case OPTION_NO_PRINT_MAP_DISCARDED:
1623 config.print_map_discarded = FALSE;
1624 break;
1625
1626 case OPTION_PRINT_MAP_DISCARDED:
1627 config.print_map_discarded = TRUE;
1628 break;
1629 }
1630 }
1631
1632 /* Run a couple of checks on the map filename. */
1633 if (config.map_filename)
1634 {
1635 if (config.map_filename[0] == 0)
1636 {
1637 einfo (_("%P: no file/directory name provided for map output; ignored\n"));
1638 config.map_filename = NULL;
1639 }
1640 else
1641 {
1642 struct stat s;
1643
1644 /* If the map filename is actually a directory then create
1645 a file inside it, based upon the output filename. */
1646 if (stat (config.map_filename, &s) >= 0
1647 && S_ISDIR (s.st_mode))
1648 {
1649 char * new_name;
1650
1651 /* FIXME: This is a (trivial) memory leak. */
1652 if (asprintf (&new_name, "%s/%s.map",
1653 config.map_filename, output_filename) < 0)
1654 {
1655 /* If this alloc fails then something is probably very
1656 wrong. Better to halt now rather than continue on
1657 into more problems. */
1658 einfo (_("%P%F: cannot create name for linker map file: %E\n"));
1659 new_name = NULL;
1660 }
1661
1662 config.map_filename = new_name;
1663 }
1664 }
1665 }
1666
1667 if (command_line.soname && command_line.soname[0] == '\0')
1668 {
1669 einfo (_("%P: SONAME must not be empty string; ignored\n"));
1670 command_line.soname = NULL;
1671 }
1672
1673 while (ingroup)
1674 {
1675 einfo (_("%P: missing --end-group; added as last command line option\n"));
1676 lang_leave_group ();
1677 ingroup--;
1678 }
1679
1680 if (default_dirlist != NULL)
1681 {
1682 set_default_dirlist (default_dirlist);
1683 free (default_dirlist);
1684 }
1685
1686 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1687 /* FIXME: Should we allow emulations a chance to set this ? */
1688 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
1689
1690 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1691 /* FIXME: Should we allow emulations a chance to set this ? */
1692 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
1693
1694 if (bfd_link_relocatable (&link_info)
1695 && command_line.check_section_addresses < 0)
1696 command_line.check_section_addresses = 0;
1697
1698 if (export_list)
1699 {
1700 struct bfd_elf_version_expr *head = export_list->head.list;
1701 struct bfd_elf_version_expr *next;
1702
1703 /* For --export-dynamic-symbol[-list]:
1704 1. When building executable, treat like --dynamic-list.
1705 2. When building shared object:
1706 a. If -Bsymbolic or --dynamic-list are used, treat like
1707 --dynamic-list.
1708 b. Otherwise, ignored.
1709 */
1710 if (!bfd_link_relocatable (&link_info)
1711 && (bfd_link_executable (&link_info)
1712 || opt_symbolic != symbolic_unset
1713 || opt_dynamic_list != dynamic_list_unset))
1714 {
1715 /* Append the export list to link_info.dynamic_list. */
1716 if (link_info.dynamic_list)
1717 {
1718 for (next = head; next->next != NULL; next = next->next)
1719 ;
1720 next->next = link_info.dynamic_list->head.list;
1721 link_info.dynamic_list->head.list = head;
1722 }
1723 else
1724 link_info.dynamic_list = export_list;
1725
1726 if (opt_dynamic_list != dynamic_list_data)
1727 opt_dynamic_list = dynamic_list;
1728 }
1729 else
1730 {
1731 /* Free the export list. */
1732 for (; head->next != NULL; head = next)
1733 {
1734 next = head->next;
1735 free (head);
1736 }
1737 free (export_list);
1738 }
1739 }
1740
1741 switch (opt_dynamic_list)
1742 {
1743 case dynamic_list_unset:
1744 break;
1745 case dynamic_list_data:
1746 link_info.dynamic_data = TRUE;
1747 /* Fall through. */
1748 case dynamic_list:
1749 link_info.dynamic = TRUE;
1750 opt_symbolic = symbolic_unset;
1751 break;
1752 }
1753
1754 /* -Bsymbolic and -Bsymbols-functions are for shared library output. */
1755 if (bfd_link_dll (&link_info))
1756 switch (opt_symbolic)
1757 {
1758 case symbolic_unset:
1759 break;
1760 case symbolic:
1761 link_info.symbolic = TRUE;
1762 if (link_info.dynamic_list)
1763 {
1764 struct bfd_elf_version_expr *ent, *next;
1765 for (ent = link_info.dynamic_list->head.list; ent; ent = next)
1766 {
1767 next = ent->next;
1768 free (ent);
1769 }
1770 free (link_info.dynamic_list);
1771 link_info.dynamic_list = NULL;
1772 }
1773 break;
1774 case symbolic_functions:
1775 link_info.dynamic = TRUE;
1776 link_info.dynamic_data = TRUE;
1777 break;
1778 }
1779
1780 if (!bfd_link_dll (&link_info))
1781 {
1782 if (command_line.filter_shlib)
1783 einfo (_("%F%P: -F may not be used without -shared\n"));
1784 if (command_line.auxiliary_filters)
1785 einfo (_("%F%P: -f may not be used without -shared\n"));
1786 }
1787
1788 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1789 don't see how else this can be handled, since in this case we
1790 must preserve all externally visible symbols. */
1791 if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all)
1792 {
1793 link_info.strip = strip_debugger;
1794 if (link_info.discard == discard_sec_merge)
1795 link_info.discard = discard_all;
1796 }
1797 }
1798
1799 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1800 library search path. */
1801
1802 static void
1803 set_default_dirlist (char *dirlist_ptr)
1804 {
1805 char *p;
1806
1807 while (1)
1808 {
1809 p = strchr (dirlist_ptr, PATH_SEPARATOR);
1810 if (p != NULL)
1811 *p = '\0';
1812 if (*dirlist_ptr != '\0')
1813 ldfile_add_library_path (dirlist_ptr, TRUE);
1814 if (p == NULL)
1815 break;
1816 dirlist_ptr = p + 1;
1817 }
1818 }
1819
1820 static void
1821 set_section_start (char *sect, char *valstr)
1822 {
1823 const char *end;
1824 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1825 if (*end)
1826 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
1827 lang_section_start (sect, exp_intop (val), NULL);
1828 }
1829
1830 static void
1831 set_segment_start (const char *section, char *valstr)
1832 {
1833 const char *name;
1834 const char *end;
1835 segment_type *seg;
1836
1837 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1838 if (*end)
1839 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
1840 /* If we already have an entry for this segment, update the existing
1841 value. */
1842 name = section + 1;
1843 for (seg = segments; seg; seg = seg->next)
1844 if (strcmp (seg->name, name) == 0)
1845 {
1846 seg->value = val;
1847 lang_section_start (section, exp_intop (val), seg);
1848 return;
1849 }
1850 /* There was no existing value so we must create a new segment
1851 entry. */
1852 seg = stat_alloc (sizeof (*seg));
1853 seg->name = name;
1854 seg->value = val;
1855 seg->used = FALSE;
1856 /* Add it to the linked list of segments. */
1857 seg->next = segments;
1858 segments = seg;
1859 /* Historically, -Ttext and friends set the base address of a
1860 particular section. For backwards compatibility, we still do
1861 that. If a SEGMENT_START directive is seen, the section address
1862 assignment will be disabled. */
1863 lang_section_start (section, exp_intop (val), seg);
1864 }
1865
1866 static void
1867 elf_shlib_list_options (FILE *file)
1868 {
1869 fprintf (file, _("\
1870 --audit=AUDITLIB Specify a library to use for auditing\n"));
1871 fprintf (file, _("\
1872 -Bgroup Selects group name lookup rules for DSO\n"));
1873 fprintf (file, _("\
1874 --disable-new-dtags Disable new dynamic tags\n"));
1875 fprintf (file, _("\
1876 --enable-new-dtags Enable new dynamic tags\n"));
1877 fprintf (file, _("\
1878 --eh-frame-hdr Create .eh_frame_hdr section\n"));
1879 fprintf (file, _("\
1880 --no-eh-frame-hdr Do not create .eh_frame_hdr section\n"));
1881 fprintf (file, _("\
1882 --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
1883 fprintf (file, _("\
1884 --hash-style=STYLE Set hash style to sysv/gnu/both. Default: "));
1885 if (DEFAULT_EMIT_SYSV_HASH)
1886 {
1887 /* Note - these strings are not translated as
1888 they are keywords not descriptive text. */
1889 if (DEFAULT_EMIT_GNU_HASH)
1890 fprintf (file, "both\n");
1891 else
1892 fprintf (file, "sysv\n");
1893 }
1894 else
1895 {
1896 if (DEFAULT_EMIT_GNU_HASH)
1897 fprintf (file, "gnu\n");
1898 else
1899 /* FIXME: Can this happen ? */
1900 fprintf (file, "none\n");
1901 }
1902 fprintf (file, _("\
1903 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
1904 Specify a library to use for auditing dependencies\n"));
1905 fprintf (file, _("\
1906 -z combreloc Merge dynamic relocs into one section and sort\n"));
1907 fprintf (file, _("\
1908 -z nocombreloc Don't merge dynamic relocs into one section\n"));
1909 fprintf (file, _("\
1910 -z global Make symbols in DSO available for subsequently\n\
1911 loaded objects\n"));
1912 fprintf (file, _("\
1913 -z initfirst Mark DSO to be initialized first at runtime\n"));
1914 fprintf (file, _("\
1915 -z interpose Mark object to interpose all DSOs but executable\n"));
1916 fprintf (file, _("\
1917 -z lazy Mark object lazy runtime binding (default)\n"));
1918 fprintf (file, _("\
1919 -z loadfltr Mark object requiring immediate process\n"));
1920 fprintf (file, _("\
1921 -z nocopyreloc Don't create copy relocs\n"));
1922 fprintf (file, _("\
1923 -z nodefaultlib Mark object not to use default search paths\n"));
1924 fprintf (file, _("\
1925 -z nodelete Mark DSO non-deletable at runtime\n"));
1926 fprintf (file, _("\
1927 -z nodlopen Mark DSO not available to dlopen\n"));
1928 fprintf (file, _("\
1929 -z nodump Mark DSO not available to dldump\n"));
1930 fprintf (file, _("\
1931 -z now Mark object non-lazy runtime binding\n"));
1932 fprintf (file, _("\
1933 -z origin Mark object requiring immediate $ORIGIN\n\
1934 processing at runtime\n"));
1935 #if DEFAULT_LD_Z_RELRO
1936 fprintf (file, _("\
1937 -z relro Create RELRO program header (default)\n"));
1938 fprintf (file, _("\
1939 -z norelro Don't create RELRO program header\n"));
1940 #else
1941 fprintf (file, _("\
1942 -z relro Create RELRO program header\n"));
1943 fprintf (file, _("\
1944 -z norelro Don't create RELRO program header (default)\n"));
1945 #endif
1946 #if DEFAULT_LD_Z_SEPARATE_CODE
1947 fprintf (file, _("\
1948 -z separate-code Create separate code program header (default)\n"));
1949 fprintf (file, _("\
1950 -z noseparate-code Don't create separate code program header\n"));
1951 #else
1952 fprintf (file, _("\
1953 -z separate-code Create separate code program header\n"));
1954 fprintf (file, _("\
1955 -z noseparate-code Don't create separate code program header (default)\n"));
1956 #endif
1957 fprintf (file, _("\
1958 -z common Generate common symbols with STT_COMMON type\n"));
1959 fprintf (file, _("\
1960 -z nocommon Generate common symbols with STT_OBJECT type\n"));
1961 fprintf (file, _("\
1962 -z stack-size=SIZE Set size of stack segment\n"));
1963 if (link_info.textrel_check == textrel_check_error)
1964 fprintf (file, _("\
1965 -z text Treat DT_TEXTREL in output as error (default)\n"));
1966 else
1967 fprintf (file, _("\
1968 -z text Treat DT_TEXTREL in output as error\n"));
1969 if (link_info.textrel_check == textrel_check_none)
1970 {
1971 fprintf (file, _("\
1972 -z notext Don't treat DT_TEXTREL in output as error (default)\n"));
1973 fprintf (file, _("\
1974 -z textoff Don't treat DT_TEXTREL in output as error (default)\n"));
1975 }
1976 else
1977 {
1978 fprintf (file, _("\
1979 -z notext Don't treat DT_TEXTREL in output as error\n"));
1980 fprintf (file, _("\
1981 -z textoff Don't treat DT_TEXTREL in output as error\n"));
1982 }
1983 }
1984
1985 static void
1986 elf_static_list_options (FILE *file)
1987 {
1988 fprintf (file, _("\
1989 --build-id[=STYLE] Generate build ID note\n"));
1990 fprintf (file, _("\
1991 --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\
1992 Compress DWARF debug sections using zlib\n"));
1993 #ifdef DEFAULT_FLAG_COMPRESS_DEBUG
1994 fprintf (file, _("\
1995 Default: zlib-gabi\n"));
1996 #else
1997 fprintf (file, _("\
1998 Default: none\n"));
1999 #endif
2000 fprintf (file, _("\
2001 -z common-page-size=SIZE Set common page size to SIZE\n"));
2002 fprintf (file, _("\
2003 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
2004 fprintf (file, _("\
2005 -z defs Report unresolved symbols in object files\n"));
2006 fprintf (file, _("\
2007 -z muldefs Allow multiple definitions\n"));
2008 fprintf (file, _("\
2009 -z execstack Mark executable as requiring executable stack\n"));
2010 fprintf (file, _("\
2011 -z noexecstack Mark executable as not requiring executable stack\n"));
2012 fprintf (file, _("\
2013 -z globalaudit Mark executable requiring global auditing\n"));
2014 }
2015
2016 static void
2017 elf_plt_unwind_list_options (FILE *file)
2018 {
2019 fprintf (file, _("\
2020 --ld-generated-unwind-info Generate exception handling info for PLT\n"));
2021 fprintf (file, _("\
2022 --no-ld-generated-unwind-info\n\
2023 Don't generate exception handling info for PLT\n"));
2024 }
2025
2026 static void
2027 ld_list_options (FILE *file, bfd_boolean elf, bfd_boolean shlib,
2028 bfd_boolean plt_unwind)
2029 {
2030 if (!elf)
2031 return;
2032 printf (_("ELF emulations:\n"));
2033 if (plt_unwind)
2034 elf_plt_unwind_list_options (file);
2035 elf_static_list_options (file);
2036 if (shlib)
2037 elf_shlib_list_options (file);
2038 }
2039
2040 \f
2041 /* Print help messages for the options. */
2042
2043 static void
2044 help (void)
2045 {
2046 unsigned i;
2047 const char **targets, **pp;
2048 int len;
2049
2050 printf (_("Usage: %s [options] file...\n"), program_name);
2051
2052 printf (_("Options:\n"));
2053 for (i = 0; i < OPTION_COUNT; i++)
2054 {
2055 if (ld_options[i].doc != NULL)
2056 {
2057 bfd_boolean comma;
2058 unsigned j;
2059
2060 printf (" ");
2061
2062 comma = FALSE;
2063 len = 2;
2064
2065 j = i;
2066 do
2067 {
2068 if (ld_options[j].shortopt != '\0'
2069 && ld_options[j].control != NO_HELP)
2070 {
2071 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
2072 len += (comma ? 2 : 0) + 2;
2073 if (ld_options[j].arg != NULL)
2074 {
2075 if (ld_options[j].opt.has_arg != optional_argument)
2076 {
2077 printf (" ");
2078 ++len;
2079 }
2080 printf ("%s", _(ld_options[j].arg));
2081 len += strlen (_(ld_options[j].arg));
2082 }
2083 comma = TRUE;
2084 }
2085 ++j;
2086 }
2087 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
2088
2089 j = i;
2090 do
2091 {
2092 if (ld_options[j].opt.name != NULL
2093 && ld_options[j].control != NO_HELP)
2094 {
2095 int two_dashes =
2096 (ld_options[j].control == TWO_DASHES
2097 || ld_options[j].control == EXACTLY_TWO_DASHES);
2098
2099 printf ("%s-%s%s",
2100 comma ? ", " : "",
2101 two_dashes ? "-" : "",
2102 ld_options[j].opt.name);
2103 len += ((comma ? 2 : 0)
2104 + 1
2105 + (two_dashes ? 1 : 0)
2106 + strlen (ld_options[j].opt.name));
2107 if (ld_options[j].arg != NULL)
2108 {
2109 printf (" %s", _(ld_options[j].arg));
2110 len += 1 + strlen (_(ld_options[j].arg));
2111 }
2112 comma = TRUE;
2113 }
2114 ++j;
2115 }
2116 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
2117
2118 if (len >= 30)
2119 {
2120 printf ("\n");
2121 len = 0;
2122 }
2123
2124 for (; len < 30; len++)
2125 putchar (' ');
2126
2127 printf ("%s\n", _(ld_options[i].doc));
2128 }
2129 }
2130 printf (_(" @FILE"));
2131 for (len = strlen (" @FILE"); len < 30; len++)
2132 putchar (' ');
2133 printf (_("Read options from FILE\n"));
2134
2135 /* Note: Various tools (such as libtool) depend upon the
2136 format of the listings below - do not change them. */
2137 /* xgettext:c-format */
2138 printf (_("%s: supported targets:"), program_name);
2139 targets = bfd_target_list ();
2140 for (pp = targets; *pp != NULL; pp++)
2141 printf (" %s", *pp);
2142 free (targets);
2143 printf ("\n");
2144
2145 /* xgettext:c-format */
2146 printf (_("%s: supported emulations: "), program_name);
2147 ldemul_list_emulations (stdout);
2148 printf ("\n");
2149
2150 /* xgettext:c-format */
2151 printf (_("%s: emulation specific options:\n"), program_name);
2152 ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
2153 ELF_PLT_UNWIND_LIST_OPTIONS);
2154 ldemul_list_emulation_options (stdout);
2155 printf ("\n");
2156
2157 if (REPORT_BUGS_TO[0])
2158 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
2159 }
This page took 0.087276 seconds and 4 git commands to generate.