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