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