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