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