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