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