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