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