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