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