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