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