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