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