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