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