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