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