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