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