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