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