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