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