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