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