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