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