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