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