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