Add powerpc cell support.
[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 default:
684 einfo (_("%P%F: use the --help option for usage information\n"));
685
686 case 1: /* File name. */
687 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
688 break;
689
690 case OPTION_IGNORE:
691 break;
692 case 'a':
693 /* For HP/UX compatibility. Actually -a shared should mean
694 ``use only shared libraries'' but, then, we don't
695 currently support shared libraries on HP/UX anyhow. */
696 if (strcmp (optarg, "archive") == 0)
697 config.dynamic_link = FALSE;
698 else if (strcmp (optarg, "shared") == 0
699 || strcmp (optarg, "default") == 0)
700 config.dynamic_link = TRUE;
701 else
702 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
703 break;
704 case OPTION_ASSERT:
705 /* FIXME: We just ignore these, but we should handle them. */
706 if (strcmp (optarg, "definitions") == 0)
707 ;
708 else if (strcmp (optarg, "nodefinitions") == 0)
709 ;
710 else if (strcmp (optarg, "nosymbolic") == 0)
711 ;
712 else if (strcmp (optarg, "pure-text") == 0)
713 ;
714 else
715 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
716 break;
717 case 'A':
718 ldfile_add_arch (optarg);
719 break;
720 case 'b':
721 lang_add_target (optarg);
722 break;
723 case 'c':
724 ldfile_open_command_file (optarg);
725 parser_input = input_mri_script;
726 yyparse ();
727 break;
728 case OPTION_CALL_SHARED:
729 config.dynamic_link = TRUE;
730 break;
731 case OPTION_NON_SHARED:
732 config.dynamic_link = FALSE;
733 break;
734 case OPTION_CREF:
735 command_line.cref = TRUE;
736 link_info.notice_all = TRUE;
737 break;
738 case 'd':
739 command_line.force_common_definition = TRUE;
740 break;
741 case OPTION_DEFSYM:
742 lex_string = optarg;
743 lex_redirect (optarg);
744 parser_input = input_defsym;
745 parsing_defsym = 1;
746 yyparse ();
747 parsing_defsym = 0;
748 lex_string = NULL;
749 break;
750 case OPTION_DEMANGLE:
751 demangling = TRUE;
752 if (optarg != NULL)
753 {
754 enum demangling_styles style;
755
756 style = cplus_demangle_name_to_style (optarg);
757 if (style == unknown_demangling)
758 einfo (_("%F%P: unknown demangling style `%s'"),
759 optarg);
760
761 cplus_demangle_set_style (style);
762 }
763 break;
764 case 'I': /* Used on Solaris. */
765 case OPTION_DYNAMIC_LINKER:
766 command_line.interpreter = optarg;
767 break;
768 case OPTION_SYSROOT:
769 /* Already handled in ldmain.c. */
770 break;
771 case OPTION_EB:
772 command_line.endian = ENDIAN_BIG;
773 break;
774 case OPTION_EL:
775 command_line.endian = ENDIAN_LITTLE;
776 break;
777 case OPTION_EMBEDDED_RELOCS:
778 command_line.embedded_relocs = TRUE;
779 break;
780 case OPTION_EXPORT_DYNAMIC:
781 case 'E': /* HP/UX compatibility. */
782 link_info.export_dynamic = TRUE;
783 break;
784 case 'e':
785 lang_add_entry (optarg, TRUE);
786 break;
787 case 'f':
788 if (command_line.auxiliary_filters == NULL)
789 {
790 command_line.auxiliary_filters = xmalloc (2 * sizeof (char *));
791 command_line.auxiliary_filters[0] = optarg;
792 command_line.auxiliary_filters[1] = NULL;
793 }
794 else
795 {
796 int c;
797 char **p;
798
799 c = 0;
800 for (p = command_line.auxiliary_filters; *p != NULL; p++)
801 ++c;
802 command_line.auxiliary_filters
803 = xrealloc (command_line.auxiliary_filters,
804 (c + 2) * sizeof (char *));
805 command_line.auxiliary_filters[c] = optarg;
806 command_line.auxiliary_filters[c + 1] = NULL;
807 }
808 break;
809 case 'F':
810 command_line.filter_shlib = optarg;
811 break;
812 case OPTION_FORCE_EXE_SUFFIX:
813 command_line.force_exe_suffix = TRUE;
814 break;
815 case 'G':
816 {
817 char *end;
818 g_switch_value = strtoul (optarg, &end, 0);
819 if (*end)
820 einfo (_("%P%F: invalid number `%s'\n"), optarg);
821 }
822 break;
823 case 'g':
824 /* Ignore. */
825 break;
826 case OPTION_GC_SECTIONS:
827 link_info.gc_sections = TRUE;
828 break;
829 case OPTION_PRINT_GC_SECTIONS:
830 link_info.print_gc_sections = TRUE;
831 break;
832 case OPTION_HELP:
833 help ();
834 xexit (0);
835 break;
836 case 'L':
837 ldfile_add_library_path (optarg, TRUE);
838 break;
839 case 'l':
840 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
841 break;
842 case 'M':
843 config.map_filename = "-";
844 break;
845 case 'm':
846 /* Ignore. Was handled in a pre-parse. */
847 break;
848 case OPTION_MAP:
849 config.map_filename = optarg;
850 break;
851 case 'N':
852 config.text_read_only = FALSE;
853 config.magic_demand_paged = FALSE;
854 config.dynamic_link = FALSE;
855 break;
856 case OPTION_NO_OMAGIC:
857 config.text_read_only = TRUE;
858 config.magic_demand_paged = TRUE;
859 /* NB/ Does not set dynamic_link to TRUE.
860 Use --call-shared or -Bdynamic for this. */
861 break;
862 case 'n':
863 config.magic_demand_paged = FALSE;
864 config.dynamic_link = FALSE;
865 break;
866 case OPTION_NO_DEFINE_COMMON:
867 command_line.inhibit_common_definition = TRUE;
868 break;
869 case OPTION_NO_DEMANGLE:
870 demangling = FALSE;
871 break;
872 case OPTION_NO_GC_SECTIONS:
873 link_info.gc_sections = FALSE;
874 break;
875 case OPTION_NO_PRINT_GC_SECTIONS:
876 link_info.print_gc_sections = FALSE;
877 break;
878 case OPTION_NO_KEEP_MEMORY:
879 link_info.keep_memory = FALSE;
880 break;
881 case OPTION_NO_UNDEFINED:
882 link_info.unresolved_syms_in_objects
883 = how_to_report_unresolved_symbols;
884 break;
885 case OPTION_ALLOW_SHLIB_UNDEFINED:
886 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
887 break;
888 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
889 link_info.unresolved_syms_in_shared_libs
890 = how_to_report_unresolved_symbols;
891 break;
892 case OPTION_UNRESOLVED_SYMBOLS:
893 if (strcmp (optarg, "ignore-all") == 0)
894 {
895 link_info.unresolved_syms_in_objects = RM_IGNORE;
896 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
897 }
898 else if (strcmp (optarg, "report-all") == 0)
899 {
900 link_info.unresolved_syms_in_objects
901 = how_to_report_unresolved_symbols;
902 link_info.unresolved_syms_in_shared_libs
903 = how_to_report_unresolved_symbols;
904 }
905 else if (strcmp (optarg, "ignore-in-object-files") == 0)
906 {
907 link_info.unresolved_syms_in_objects = RM_IGNORE;
908 link_info.unresolved_syms_in_shared_libs
909 = how_to_report_unresolved_symbols;
910 }
911 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
912 {
913 link_info.unresolved_syms_in_objects
914 = how_to_report_unresolved_symbols;
915 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
916 }
917 else
918 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg);
919 break;
920 case OPTION_WARN_UNRESOLVED_SYMBOLS:
921 how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
922 if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
923 link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
924 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
925 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
926 break;
927
928 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
929 how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
930 if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
931 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
932 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
933 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
934 break;
935 case OPTION_ALLOW_MULTIPLE_DEFINITION:
936 link_info.allow_multiple_definition = TRUE;
937 break;
938 case OPTION_NO_UNDEFINED_VERSION:
939 link_info.allow_undefined_version = FALSE;
940 break;
941 case OPTION_DEFAULT_SYMVER:
942 link_info.create_default_symver = TRUE;
943 break;
944 case OPTION_DEFAULT_IMPORTED_SYMVER:
945 link_info.default_imported_symver = TRUE;
946 break;
947 case OPTION_NO_WARN_MISMATCH:
948 command_line.warn_mismatch = FALSE;
949 break;
950 case OPTION_NOINHIBIT_EXEC:
951 force_make_executable = TRUE;
952 break;
953 case OPTION_NOSTDLIB:
954 config.only_cmd_line_lib_dirs = TRUE;
955 break;
956 case OPTION_NO_WHOLE_ARCHIVE:
957 whole_archive = FALSE;
958 break;
959 case 'O':
960 /* FIXME "-O<non-digits> <value>" used to set the address of
961 section <non-digits>. Was this for compatibility with
962 something, or can we create a new option to do that
963 (with a syntax similar to -defsym)?
964 getopt can't handle two args to an option without kludges. */
965
966 /* Enable optimizations of output files. */
967 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
968 break;
969 case 'o':
970 lang_add_output (optarg, 0);
971 break;
972 case OPTION_OFORMAT:
973 lang_add_output_format (optarg, NULL, NULL, 0);
974 break;
975 case 'q':
976 link_info.emitrelocations = TRUE;
977 break;
978 case 'i':
979 case 'r':
980 if (optind == last_optind)
981 /* This can happen if the user put "-rpath,a" on the command
982 line. (Or something similar. The comma is important).
983 Getopt becomes confused and thinks that this is a -r option
984 but it cannot parse the text after the -r so it refuses to
985 increment the optind counter. Detect this case and issue
986 an error message here. We cannot just make this a warning,
987 increment optind, and continue because getopt is too confused
988 and will seg-fault the next time around. */
989 einfo(_("%P%F: bad -rpath option\n"));
990
991 link_info.relocatable = TRUE;
992 config.build_constructors = FALSE;
993 config.magic_demand_paged = FALSE;
994 config.text_read_only = FALSE;
995 config.dynamic_link = FALSE;
996 break;
997 case 'R':
998 /* The GNU linker traditionally uses -R to mean to include
999 only the symbols from a file. The Solaris linker uses -R
1000 to set the path used by the runtime linker to find
1001 libraries. This is the GNU linker -rpath argument. We
1002 try to support both simultaneously by checking the file
1003 named. If it is a directory, rather than a regular file,
1004 we assume -rpath was meant. */
1005 {
1006 struct stat s;
1007
1008 if (stat (optarg, &s) >= 0
1009 && ! S_ISDIR (s.st_mode))
1010 {
1011 lang_add_input_file (optarg,
1012 lang_input_file_is_symbols_only_enum,
1013 NULL);
1014 break;
1015 }
1016 }
1017 /* Fall through. */
1018 case OPTION_RPATH:
1019 if (command_line.rpath == NULL)
1020 command_line.rpath = xstrdup (optarg);
1021 else
1022 {
1023 size_t rpath_len = strlen (command_line.rpath);
1024 size_t optarg_len = strlen (optarg);
1025 char *buf;
1026 char *cp = command_line.rpath;
1027
1028 /* First see whether OPTARG is already in the path. */
1029 do
1030 {
1031 size_t idx = 0;
1032
1033 while (optarg[idx] != '\0' && optarg[idx] == cp[idx])
1034 ++idx;
1035 if (optarg[idx] == '\0'
1036 && (cp[idx] == '\0' || cp[idx] == ':'))
1037 /* We found it. */
1038 break;
1039
1040 /* Not yet found. */
1041 cp = strchr (cp, ':');
1042 if (cp != NULL)
1043 ++cp;
1044 }
1045 while (cp != NULL);
1046
1047 if (cp == NULL)
1048 {
1049 buf = xmalloc (rpath_len + optarg_len + 2);
1050 sprintf (buf, "%s:%s", command_line.rpath, optarg);
1051 free (command_line.rpath);
1052 command_line.rpath = buf;
1053 }
1054 }
1055 break;
1056 case OPTION_RPATH_LINK:
1057 if (command_line.rpath_link == NULL)
1058 command_line.rpath_link = xstrdup (optarg);
1059 else
1060 {
1061 char *buf;
1062
1063 buf = xmalloc (strlen (command_line.rpath_link)
1064 + strlen (optarg)
1065 + 2);
1066 sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
1067 free (command_line.rpath_link);
1068 command_line.rpath_link = buf;
1069 }
1070 break;
1071 case OPTION_RELAX:
1072 command_line.relax = TRUE;
1073 break;
1074 case OPTION_RETAIN_SYMBOLS_FILE:
1075 add_keepsyms_file (optarg);
1076 break;
1077 case 'S':
1078 link_info.strip = strip_debugger;
1079 break;
1080 case 's':
1081 link_info.strip = strip_all;
1082 break;
1083 case OPTION_STRIP_DISCARDED:
1084 link_info.strip_discarded = TRUE;
1085 break;
1086 case OPTION_NO_STRIP_DISCARDED:
1087 link_info.strip_discarded = FALSE;
1088 break;
1089 case OPTION_SHARED:
1090 if (config.has_shared)
1091 {
1092 link_info.shared = TRUE;
1093 /* When creating a shared library, the default
1094 behaviour is to ignore any unresolved references. */
1095 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1096 link_info.unresolved_syms_in_objects = RM_IGNORE;
1097 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1098 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1099 }
1100 else
1101 einfo (_("%P%F: -shared not supported\n"));
1102 break;
1103 case OPTION_PIE:
1104 if (config.has_shared)
1105 {
1106 link_info.shared = TRUE;
1107 link_info.pie = TRUE;
1108 }
1109 else
1110 einfo (_("%P%F: -pie not supported\n"));
1111 break;
1112 case 'h': /* Used on Solaris. */
1113 case OPTION_SONAME:
1114 command_line.soname = optarg;
1115 break;
1116 case OPTION_SORT_COMMON:
1117 config.sort_common = TRUE;
1118 break;
1119 case OPTION_SORT_SECTION:
1120 if (strcmp (optarg, N_("name")) == 0)
1121 sort_section = by_name;
1122 else if (strcmp (optarg, N_("alignment")) == 0)
1123 sort_section = by_alignment;
1124 else
1125 einfo (_("%P%F: invalid section sorting option: %s\n"),
1126 optarg);
1127 break;
1128 case OPTION_STATS:
1129 config.stats = TRUE;
1130 break;
1131 case OPTION_SYMBOLIC:
1132 link_info.symbolic = TRUE;
1133 break;
1134 case 't':
1135 trace_files = TRUE;
1136 break;
1137 case 'T':
1138 ldfile_open_command_file (optarg);
1139 parser_input = input_script;
1140 yyparse ();
1141 break;
1142 case OPTION_SECTION_START:
1143 {
1144 char *optarg2;
1145 char *sec_name;
1146 int len;
1147
1148 /* Check for <something>=<somthing>... */
1149 optarg2 = strchr (optarg, '=');
1150 if (optarg2 == NULL)
1151 einfo (_("%P%F: invalid argument to option"
1152 " \"--section-start\"\n"));
1153
1154 optarg2++;
1155
1156 /* So far so good. Are all the args present? */
1157 if ((*optarg == '\0') || (*optarg2 == '\0'))
1158 einfo (_("%P%F: missing argument(s) to option"
1159 " \"--section-start\"\n"));
1160
1161 /* We must copy the section name as set_section_start
1162 doesn't do it for us. */
1163 len = optarg2 - optarg;
1164 sec_name = xmalloc (len);
1165 memcpy (sec_name, optarg, len - 1);
1166 sec_name[len - 1] = 0;
1167
1168 /* Then set it... */
1169 set_section_start (sec_name, optarg2);
1170 }
1171 break;
1172 case OPTION_TARGET_HELP:
1173 /* Mention any target specific options. */
1174 ldemul_list_emulation_options (stdout);
1175 exit (0);
1176 case OPTION_TBSS:
1177 set_segment_start (".bss", optarg);
1178 break;
1179 case OPTION_TDATA:
1180 set_segment_start (".data", optarg);
1181 break;
1182 case OPTION_TTEXT:
1183 set_segment_start (".text", optarg);
1184 break;
1185 case OPTION_TRADITIONAL_FORMAT:
1186 link_info.traditional_format = TRUE;
1187 break;
1188 case OPTION_TASK_LINK:
1189 link_info.task_link = TRUE;
1190 /* Fall through - do an implied -r option. */
1191 case OPTION_UR:
1192 link_info.relocatable = TRUE;
1193 config.build_constructors = TRUE;
1194 config.magic_demand_paged = FALSE;
1195 config.text_read_only = FALSE;
1196 config.dynamic_link = FALSE;
1197 break;
1198 case 'u':
1199 ldlang_add_undef (optarg);
1200 break;
1201 case OPTION_UNIQUE:
1202 if (optarg != NULL)
1203 lang_add_unique (optarg);
1204 else
1205 config.unique_orphan_sections = TRUE;
1206 break;
1207 case OPTION_VERBOSE:
1208 ldversion (1);
1209 version_printed = TRUE;
1210 trace_file_tries = TRUE;
1211 overflow_cutoff_limit = -2;
1212 break;
1213 case 'v':
1214 ldversion (0);
1215 version_printed = TRUE;
1216 break;
1217 case 'V':
1218 ldversion (1);
1219 version_printed = TRUE;
1220 break;
1221 case OPTION_VERSION:
1222 ldversion (2);
1223 xexit (0);
1224 break;
1225 case OPTION_VERSION_SCRIPT:
1226 /* This option indicates a small script that only specifies
1227 version information. Read it, but don't assume that
1228 we've seen a linker script. */
1229 {
1230 FILE *hold_script_handle;
1231
1232 hold_script_handle = saved_script_handle;
1233 ldfile_open_command_file (optarg);
1234 saved_script_handle = hold_script_handle;
1235 parser_input = input_version_script;
1236 yyparse ();
1237 }
1238 break;
1239 case OPTION_VERSION_EXPORTS_SECTION:
1240 /* This option records a version symbol to be applied to the
1241 symbols listed for export to be found in the object files
1242 .exports sections. */
1243 command_line.version_exports_section = optarg;
1244 break;
1245 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1246 lang_append_dynamic_list_cpp_typeinfo ();
1247 break;
1248 case OPTION_DYNAMIC_LIST:
1249 /* This option indicates a small script that only specifies
1250 a dynamic list. Read it, but don't assume that we've
1251 seen a linker script. */
1252 {
1253 FILE *hold_script_handle;
1254
1255 hold_script_handle = saved_script_handle;
1256 ldfile_open_command_file (optarg);
1257 saved_script_handle = hold_script_handle;
1258 parser_input = input_dynamic_list;
1259 yyparse ();
1260 }
1261 break;
1262 case OPTION_WARN_COMMON:
1263 config.warn_common = TRUE;
1264 break;
1265 case OPTION_WARN_CONSTRUCTORS:
1266 config.warn_constructors = TRUE;
1267 break;
1268 case OPTION_WARN_FATAL:
1269 config.fatal_warnings = TRUE;
1270 break;
1271 case OPTION_WARN_MULTIPLE_GP:
1272 config.warn_multiple_gp = TRUE;
1273 break;
1274 case OPTION_WARN_ONCE:
1275 config.warn_once = TRUE;
1276 break;
1277 case OPTION_WARN_SECTION_ALIGN:
1278 config.warn_section_align = TRUE;
1279 break;
1280 case OPTION_WARN_SHARED_TEXTREL:
1281 link_info.warn_shared_textrel = TRUE;
1282 break;
1283 case OPTION_WHOLE_ARCHIVE:
1284 whole_archive = TRUE;
1285 break;
1286 case OPTION_ADD_NEEDED:
1287 add_needed = TRUE;
1288 break;
1289 case OPTION_NO_ADD_NEEDED:
1290 add_needed = FALSE;
1291 break;
1292 case OPTION_AS_NEEDED:
1293 as_needed = TRUE;
1294 break;
1295 case OPTION_NO_AS_NEEDED:
1296 as_needed = FALSE;
1297 break;
1298 case OPTION_WRAP:
1299 add_wrap (optarg);
1300 break;
1301 case OPTION_DISCARD_NONE:
1302 link_info.discard = discard_none;
1303 break;
1304 case 'X':
1305 link_info.discard = discard_l;
1306 break;
1307 case 'x':
1308 link_info.discard = discard_all;
1309 break;
1310 case 'Y':
1311 if (CONST_STRNEQ (optarg, "P,"))
1312 optarg += 2;
1313 if (default_dirlist != NULL)
1314 free (default_dirlist);
1315 default_dirlist = xstrdup (optarg);
1316 break;
1317 case 'y':
1318 add_ysym (optarg);
1319 break;
1320 case OPTION_SPARE_DYNAMIC_TAGS:
1321 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1322 break;
1323 case OPTION_SPLIT_BY_RELOC:
1324 if (optarg != NULL)
1325 config.split_by_reloc = strtoul (optarg, NULL, 0);
1326 else
1327 config.split_by_reloc = 32768;
1328 break;
1329 case OPTION_SPLIT_BY_FILE:
1330 if (optarg != NULL)
1331 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1332 else
1333 config.split_by_file = 1;
1334 break;
1335 case OPTION_CHECK_SECTIONS:
1336 command_line.check_section_addresses = TRUE;
1337 break;
1338 case OPTION_NO_CHECK_SECTIONS:
1339 command_line.check_section_addresses = FALSE;
1340 break;
1341 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1342 command_line.accept_unknown_input_arch = TRUE;
1343 break;
1344 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1345 command_line.accept_unknown_input_arch = FALSE;
1346 break;
1347 case '(':
1348 if (ingroup)
1349 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1350
1351 lang_enter_group ();
1352 ingroup = 1;
1353 break;
1354 case ')':
1355 if (! ingroup)
1356 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1357
1358 lang_leave_group ();
1359 ingroup = 0;
1360 break;
1361
1362 case OPTION_INIT:
1363 link_info.init_function = optarg;
1364 break;
1365
1366 case OPTION_FINI:
1367 link_info.fini_function = optarg;
1368 break;
1369
1370 case OPTION_REDUCE_MEMORY_OVERHEADS:
1371 command_line.reduce_memory_overheads = TRUE;
1372 if (config.hash_table_size == 0)
1373 config.hash_table_size = 1021;
1374 break;
1375
1376 case OPTION_HASH_SIZE:
1377 {
1378 bfd_size_type new_size;
1379
1380 new_size = strtoul (optarg, NULL, 0);
1381 if (new_size)
1382 config.hash_table_size = new_size;
1383 else
1384 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1385 }
1386 break;
1387 }
1388 }
1389
1390 if (ingroup)
1391 lang_leave_group ();
1392
1393 if (default_dirlist != NULL)
1394 {
1395 set_default_dirlist (default_dirlist);
1396 free (default_dirlist);
1397 }
1398
1399 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1400 /* FIXME: Should we allow emulations a chance to set this ? */
1401 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
1402
1403 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1404 /* FIXME: Should we allow emulations a chance to set this ? */
1405 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
1406 }
1407
1408 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1409 library search path. */
1410
1411 static void
1412 set_default_dirlist (char *dirlist_ptr)
1413 {
1414 char *p;
1415
1416 while (1)
1417 {
1418 p = strchr (dirlist_ptr, PATH_SEPARATOR);
1419 if (p != NULL)
1420 *p = '\0';
1421 if (*dirlist_ptr != '\0')
1422 ldfile_add_library_path (dirlist_ptr, TRUE);
1423 if (p == NULL)
1424 break;
1425 dirlist_ptr = p + 1;
1426 }
1427 }
1428
1429 static void
1430 set_section_start (char *sect, char *valstr)
1431 {
1432 const char *end;
1433 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1434 if (*end)
1435 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1436 lang_section_start (sect, exp_intop (val), NULL);
1437 }
1438
1439 static void
1440 set_segment_start (const char *section, char *valstr)
1441 {
1442 const char *name;
1443 const char *end;
1444 segment_type *seg;
1445
1446 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1447 if (*end)
1448 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1449 /* If we already have an entry for this segment, update the existing
1450 value. */
1451 name = section + 1;
1452 for (seg = segments; seg; seg = seg->next)
1453 if (strcmp (seg->name, name) == 0)
1454 {
1455 seg->value = val;
1456 return;
1457 }
1458 /* There was no existing value so we must create a new segment
1459 entry. */
1460 seg = stat_alloc (sizeof (*seg));
1461 seg->name = name;
1462 seg->value = val;
1463 seg->used = FALSE;
1464 /* Add it to the linked list of segments. */
1465 seg->next = segments;
1466 segments = seg;
1467 /* Historically, -Ttext and friends set the base address of a
1468 particular section. For backwards compatibility, we still do
1469 that. If a SEGMENT_START directive is seen, the section address
1470 assignment will be disabled. */
1471 lang_section_start (section, exp_intop (val), seg);
1472 }
1473
1474 \f
1475 /* Print help messages for the options. */
1476
1477 static void
1478 help (void)
1479 {
1480 unsigned i;
1481 const char **targets, **pp;
1482 int len;
1483
1484 printf (_("Usage: %s [options] file...\n"), program_name);
1485
1486 printf (_("Options:\n"));
1487 for (i = 0; i < OPTION_COUNT; i++)
1488 {
1489 if (ld_options[i].doc != NULL)
1490 {
1491 bfd_boolean comma;
1492 unsigned j;
1493
1494 printf (" ");
1495
1496 comma = FALSE;
1497 len = 2;
1498
1499 j = i;
1500 do
1501 {
1502 if (ld_options[j].shortopt != '\0'
1503 && ld_options[j].control != NO_HELP)
1504 {
1505 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1506 len += (comma ? 2 : 0) + 2;
1507 if (ld_options[j].arg != NULL)
1508 {
1509 if (ld_options[j].opt.has_arg != optional_argument)
1510 {
1511 printf (" ");
1512 ++len;
1513 }
1514 printf ("%s", _(ld_options[j].arg));
1515 len += strlen (_(ld_options[j].arg));
1516 }
1517 comma = TRUE;
1518 }
1519 ++j;
1520 }
1521 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1522
1523 j = i;
1524 do
1525 {
1526 if (ld_options[j].opt.name != NULL
1527 && ld_options[j].control != NO_HELP)
1528 {
1529 int two_dashes =
1530 (ld_options[j].control == TWO_DASHES
1531 || ld_options[j].control == EXACTLY_TWO_DASHES);
1532
1533 printf ("%s-%s%s",
1534 comma ? ", " : "",
1535 two_dashes ? "-" : "",
1536 ld_options[j].opt.name);
1537 len += ((comma ? 2 : 0)
1538 + 1
1539 + (two_dashes ? 1 : 0)
1540 + strlen (ld_options[j].opt.name));
1541 if (ld_options[j].arg != NULL)
1542 {
1543 printf (" %s", _(ld_options[j].arg));
1544 len += 1 + strlen (_(ld_options[j].arg));
1545 }
1546 comma = TRUE;
1547 }
1548 ++j;
1549 }
1550 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1551
1552 if (len >= 30)
1553 {
1554 printf ("\n");
1555 len = 0;
1556 }
1557
1558 for (; len < 30; len++)
1559 putchar (' ');
1560
1561 printf ("%s\n", _(ld_options[i].doc));
1562 }
1563 }
1564 printf (_(" @FILE"));
1565 for (len = strlen (" @FILE"); len < 30; len++)
1566 putchar (' ');
1567 printf (_("Read options from FILE\n"));
1568
1569 /* Note: Various tools (such as libtool) depend upon the
1570 format of the listings below - do not change them. */
1571 /* xgettext:c-format */
1572 printf (_("%s: supported targets:"), program_name);
1573 targets = bfd_target_list ();
1574 for (pp = targets; *pp != NULL; pp++)
1575 printf (" %s", *pp);
1576 free (targets);
1577 printf ("\n");
1578
1579 /* xgettext:c-format */
1580 printf (_("%s: supported emulations: "), program_name);
1581 ldemul_list_emulations (stdout);
1582 printf ("\n");
1583
1584 /* xgettext:c-format */
1585 printf (_("%s: emulation specific options:\n"), program_name);
1586 ldemul_list_emulation_options (stdout);
1587 printf ("\n");
1588
1589 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
1590 }
This page took 0.1016 seconds and 4 git commands to generate.