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