Change regcache list to be an hash map
[deliverable/binutils-gdb.git] / ld / lexsup.c
CommitLineData
252b5132 1/* Parse options for the GNU linker.
82704155 2 Copyright (C) 1991-2019 Free Software Foundation, Inc.
252b5132 3
f96b4a7b 4 This file is part of the GNU Binutils.
252b5132 5
f96b4a7b 6 This program is free software; you can redistribute it and/or modify
53b2a62f 7 it under the terms of the GNU General Public License as published by
f96b4a7b
NC
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
252b5132 10
f96b4a7b 11 This program is distributed in the hope that it will be useful,
53b2a62f
NC
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
252b5132 15
53b2a62f 16 You should have received a copy of the GNU General Public License
f96b4a7b
NC
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
252b5132 20
3db64b00 21#include "sysdep.h"
252b5132 22#include "bfd.h"
c428fa83 23#include "bfdver.h"
252b5132
RH
24#include "libiberty.h"
25#include <stdio.h>
26#include <string.h>
3882b010 27#include "safe-ctype.h"
252b5132
RH
28#include "getopt.h"
29#include "bfdlink.h"
1ff6de03 30#include "ctf-api.h"
252b5132
RH
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"
5d3236ee
DK
42#ifdef ENABLE_PLUGINS
43#include "plugin.h"
44#endif /* ENABLE_PLUGINS */
252b5132
RH
45
46#ifndef PATH_SEPARATOR
47#if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
48#define PATH_SEPARATOR ';'
49#else
50#define PATH_SEPARATOR ':'
51#endif
52#endif
53
5cc18311 54/* Somewhere above, sys/stat.h got included . . . . */
252b5132
RH
55#if !defined(S_ISDIR) && defined(S_IFDIR)
56#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
57#endif
58
1579bae1
AM
59static void set_default_dirlist (char *);
60static void set_section_start (char *, char *);
ba916c8a 61static void set_segment_start (const char *, char *);
1579bae1 62static void help (void);
252b5132 63
252b5132
RH
64/* The long options. This structure is used for both the option
65 parsing and the help text. */
66
1e9cc1c2
NC
67enum control_enum {
68 /* Use one dash before long option name. */
f82aa165 69 ONE_DASH = 1,
1e9cc1c2 70 /* Use two dashes before long option name. */
f82aa165 71 TWO_DASHES = 2,
1e9cc1c2
NC
72 /* Only accept two dashes before the long option name.
73 This is an overloading of the use of this enum, since originally it
74 was only intended to tell the --help display function how to display
75 the long option name. This feature was added in order to resolve
76 the confusion about the -omagic command line switch. Is it setting
77 the output file name to "magic" or is it setting the NMAGIC flag on
78 the output ? It has been decided that it is setting the output file
79 name, and that if you want to set the NMAGIC flag you should use -N
80 or --omagic. */
81 EXACTLY_TWO_DASHES,
82 /* Don't mention this option in --help output. */
83 NO_HELP
84};
85
b79e8c78
NC
86struct ld_option
87{
252b5132
RH
88 /* The long option information. */
89 struct option opt;
90 /* The short option with the same meaning ('\0' if none). */
91 char shortopt;
92 /* The name of the argument (NULL if none). */
93 const char *arg;
94 /* The documentation string. If this is NULL, this is a synonym for
95 the previous option. */
96 const char *doc;
1e9cc1c2 97 enum control_enum control;
252b5132
RH
98};
99
b79e8c78
NC
100static const struct ld_option ld_options[] =
101{
252b5132 102 { {NULL, required_argument, NULL, '\0'},
6feb9908
AM
103 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
104 ONE_DASH },
252b5132 105 { {"architecture", required_argument, NULL, 'A'},
6feb9908 106 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
252b5132 107 { {"format", required_argument, NULL, 'b'},
6feb9908
AM
108 'b', N_("TARGET"), N_("Specify target for following input files"),
109 TWO_DASHES },
252b5132 110 { {"mri-script", required_argument, NULL, 'c'},
6feb9908 111 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
252b5132 112 { {"dc", no_argument, NULL, 'd'},
6feb9908 113 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
252b5132 114 { {"dp", no_argument, NULL, 'd'},
6feb9908 115 '\0', NULL, NULL, ONE_DASH },
7bdf4127
AB
116 { {"force-group-allocation", no_argument, NULL,
117 OPTION_FORCE_GROUP_ALLOCATION},
118 '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
252b5132 119 { {"entry", required_argument, NULL, 'e'},
6feb9908 120 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
252b5132 121 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
6feb9908 122 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
267e2722
CD
123 { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC},
124 '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES },
252b5132 125 { {"EB", no_argument, NULL, OPTION_EB},
6feb9908 126 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
252b5132 127 { {"EL", no_argument, NULL, OPTION_EL},
6feb9908 128 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
252b5132 129 { {"auxiliary", required_argument, NULL, 'f'},
6feb9908
AM
130 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
131 TWO_DASHES },
252b5132 132 { {"filter", required_argument, NULL, 'F'},
6feb9908
AM
133 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
134 TWO_DASHES },
252b5132 135 { {NULL, no_argument, NULL, '\0'},
6feb9908 136 'g', NULL, N_("Ignored"), ONE_DASH },
252b5132 137 { {"gpsize", required_argument, NULL, 'G'},
6feb9908
AM
138 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
139 TWO_DASHES },
252b5132 140 { {"soname", required_argument, NULL, OPTION_SONAME},
6feb9908 141 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
506eee22 142 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
6feb9908
AM
143 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
144 TWO_DASHES },
9b8b325a
RF
145 { {"no-dynamic-linker", no_argument, NULL, OPTION_NO_DYNAMIC_LINKER},
146 '\0', NULL, N_("Produce an executable with no program interpreter header"),
147 TWO_DASHES },
252b5132 148 { {"library", required_argument, NULL, 'l'},
6feb9908 149 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
252b5132 150 { {"library-path", required_argument, NULL, 'L'},
6feb9908
AM
151 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
152 TWO_DASHES },
e2243057
RS
153 { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
154 '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
252b5132 155 { {NULL, required_argument, NULL, '\0'},
6feb9908 156 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
252b5132 157 { {"print-map", no_argument, NULL, 'M'},
6feb9908 158 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
252b5132 159 { {"nmagic", no_argument, NULL, 'n'},
6feb9908 160 'n', NULL, N_("Do not page align data"), TWO_DASHES },
252b5132 161 { {"omagic", no_argument, NULL, 'N'},
6feb9908
AM
162 'N', NULL, N_("Do not page align data, do not make text readonly"),
163 EXACTLY_TWO_DASHES },
63fd3b82 164 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
6feb9908
AM
165 '\0', NULL, N_("Page align data, make text readonly"),
166 EXACTLY_TWO_DASHES },
252b5132 167 { {"output", required_argument, NULL, 'o'},
6feb9908 168 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
252b5132 169 { {NULL, required_argument, NULL, '\0'},
6feb9908 170 'O', NULL, N_("Optimize output file"), ONE_DASH },
76359541
TP
171 { {"out-implib", required_argument, NULL, OPTION_OUT_IMPLIB},
172 '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES },
5d3236ee
DK
173#ifdef ENABLE_PLUGINS
174 { {"plugin", required_argument, NULL, OPTION_PLUGIN},
175 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
176 { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
177 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
94bf3a11
L
178 { {"flto", optional_argument, NULL, OPTION_IGNORE},
179 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
180 ONE_DASH },
181 { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
182 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
183 ONE_DASH },
5d3236ee 184#endif /* ENABLE_PLUGINS */
add24320
L
185 { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE},
186 '\0', NULL, N_("Ignored for GCC linker option compatibility"),
187 ONE_DASH },
88b9e2eb
L
188 { {"map-whole-files", optional_argument, NULL, OPTION_IGNORE},
189 '\0', NULL, N_("Ignored for gold option compatibility"),
190 TWO_DASHES },
191 { {"no-map-whole-files", optional_argument, NULL, OPTION_IGNORE},
192 '\0', NULL, N_("Ignored for gold option compatibility"),
193 TWO_DASHES },
252b5132 194 { {"Qy", no_argument, NULL, OPTION_IGNORE},
6feb9908 195 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
a712da20 196 { {"emit-relocs", no_argument, NULL, 'q'},
6feb9908 197 'q', NULL, "Generate relocations in final output", TWO_DASHES },
1049f94e 198 { {"relocatable", no_argument, NULL, 'r'},
6feb9908 199 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
252b5132 200 { {NULL, no_argument, NULL, '\0'},
6feb9908 201 'i', NULL, NULL, ONE_DASH },
252b5132 202 { {"just-symbols", required_argument, NULL, 'R'},
6feb9908
AM
203 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
204 TWO_DASHES },
252b5132 205 { {"strip-all", no_argument, NULL, 's'},
6feb9908 206 's', NULL, N_("Strip all symbols"), TWO_DASHES },
252b5132 207 { {"strip-debug", no_argument, NULL, 'S'},
6feb9908 208 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
d5cd3933 209 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
6feb9908 210 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
d5cd3933 211 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
6feb9908 212 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
252b5132 213 { {"trace", no_argument, NULL, 't'},
6feb9908 214 't', NULL, N_("Trace file opens"), TWO_DASHES },
252b5132 215 { {"script", required_argument, NULL, 'T'},
6feb9908 216 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
14be8564
L
217 { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
218 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
219 { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
220 '\0', NULL, NULL, ONE_DASH },
252b5132 221 { {"undefined", required_argument, NULL, 'u'},
6feb9908
AM
222 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
223 TWO_DASHES },
0a618243
AB
224 { {"require-defined", required_argument, NULL, OPTION_REQUIRE_DEFINED_SYMBOL},
225 '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"),
226 TWO_DASHES },
577a0623 227 { {"unique", optional_argument, NULL, OPTION_UNIQUE},
6feb9908
AM
228 '\0', N_("[=SECTION]"),
229 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
252b5132 230 { {"Ur", no_argument, NULL, OPTION_UR},
6feb9908 231 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
252b5132 232 { {"version", no_argument, NULL, OPTION_VERSION},
6feb9908 233 'v', NULL, N_("Print version information"), TWO_DASHES },
252b5132 234 { {NULL, no_argument, NULL, '\0'},
6feb9908 235 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
252b5132 236 { {"discard-all", no_argument, NULL, 'x'},
6feb9908 237 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
252b5132 238 { {"discard-locals", no_argument, NULL, 'X'},
6feb9908 239 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
f5fa8ca2 240 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
6feb9908 241 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
252b5132 242 { {"trace-symbol", required_argument, NULL, 'y'},
6feb9908 243 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
252b5132 244 { {NULL, required_argument, NULL, '\0'},
6feb9908
AM
245 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
246 ONE_DASH },
252b5132 247 { {"start-group", no_argument, NULL, '('},
6feb9908 248 '(', NULL, N_("Start a group"), TWO_DASHES },
252b5132 249 { {"end-group", no_argument, NULL, ')'},
6feb9908
AM
250 ')', NULL, N_("End a group"), TWO_DASHES },
251 { {"accept-unknown-input-arch", no_argument, NULL,
252 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
253 '\0', NULL,
254 N_("Accept input files whose architecture cannot be determined"),
255 TWO_DASHES },
256 { {"no-accept-unknown-input-arch", no_argument, NULL,
257 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
258 '\0', NULL, N_("Reject input files whose architecture is unknown"),
259 TWO_DASHES },
ddbb8a31
NC
260
261 /* The next two options are deprecated because of their similarity to
262 --as-needed and --no-as-needed. They have been replaced by
99bca8f9 263 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
ddbb8a31
NC
264 { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
265 '\0', NULL, NULL, NO_HELP },
266 { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
267 '\0', NULL, NULL, NO_HELP },
268
269 { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
8fdd7217
NC
270 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
271 TWO_DASHES },
ddbb8a31
NC
272 { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
273 '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
274 " the command line"),
8fdd7217 275 TWO_DASHES },
252b5132 276 { {"assert", required_argument, NULL, OPTION_ASSERT},
6feb9908 277 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
252b5132 278 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
6feb9908 279 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
252b5132 280 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
6feb9908 281 '\0', NULL, NULL, ONE_DASH },
252b5132 282 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
6feb9908 283 '\0', NULL, NULL, ONE_DASH },
252b5132 284 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
6feb9908 285 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
252b5132 286 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
6feb9908 287 '\0', NULL, NULL, ONE_DASH },
252b5132 288 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
6feb9908 289 '\0', NULL, NULL, ONE_DASH },
252b5132 290 { {"static", no_argument, NULL, OPTION_NON_SHARED},
6feb9908 291 '\0', NULL, NULL, ONE_DASH },
252b5132 292 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
6feb9908 293 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
d8cf8b51 294 { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
40b36307 295 '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
252b5132 296 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
6feb9908
AM
297 '\0', NULL, N_("Check section addresses for overlaps (default)"),
298 TWO_DASHES },
252b5132 299 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
6feb9908
AM
300 '\0', NULL, N_("Do not check section addresses for overlaps"),
301 TWO_DASHES },
ddbb8a31
NC
302 { {"copy-dt-needed-entries", no_argument, NULL,
303 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
304 '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
305 TWO_DASHES },
306 { {"no-copy-dt-needed-entries", no_argument, NULL,
307 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
308 '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
309 TWO_DASHES },
310
252b5132 311 { {"cref", no_argument, NULL, OPTION_CREF},
6feb9908 312 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
252b5132 313 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
6feb9908 314 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
28c309a2 315 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
6feb9908
AM
316 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
317 TWO_DASHES },
3f0a5f17
ME
318 { {"disable-multiple-abs-defs", no_argument, NULL,
319 OPTION_DISABLE_MULTIPLE_DEFS_ABS},
320 '\0', NULL, N_("Do not allow multiple definitions with symbols included\n"
321 " in filename invoked by -R or --just-symbols"),
322 TWO_DASHES},
252b5132 323 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
6feb9908 324 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
8fdd7217
NC
325 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
326 '\0', NULL, N_("Treat warnings as errors"),
327 TWO_DASHES },
0fe58ccd
NC
328 { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL},
329 '\0', NULL, N_("Do not treat warnings as errors (default)"),
330 TWO_DASHES },
3dbf70a2 331 { {"fini", required_argument, NULL, OPTION_FINI},
6feb9908 332 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
252b5132 333 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
6feb9908 334 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
252b5132 335 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
6feb9908
AM
336 '\0', NULL, N_("Remove unused sections (on some targets)"),
337 TWO_DASHES },
252b5132 338 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
6feb9908
AM
339 '\0', NULL, N_("Don't remove unused sections (default)"),
340 TWO_DASHES },
c17d87de
NC
341 { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
342 '\0', NULL, N_("List removed unused sections on stderr"),
343 TWO_DASHES },
344 { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
345 '\0', NULL, N_("Do not list removed unused sections"),
346 TWO_DASHES },
22185505 347 { {"gc-keep-exported", no_argument, NULL, OPTION_GC_KEEP_EXPORTED},
348 '\0', NULL, N_("Keep exported symbols when removing unused sections"),
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},
cc643b88 369 '\0', NULL, N_("Allow unresolved references in shared libraries"),
6feb9908
AM
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 },
3e3b46e5
PB
380 { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
381 '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
fc0e6df6
PB
382 { {"default-imported-symver", no_argument, NULL,
383 OPTION_DEFAULT_IMPORTED_SYMVER},
384 '\0', NULL, N_("Create default symbol version for imported symbols"),
385 TWO_DASHES },
252b5132 386 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
6feb9908 387 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
fe7929ce
AM
388 { {"no-warn-search-mismatch", no_argument, NULL,
389 OPTION_NO_WARN_SEARCH_MISMATCH},
390 '\0', NULL, N_("Don't warn on finding an incompatible library"),
391 TWO_DASHES},
252b5132 392 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
6feb9908 393 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
252b5132 394 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
6feb9908
AM
395 '\0', NULL, N_("Create an output file even if errors occur"),
396 TWO_DASHES },
252b5132 397 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
6feb9908 398 '\0', NULL, NULL, NO_HELP },
361b220e 399 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
6feb9908 400 '\0', NULL, N_("Only use library directories specified on\n"
c58dea77
AM
401 " the command line"),
402 ONE_DASH },
252b5132 403 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
6feb9908
AM
404 '\0', N_("TARGET"), N_("Specify target of output file"),
405 EXACTLY_TWO_DASHES },
30824704
RM
406 { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
407 '\0', NULL, N_("Print default output format"), TWO_DASHES },
cb9322a8
HPN
408 { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT},
409 '\0', NULL, N_("Print current sysroot"), TWO_DASHES },
252b5132 410 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
6feb9908
AM
411 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
412 { {"reduce-memory-overheads", no_argument, NULL,
413 OPTION_REDUCE_MEMORY_OVERHEADS},
414 '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
415 TWO_DASHES },
252b5132 416 { {"relax", no_argument, NULL, OPTION_RELAX},
28d5f677
NC
417 '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
418 { {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
419 '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES },
252b5132 420 { {"retain-symbols-file", required_argument, NULL,
6feb9908
AM
421 OPTION_RETAIN_SYMBOLS_FILE},
422 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
252b5132 423 { {"rpath", required_argument, NULL, OPTION_RPATH},
6feb9908 424 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
252b5132 425 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
6feb9908
AM
426 '\0', N_("PATH"), N_("Set link time shared library search path"),
427 ONE_DASH },
252b5132 428 { {"shared", no_argument, NULL, OPTION_SHARED},
6feb9908 429 '\0', NULL, N_("Create a shared library"), ONE_DASH },
252b5132 430 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
6feb9908 431 '\0', NULL, NULL, ONE_DASH },
36af4a4e 432 { {"pie", no_argument, NULL, OPTION_PIE},
6feb9908 433 '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
36af4a4e 434 { {"pic-executable", no_argument, NULL, OPTION_PIE},
6feb9908 435 '\0', NULL, NULL, TWO_DASHES },
de7dd2bd 436 { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
9d5777a3
RM
437 '\0', N_("[=ascending|descending]"),
438 N_("Sort common symbols by alignment [in specified order]"),
de7dd2bd 439 TWO_DASHES },
252b5132 440 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
6feb9908 441 '\0', NULL, NULL, NO_HELP },
bcaa7b3e 442 { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
9d5777a3 443 '\0', N_("name|alignment"),
bcaa7b3e 444 N_("Sort sections by name or maximum alignment"), TWO_DASHES },
db6751f2 445 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
6feb9908
AM
446 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
447 TWO_DASHES },
a854a4a7 448 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
6feb9908
AM
449 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
450 TWO_DASHES },
a854a4a7 451 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
6feb9908
AM
452 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
453 TWO_DASHES },
252b5132 454 { {"stats", no_argument, NULL, OPTION_STATS},
6feb9908 455 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
ea20a7da 456 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
6feb9908 457 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
252b5132 458 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
6feb9908 459 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
252b5132 460 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
6feb9908 461 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
176355da 462 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
6feb9908
AM
463 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
464 TWO_DASHES },
252b5132 465 { {"Tbss", required_argument, NULL, OPTION_TBSS},
6feb9908 466 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
252b5132 467 { {"Tdata", required_argument, NULL, OPTION_TDATA},
6feb9908 468 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
252b5132 469 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
6feb9908 470 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
258795f5
L
471 { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT},
472 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH },
9d5777a3
RM
473 { {"Trodata-segment", required_argument, NULL, OPTION_TRODATA_SEGMENT},
474 '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH },
0d705e9f
AM
475 { {"Tldata-segment", required_argument, NULL, OPTION_TLDATA_SEGMENT},
476 '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH },
6feb9908
AM
477 { {"unresolved-symbols=<method>", required_argument, NULL,
478 OPTION_UNRESOLVED_SYMBOLS},
479 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n"
c58dea77
AM
480 " ignore-all, report-all, ignore-in-object-files,\n"
481 " ignore-in-shared-libs"),
482 TWO_DASHES },
1715a13c
L
483 { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
484 '\0', N_("[=NUMBER]"),
485 N_("Output lots of information during link"), TWO_DASHES },
252b5132 486 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
6feb9908 487 '\0', NULL, NULL, NO_HELP },
252b5132 488 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
6feb9908 489 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
252b5132
RH
490 { {"version-exports-section", required_argument, NULL,
491 OPTION_VERSION_EXPORTS_SECTION },
6feb9908 492 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
c58dea77
AM
493 " SYMBOL as the version."),
494 TWO_DASHES },
40b36307
L
495 { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
496 '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
497 { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
498 '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
55255dae
L
499 { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
500 '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
501 { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
502 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
252b5132 503 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
6feb9908 504 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
252b5132 505 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
6feb9908
AM
506 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
507 TWO_DASHES },
252b5132 508 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
6feb9908 509 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
252b5132 510 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
6feb9908 511 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
252b5132 512 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
6feb9908
AM
513 '\0', NULL, N_("Warn if start of section changes due to alignment"),
514 TWO_DASHES },
8fdd7217
NC
515 { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
516 '\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
517 TWO_DASHES },
a0c402a5
L
518 { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
519 '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
520 TWO_DASHES },
6feb9908
AM
521 { {"warn-unresolved-symbols", no_argument, NULL,
522 OPTION_WARN_UNRESOLVED_SYMBOLS},
560e09e9 523 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
6feb9908
AM
524 { {"error-unresolved-symbols", no_argument, NULL,
525 OPTION_ERROR_UNRESOLVED_SYMBOLS},
560e09e9 526 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
252b5132 527 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
6feb9908
AM
528 '\0', NULL, N_("Include all objects from following archives"),
529 TWO_DASHES },
252b5132 530 { {"wrap", required_argument, NULL, OPTION_WRAP},
6feb9908 531 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
0e86e20e
AM
532 { {"ignore-unresolved-symbol", required_argument, NULL,
533 OPTION_IGNORE_UNRESOLVED_SYMBOL},
534 '\0', N_("SYMBOL"),
535 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
26278bb8
UD
536 { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
537 '\0', NULL, N_("Push state of flags governing input file handling"),
538 TWO_DASHES },
539 { {"pop-state", no_argument, NULL, OPTION_POP_STATE},
540 '\0', NULL, N_("Pop state of flags governing input file handling"),
541 TWO_DASHES },
3604cb1f
TG
542 { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE},
543 '\0', NULL, N_("Report target memory usage"), TWO_DASHES },
c005eb9e
AB
544 { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING},
545 '\0', N_("=MODE"), N_("Control how orphan sections are handled."),
546 TWO_DASHES },
035801ce
FS
547 { {"print-map-discarded", no_argument, NULL, OPTION_PRINT_MAP_DISCARDED},
548 '\0', NULL, N_("Show discarded sections in map file output (default)"),
549 TWO_DASHES },
550 { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISCARDED},
551 '\0', NULL, N_("Do not show discarded sections in map file output"),
552 TWO_DASHES },
252b5132
RH
553};
554
e4897a32 555#define OPTION_COUNT ARRAY_SIZE (ld_options)
252b5132 556
252b5132 557void
1579bae1 558parse_args (unsigned argc, char **argv)
252b5132 559{
e4897a32
NC
560 unsigned i;
561 int is, il, irl;
252b5132
RH
562 int ingroup = 0;
563 char *default_dirlist = NULL;
3bcf5557
AM
564 char *shortopts;
565 struct option *longopts;
566 struct option *really_longopts;
252b5132 567 int last_optind;
560e09e9 568 enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
1914e264
AM
569 enum symbolic_enum
570 {
571 symbolic_unset = 0,
572 symbolic,
573 symbolic_functions,
574 } opt_symbolic = symbolic_unset;
575 enum dynamic_list_enum
576 {
577 dynamic_list_unset = 0,
578 dynamic_list_data,
579 dynamic_list
580 } opt_dynamic_list = dynamic_list_unset;
252b5132 581
1e9cc1c2
NC
582 shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
583 longopts = (struct option *)
584 xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
585 really_longopts = (struct option *)
586 malloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
3bcf5557 587
252b5132
RH
588 /* Starting the short option string with '-' is for programs that
589 expect options and other ARGV-elements in any order and that care about
590 the ordering of the two. We describe each non-option ARGV-element
591 as if it were the argument of an option with character code 1. */
592 shortopts[0] = '-';
593 is = 1;
594 il = 0;
e4897a32 595 irl = 0;
252b5132
RH
596 for (i = 0; i < OPTION_COUNT; i++)
597 {
598 if (ld_options[i].shortopt != '\0')
599 {
600 shortopts[is] = ld_options[i].shortopt;
601 ++is;
602 if (ld_options[i].opt.has_arg == required_argument
603 || ld_options[i].opt.has_arg == optional_argument)
604 {
605 shortopts[is] = ':';
606 ++is;
607 if (ld_options[i].opt.has_arg == optional_argument)
608 {
609 shortopts[is] = ':';
610 ++is;
611 }
612 }
613 }
614 if (ld_options[i].opt.name != NULL)
615 {
e4897a32
NC
616 if (ld_options[i].control == EXACTLY_TWO_DASHES)
617 {
618 really_longopts[irl] = ld_options[i].opt;
619 ++irl;
620 }
621 else
622 {
623 longopts[il] = ld_options[i].opt;
624 ++il;
625 }
252b5132
RH
626 }
627 }
628 shortopts[is] = '\0';
629 longopts[il].name = NULL;
e4897a32 630 really_longopts[irl].name = NULL;
252b5132 631
3bcf5557
AM
632 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
633
252b5132
RH
634 /* The -G option is ambiguous on different platforms. Sometimes it
635 specifies the largest data size to put into the small data
636 section. Sometimes it is equivalent to --shared. Unfortunately,
637 the first form takes an argument, while the second does not.
638
639 We need to permit the --shared form because on some platforms,
640 such as Solaris, gcc -shared will pass -G to the linker.
641
642 To permit either usage, we look through the argument list. If we
643 find -G not followed by a number, we change it into --shared.
644 This will work for most normal cases. */
645 for (i = 1; i < argc; i++)
646 if (strcmp (argv[i], "-G") == 0
647 && (i + 1 >= argc
3882b010 648 || ! ISDIGIT (argv[i + 1][0])))
252b5132
RH
649 argv[i] = (char *) "--shared";
650
651 /* Because we permit long options to start with a single dash, and
652 we have a --library option, and the -l option is conventionally
653 used with an immediately following argument, we can have bad
654 results if somebody tries to use -l with a library whose name
655 happens to start with "ibrary", as in -li. We avoid problems by
656 simply turning -l into --library. This means that users will
657 have to use two dashes in order to use --library, which is OK
658 since that's how it is documented.
659
660 FIXME: It's possible that this problem can arise for other short
661 options as well, although the user does always have the recourse
662 of adding a space between the option and the argument. */
663 for (i = 1; i < argc; i++)
664 {
665 if (argv[i][0] == '-'
666 && argv[i][1] == 'l'
667 && argv[i][2] != '\0')
668 {
669 char *n;
670
1e9cc1c2 671 n = (char *) xmalloc (strlen (argv[i]) + 20);
252b5132
RH
672 sprintf (n, "--library=%s", argv[i] + 2);
673 argv[i] = n;
674 }
675 }
676
677 last_optind = -1;
678 while (1)
679 {
89894c62 680 int longind;
252b5132 681 int optc;
dab69f68 682 static unsigned int defsym_count;
252b5132
RH
683
684 /* Using last_optind lets us avoid calling ldemul_parse_args
685 multiple times on a single option, which would lead to
686 confusion in the internal static variables maintained by
687 getopt. This could otherwise happen for an argument like
688 -nx, in which the -n is parsed as a single option, and we
689 loop around to pick up the -x. */
690 if (optind != last_optind)
89894c62
AM
691 if (ldemul_parse_args (argc, argv))
692 continue;
252b5132
RH
693
694 /* getopt_long_only is like getopt_long, but '-' as well as '--'
695 can indicate a long option. */
0fc3347a 696 opterr = 0;
89894c62 697 last_optind = optind;
252b5132 698 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
0fc3347a
NC
699 if (optc == '?')
700 {
89894c62
AM
701 optind = last_optind;
702 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
0fc3347a 703 }
b7ed8fad 704
3bcf5557
AM
705 if (ldemul_handle_option (optc))
706 continue;
707
252b5132
RH
708 if (optc == -1)
709 break;
0fc3347a 710
252b5132
RH
711 switch (optc)
712 {
0fc3347a 713 case '?':
f82aa165
NC
714 {
715 /* If the last word on the command line is an option that
716 requires an argument, getopt will refuse to recognise it.
717 Try to catch such options here and issue a more helpful
718 error message than just "unrecognized option". */
719 int opt;
720
721 for (opt = ARRAY_SIZE (ld_options); opt--;)
722 if (ld_options[opt].opt.has_arg == required_argument
723 /* FIXME: There are a few short options that do not
724 have long equivalents, but which require arguments.
725 We should handle them too. */
726 && ld_options[opt].opt.name != NULL
727 && strcmp (argv[last_optind] + ld_options[opt].control, ld_options[opt].opt.name) == 0)
728 {
729 einfo (_("%P: %s: missing argument\n"), argv[last_optind]);
730 break;
731 }
732
733 if (opt == -1)
734 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
735 }
058a363d
BE
736 /* Fall through. */
737
252b5132 738 default:
df5f2391 739 einfo (_("%F%P: use the --help option for usage information\n"));
80bb3407 740 break;
210a7bd1 741
252b5132 742 case 1: /* File name. */
1579bae1 743 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
252b5132
RH
744 break;
745
746 case OPTION_IGNORE:
747 break;
748 case 'a':
749 /* For HP/UX compatibility. Actually -a shared should mean
1579bae1
AM
750 ``use only shared libraries'' but, then, we don't
751 currently support shared libraries on HP/UX anyhow. */
252b5132 752 if (strcmp (optarg, "archive") == 0)
66be1055 753 input_flags.dynamic = FALSE;
252b5132
RH
754 else if (strcmp (optarg, "shared") == 0
755 || strcmp (optarg, "default") == 0)
66be1055 756 input_flags.dynamic = TRUE;
252b5132 757 else
df5f2391 758 einfo (_("%F%P: unrecognized -a option `%s'\n"), optarg);
252b5132
RH
759 break;
760 case OPTION_ASSERT:
761 /* FIXME: We just ignore these, but we should handle them. */
762 if (strcmp (optarg, "definitions") == 0)
763 ;
764 else if (strcmp (optarg, "nodefinitions") == 0)
765 ;
766 else if (strcmp (optarg, "nosymbolic") == 0)
767 ;
768 else if (strcmp (optarg, "pure-text") == 0)
769 ;
770 else
df5f2391 771 einfo (_("%F%P: unrecognized -assert option `%s'\n"), optarg);
252b5132
RH
772 break;
773 case 'A':
774 ldfile_add_arch (optarg);
775 break;
776 case 'b':
777 lang_add_target (optarg);
778 break;
779 case 'c':
780 ldfile_open_command_file (optarg);
781 parser_input = input_mri_script;
782 yyparse ();
783 break;
784 case OPTION_CALL_SHARED:
66be1055 785 input_flags.dynamic = TRUE;
252b5132
RH
786 break;
787 case OPTION_NON_SHARED:
66be1055 788 input_flags.dynamic = FALSE;
252b5132
RH
789 break;
790 case OPTION_CREF:
b34976b6
AM
791 command_line.cref = TRUE;
792 link_info.notice_all = TRUE;
252b5132
RH
793 break;
794 case 'd':
b34976b6 795 command_line.force_common_definition = TRUE;
252b5132 796 break;
6c19b93b
AM
797 case OPTION_FORCE_GROUP_ALLOCATION:
798 command_line.force_group_allocation = TRUE;
799 break;
252b5132
RH
800 case OPTION_DEFSYM:
801 lex_string = optarg;
dab69f68 802 lex_redirect (optarg, "--defsym", ++defsym_count);
252b5132 803 parser_input = input_defsym;
252b5132 804 yyparse ();
252b5132
RH
805 lex_string = NULL;
806 break;
807 case OPTION_DEMANGLE:
b34976b6 808 demangling = TRUE;
28c309a2
NC
809 if (optarg != NULL)
810 {
811 enum demangling_styles style;
5cc18311 812
28c309a2 813 style = cplus_demangle_name_to_style (optarg);
5cc18311 814 if (style == unknown_demangling)
1d6d1a2c 815 einfo (_("%F%P: unknown demangling style `%s'\n"),
28c309a2 816 optarg);
5cc18311 817
28c309a2 818 cplus_demangle_set_style (style);
e47d05ad 819 }
252b5132 820 break;
506eee22 821 case 'I': /* Used on Solaris. */
252b5132
RH
822 case OPTION_DYNAMIC_LINKER:
823 command_line.interpreter = optarg;
9b8b325a
RF
824 link_info.nointerp = 0;
825 break;
826 case OPTION_NO_DYNAMIC_LINKER:
827 link_info.nointerp = 1;
252b5132 828 break;
e2243057
RS
829 case OPTION_SYSROOT:
830 /* Already handled in ldmain.c. */
831 break;
252b5132
RH
832 case OPTION_EB:
833 command_line.endian = ENDIAN_BIG;
834 break;
835 case OPTION_EL:
836 command_line.endian = ENDIAN_LITTLE;
837 break;
838 case OPTION_EMBEDDED_RELOCS:
b34976b6 839 command_line.embedded_relocs = TRUE;
252b5132
RH
840 break;
841 case OPTION_EXPORT_DYNAMIC:
842 case 'E': /* HP/UX compatibility. */
b34976b6 843 link_info.export_dynamic = TRUE;
252b5132 844 break;
267e2722
CD
845 case OPTION_NO_EXPORT_DYNAMIC:
846 link_info.export_dynamic = FALSE;
847 break;
252b5132 848 case 'e':
b34976b6 849 lang_add_entry (optarg, TRUE);
252b5132
RH
850 break;
851 case 'f':
852 if (command_line.auxiliary_filters == NULL)
853 {
1e9cc1c2 854 command_line.auxiliary_filters = (char **)
6c19b93b 855 xmalloc (2 * sizeof (char *));
252b5132
RH
856 command_line.auxiliary_filters[0] = optarg;
857 command_line.auxiliary_filters[1] = NULL;
858 }
859 else
860 {
861 int c;
862 char **p;
863
864 c = 0;
865 for (p = command_line.auxiliary_filters; *p != NULL; p++)
866 ++c;
1e9cc1c2 867 command_line.auxiliary_filters = (char **)
6c19b93b
AM
868 xrealloc (command_line.auxiliary_filters,
869 (c + 2) * sizeof (char *));
252b5132
RH
870 command_line.auxiliary_filters[c] = optarg;
871 command_line.auxiliary_filters[c + 1] = NULL;
872 }
873 break;
874 case 'F':
875 command_line.filter_shlib = optarg;
876 break;
877 case OPTION_FORCE_EXE_SUFFIX:
b34976b6 878 command_line.force_exe_suffix = TRUE;
252b5132
RH
879 break;
880 case 'G':
881 {
882 char *end;
883 g_switch_value = strtoul (optarg, &end, 0);
884 if (*end)
df5f2391 885 einfo (_("%F%P: invalid number `%s'\n"), optarg);
252b5132
RH
886 }
887 break;
888 case 'g':
889 /* Ignore. */
890 break;
891 case OPTION_GC_SECTIONS:
57316bff 892 link_info.gc_sections = TRUE;
252b5132 893 break;
c17d87de
NC
894 case OPTION_PRINT_GC_SECTIONS:
895 link_info.print_gc_sections = TRUE;
896 break;
22185505 897 case OPTION_GC_KEEP_EXPORTED:
898 link_info.gc_keep_exported = TRUE;
899 break;
252b5132
RH
900 case OPTION_HELP:
901 help ();
902 xexit (0);
903 break;
904 case 'L':
b34976b6 905 ldfile_add_library_path (optarg, TRUE);
252b5132
RH
906 break;
907 case 'l':
1579bae1 908 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
252b5132
RH
909 break;
910 case 'M':
911 config.map_filename = "-";
912 break;
913 case 'm':
914 /* Ignore. Was handled in a pre-parse. */
915 break;
916 case OPTION_MAP:
917 config.map_filename = optarg;
918 break;
919 case 'N':
b34976b6
AM
920 config.text_read_only = FALSE;
921 config.magic_demand_paged = FALSE;
66be1055 922 input_flags.dynamic = FALSE;
252b5132 923 break;
63fd3b82 924 case OPTION_NO_OMAGIC:
b34976b6
AM
925 config.text_read_only = TRUE;
926 config.magic_demand_paged = TRUE;
66be1055 927 /* NB/ Does not set input_flags.dynamic to TRUE.
63fd3b82
NC
928 Use --call-shared or -Bdynamic for this. */
929 break;
252b5132 930 case 'n':
b34976b6 931 config.magic_demand_paged = FALSE;
66be1055 932 input_flags.dynamic = FALSE;
252b5132 933 break;
4818e05f 934 case OPTION_NO_DEFINE_COMMON:
a4819f54 935 link_info.inhibit_common_definition = TRUE;
4818e05f 936 break;
252b5132 937 case OPTION_NO_DEMANGLE:
b34976b6 938 demangling = FALSE;
252b5132
RH
939 break;
940 case OPTION_NO_GC_SECTIONS:
57316bff 941 link_info.gc_sections = FALSE;
252b5132 942 break;
c17d87de
NC
943 case OPTION_NO_PRINT_GC_SECTIONS:
944 link_info.print_gc_sections = FALSE;
945 break;
252b5132 946 case OPTION_NO_KEEP_MEMORY:
b34976b6 947 link_info.keep_memory = FALSE;
252b5132
RH
948 break;
949 case OPTION_NO_UNDEFINED:
6feb9908
AM
950 link_info.unresolved_syms_in_objects
951 = how_to_report_unresolved_symbols;
252b5132 952 break;
b79e8c78 953 case OPTION_ALLOW_SHLIB_UNDEFINED:
560e09e9 954 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
b79e8c78 955 break;
ae9a127f 956 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
6feb9908
AM
957 link_info.unresolved_syms_in_shared_libs
958 = how_to_report_unresolved_symbols;
ae9a127f 959 break;
560e09e9
NC
960 case OPTION_UNRESOLVED_SYMBOLS:
961 if (strcmp (optarg, "ignore-all") == 0)
962 {
963 link_info.unresolved_syms_in_objects = RM_IGNORE;
964 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
965 }
966 else if (strcmp (optarg, "report-all") == 0)
967 {
6feb9908
AM
968 link_info.unresolved_syms_in_objects
969 = how_to_report_unresolved_symbols;
970 link_info.unresolved_syms_in_shared_libs
971 = how_to_report_unresolved_symbols;
560e09e9
NC
972 }
973 else if (strcmp (optarg, "ignore-in-object-files") == 0)
974 {
975 link_info.unresolved_syms_in_objects = RM_IGNORE;
6feb9908
AM
976 link_info.unresolved_syms_in_shared_libs
977 = how_to_report_unresolved_symbols;
560e09e9 978 }
6c19b93b 979 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
560e09e9 980 {
6feb9908
AM
981 link_info.unresolved_syms_in_objects
982 = how_to_report_unresolved_symbols;
560e09e9
NC
983 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
984 }
985 else
df5f2391 986 einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg);
560e09e9
NC
987 break;
988 case OPTION_WARN_UNRESOLVED_SYMBOLS:
989 how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
990 if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
991 link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
992 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
993 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
994 break;
6feb9908 995
560e09e9
NC
996 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
997 how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
998 if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
999 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
1000 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
1001 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
6feb9908 1002 break;
aa713662 1003 case OPTION_ALLOW_MULTIPLE_DEFINITION:
b34976b6 1004 link_info.allow_multiple_definition = TRUE;
aa713662 1005 break;
31941635 1006 case OPTION_NO_UNDEFINED_VERSION:
b34976b6 1007 link_info.allow_undefined_version = FALSE;
31941635 1008 break;
3e3b46e5
PB
1009 case OPTION_DEFAULT_SYMVER:
1010 link_info.create_default_symver = TRUE;
1011 break;
fc0e6df6
PB
1012 case OPTION_DEFAULT_IMPORTED_SYMVER:
1013 link_info.default_imported_symver = TRUE;
1014 break;
252b5132 1015 case OPTION_NO_WARN_MISMATCH:
b34976b6 1016 command_line.warn_mismatch = FALSE;
252b5132 1017 break;
fe7929ce
AM
1018 case OPTION_NO_WARN_SEARCH_MISMATCH:
1019 command_line.warn_search_mismatch = FALSE;
1020 break;
252b5132 1021 case OPTION_NOINHIBIT_EXEC:
b34976b6 1022 force_make_executable = TRUE;
252b5132 1023 break;
361b220e 1024 case OPTION_NOSTDLIB:
b34976b6 1025 config.only_cmd_line_lib_dirs = TRUE;
361b220e 1026 break;
252b5132 1027 case OPTION_NO_WHOLE_ARCHIVE:
66be1055 1028 input_flags.whole_archive = FALSE;
252b5132
RH
1029 break;
1030 case 'O':
1031 /* FIXME "-O<non-digits> <value>" used to set the address of
1032 section <non-digits>. Was this for compatibility with
1033 something, or can we create a new option to do that
1034 (with a syntax similar to -defsym)?
1035 getopt can't handle two args to an option without kludges. */
1036
1037 /* Enable optimizations of output files. */
b34976b6 1038 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
252b5132
RH
1039 break;
1040 case 'o':
5cc18311 1041 lang_add_output (optarg, 0);
252b5132
RH
1042 break;
1043 case OPTION_OFORMAT:
1579bae1 1044 lang_add_output_format (optarg, NULL, NULL, 0);
252b5132 1045 break;
76359541
TP
1046 case OPTION_OUT_IMPLIB:
1047 command_line.out_implib_filename = xstrdup (optarg);
1048 break;
cb9322a8
HPN
1049 case OPTION_PRINT_SYSROOT:
1050 if (*ld_sysroot)
1051 puts (ld_sysroot);
1052 xexit (0);
1053 break;
30824704
RM
1054 case OPTION_PRINT_OUTPUT_FORMAT:
1055 command_line.print_output_format = TRUE;
1056 break;
5d3236ee
DK
1057#ifdef ENABLE_PLUGINS
1058 case OPTION_PLUGIN:
d82184d7 1059 plugin_opt_plugin (optarg);
5d3236ee
DK
1060 break;
1061 case OPTION_PLUGIN_OPT:
1062 if (plugin_opt_plugin_arg (optarg))
df5f2391 1063 einfo (_("%F%P: bad -plugin-opt option\n"));
5d3236ee
DK
1064 break;
1065#endif /* ENABLE_PLUGINS */
a712da20 1066 case 'q':
b34976b6 1067 link_info.emitrelocations = TRUE;
a712da20 1068 break;
8c5ff972 1069 case 'i':
252b5132 1070 case 'r':
210a7bd1
NC
1071 if (optind == last_optind)
1072 /* This can happen if the user put "-rpath,a" on the command
1073 line. (Or something similar. The comma is important).
1074 Getopt becomes confused and thinks that this is a -r option
1075 but it cannot parse the text after the -r so it refuses to
1076 increment the optind counter. Detect this case and issue
1077 an error message here. We cannot just make this a warning,
1078 increment optind, and continue because getopt is too confused
1079 and will seg-fault the next time around. */
df5f2391 1080 einfo(_("%F%P: unrecognised option: %s\n"), argv[optind]);
b7a26f91 1081
0e1862bb 1082 if (bfd_link_pic (&link_info))
df5f2391 1083 einfo (_("%F%P: -r and %s may not be used together\n"),
0e1862bb
L
1084 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1085
1086 link_info.type = type_relocatable;
b34976b6
AM
1087 config.build_constructors = FALSE;
1088 config.magic_demand_paged = FALSE;
1089 config.text_read_only = FALSE;
66be1055 1090 input_flags.dynamic = FALSE;
252b5132
RH
1091 break;
1092 case 'R':
1093 /* The GNU linker traditionally uses -R to mean to include
1094 only the symbols from a file. The Solaris linker uses -R
1095 to set the path used by the runtime linker to find
1096 libraries. This is the GNU linker -rpath argument. We
1097 try to support both simultaneously by checking the file
1098 named. If it is a directory, rather than a regular file,
1099 we assume -rpath was meant. */
1100 {
1101 struct stat s;
1102
1103 if (stat (optarg, &s) >= 0
1104 && ! S_ISDIR (s.st_mode))
1105 {
1106 lang_add_input_file (optarg,
1107 lang_input_file_is_symbols_only_enum,
1579bae1 1108 NULL);
252b5132
RH
1109 break;
1110 }
1111 }
1112 /* Fall through. */
1113 case OPTION_RPATH:
1114 if (command_line.rpath == NULL)
d1b2b2dc 1115 command_line.rpath = xstrdup (optarg);
252b5132
RH
1116 else
1117 {
1118 size_t rpath_len = strlen (command_line.rpath);
1119 size_t optarg_len = strlen (optarg);
1120 char *buf;
1121 char *cp = command_line.rpath;
1122
1123 /* First see whether OPTARG is already in the path. */
1124 do
1125 {
c76308d2
RS
1126 if (strncmp (optarg, cp, optarg_len) == 0
1127 && (cp[optarg_len] == 0
1128 || cp[optarg_len] == config.rpath_separator))
252b5132
RH
1129 /* We found it. */
1130 break;
1131
1132 /* Not yet found. */
c76308d2 1133 cp = strchr (cp, config.rpath_separator);
252b5132
RH
1134 if (cp != NULL)
1135 ++cp;
1136 }
1137 while (cp != NULL);
1138
1139 if (cp == NULL)
1140 {
1e9cc1c2 1141 buf = (char *) xmalloc (rpath_len + optarg_len + 2);
c76308d2
RS
1142 sprintf (buf, "%s%c%s", command_line.rpath,
1143 config.rpath_separator, optarg);
252b5132
RH
1144 free (command_line.rpath);
1145 command_line.rpath = buf;
1146 }
1147 }
1148 break;
1149 case OPTION_RPATH_LINK:
1150 if (command_line.rpath_link == NULL)
d1b2b2dc 1151 command_line.rpath_link = xstrdup (optarg);
252b5132
RH
1152 else
1153 {
1154 char *buf;
1155
1e9cc1c2 1156 buf = (char *) xmalloc (strlen (command_line.rpath_link)
6c19b93b
AM
1157 + strlen (optarg)
1158 + 2);
c76308d2
RS
1159 sprintf (buf, "%s%c%s", command_line.rpath_link,
1160 config.rpath_separator, optarg);
252b5132
RH
1161 free (command_line.rpath_link);
1162 command_line.rpath_link = buf;
1163 }
1164 break;
28d5f677
NC
1165 case OPTION_NO_RELAX:
1166 DISABLE_RELAXATION;
1167 break;
252b5132 1168 case OPTION_RELAX:
28d5f677 1169 ENABLE_RELAXATION;
252b5132
RH
1170 break;
1171 case OPTION_RETAIN_SYMBOLS_FILE:
1172 add_keepsyms_file (optarg);
1173 break;
1174 case 'S':
1175 link_info.strip = strip_debugger;
1176 break;
1177 case 's':
1178 link_info.strip = strip_all;
1179 break;
d5cd3933
AM
1180 case OPTION_STRIP_DISCARDED:
1181 link_info.strip_discarded = TRUE;
1182 break;
1183 case OPTION_NO_STRIP_DISCARDED:
1184 link_info.strip_discarded = FALSE;
1185 break;
3f0a5f17
ME
1186 case OPTION_DISABLE_MULTIPLE_DEFS_ABS:
1187 link_info.prohibit_multiple_definition_absolute = TRUE;
1188 break;
252b5132
RH
1189 case OPTION_SHARED:
1190 if (config.has_shared)
560e09e9 1191 {
0e1862bb 1192 if (bfd_link_relocatable (&link_info))
df5f2391
AM
1193 einfo (_("%F%P: -r and %s may not be used together\n"),
1194 "-shared");
0e1862bb
L
1195
1196 link_info.type = type_dll;
560e09e9
NC
1197 /* When creating a shared library, the default
1198 behaviour is to ignore any unresolved references. */
1199 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1200 link_info.unresolved_syms_in_objects = RM_IGNORE;
1201 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1202 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1203 }
252b5132 1204 else
df5f2391 1205 einfo (_("%F%P: -shared not supported\n"));
252b5132 1206 break;
36af4a4e
JJ
1207 case OPTION_PIE:
1208 if (config.has_shared)
1209 {
0e1862bb 1210 if (bfd_link_relocatable (&link_info))
df5f2391 1211 einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
0e1862bb 1212
64d94ba0 1213 link_info.type = type_pie;
36af4a4e
JJ
1214 }
1215 else
df5f2391 1216 einfo (_("%F%P: -pie not supported\n"));
36af4a4e 1217 break;
252b5132
RH
1218 case 'h': /* Used on Solaris. */
1219 case OPTION_SONAME:
b0054819
UD
1220 if (optarg[0] == '\0' && command_line.soname
1221 && command_line.soname[0])
1222 einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
1223 else
1224 command_line.soname = optarg;
252b5132
RH
1225 break;
1226 case OPTION_SORT_COMMON:
de7dd2bd
NC
1227 if (optarg == NULL
1228 || strcmp (optarg, N_("descending")) == 0)
6c19b93b
AM
1229 config.sort_common = sort_descending;
1230 else if (strcmp (optarg, N_("ascending")) == 0)
de7dd2bd
NC
1231 config.sort_common = sort_ascending;
1232 else
df5f2391 1233 einfo (_("%F%P: invalid common section sorting option: %s\n"),
de7dd2bd 1234 optarg);
252b5132 1235 break;
bcaa7b3e
L
1236 case OPTION_SORT_SECTION:
1237 if (strcmp (optarg, N_("name")) == 0)
1238 sort_section = by_name;
1239 else if (strcmp (optarg, N_("alignment")) == 0)
1240 sort_section = by_alignment;
1241 else
df5f2391 1242 einfo (_("%F%P: invalid section sorting option: %s\n"),
bcaa7b3e
L
1243 optarg);
1244 break;
252b5132 1245 case OPTION_STATS:
b34976b6 1246 config.stats = TRUE;
252b5132
RH
1247 break;
1248 case OPTION_SYMBOLIC:
1914e264 1249 opt_symbolic = symbolic;
d8cf8b51
L
1250 break;
1251 case OPTION_SYMBOLIC_FUNCTIONS:
1914e264 1252 opt_symbolic = symbolic_functions;
252b5132
RH
1253 break;
1254 case 't':
727a29ba 1255 ++trace_files;
252b5132
RH
1256 break;
1257 case 'T':
53d25da6 1258 previous_script_handle = saved_script_handle;
6ec6968b 1259 ldfile_open_script_file (optarg);
252b5132
RH
1260 parser_input = input_script;
1261 yyparse ();
53d25da6 1262 previous_script_handle = NULL;
252b5132 1263 break;
14be8564
L
1264 case OPTION_DEFAULT_SCRIPT:
1265 command_line.default_script = optarg;
1266 break;
176355da
NC
1267 case OPTION_SECTION_START:
1268 {
1269 char *optarg2;
227aeb07
AM
1270 char *sec_name;
1271 int len;
176355da
NC
1272
1273 /* Check for <something>=<somthing>... */
1274 optarg2 = strchr (optarg, '=');
1275 if (optarg2 == NULL)
df5f2391 1276 einfo (_("%F%P: invalid argument to option"
6feb9908 1277 " \"--section-start\"\n"));
176355da 1278
e47d05ad 1279 optarg2++;
5cc18311 1280
176355da
NC
1281 /* So far so good. Are all the args present? */
1282 if ((*optarg == '\0') || (*optarg2 == '\0'))
df5f2391 1283 einfo (_("%F%P: missing argument(s) to option"
6feb9908 1284 " \"--section-start\"\n"));
176355da 1285
227aeb07
AM
1286 /* We must copy the section name as set_section_start
1287 doesn't do it for us. */
1288 len = optarg2 - optarg;
1e9cc1c2 1289 sec_name = (char *) xmalloc (len);
227aeb07
AM
1290 memcpy (sec_name, optarg, len - 1);
1291 sec_name[len - 1] = 0;
176355da
NC
1292
1293 /* Then set it... */
227aeb07 1294 set_section_start (sec_name, optarg2);
176355da
NC
1295 }
1296 break;
ea20a7da
CC
1297 case OPTION_TARGET_HELP:
1298 /* Mention any target specific options. */
b7a26f91
KH
1299 ldemul_list_emulation_options (stdout);
1300 exit (0);
252b5132 1301 case OPTION_TBSS:
ba916c8a 1302 set_segment_start (".bss", optarg);
252b5132
RH
1303 break;
1304 case OPTION_TDATA:
ba916c8a 1305 set_segment_start (".data", optarg);
252b5132
RH
1306 break;
1307 case OPTION_TTEXT:
ba916c8a 1308 set_segment_start (".text", optarg);
252b5132 1309 break;
258795f5
L
1310 case OPTION_TTEXT_SEGMENT:
1311 set_segment_start (".text-segment", optarg);
1312 break;
9d5777a3
RM
1313 case OPTION_TRODATA_SEGMENT:
1314 set_segment_start (".rodata-segment", optarg);
1315 break;
0d705e9f
AM
1316 case OPTION_TLDATA_SEGMENT:
1317 set_segment_start (".ldata-segment", optarg);
1318 break;
252b5132 1319 case OPTION_TRADITIONAL_FORMAT:
b34976b6 1320 link_info.traditional_format = TRUE;
252b5132
RH
1321 break;
1322 case OPTION_TASK_LINK:
b34976b6 1323 link_info.task_link = TRUE;
1a0670f3 1324 /* Fall through. */
252b5132 1325 case OPTION_UR:
0e1862bb 1326 if (bfd_link_pic (&link_info))
df5f2391 1327 einfo (_("%F%P: -r and %s may not be used together\n"),
0e1862bb
L
1328 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1329
1330 link_info.type = type_relocatable;
b34976b6
AM
1331 config.build_constructors = TRUE;
1332 config.magic_demand_paged = FALSE;
1333 config.text_read_only = FALSE;
66be1055 1334 input_flags.dynamic = FALSE;
252b5132
RH
1335 break;
1336 case 'u':
24898b70 1337 ldlang_add_undef (optarg, TRUE);
252b5132 1338 break;
6c19b93b
AM
1339 case OPTION_REQUIRE_DEFINED_SYMBOL:
1340 ldlang_add_require_defined (optarg);
0a618243 1341 break;
a854a4a7 1342 case OPTION_UNIQUE:
577a0623
AM
1343 if (optarg != NULL)
1344 lang_add_unique (optarg);
1345 else
b34976b6 1346 config.unique_orphan_sections = TRUE;
a854a4a7 1347 break;
252b5132
RH
1348 case OPTION_VERBOSE:
1349 ldversion (1);
b34976b6 1350 version_printed = TRUE;
cd6f1cf3 1351 verbose = TRUE;
8aae64e6 1352 overflow_cutoff_limit = -2;
1715a13c
L
1353 if (optarg != NULL)
1354 {
1355 char *end;
d436a15e 1356 int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
1715a13c 1357 if (*end)
df5f2391 1358 einfo (_("%F%P: invalid number `%s'\n"), optarg);
d436a15e 1359#ifdef ENABLE_PLUGINS
1715a13c 1360 report_plugin_symbols = level > 1;
d436a15e 1361#endif /* ENABLE_PLUGINS */
1715a13c 1362 }
252b5132
RH
1363 break;
1364 case 'v':
1365 ldversion (0);
b34976b6 1366 version_printed = TRUE;
252b5132
RH
1367 break;
1368 case 'V':
1369 ldversion (1);
b34976b6 1370 version_printed = TRUE;
252b5132
RH
1371 break;
1372 case OPTION_VERSION:
d32820f2 1373 ldversion (2);
252b5132
RH
1374 xexit (0);
1375 break;
1376 case OPTION_VERSION_SCRIPT:
1377 /* This option indicates a small script that only specifies
1579bae1
AM
1378 version information. Read it, but don't assume that
1379 we've seen a linker script. */
252b5132 1380 {
b7a26f91 1381 FILE *hold_script_handle;
252b5132 1382
b9a8de1e 1383 hold_script_handle = saved_script_handle;
252b5132 1384 ldfile_open_command_file (optarg);
b9a8de1e 1385 saved_script_handle = hold_script_handle;
252b5132
RH
1386 parser_input = input_version_script;
1387 yyparse ();
1388 }
1389 break;
1390 case OPTION_VERSION_EXPORTS_SECTION:
1391 /* This option records a version symbol to be applied to the
1392 symbols listed for export to be found in the object files
1393 .exports sections. */
1394 command_line.version_exports_section = optarg;
1395 break;
40b36307 1396 case OPTION_DYNAMIC_LIST_DATA:
1914e264
AM
1397 opt_dynamic_list = dynamic_list_data;
1398 if (opt_symbolic == symbolic)
1399 opt_symbolic = symbolic_unset;
40b36307 1400 break;
55255dae
L
1401 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1402 lang_append_dynamic_list_cpp_typeinfo ();
1914e264
AM
1403 if (opt_dynamic_list != dynamic_list_data)
1404 opt_dynamic_list = dynamic_list;
1405 if (opt_symbolic == symbolic)
1406 opt_symbolic = symbolic_unset;
40b36307
L
1407 break;
1408 case OPTION_DYNAMIC_LIST_CPP_NEW:
1409 lang_append_dynamic_list_cpp_new ();
1914e264
AM
1410 if (opt_dynamic_list != dynamic_list_data)
1411 opt_dynamic_list = dynamic_list;
1412 if (opt_symbolic == symbolic)
1413 opt_symbolic = symbolic_unset;
55255dae
L
1414 break;
1415 case OPTION_DYNAMIC_LIST:
1416 /* This option indicates a small script that only specifies
1417 a dynamic list. Read it, but don't assume that we've
1418 seen a linker script. */
1419 {
1420 FILE *hold_script_handle;
1421
1422 hold_script_handle = saved_script_handle;
1423 ldfile_open_command_file (optarg);
1424 saved_script_handle = hold_script_handle;
1425 parser_input = input_dynamic_list;
1426 yyparse ();
1427 }
1914e264
AM
1428 if (opt_dynamic_list != dynamic_list_data)
1429 opt_dynamic_list = dynamic_list;
1430 if (opt_symbolic == symbolic)
1431 opt_symbolic = symbolic_unset;
55255dae 1432 break;
252b5132 1433 case OPTION_WARN_COMMON:
b34976b6 1434 config.warn_common = TRUE;
252b5132
RH
1435 break;
1436 case OPTION_WARN_CONSTRUCTORS:
b34976b6 1437 config.warn_constructors = TRUE;
252b5132 1438 break;
7ce691ae 1439 case OPTION_WARN_FATAL:
b34976b6 1440 config.fatal_warnings = TRUE;
7ce691ae 1441 break;
0fe58ccd
NC
1442 case OPTION_NO_WARN_FATAL:
1443 config.fatal_warnings = FALSE;
1444 break;
252b5132 1445 case OPTION_WARN_MULTIPLE_GP:
b34976b6 1446 config.warn_multiple_gp = TRUE;
252b5132
RH
1447 break;
1448 case OPTION_WARN_ONCE:
b34976b6 1449 config.warn_once = TRUE;
252b5132
RH
1450 break;
1451 case OPTION_WARN_SECTION_ALIGN:
b34976b6 1452 config.warn_section_align = TRUE;
252b5132 1453 break;
8fdd7217
NC
1454 case OPTION_WARN_SHARED_TEXTREL:
1455 link_info.warn_shared_textrel = TRUE;
1456 break;
a0c402a5
L
1457 case OPTION_WARN_ALTERNATE_EM:
1458 link_info.warn_alternate_em = TRUE;
1459 break;
252b5132 1460 case OPTION_WHOLE_ARCHIVE:
66be1055 1461 input_flags.whole_archive = TRUE;
252b5132 1462 break;
ddbb8a31 1463 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
66be1055 1464 input_flags.add_DT_NEEDED_for_dynamic = TRUE;
e56f61be 1465 break;
ddbb8a31 1466 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
66be1055 1467 input_flags.add_DT_NEEDED_for_dynamic = FALSE;
e56f61be 1468 break;
ddbb8a31 1469 case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
66be1055 1470 input_flags.add_DT_NEEDED_for_regular = TRUE;
4a43e768 1471 break;
ddbb8a31 1472 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
66be1055 1473 input_flags.add_DT_NEEDED_for_regular = FALSE;
4a43e768 1474 break;
252b5132
RH
1475 case OPTION_WRAP:
1476 add_wrap (optarg);
1477 break;
0e86e20e
AM
1478 case OPTION_IGNORE_UNRESOLVED_SYMBOL:
1479 add_ignoresym (&link_info, optarg);
1480 break;
f5fa8ca2
JJ
1481 case OPTION_DISCARD_NONE:
1482 link_info.discard = discard_none;
1483 break;
252b5132
RH
1484 case 'X':
1485 link_info.discard = discard_l;
1486 break;
1487 case 'x':
1488 link_info.discard = discard_all;
1489 break;
1490 case 'Y':
0112cd26 1491 if (CONST_STRNEQ (optarg, "P,"))
252b5132 1492 optarg += 2;
5ed6aba4
NC
1493 if (default_dirlist != NULL)
1494 free (default_dirlist);
252b5132
RH
1495 default_dirlist = xstrdup (optarg);
1496 break;
1497 case 'y':
1498 add_ysym (optarg);
1499 break;
db6751f2
JJ
1500 case OPTION_SPARE_DYNAMIC_TAGS:
1501 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1502 break;
252b5132 1503 case OPTION_SPLIT_BY_RELOC:
a854a4a7
AM
1504 if (optarg != NULL)
1505 config.split_by_reloc = strtoul (optarg, NULL, 0);
1506 else
1507 config.split_by_reloc = 32768;
5cc18311 1508 break;
252b5132 1509 case OPTION_SPLIT_BY_FILE:
a854a4a7
AM
1510 if (optarg != NULL)
1511 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1512 else
1513 config.split_by_file = 1;
5cc18311 1514 break;
252b5132 1515 case OPTION_CHECK_SECTIONS:
02b0b1aa 1516 command_line.check_section_addresses = 1;
252b5132
RH
1517 break;
1518 case OPTION_NO_CHECK_SECTIONS:
02b0b1aa 1519 command_line.check_section_addresses = 0;
252b5132 1520 break;
312b768e
NC
1521 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1522 command_line.accept_unknown_input_arch = TRUE;
1523 break;
1524 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1525 command_line.accept_unknown_input_arch = FALSE;
1526 break;
252b5132 1527 case '(':
252b5132 1528 lang_enter_group ();
20f3d0d6 1529 ingroup++;
252b5132
RH
1530 break;
1531 case ')':
1532 if (! ingroup)
df5f2391 1533 einfo (_("%F%P: group ended before it began (--help for usage)\n"));
210a7bd1 1534
252b5132 1535 lang_leave_group ();
20f3d0d6 1536 ingroup--;
252b5132 1537 break;
3dbf70a2
MM
1538
1539 case OPTION_INIT:
1540 link_info.init_function = optarg;
1541 break;
5cc18311 1542
3dbf70a2
MM
1543 case OPTION_FINI:
1544 link_info.fini_function = optarg;
1545 break;
2d643429 1546
35835446 1547 case OPTION_REDUCE_MEMORY_OVERHEADS:
c0f00686 1548 link_info.reduce_memory_overheads = TRUE;
2d643429
NC
1549 if (config.hash_table_size == 0)
1550 config.hash_table_size = 1021;
35835446 1551 break;
2d643429 1552
6c19b93b 1553 case OPTION_HASH_SIZE:
2d643429
NC
1554 {
1555 bfd_size_type new_size;
1556
6c19b93b
AM
1557 new_size = strtoul (optarg, NULL, 0);
1558 if (new_size)
1559 config.hash_table_size = new_size;
1560 else
df5f2391 1561 einfo (_("%X%P: --hash-size needs a numeric argument\n"));
6c19b93b
AM
1562 }
1563 break;
26278bb8
UD
1564
1565 case OPTION_PUSH_STATE:
1566 input_flags.pushed = xmemdup (&input_flags,
1567 sizeof (input_flags),
1568 sizeof (input_flags));
1569 break;
1570
1571 case OPTION_POP_STATE:
1572 if (input_flags.pushed == NULL)
df5f2391 1573 einfo (_("%F%P: no state pushed before popping\n"));
26278bb8
UD
1574 else
1575 {
1576 struct lang_input_statement_flags *oldp = input_flags.pushed;
1577 memcpy (&input_flags, oldp, sizeof (input_flags));
1578 free (oldp);
1579 }
1580 break;
3604cb1f
TG
1581
1582 case OPTION_PRINT_MEMORY_USAGE:
1583 command_line.print_memory_usage = TRUE;
1584 break;
c005eb9e
AB
1585
1586 case OPTION_ORPHAN_HANDLING:
1587 if (strcasecmp (optarg, "place") == 0)
1588 config.orphan_handling = orphan_handling_place;
1589 else if (strcasecmp (optarg, "warn") == 0)
1590 config.orphan_handling = orphan_handling_warn;
1591 else if (strcasecmp (optarg, "error") == 0)
1592 config.orphan_handling = orphan_handling_error;
1593 else if (strcasecmp (optarg, "discard") == 0)
1594 config.orphan_handling = orphan_handling_discard;
1595 else
df5f2391 1596 einfo (_("%F%P: invalid argument to option"
c005eb9e
AB
1597 " \"--orphan-handling\"\n"));
1598 break;
035801ce
FS
1599
1600 case OPTION_NO_PRINT_MAP_DISCARDED:
1601 config.print_map_discarded = FALSE;
1602 break;
1603
1604 case OPTION_PRINT_MAP_DISCARDED:
1605 config.print_map_discarded = TRUE;
1606 break;
252b5132
RH
1607 }
1608 }
1609
b0054819
UD
1610 if (command_line.soname && command_line.soname[0] == '\0')
1611 {
1612 einfo (_("%P: SONAME must not be empty string; ignored\n"));
1613 command_line.soname = NULL;
1614 }
1615
20f3d0d6
AM
1616 while (ingroup)
1617 {
776ab89f 1618 einfo (_("%P: missing --end-group; added as last command line option\n"));
20f3d0d6
AM
1619 lang_leave_group ();
1620 ingroup--;
1621 }
252b5132
RH
1622
1623 if (default_dirlist != NULL)
5ed6aba4
NC
1624 {
1625 set_default_dirlist (default_dirlist);
1626 free (default_dirlist);
1627 }
560e09e9
NC
1628
1629 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1630 /* FIXME: Should we allow emulations a chance to set this ? */
1631 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
6feb9908 1632
560e09e9
NC
1633 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1634 /* FIXME: Should we allow emulations a chance to set this ? */
1635 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
5d3236ee 1636
0e1862bb
L
1637 if (bfd_link_relocatable (&link_info)
1638 && command_line.check_section_addresses < 0)
1639 command_line.check_section_addresses = 0;
9bbc1a67 1640
1914e264
AM
1641 /* -Bsymbolic and -Bsymbols-functions are for shared library output. */
1642 if (bfd_link_dll (&link_info))
1643 switch (opt_symbolic)
1644 {
1645 case symbolic_unset:
1646 break;
1647 case symbolic:
1648 link_info.symbolic = TRUE;
1649 if (link_info.dynamic_list)
1650 {
1651 struct bfd_elf_version_expr *ent, *next;
1652 for (ent = link_info.dynamic_list->head.list; ent; ent = next)
1653 {
1654 next = ent->next;
1655 free (ent);
1656 }
1657 free (link_info.dynamic_list);
1658 link_info.dynamic_list = NULL;
1659 }
1660 opt_dynamic_list = dynamic_list_unset;
1661 break;
1662 case symbolic_functions:
1663 opt_dynamic_list = dynamic_list_data;
1664 break;
1665 }
9bbc1a67 1666
1914e264 1667 switch (opt_dynamic_list)
9bbc1a67
AM
1668 {
1669 case dynamic_list_unset:
1670 break;
1671 case dynamic_list_data:
1672 link_info.dynamic_data = TRUE;
1a0670f3 1673 /* Fall through. */
9bbc1a67
AM
1674 case dynamic_list:
1675 link_info.dynamic = TRUE;
1676 break;
1677 }
1678
0e1862bb 1679 if (!bfd_link_dll (&link_info))
9bbc1a67
AM
1680 {
1681 if (command_line.filter_shlib)
df5f2391 1682 einfo (_("%F%P: -F may not be used without -shared\n"));
9bbc1a67 1683 if (command_line.auxiliary_filters)
df5f2391 1684 einfo (_("%F%P: -f may not be used without -shared\n"));
9bbc1a67
AM
1685 }
1686
9bbc1a67
AM
1687 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1688 don't see how else this can be handled, since in this case we
1689 must preserve all externally visible symbols. */
0e1862bb 1690 if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all)
9bbc1a67
AM
1691 {
1692 link_info.strip = strip_debugger;
1693 if (link_info.discard == discard_sec_merge)
1694 link_info.discard = discard_all;
1695 }
252b5132
RH
1696}
1697
1698/* Add the (colon-separated) elements of DIRLIST_PTR to the
1699 library search path. */
1700
1701static void
1579bae1 1702set_default_dirlist (char *dirlist_ptr)
252b5132
RH
1703{
1704 char *p;
1705
1706 while (1)
1707 {
1708 p = strchr (dirlist_ptr, PATH_SEPARATOR);
1709 if (p != NULL)
1710 *p = '\0';
1711 if (*dirlist_ptr != '\0')
b34976b6 1712 ldfile_add_library_path (dirlist_ptr, TRUE);
252b5132
RH
1713 if (p == NULL)
1714 break;
1715 dirlist_ptr = p + 1;
1716 }
1717}
1718
1719static void
1579bae1 1720set_section_start (char *sect, char *valstr)
252b5132 1721{
93697284
AM
1722 const char *end;
1723 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
252b5132 1724 if (*end)
df5f2391 1725 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
ba916c8a 1726 lang_section_start (sect, exp_intop (val), NULL);
252b5132 1727}
ba916c8a
MM
1728
1729static void
1730set_segment_start (const char *section, char *valstr)
1731{
1732 const char *name;
1733 const char *end;
1734 segment_type *seg;
1735
1736 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1737 if (*end)
df5f2391 1738 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
ba916c8a
MM
1739 /* If we already have an entry for this segment, update the existing
1740 value. */
1741 name = section + 1;
1742 for (seg = segments; seg; seg = seg->next)
1743 if (strcmp (seg->name, name) == 0)
1744 {
1745 seg->value = val;
42b7a39b 1746 lang_section_start (section, exp_intop (val), seg);
ba916c8a
MM
1747 return;
1748 }
1749 /* There was no existing value so we must create a new segment
1750 entry. */
988de25b 1751 seg = stat_alloc (sizeof (*seg));
ba916c8a
MM
1752 seg->name = name;
1753 seg->value = val;
1754 seg->used = FALSE;
1755 /* Add it to the linked list of segments. */
1756 seg->next = segments;
1757 segments = seg;
1758 /* Historically, -Ttext and friends set the base address of a
1759 particular section. For backwards compatibility, we still do
1760 that. If a SEGMENT_START directive is seen, the section address
1761 assignment will be disabled. */
1762 lang_section_start (section, exp_intop (val), seg);
1763}
1764
c58212ea
L
1765static void
1766elf_shlib_list_options (FILE *file)
1767{
1768 fprintf (file, _("\
1769 --audit=AUDITLIB Specify a library to use for auditing\n"));
1770 fprintf (file, _("\
1771 -Bgroup Selects group name lookup rules for DSO\n"));
1772 fprintf (file, _("\
1773 --disable-new-dtags Disable new dynamic tags\n"));
1774 fprintf (file, _("\
1775 --enable-new-dtags Enable new dynamic tags\n"));
1776 fprintf (file, _("\
1777 --eh-frame-hdr Create .eh_frame_hdr section\n"));
29063f8b
NC
1778 fprintf (file, _("\
1779 --no-eh-frame-hdr Do not create .eh_frame_hdr section\n"));
c58212ea
L
1780 fprintf (file, _("\
1781 --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
1782 fprintf (file, _("\
1783 --hash-style=STYLE Set hash style to sysv, gnu or both\n"));
1784 fprintf (file, _("\
1785 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
df5f2391 1786 Specify a library to use for auditing dependencies\n"));
c58212ea
L
1787 fprintf (file, _("\
1788 -z combreloc Merge dynamic relocs into one section and sort\n"));
1789 fprintf (file, _("\
1790 -z nocombreloc Don't merge dynamic relocs into one section\n"));
1791 fprintf (file, _("\
1792 -z global Make symbols in DSO available for subsequently\n\
df5f2391 1793 loaded objects\n"));
c58212ea
L
1794 fprintf (file, _("\
1795 -z initfirst Mark DSO to be initialized first at runtime\n"));
1796 fprintf (file, _("\
1797 -z interpose Mark object to interpose all DSOs but executable\n"));
1798 fprintf (file, _("\
1799 -z lazy Mark object lazy runtime binding (default)\n"));
1800 fprintf (file, _("\
1801 -z loadfltr Mark object requiring immediate process\n"));
1802 fprintf (file, _("\
1803 -z nocopyreloc Don't create copy relocs\n"));
1804 fprintf (file, _("\
1805 -z nodefaultlib Mark object not to use default search paths\n"));
1806 fprintf (file, _("\
1807 -z nodelete Mark DSO non-deletable at runtime\n"));
1808 fprintf (file, _("\
1809 -z nodlopen Mark DSO not available to dlopen\n"));
1810 fprintf (file, _("\
1811 -z nodump Mark DSO not available to dldump\n"));
1812 fprintf (file, _("\
1813 -z now Mark object non-lazy runtime binding\n"));
1814 fprintf (file, _("\
1815 -z origin Mark object requiring immediate $ORIGIN\n\
df5f2391 1816 processing at runtime\n"));
da4463c7 1817#if DEFAULT_LD_Z_RELRO
c58212ea 1818 fprintf (file, _("\
da4463c7 1819 -z relro Create RELRO program header (default)\n"));
c58212ea
L
1820 fprintf (file, _("\
1821 -z norelro Don't create RELRO program header\n"));
da4463c7
L
1822#else
1823 fprintf (file, _("\
1824 -z relro Create RELRO program header\n"));
1825 fprintf (file, _("\
1826 -z norelro Don't create RELRO program header (default)\n"));
1827#endif
b14b7ff1
L
1828#if DEFAULT_LD_Z_SEPARATE_CODE
1829 fprintf (file, _("\
1830 -z separate-code Create separate code program header (default)\n"));
1831 fprintf (file, _("\
1832 -z noseparate-code Don't create separate code program header\n"));
1833#else
47acac12
L
1834 fprintf (file, _("\
1835 -z separate-code Create separate code program header\n"));
1836 fprintf (file, _("\
1837 -z noseparate-code Don't create separate code program header (default)\n"));
b14b7ff1 1838#endif
c58212ea 1839 fprintf (file, _("\
b8871f35
L
1840 -z common Generate common symbols with STT_COMMON type\n"));
1841 fprintf (file, _("\
1842 -z nocommon Generate common symbols with STT_OBJECT type\n"));
1843 fprintf (file, _("\
75e06f97 1844 -z stack-size=SIZE Set size of stack segment\n"));
c58212ea
L
1845 fprintf (file, _("\
1846 -z text Treat DT_TEXTREL in shared object as error\n"));
1847 fprintf (file, _("\
1848 -z notext Don't treat DT_TEXTREL in shared object as error\n"));
1849 fprintf (file, _("\
1850 -z textoff Don't treat DT_TEXTREL in shared object as error\n"));
1851}
1852
1853static void
1854elf_static_list_options (FILE *file)
1855{
1856 fprintf (file, _("\
1857 --build-id[=STYLE] Generate build ID note\n"));
1858 fprintf (file, _("\
0ce398f1
L
1859 --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\
1860 Compress DWARF debug sections using zlib\n"));
6c3bc0f8
NC
1861#ifdef DEFAULT_FLAG_COMPRESS_DEBUG
1862 fprintf (file, _("\
1863 Default: zlib-gabi\n"));
1864#else
1865 fprintf (file, _("\
1866 Default: none\n"));
1867#endif
0ce398f1 1868 fprintf (file, _("\
c58212ea
L
1869 -z common-page-size=SIZE Set common page size to SIZE\n"));
1870 fprintf (file, _("\
1871 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
1872 fprintf (file, _("\
df5f2391 1873 -z defs Report unresolved symbols in object files\n"));
c58212ea
L
1874 fprintf (file, _("\
1875 -z muldefs Allow multiple definitions\n"));
1876 fprintf (file, _("\
1877 -z execstack Mark executable as requiring executable stack\n"));
1878 fprintf (file, _("\
1879 -z noexecstack Mark executable as not requiring executable stack\n"));
93ab9c0d
NC
1880 fprintf (file, _("\
1881 -z globalaudit Mark executable requiring global auditing\n"));
c58212ea
L
1882}
1883
1884static void
1885elf_plt_unwind_list_options (FILE *file)
1886{
1887 fprintf (file, _("\
df5f2391
AM
1888 --ld-generated-unwind-info Generate exception handling info for PLT\n"));
1889 fprintf (file, _("\
c58212ea
L
1890 --no-ld-generated-unwind-info\n\
1891 Don't generate exception handling info for PLT\n"));
1892}
1893
1894static void
1895ld_list_options (FILE *file, bfd_boolean elf, bfd_boolean shlib,
1896 bfd_boolean plt_unwind)
1897{
1898 if (!elf)
1899 return;
1900 printf (_("ELF emulations:\n"));
1901 if (plt_unwind)
1902 elf_plt_unwind_list_options (file);
1903 elf_static_list_options (file);
1904 if (shlib)
1905 elf_shlib_list_options (file);
1906}
1907
252b5132
RH
1908\f
1909/* Print help messages for the options. */
1910
1911static void
1579bae1 1912help (void)
252b5132 1913{
e4897a32 1914 unsigned i;
252b5132 1915 const char **targets, **pp;
a55ff675 1916 int len;
252b5132
RH
1917
1918 printf (_("Usage: %s [options] file...\n"), program_name);
1919
1920 printf (_("Options:\n"));
1921 for (i = 0; i < OPTION_COUNT; i++)
1922 {
1923 if (ld_options[i].doc != NULL)
1924 {
b34976b6 1925 bfd_boolean comma;
e4897a32 1926 unsigned j;
252b5132
RH
1927
1928 printf (" ");
1929
b34976b6 1930 comma = FALSE;
252b5132
RH
1931 len = 2;
1932
1933 j = i;
1934 do
1935 {
1936 if (ld_options[j].shortopt != '\0'
1937 && ld_options[j].control != NO_HELP)
1938 {
1939 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1940 len += (comma ? 2 : 0) + 2;
1941 if (ld_options[j].arg != NULL)
1942 {
1943 if (ld_options[j].opt.has_arg != optional_argument)
1944 {
1945 printf (" ");
1946 ++len;
1947 }
1948 printf ("%s", _(ld_options[j].arg));
1949 len += strlen (_(ld_options[j].arg));
1950 }
b34976b6 1951 comma = TRUE;
252b5132
RH
1952 }
1953 ++j;
1954 }
1955 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1956
1957 j = i;
1958 do
1959 {
1960 if (ld_options[j].opt.name != NULL
1961 && ld_options[j].control != NO_HELP)
1962 {
e4897a32
NC
1963 int two_dashes =
1964 (ld_options[j].control == TWO_DASHES
1965 || ld_options[j].control == EXACTLY_TWO_DASHES);
b7a26f91 1966
252b5132
RH
1967 printf ("%s-%s%s",
1968 comma ? ", " : "",
e4897a32 1969 two_dashes ? "-" : "",
252b5132
RH
1970 ld_options[j].opt.name);
1971 len += ((comma ? 2 : 0)
1972 + 1
e4897a32 1973 + (two_dashes ? 1 : 0)
252b5132
RH
1974 + strlen (ld_options[j].opt.name));
1975 if (ld_options[j].arg != NULL)
1976 {
1977 printf (" %s", _(ld_options[j].arg));
1978 len += 1 + strlen (_(ld_options[j].arg));
1979 }
b34976b6 1980 comma = TRUE;
252b5132
RH
1981 }
1982 ++j;
1983 }
1984 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1985
1986 if (len >= 30)
1987 {
1988 printf ("\n");
1989 len = 0;
1990 }
1991
1992 for (; len < 30; len++)
1993 putchar (' ');
1994
1995 printf ("%s\n", _(ld_options[i].doc));
1996 }
1997 }
a55ff675
MM
1998 printf (_(" @FILE"));
1999 for (len = strlen (" @FILE"); len < 30; len++)
2000 putchar (' ');
2001 printf (_("Read options from FILE\n"));
252b5132 2002
f75692fe
NC
2003 /* Note: Various tools (such as libtool) depend upon the
2004 format of the listings below - do not change them. */
252b5132 2005 /* xgettext:c-format */
f75692fe 2006 printf (_("%s: supported targets:"), program_name);
252b5132
RH
2007 targets = bfd_target_list ();
2008 for (pp = targets; *pp != NULL; pp++)
2009 printf (" %s", *pp);
2010 free (targets);
2011 printf ("\n");
2012
2013 /* xgettext:c-format */
f75692fe 2014 printf (_("%s: supported emulations: "), program_name);
252b5132
RH
2015 ldemul_list_emulations (stdout);
2016 printf ("\n");
2017
2018 /* xgettext:c-format */
2019 printf (_("%s: emulation specific options:\n"), program_name);
c58212ea
L
2020 ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
2021 ELF_PLT_UNWIND_LIST_OPTIONS);
252b5132
RH
2022 ldemul_list_emulation_options (stdout);
2023 printf ("\n");
c20f4f8c 2024
92f01d61
JM
2025 if (REPORT_BUGS_TO[0])
2026 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
252b5132 2027}
This page took 0.957413 seconds and 4 git commands to generate.