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