ld: Set COMMONPAGESIZE for i386 Solaris
[deliverable/binutils-gdb.git] / ld / lexsup.c
1 /* Parse options for the GNU linker.
2 Copyright (C) 1991-2020 Free Software Foundation, Inc.
3
4 This file is part of the GNU Binutils.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21 #include "sysdep.h"
22 #include "bfd.h"
23 #include "bfdver.h"
24 #include "libiberty.h"
25 #include <stdio.h>
26 #include <string.h>
27 #include "safe-ctype.h"
28 #include "getopt.h"
29 #include "bfdlink.h"
30 #include "ctf-api.h"
31 #include "ld.h"
32 #include "ldmain.h"
33 #include "ldmisc.h"
34 #include "ldexp.h"
35 #include "ldlang.h"
36 #include <ldgram.h>
37 #include "ldlex.h"
38 #include "ldfile.h"
39 #include "ldver.h"
40 #include "ldemul.h"
41 #include "demangle.h"
42 #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.magic_demand_paged = FALSE;
942 input_flags.dynamic = FALSE;
943 break;
944 case OPTION_NO_DEFINE_COMMON:
945 link_info.inhibit_common_definition = TRUE;
946 break;
947 case OPTION_NO_DEMANGLE:
948 demangling = FALSE;
949 break;
950 case OPTION_NO_GC_SECTIONS:
951 link_info.gc_sections = FALSE;
952 break;
953 case OPTION_NO_PRINT_GC_SECTIONS:
954 link_info.print_gc_sections = FALSE;
955 break;
956 case OPTION_NO_KEEP_MEMORY:
957 link_info.keep_memory = FALSE;
958 break;
959 case OPTION_NO_UNDEFINED:
960 link_info.unresolved_syms_in_objects
961 = how_to_report_unresolved_symbols;
962 break;
963 case OPTION_ALLOW_SHLIB_UNDEFINED:
964 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
965 break;
966 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
967 link_info.unresolved_syms_in_shared_libs
968 = how_to_report_unresolved_symbols;
969 break;
970 case OPTION_UNRESOLVED_SYMBOLS:
971 if (strcmp (optarg, "ignore-all") == 0)
972 {
973 link_info.unresolved_syms_in_objects = RM_IGNORE;
974 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
975 }
976 else if (strcmp (optarg, "report-all") == 0)
977 {
978 link_info.unresolved_syms_in_objects
979 = how_to_report_unresolved_symbols;
980 link_info.unresolved_syms_in_shared_libs
981 = how_to_report_unresolved_symbols;
982 }
983 else if (strcmp (optarg, "ignore-in-object-files") == 0)
984 {
985 link_info.unresolved_syms_in_objects = RM_IGNORE;
986 link_info.unresolved_syms_in_shared_libs
987 = how_to_report_unresolved_symbols;
988 }
989 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
990 {
991 link_info.unresolved_syms_in_objects
992 = how_to_report_unresolved_symbols;
993 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
994 }
995 else
996 einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg);
997 break;
998 case OPTION_WARN_UNRESOLVED_SYMBOLS:
999 how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
1000 if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
1001 link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
1002 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
1003 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
1004 break;
1005
1006 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
1007 how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
1008 if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
1009 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
1010 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
1011 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
1012 break;
1013 case OPTION_ALLOW_MULTIPLE_DEFINITION:
1014 link_info.allow_multiple_definition = TRUE;
1015 break;
1016 case OPTION_NO_UNDEFINED_VERSION:
1017 link_info.allow_undefined_version = FALSE;
1018 break;
1019 case OPTION_DEFAULT_SYMVER:
1020 link_info.create_default_symver = TRUE;
1021 break;
1022 case OPTION_DEFAULT_IMPORTED_SYMVER:
1023 link_info.default_imported_symver = TRUE;
1024 break;
1025 case OPTION_NO_WARN_MISMATCH:
1026 command_line.warn_mismatch = FALSE;
1027 break;
1028 case OPTION_NO_WARN_SEARCH_MISMATCH:
1029 command_line.warn_search_mismatch = FALSE;
1030 break;
1031 case OPTION_NOINHIBIT_EXEC:
1032 force_make_executable = TRUE;
1033 break;
1034 case OPTION_NOSTDLIB:
1035 config.only_cmd_line_lib_dirs = TRUE;
1036 break;
1037 case OPTION_NO_WHOLE_ARCHIVE:
1038 input_flags.whole_archive = FALSE;
1039 break;
1040 case 'O':
1041 /* FIXME "-O<non-digits> <value>" used to set the address of
1042 section <non-digits>. Was this for compatibility with
1043 something, or can we create a new option to do that
1044 (with a syntax similar to -defsym)?
1045 getopt can't handle two args to an option without kludges. */
1046
1047 /* Enable optimizations of output files. */
1048 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
1049 break;
1050 case 'o':
1051 lang_add_output (optarg, 0);
1052 break;
1053 case OPTION_OFORMAT:
1054 lang_add_output_format (optarg, NULL, NULL, 0);
1055 break;
1056 case OPTION_OUT_IMPLIB:
1057 command_line.out_implib_filename = xstrdup (optarg);
1058 break;
1059 case OPTION_PRINT_SYSROOT:
1060 if (*ld_sysroot)
1061 puts (ld_sysroot);
1062 xexit (0);
1063 break;
1064 case OPTION_PRINT_OUTPUT_FORMAT:
1065 command_line.print_output_format = TRUE;
1066 break;
1067 #ifdef ENABLE_PLUGINS
1068 case OPTION_PLUGIN:
1069 plugin_opt_plugin (optarg);
1070 break;
1071 case OPTION_PLUGIN_OPT:
1072 if (plugin_opt_plugin_arg (optarg))
1073 einfo (_("%F%P: bad -plugin-opt option\n"));
1074 break;
1075 #endif /* ENABLE_PLUGINS */
1076 case 'q':
1077 link_info.emitrelocations = TRUE;
1078 break;
1079 case 'i':
1080 case 'r':
1081 if (optind == last_optind)
1082 /* This can happen if the user put "-rpath,a" on the command
1083 line. (Or something similar. The comma is important).
1084 Getopt becomes confused and thinks that this is a -r option
1085 but it cannot parse the text after the -r so it refuses to
1086 increment the optind counter. Detect this case and issue
1087 an error message here. We cannot just make this a warning,
1088 increment optind, and continue because getopt is too confused
1089 and will seg-fault the next time around. */
1090 einfo(_("%F%P: unrecognised option: %s\n"), argv[optind]);
1091
1092 if (bfd_link_pic (&link_info))
1093 einfo (_("%F%P: -r and %s may not be used together\n"),
1094 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1095
1096 link_info.type = type_relocatable;
1097 config.build_constructors = FALSE;
1098 config.magic_demand_paged = FALSE;
1099 config.text_read_only = FALSE;
1100 input_flags.dynamic = FALSE;
1101 break;
1102 case 'R':
1103 /* The GNU linker traditionally uses -R to mean to include
1104 only the symbols from a file. The Solaris linker uses -R
1105 to set the path used by the runtime linker to find
1106 libraries. This is the GNU linker -rpath argument. We
1107 try to support both simultaneously by checking the file
1108 named. If it is a directory, rather than a regular file,
1109 we assume -rpath was meant. */
1110 {
1111 struct stat s;
1112
1113 if (stat (optarg, &s) >= 0
1114 && ! S_ISDIR (s.st_mode))
1115 {
1116 lang_add_input_file (optarg,
1117 lang_input_file_is_symbols_only_enum,
1118 NULL);
1119 break;
1120 }
1121 }
1122 /* Fall through. */
1123 case OPTION_RPATH:
1124 if (command_line.rpath == NULL)
1125 command_line.rpath = xstrdup (optarg);
1126 else
1127 {
1128 size_t rpath_len = strlen (command_line.rpath);
1129 size_t optarg_len = strlen (optarg);
1130 char *buf;
1131 char *cp = command_line.rpath;
1132
1133 /* First see whether OPTARG is already in the path. */
1134 do
1135 {
1136 if (strncmp (optarg, cp, optarg_len) == 0
1137 && (cp[optarg_len] == 0
1138 || cp[optarg_len] == config.rpath_separator))
1139 /* We found it. */
1140 break;
1141
1142 /* Not yet found. */
1143 cp = strchr (cp, config.rpath_separator);
1144 if (cp != NULL)
1145 ++cp;
1146 }
1147 while (cp != NULL);
1148
1149 if (cp == NULL)
1150 {
1151 buf = (char *) xmalloc (rpath_len + optarg_len + 2);
1152 sprintf (buf, "%s%c%s", command_line.rpath,
1153 config.rpath_separator, optarg);
1154 free (command_line.rpath);
1155 command_line.rpath = buf;
1156 }
1157 }
1158 break;
1159 case OPTION_RPATH_LINK:
1160 if (command_line.rpath_link == NULL)
1161 command_line.rpath_link = xstrdup (optarg);
1162 else
1163 {
1164 char *buf;
1165
1166 buf = (char *) xmalloc (strlen (command_line.rpath_link)
1167 + strlen (optarg)
1168 + 2);
1169 sprintf (buf, "%s%c%s", command_line.rpath_link,
1170 config.rpath_separator, optarg);
1171 free (command_line.rpath_link);
1172 command_line.rpath_link = buf;
1173 }
1174 break;
1175 case OPTION_NO_RELAX:
1176 DISABLE_RELAXATION;
1177 break;
1178 case OPTION_RELAX:
1179 ENABLE_RELAXATION;
1180 break;
1181 case OPTION_RETAIN_SYMBOLS_FILE:
1182 add_keepsyms_file (optarg);
1183 break;
1184 case 'S':
1185 link_info.strip = strip_debugger;
1186 break;
1187 case 's':
1188 link_info.strip = strip_all;
1189 break;
1190 case OPTION_STRIP_DISCARDED:
1191 link_info.strip_discarded = TRUE;
1192 break;
1193 case OPTION_NO_STRIP_DISCARDED:
1194 link_info.strip_discarded = FALSE;
1195 break;
1196 case OPTION_DISABLE_MULTIPLE_DEFS_ABS:
1197 link_info.prohibit_multiple_definition_absolute = TRUE;
1198 break;
1199 case OPTION_SHARED:
1200 if (config.has_shared)
1201 {
1202 if (bfd_link_relocatable (&link_info))
1203 einfo (_("%F%P: -r and %s may not be used together\n"),
1204 "-shared");
1205
1206 link_info.type = type_dll;
1207 /* When creating a shared library, the default
1208 behaviour is to ignore any unresolved references. */
1209 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1210 link_info.unresolved_syms_in_objects = RM_IGNORE;
1211 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1212 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1213 }
1214 else
1215 einfo (_("%F%P: -shared not supported\n"));
1216 break;
1217 case OPTION_PIE:
1218 if (config.has_shared)
1219 {
1220 if (bfd_link_relocatable (&link_info))
1221 einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
1222
1223 link_info.type = type_pie;
1224 }
1225 else
1226 einfo (_("%F%P: -pie not supported\n"));
1227 break;
1228 case 'h': /* Used on Solaris. */
1229 case OPTION_SONAME:
1230 if (optarg[0] == '\0' && command_line.soname
1231 && command_line.soname[0])
1232 einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
1233 else
1234 command_line.soname = optarg;
1235 break;
1236 case OPTION_SORT_COMMON:
1237 if (optarg == NULL
1238 || strcmp (optarg, N_("descending")) == 0)
1239 config.sort_common = sort_descending;
1240 else if (strcmp (optarg, N_("ascending")) == 0)
1241 config.sort_common = sort_ascending;
1242 else
1243 einfo (_("%F%P: invalid common section sorting option: %s\n"),
1244 optarg);
1245 break;
1246 case OPTION_SORT_SECTION:
1247 if (strcmp (optarg, N_("name")) == 0)
1248 sort_section = by_name;
1249 else if (strcmp (optarg, N_("alignment")) == 0)
1250 sort_section = by_alignment;
1251 else
1252 einfo (_("%F%P: invalid section sorting option: %s\n"),
1253 optarg);
1254 break;
1255 case OPTION_STATS:
1256 config.stats = TRUE;
1257 break;
1258 case OPTION_SYMBOLIC:
1259 opt_symbolic = symbolic;
1260 break;
1261 case OPTION_SYMBOLIC_FUNCTIONS:
1262 opt_symbolic = symbolic_functions;
1263 break;
1264 case 't':
1265 ++trace_files;
1266 break;
1267 case 'T':
1268 previous_script_handle = saved_script_handle;
1269 ldfile_open_script_file (optarg);
1270 parser_input = input_script;
1271 yyparse ();
1272 previous_script_handle = NULL;
1273 break;
1274 case OPTION_DEFAULT_SCRIPT:
1275 command_line.default_script = optarg;
1276 break;
1277 case OPTION_SECTION_START:
1278 {
1279 char *optarg2;
1280 char *sec_name;
1281 int len;
1282
1283 /* Check for <something>=<somthing>... */
1284 optarg2 = strchr (optarg, '=');
1285 if (optarg2 == NULL)
1286 einfo (_("%F%P: invalid argument to option"
1287 " \"--section-start\"\n"));
1288
1289 optarg2++;
1290
1291 /* So far so good. Are all the args present? */
1292 if ((*optarg == '\0') || (*optarg2 == '\0'))
1293 einfo (_("%F%P: missing argument(s) to option"
1294 " \"--section-start\"\n"));
1295
1296 /* We must copy the section name as set_section_start
1297 doesn't do it for us. */
1298 len = optarg2 - optarg;
1299 sec_name = (char *) xmalloc (len);
1300 memcpy (sec_name, optarg, len - 1);
1301 sec_name[len - 1] = 0;
1302
1303 /* Then set it... */
1304 set_section_start (sec_name, optarg2);
1305 }
1306 break;
1307 case OPTION_TARGET_HELP:
1308 /* Mention any target specific options. */
1309 ldemul_list_emulation_options (stdout);
1310 exit (0);
1311 case OPTION_TBSS:
1312 set_segment_start (".bss", optarg);
1313 break;
1314 case OPTION_TDATA:
1315 set_segment_start (".data", optarg);
1316 break;
1317 case OPTION_TTEXT:
1318 set_segment_start (".text", optarg);
1319 break;
1320 case OPTION_TTEXT_SEGMENT:
1321 set_segment_start (".text-segment", optarg);
1322 break;
1323 case OPTION_TRODATA_SEGMENT:
1324 set_segment_start (".rodata-segment", optarg);
1325 break;
1326 case OPTION_TLDATA_SEGMENT:
1327 set_segment_start (".ldata-segment", optarg);
1328 break;
1329 case OPTION_TRADITIONAL_FORMAT:
1330 link_info.traditional_format = TRUE;
1331 break;
1332 case OPTION_TASK_LINK:
1333 link_info.task_link = TRUE;
1334 /* Fall through. */
1335 case OPTION_UR:
1336 if (bfd_link_pic (&link_info))
1337 einfo (_("%F%P: -r and %s may not be used together\n"),
1338 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1339
1340 link_info.type = type_relocatable;
1341 config.build_constructors = TRUE;
1342 config.magic_demand_paged = FALSE;
1343 config.text_read_only = FALSE;
1344 input_flags.dynamic = FALSE;
1345 break;
1346 case 'u':
1347 ldlang_add_undef (optarg, TRUE);
1348 break;
1349 case OPTION_REQUIRE_DEFINED_SYMBOL:
1350 ldlang_add_require_defined (optarg);
1351 break;
1352 case OPTION_UNIQUE:
1353 if (optarg != NULL)
1354 lang_add_unique (optarg);
1355 else
1356 config.unique_orphan_sections = TRUE;
1357 break;
1358 case OPTION_VERBOSE:
1359 ldversion (1);
1360 version_printed = TRUE;
1361 verbose = TRUE;
1362 overflow_cutoff_limit = -2;
1363 if (optarg != NULL)
1364 {
1365 char *end;
1366 int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
1367 if (*end)
1368 einfo (_("%F%P: invalid number `%s'\n"), optarg);
1369 #ifdef ENABLE_PLUGINS
1370 report_plugin_symbols = level > 1;
1371 #endif /* ENABLE_PLUGINS */
1372 }
1373 break;
1374 case 'v':
1375 ldversion (0);
1376 version_printed = TRUE;
1377 break;
1378 case 'V':
1379 ldversion (1);
1380 version_printed = TRUE;
1381 break;
1382 case OPTION_VERSION:
1383 ldversion (2);
1384 xexit (0);
1385 break;
1386 case OPTION_VERSION_SCRIPT:
1387 /* This option indicates a small script that only specifies
1388 version information. Read it, but don't assume that
1389 we've seen a linker script. */
1390 {
1391 FILE *hold_script_handle;
1392
1393 hold_script_handle = saved_script_handle;
1394 ldfile_open_command_file (optarg);
1395 saved_script_handle = hold_script_handle;
1396 parser_input = input_version_script;
1397 yyparse ();
1398 }
1399 break;
1400 case OPTION_VERSION_EXPORTS_SECTION:
1401 /* This option records a version symbol to be applied to the
1402 symbols listed for export to be found in the object files
1403 .exports sections. */
1404 command_line.version_exports_section = optarg;
1405 break;
1406 case OPTION_DYNAMIC_LIST_DATA:
1407 opt_dynamic_list = dynamic_list_data;
1408 if (opt_symbolic == symbolic)
1409 opt_symbolic = symbolic_unset;
1410 break;
1411 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1412 lang_append_dynamic_list_cpp_typeinfo ();
1413 if (opt_dynamic_list != dynamic_list_data)
1414 opt_dynamic_list = dynamic_list;
1415 if (opt_symbolic == symbolic)
1416 opt_symbolic = symbolic_unset;
1417 break;
1418 case OPTION_DYNAMIC_LIST_CPP_NEW:
1419 lang_append_dynamic_list_cpp_new ();
1420 if (opt_dynamic_list != dynamic_list_data)
1421 opt_dynamic_list = dynamic_list;
1422 if (opt_symbolic == symbolic)
1423 opt_symbolic = symbolic_unset;
1424 break;
1425 case OPTION_DYNAMIC_LIST:
1426 /* This option indicates a small script that only specifies
1427 a dynamic list. Read it, but don't assume that we've
1428 seen a linker script. */
1429 {
1430 FILE *hold_script_handle;
1431
1432 hold_script_handle = saved_script_handle;
1433 ldfile_open_command_file (optarg);
1434 saved_script_handle = hold_script_handle;
1435 parser_input = input_dynamic_list;
1436 yyparse ();
1437 }
1438 if (opt_dynamic_list != dynamic_list_data)
1439 opt_dynamic_list = dynamic_list;
1440 if (opt_symbolic == symbolic)
1441 opt_symbolic = symbolic_unset;
1442 break;
1443 case OPTION_WARN_COMMON:
1444 config.warn_common = TRUE;
1445 break;
1446 case OPTION_WARN_CONSTRUCTORS:
1447 config.warn_constructors = TRUE;
1448 break;
1449 case OPTION_WARN_FATAL:
1450 config.fatal_warnings = TRUE;
1451 break;
1452 case OPTION_NO_WARN_FATAL:
1453 config.fatal_warnings = FALSE;
1454 break;
1455 case OPTION_WARN_MULTIPLE_GP:
1456 config.warn_multiple_gp = TRUE;
1457 break;
1458 case OPTION_WARN_ONCE:
1459 config.warn_once = TRUE;
1460 break;
1461 case OPTION_WARN_SECTION_ALIGN:
1462 config.warn_section_align = TRUE;
1463 break;
1464 case OPTION_WARN_SHARED_TEXTREL:
1465 link_info.warn_shared_textrel = TRUE;
1466 break;
1467 case OPTION_WARN_ALTERNATE_EM:
1468 link_info.warn_alternate_em = TRUE;
1469 break;
1470 case OPTION_WHOLE_ARCHIVE:
1471 input_flags.whole_archive = TRUE;
1472 break;
1473 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
1474 input_flags.add_DT_NEEDED_for_dynamic = TRUE;
1475 break;
1476 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
1477 input_flags.add_DT_NEEDED_for_dynamic = FALSE;
1478 break;
1479 case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
1480 input_flags.add_DT_NEEDED_for_regular = TRUE;
1481 break;
1482 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
1483 input_flags.add_DT_NEEDED_for_regular = FALSE;
1484 break;
1485 case OPTION_WRAP:
1486 add_wrap (optarg);
1487 break;
1488 case OPTION_IGNORE_UNRESOLVED_SYMBOL:
1489 add_ignoresym (&link_info, optarg);
1490 break;
1491 case OPTION_DISCARD_NONE:
1492 link_info.discard = discard_none;
1493 break;
1494 case 'X':
1495 link_info.discard = discard_l;
1496 break;
1497 case 'x':
1498 link_info.discard = discard_all;
1499 break;
1500 case 'Y':
1501 if (CONST_STRNEQ (optarg, "P,"))
1502 optarg += 2;
1503 if (default_dirlist != NULL)
1504 free (default_dirlist);
1505 default_dirlist = xstrdup (optarg);
1506 break;
1507 case 'y':
1508 add_ysym (optarg);
1509 break;
1510 case OPTION_SPARE_DYNAMIC_TAGS:
1511 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1512 break;
1513 case OPTION_SPLIT_BY_RELOC:
1514 if (optarg != NULL)
1515 config.split_by_reloc = strtoul (optarg, NULL, 0);
1516 else
1517 config.split_by_reloc = 32768;
1518 break;
1519 case OPTION_SPLIT_BY_FILE:
1520 if (optarg != NULL)
1521 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1522 else
1523 config.split_by_file = 1;
1524 break;
1525 case OPTION_CHECK_SECTIONS:
1526 command_line.check_section_addresses = 1;
1527 break;
1528 case OPTION_NO_CHECK_SECTIONS:
1529 command_line.check_section_addresses = 0;
1530 break;
1531 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1532 command_line.accept_unknown_input_arch = TRUE;
1533 break;
1534 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1535 command_line.accept_unknown_input_arch = FALSE;
1536 break;
1537 case '(':
1538 lang_enter_group ();
1539 ingroup++;
1540 break;
1541 case ')':
1542 if (! ingroup)
1543 einfo (_("%F%P: group ended before it began (--help for usage)\n"));
1544
1545 lang_leave_group ();
1546 ingroup--;
1547 break;
1548
1549 case OPTION_INIT:
1550 link_info.init_function = optarg;
1551 break;
1552
1553 case OPTION_FINI:
1554 link_info.fini_function = optarg;
1555 break;
1556
1557 case OPTION_REDUCE_MEMORY_OVERHEADS:
1558 link_info.reduce_memory_overheads = TRUE;
1559 if (config.hash_table_size == 0)
1560 config.hash_table_size = 1021;
1561 break;
1562
1563 case OPTION_HASH_SIZE:
1564 {
1565 bfd_size_type new_size;
1566
1567 new_size = strtoul (optarg, NULL, 0);
1568 if (new_size)
1569 config.hash_table_size = new_size;
1570 else
1571 einfo (_("%X%P: --hash-size needs a numeric argument\n"));
1572 }
1573 break;
1574
1575 case OPTION_PUSH_STATE:
1576 input_flags.pushed = xmemdup (&input_flags,
1577 sizeof (input_flags),
1578 sizeof (input_flags));
1579 break;
1580
1581 case OPTION_POP_STATE:
1582 if (input_flags.pushed == NULL)
1583 einfo (_("%F%P: no state pushed before popping\n"));
1584 else
1585 {
1586 struct lang_input_statement_flags *oldp = input_flags.pushed;
1587 memcpy (&input_flags, oldp, sizeof (input_flags));
1588 free (oldp);
1589 }
1590 break;
1591
1592 case OPTION_PRINT_MEMORY_USAGE:
1593 command_line.print_memory_usage = TRUE;
1594 break;
1595
1596 case OPTION_ORPHAN_HANDLING:
1597 if (strcasecmp (optarg, "place") == 0)
1598 config.orphan_handling = orphan_handling_place;
1599 else if (strcasecmp (optarg, "warn") == 0)
1600 config.orphan_handling = orphan_handling_warn;
1601 else if (strcasecmp (optarg, "error") == 0)
1602 config.orphan_handling = orphan_handling_error;
1603 else if (strcasecmp (optarg, "discard") == 0)
1604 config.orphan_handling = orphan_handling_discard;
1605 else
1606 einfo (_("%F%P: invalid argument to option"
1607 " \"--orphan-handling\"\n"));
1608 break;
1609
1610 case OPTION_NO_PRINT_MAP_DISCARDED:
1611 config.print_map_discarded = FALSE;
1612 break;
1613
1614 case OPTION_PRINT_MAP_DISCARDED:
1615 config.print_map_discarded = TRUE;
1616 break;
1617 }
1618 }
1619
1620 if (command_line.soname && command_line.soname[0] == '\0')
1621 {
1622 einfo (_("%P: SONAME must not be empty string; ignored\n"));
1623 command_line.soname = NULL;
1624 }
1625
1626 while (ingroup)
1627 {
1628 einfo (_("%P: missing --end-group; added as last command line option\n"));
1629 lang_leave_group ();
1630 ingroup--;
1631 }
1632
1633 if (default_dirlist != NULL)
1634 {
1635 set_default_dirlist (default_dirlist);
1636 free (default_dirlist);
1637 }
1638
1639 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1640 /* FIXME: Should we allow emulations a chance to set this ? */
1641 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
1642
1643 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1644 /* FIXME: Should we allow emulations a chance to set this ? */
1645 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
1646
1647 if (bfd_link_relocatable (&link_info)
1648 && command_line.check_section_addresses < 0)
1649 command_line.check_section_addresses = 0;
1650
1651 /* -Bsymbolic and -Bsymbols-functions are for shared library output. */
1652 if (bfd_link_dll (&link_info))
1653 switch (opt_symbolic)
1654 {
1655 case symbolic_unset:
1656 break;
1657 case symbolic:
1658 link_info.symbolic = TRUE;
1659 if (link_info.dynamic_list)
1660 {
1661 struct bfd_elf_version_expr *ent, *next;
1662 for (ent = link_info.dynamic_list->head.list; ent; ent = next)
1663 {
1664 next = ent->next;
1665 free (ent);
1666 }
1667 free (link_info.dynamic_list);
1668 link_info.dynamic_list = NULL;
1669 }
1670 opt_dynamic_list = dynamic_list_unset;
1671 break;
1672 case symbolic_functions:
1673 opt_dynamic_list = dynamic_list_data;
1674 break;
1675 }
1676
1677 switch (opt_dynamic_list)
1678 {
1679 case dynamic_list_unset:
1680 break;
1681 case dynamic_list_data:
1682 link_info.dynamic_data = TRUE;
1683 /* Fall through. */
1684 case dynamic_list:
1685 link_info.dynamic = TRUE;
1686 break;
1687 }
1688
1689 if (!bfd_link_dll (&link_info))
1690 {
1691 if (command_line.filter_shlib)
1692 einfo (_("%F%P: -F may not be used without -shared\n"));
1693 if (command_line.auxiliary_filters)
1694 einfo (_("%F%P: -f may not be used without -shared\n"));
1695 }
1696
1697 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1698 don't see how else this can be handled, since in this case we
1699 must preserve all externally visible symbols. */
1700 if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all)
1701 {
1702 link_info.strip = strip_debugger;
1703 if (link_info.discard == discard_sec_merge)
1704 link_info.discard = discard_all;
1705 }
1706 }
1707
1708 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1709 library search path. */
1710
1711 static void
1712 set_default_dirlist (char *dirlist_ptr)
1713 {
1714 char *p;
1715
1716 while (1)
1717 {
1718 p = strchr (dirlist_ptr, PATH_SEPARATOR);
1719 if (p != NULL)
1720 *p = '\0';
1721 if (*dirlist_ptr != '\0')
1722 ldfile_add_library_path (dirlist_ptr, TRUE);
1723 if (p == NULL)
1724 break;
1725 dirlist_ptr = p + 1;
1726 }
1727 }
1728
1729 static void
1730 set_section_start (char *sect, char *valstr)
1731 {
1732 const char *end;
1733 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1734 if (*end)
1735 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
1736 lang_section_start (sect, exp_intop (val), NULL);
1737 }
1738
1739 static void
1740 set_segment_start (const char *section, char *valstr)
1741 {
1742 const char *name;
1743 const char *end;
1744 segment_type *seg;
1745
1746 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1747 if (*end)
1748 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
1749 /* If we already have an entry for this segment, update the existing
1750 value. */
1751 name = section + 1;
1752 for (seg = segments; seg; seg = seg->next)
1753 if (strcmp (seg->name, name) == 0)
1754 {
1755 seg->value = val;
1756 lang_section_start (section, exp_intop (val), seg);
1757 return;
1758 }
1759 /* There was no existing value so we must create a new segment
1760 entry. */
1761 seg = stat_alloc (sizeof (*seg));
1762 seg->name = name;
1763 seg->value = val;
1764 seg->used = FALSE;
1765 /* Add it to the linked list of segments. */
1766 seg->next = segments;
1767 segments = seg;
1768 /* Historically, -Ttext and friends set the base address of a
1769 particular section. For backwards compatibility, we still do
1770 that. If a SEGMENT_START directive is seen, the section address
1771 assignment will be disabled. */
1772 lang_section_start (section, exp_intop (val), seg);
1773 }
1774
1775 static void
1776 elf_shlib_list_options (FILE *file)
1777 {
1778 fprintf (file, _("\
1779 --audit=AUDITLIB Specify a library to use for auditing\n"));
1780 fprintf (file, _("\
1781 -Bgroup Selects group name lookup rules for DSO\n"));
1782 fprintf (file, _("\
1783 --disable-new-dtags Disable new dynamic tags\n"));
1784 fprintf (file, _("\
1785 --enable-new-dtags Enable new dynamic tags\n"));
1786 fprintf (file, _("\
1787 --eh-frame-hdr Create .eh_frame_hdr section\n"));
1788 fprintf (file, _("\
1789 --no-eh-frame-hdr Do not create .eh_frame_hdr section\n"));
1790 fprintf (file, _("\
1791 --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
1792 fprintf (file, _("\
1793 --hash-style=STYLE Set hash style to sysv, gnu or both\n"));
1794 fprintf (file, _("\
1795 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
1796 Specify a library to use for auditing dependencies\n"));
1797 fprintf (file, _("\
1798 -z combreloc Merge dynamic relocs into one section and sort\n"));
1799 fprintf (file, _("\
1800 -z nocombreloc Don't merge dynamic relocs into one section\n"));
1801 fprintf (file, _("\
1802 -z global Make symbols in DSO available for subsequently\n\
1803 loaded objects\n"));
1804 fprintf (file, _("\
1805 -z initfirst Mark DSO to be initialized first at runtime\n"));
1806 fprintf (file, _("\
1807 -z interpose Mark object to interpose all DSOs but executable\n"));
1808 fprintf (file, _("\
1809 -z lazy Mark object lazy runtime binding (default)\n"));
1810 fprintf (file, _("\
1811 -z loadfltr Mark object requiring immediate process\n"));
1812 fprintf (file, _("\
1813 -z nocopyreloc Don't create copy relocs\n"));
1814 fprintf (file, _("\
1815 -z nodefaultlib Mark object not to use default search paths\n"));
1816 fprintf (file, _("\
1817 -z nodelete Mark DSO non-deletable at runtime\n"));
1818 fprintf (file, _("\
1819 -z nodlopen Mark DSO not available to dlopen\n"));
1820 fprintf (file, _("\
1821 -z nodump Mark DSO not available to dldump\n"));
1822 fprintf (file, _("\
1823 -z now Mark object non-lazy runtime binding\n"));
1824 fprintf (file, _("\
1825 -z origin Mark object requiring immediate $ORIGIN\n\
1826 processing at runtime\n"));
1827 #if DEFAULT_LD_Z_RELRO
1828 fprintf (file, _("\
1829 -z relro Create RELRO program header (default)\n"));
1830 fprintf (file, _("\
1831 -z norelro Don't create RELRO program header\n"));
1832 #else
1833 fprintf (file, _("\
1834 -z relro Create RELRO program header\n"));
1835 fprintf (file, _("\
1836 -z norelro Don't create RELRO program header (default)\n"));
1837 #endif
1838 #if DEFAULT_LD_Z_SEPARATE_CODE
1839 fprintf (file, _("\
1840 -z separate-code Create separate code program header (default)\n"));
1841 fprintf (file, _("\
1842 -z noseparate-code Don't create separate code program header\n"));
1843 #else
1844 fprintf (file, _("\
1845 -z separate-code Create separate code program header\n"));
1846 fprintf (file, _("\
1847 -z noseparate-code Don't create separate code program header (default)\n"));
1848 #endif
1849 fprintf (file, _("\
1850 -z common Generate common symbols with STT_COMMON type\n"));
1851 fprintf (file, _("\
1852 -z nocommon Generate common symbols with STT_OBJECT type\n"));
1853 fprintf (file, _("\
1854 -z stack-size=SIZE Set size of stack segment\n"));
1855 fprintf (file, _("\
1856 -z text Treat DT_TEXTREL in shared object as error\n"));
1857 fprintf (file, _("\
1858 -z notext Don't treat DT_TEXTREL in shared object as error\n"));
1859 fprintf (file, _("\
1860 -z textoff Don't treat DT_TEXTREL in shared object as error\n"));
1861 }
1862
1863 static void
1864 elf_static_list_options (FILE *file)
1865 {
1866 fprintf (file, _("\
1867 --build-id[=STYLE] Generate build ID note\n"));
1868 fprintf (file, _("\
1869 --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\
1870 Compress DWARF debug sections using zlib\n"));
1871 #ifdef DEFAULT_FLAG_COMPRESS_DEBUG
1872 fprintf (file, _("\
1873 Default: zlib-gabi\n"));
1874 #else
1875 fprintf (file, _("\
1876 Default: none\n"));
1877 #endif
1878 fprintf (file, _("\
1879 -z common-page-size=SIZE Set common page size to SIZE\n"));
1880 fprintf (file, _("\
1881 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
1882 fprintf (file, _("\
1883 -z defs Report unresolved symbols in object files\n"));
1884 fprintf (file, _("\
1885 -z muldefs Allow multiple definitions\n"));
1886 fprintf (file, _("\
1887 -z execstack Mark executable as requiring executable stack\n"));
1888 fprintf (file, _("\
1889 -z noexecstack Mark executable as not requiring executable stack\n"));
1890 fprintf (file, _("\
1891 -z globalaudit Mark executable requiring global auditing\n"));
1892 }
1893
1894 static void
1895 elf_plt_unwind_list_options (FILE *file)
1896 {
1897 fprintf (file, _("\
1898 --ld-generated-unwind-info Generate exception handling info for PLT\n"));
1899 fprintf (file, _("\
1900 --no-ld-generated-unwind-info\n\
1901 Don't generate exception handling info for PLT\n"));
1902 }
1903
1904 static void
1905 ld_list_options (FILE *file, bfd_boolean elf, bfd_boolean shlib,
1906 bfd_boolean plt_unwind)
1907 {
1908 if (!elf)
1909 return;
1910 printf (_("ELF emulations:\n"));
1911 if (plt_unwind)
1912 elf_plt_unwind_list_options (file);
1913 elf_static_list_options (file);
1914 if (shlib)
1915 elf_shlib_list_options (file);
1916 }
1917
1918 \f
1919 /* Print help messages for the options. */
1920
1921 static void
1922 help (void)
1923 {
1924 unsigned i;
1925 const char **targets, **pp;
1926 int len;
1927
1928 printf (_("Usage: %s [options] file...\n"), program_name);
1929
1930 printf (_("Options:\n"));
1931 for (i = 0; i < OPTION_COUNT; i++)
1932 {
1933 if (ld_options[i].doc != NULL)
1934 {
1935 bfd_boolean comma;
1936 unsigned j;
1937
1938 printf (" ");
1939
1940 comma = FALSE;
1941 len = 2;
1942
1943 j = i;
1944 do
1945 {
1946 if (ld_options[j].shortopt != '\0'
1947 && ld_options[j].control != NO_HELP)
1948 {
1949 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1950 len += (comma ? 2 : 0) + 2;
1951 if (ld_options[j].arg != NULL)
1952 {
1953 if (ld_options[j].opt.has_arg != optional_argument)
1954 {
1955 printf (" ");
1956 ++len;
1957 }
1958 printf ("%s", _(ld_options[j].arg));
1959 len += strlen (_(ld_options[j].arg));
1960 }
1961 comma = TRUE;
1962 }
1963 ++j;
1964 }
1965 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1966
1967 j = i;
1968 do
1969 {
1970 if (ld_options[j].opt.name != NULL
1971 && ld_options[j].control != NO_HELP)
1972 {
1973 int two_dashes =
1974 (ld_options[j].control == TWO_DASHES
1975 || ld_options[j].control == EXACTLY_TWO_DASHES);
1976
1977 printf ("%s-%s%s",
1978 comma ? ", " : "",
1979 two_dashes ? "-" : "",
1980 ld_options[j].opt.name);
1981 len += ((comma ? 2 : 0)
1982 + 1
1983 + (two_dashes ? 1 : 0)
1984 + strlen (ld_options[j].opt.name));
1985 if (ld_options[j].arg != NULL)
1986 {
1987 printf (" %s", _(ld_options[j].arg));
1988 len += 1 + strlen (_(ld_options[j].arg));
1989 }
1990 comma = TRUE;
1991 }
1992 ++j;
1993 }
1994 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1995
1996 if (len >= 30)
1997 {
1998 printf ("\n");
1999 len = 0;
2000 }
2001
2002 for (; len < 30; len++)
2003 putchar (' ');
2004
2005 printf ("%s\n", _(ld_options[i].doc));
2006 }
2007 }
2008 printf (_(" @FILE"));
2009 for (len = strlen (" @FILE"); len < 30; len++)
2010 putchar (' ');
2011 printf (_("Read options from FILE\n"));
2012
2013 /* Note: Various tools (such as libtool) depend upon the
2014 format of the listings below - do not change them. */
2015 /* xgettext:c-format */
2016 printf (_("%s: supported targets:"), program_name);
2017 targets = bfd_target_list ();
2018 for (pp = targets; *pp != NULL; pp++)
2019 printf (" %s", *pp);
2020 free (targets);
2021 printf ("\n");
2022
2023 /* xgettext:c-format */
2024 printf (_("%s: supported emulations: "), program_name);
2025 ldemul_list_emulations (stdout);
2026 printf ("\n");
2027
2028 /* xgettext:c-format */
2029 printf (_("%s: emulation specific options:\n"), program_name);
2030 ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
2031 ELF_PLT_UNWIND_LIST_OPTIONS);
2032 ldemul_list_emulation_options (stdout);
2033 printf ("\n");
2034
2035 if (REPORT_BUGS_TO[0])
2036 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
2037 }
This page took 0.114674 seconds and 4 git commands to generate.