]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/lexsup.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / ld / lexsup.c
CommitLineData
252b5132 1/* Parse options for the GNU linker.
fd67aa11 2 Copyright (C) 1991-2024 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 24#include "libiberty.h"
2c72361c 25#include "filenames.h"
252b5132
RH
26#include <stdio.h>
27#include <string.h>
2c72361c 28#include <errno.h>
3882b010 29#include "safe-ctype.h"
252b5132
RH
30#include "getopt.h"
31#include "bfdlink.h"
1ff6de03 32#include "ctf-api.h"
252b5132
RH
33#include "ld.h"
34#include "ldmain.h"
35#include "ldmisc.h"
36#include "ldexp.h"
37#include "ldlang.h"
df2a7313 38#include <ldgram.h>
252b5132
RH
39#include "ldlex.h"
40#include "ldfile.h"
41#include "ldver.h"
42#include "ldemul.h"
28c309a2 43#include "demangle.h"
0381901e 44#if BFD_SUPPORTS_PLUGINS
5d3236ee 45#include "plugin.h"
0381901e 46#endif /* BFD_SUPPORTS_PLUGINS */
252b5132
RH
47
48#ifndef PATH_SEPARATOR
49#if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
50#define PATH_SEPARATOR ';'
51#else
52#define PATH_SEPARATOR ':'
53#endif
54#endif
55
5cc18311 56/* Somewhere above, sys/stat.h got included . . . . */
252b5132
RH
57#if !defined(S_ISDIR) && defined(S_IFDIR)
58#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
59#endif
60
1579bae1
AM
61static void set_default_dirlist (char *);
62static void set_section_start (char *, char *);
ba916c8a 63static void set_segment_start (const char *, char *);
1579bae1 64static void help (void);
252b5132 65
252b5132
RH
66/* The long options. This structure is used for both the option
67 parsing and the help text. */
68
1e9cc1c2
NC
69enum control_enum {
70 /* Use one dash before long option name. */
f82aa165 71 ONE_DASH = 1,
1e9cc1c2 72 /* Use two dashes before long option name. */
f82aa165 73 TWO_DASHES = 2,
1e9cc1c2
NC
74 /* Only accept two dashes before the long option name.
75 This is an overloading of the use of this enum, since originally it
76 was only intended to tell the --help display function how to display
77 the long option name. This feature was added in order to resolve
78 the confusion about the -omagic command line switch. Is it setting
79 the output file name to "magic" or is it setting the NMAGIC flag on
80 the output ? It has been decided that it is setting the output file
81 name, and that if you want to set the NMAGIC flag you should use -N
82 or --omagic. */
83 EXACTLY_TWO_DASHES,
84 /* Don't mention this option in --help output. */
85 NO_HELP
86};
87
b79e8c78
NC
88struct ld_option
89{
252b5132
RH
90 /* The long option information. */
91 struct option opt;
92 /* The short option with the same meaning ('\0' if none). */
93 char shortopt;
94 /* The name of the argument (NULL if none). */
95 const char *arg;
96 /* The documentation string. If this is NULL, this is a synonym for
97 the previous option. */
98 const char *doc;
1e9cc1c2 99 enum control_enum control;
252b5132
RH
100};
101
b79e8c78
NC
102static const struct ld_option ld_options[] =
103{
252b5132 104 { {NULL, required_argument, NULL, '\0'},
6feb9908
AM
105 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
106 ONE_DASH },
252b5132 107 { {"architecture", required_argument, NULL, 'A'},
a79e9a07 108 'A', N_("ARCH"), N_("Set architecture") , EXACTLY_TWO_DASHES },
252b5132 109 { {"format", required_argument, NULL, 'b'},
6feb9908 110 'b', N_("TARGET"), N_("Specify target for following input files"),
b0dfd742 111 EXACTLY_TWO_DASHES },
252b5132 112 { {"mri-script", required_argument, NULL, 'c'},
b2a6584d 113 'c', N_("FILE"), N_("Read MRI format linker script"), EXACTLY_TWO_DASHES },
252b5132 114 { {"dc", no_argument, NULL, 'd'},
6feb9908 115 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
252b5132 116 { {"dp", no_argument, NULL, 'd'},
6feb9908 117 '\0', NULL, NULL, ONE_DASH },
4bf05d4a
L
118 { {"dependency-file", required_argument, NULL, OPTION_DEPENDENCY_FILE},
119 '\0', N_("FILE"), N_("Write dependency file"), TWO_DASHES },
7bdf4127
AB
120 { {"force-group-allocation", no_argument, NULL,
121 OPTION_FORCE_GROUP_ALLOCATION},
122 '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
252b5132 123 { {"entry", required_argument, NULL, 'e'},
6feb9908 124 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
252b5132 125 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
6feb9908 126 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
267e2722
CD
127 { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC},
128 '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES },
abf874aa
CL
129 { {"enable-non-contiguous-regions", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS},
130 '\0', NULL, N_("Enable support of non-contiguous memory regions"), TWO_DASHES },
131 { {"enable-non-contiguous-regions-warnings", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS},
132 '\0', NULL, N_("Enable warnings when --enable-non-contiguous-regions may cause unexpected behaviour"), TWO_DASHES },
2d5783fa
NC
133 { {"disable-linker-version", no_argument, NULL, OPTION_DISABLE_LINKER_VERSION},
134 '\0', NULL, N_("Disable the LINKER_VERSION linker script directive"), TWO_DASHES },
135 { {"enable-linker-version", no_argument, NULL, OPTION_ENABLE_LINKER_VERSION},
136 '\0', NULL, N_("Enable the LINKER_VERSION linker script directive"), TWO_DASHES },
252b5132 137 { {"EB", no_argument, NULL, OPTION_EB},
6feb9908 138 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
252b5132 139 { {"EL", no_argument, NULL, OPTION_EL},
6feb9908 140 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
252b5132 141 { {"auxiliary", required_argument, NULL, 'f'},
6feb9908
AM
142 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
143 TWO_DASHES },
252b5132 144 { {"filter", required_argument, NULL, 'F'},
6feb9908
AM
145 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
146 TWO_DASHES },
252b5132 147 { {NULL, no_argument, NULL, '\0'},
6feb9908 148 'g', NULL, N_("Ignored"), ONE_DASH },
252b5132 149 { {"gpsize", required_argument, NULL, 'G'},
6feb9908
AM
150 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
151 TWO_DASHES },
252b5132 152 { {"soname", required_argument, NULL, OPTION_SONAME},
6feb9908 153 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
506eee22 154 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
6feb9908
AM
155 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
156 TWO_DASHES },
9b8b325a
RF
157 { {"no-dynamic-linker", no_argument, NULL, OPTION_NO_DYNAMIC_LINKER},
158 '\0', NULL, N_("Produce an executable with no program interpreter header"),
159 TWO_DASHES },
252b5132 160 { {"library", required_argument, NULL, 'l'},
6feb9908 161 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
252b5132 162 { {"library-path", required_argument, NULL, 'L'},
6feb9908
AM
163 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
164 TWO_DASHES },
e2243057
RS
165 { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
166 '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
252b5132 167 { {NULL, required_argument, NULL, '\0'},
6feb9908 168 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
252b5132 169 { {"print-map", no_argument, NULL, 'M'},
6feb9908 170 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
252b5132 171 { {"nmagic", no_argument, NULL, 'n'},
6feb9908 172 'n', NULL, N_("Do not page align data"), TWO_DASHES },
252b5132 173 { {"omagic", no_argument, NULL, 'N'},
6feb9908
AM
174 'N', NULL, N_("Do not page align data, do not make text readonly"),
175 EXACTLY_TWO_DASHES },
63fd3b82 176 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
6feb9908
AM
177 '\0', NULL, N_("Page align data, make text readonly"),
178 EXACTLY_TWO_DASHES },
252b5132 179 { {"output", required_argument, NULL, 'o'},
6feb9908 180 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
252b5132 181 { {NULL, required_argument, NULL, '\0'},
6feb9908 182 'O', NULL, N_("Optimize output file"), ONE_DASH },
76359541
TP
183 { {"out-implib", required_argument, NULL, OPTION_OUT_IMPLIB},
184 '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES },
0381901e 185#if BFD_SUPPORTS_PLUGINS
5d3236ee
DK
186 { {"plugin", required_argument, NULL, OPTION_PLUGIN},
187 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
188 { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
189 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
d9511b64
L
190 { {"plugin-save-temps", no_argument, NULL, OPTION_PLUGIN_SAVE_TEMPS},
191 '\0', NULL, N_("Store plugin intermediate files permanently"),
192 ONE_DASH },
94bf3a11
L
193 { {"flto", optional_argument, NULL, OPTION_IGNORE},
194 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
195 ONE_DASH },
196 { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
197 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
198 ONE_DASH },
070558eb
AM
199#else
200 { {"plugin", required_argument, NULL, OPTION_IGNORE},
201 '\0', N_("PLUGIN"), N_("Load named plugin (ignored)"), ONE_DASH },
202 { {"plugin-opt", required_argument, NULL, OPTION_IGNORE},
203 '\0', N_("ARG"), N_("Send arg to last-loaded plugin (ignored)"), ONE_DASH },
0381901e 204#endif /* BFD_SUPPORTS_PLUGINS */
add24320
L
205 { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE},
206 '\0', NULL, N_("Ignored for GCC linker option compatibility"),
207 ONE_DASH },
88b9e2eb
L
208 { {"map-whole-files", optional_argument, NULL, OPTION_IGNORE},
209 '\0', NULL, N_("Ignored for gold option compatibility"),
210 TWO_DASHES },
211 { {"no-map-whole-files", optional_argument, NULL, OPTION_IGNORE},
212 '\0', NULL, N_("Ignored for gold option compatibility"),
213 TWO_DASHES },
252b5132 214 { {"Qy", no_argument, NULL, OPTION_IGNORE},
6feb9908 215 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
a712da20 216 { {"emit-relocs", no_argument, NULL, 'q'},
6feb9908 217 'q', NULL, "Generate relocations in final output", TWO_DASHES },
1049f94e 218 { {"relocatable", no_argument, NULL, 'r'},
6feb9908 219 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
252b5132 220 { {NULL, no_argument, NULL, '\0'},
6feb9908 221 'i', NULL, NULL, ONE_DASH },
252b5132 222 { {"just-symbols", required_argument, NULL, 'R'},
6feb9908
AM
223 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
224 TWO_DASHES },
fb221fba
NC
225
226 { {"remap-inputs-file", required_argument, NULL, OPTION_REMAP_INPUTS_FILE},
227 '\0', N_("FILE"), "Provide a FILE containing input remapings", TWO_DASHES },
228 { {"remap-inputs", required_argument, NULL, OPTION_REMAP_INPUTS},
229 '\0', N_("PATTERN=FILE"), "Remap input files matching PATTERN to FILE", TWO_DASHES },
230
252b5132 231 { {"strip-all", no_argument, NULL, 's'},
6feb9908 232 's', NULL, N_("Strip all symbols"), TWO_DASHES },
252b5132 233 { {"strip-debug", no_argument, NULL, 'S'},
6feb9908 234 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
d5cd3933 235 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
6feb9908 236 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
d5cd3933 237 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
6feb9908 238 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
252b5132 239 { {"trace", no_argument, NULL, 't'},
6feb9908 240 't', NULL, N_("Trace file opens"), TWO_DASHES },
252b5132 241 { {"script", required_argument, NULL, 'T'},
6feb9908 242 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
14be8564
L
243 { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
244 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
245 { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
246 '\0', NULL, NULL, ONE_DASH },
252b5132 247 { {"undefined", required_argument, NULL, 'u'},
6feb9908
AM
248 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
249 TWO_DASHES },
0a618243
AB
250 { {"require-defined", required_argument, NULL, OPTION_REQUIRE_DEFINED_SYMBOL},
251 '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"),
252 TWO_DASHES },
577a0623 253 { {"unique", optional_argument, NULL, OPTION_UNIQUE},
6feb9908
AM
254 '\0', N_("[=SECTION]"),
255 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
252b5132 256 { {"Ur", no_argument, NULL, OPTION_UR},
6feb9908 257 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
252b5132 258 { {"version", no_argument, NULL, OPTION_VERSION},
6feb9908 259 'v', NULL, N_("Print version information"), TWO_DASHES },
252b5132 260 { {NULL, no_argument, NULL, '\0'},
6feb9908 261 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
252b5132 262 { {"discard-all", no_argument, NULL, 'x'},
6feb9908 263 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
252b5132 264 { {"discard-locals", no_argument, NULL, 'X'},
6feb9908 265 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
f5fa8ca2 266 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
6feb9908 267 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
252b5132 268 { {"trace-symbol", required_argument, NULL, 'y'},
6feb9908 269 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
252b5132 270 { {NULL, required_argument, NULL, '\0'},
6feb9908
AM
271 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
272 ONE_DASH },
252b5132 273 { {"start-group", no_argument, NULL, '('},
6feb9908 274 '(', NULL, N_("Start a group"), TWO_DASHES },
252b5132 275 { {"end-group", no_argument, NULL, ')'},
6feb9908
AM
276 ')', NULL, N_("End a group"), TWO_DASHES },
277 { {"accept-unknown-input-arch", no_argument, NULL,
278 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
279 '\0', NULL,
280 N_("Accept input files whose architecture cannot be determined"),
281 TWO_DASHES },
282 { {"no-accept-unknown-input-arch", no_argument, NULL,
283 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
284 '\0', NULL, N_("Reject input files whose architecture is unknown"),
285 TWO_DASHES },
ddbb8a31
NC
286
287 /* The next two options are deprecated because of their similarity to
288 --as-needed and --no-as-needed. They have been replaced by
99bca8f9 289 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
ddbb8a31
NC
290 { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
291 '\0', NULL, NULL, NO_HELP },
292 { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
293 '\0', NULL, NULL, NO_HELP },
294
295 { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
8fdd7217
NC
296 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
297 TWO_DASHES },
ddbb8a31
NC
298 { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
299 '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
300 " the command line"),
8fdd7217 301 TWO_DASHES },
252b5132 302 { {"assert", required_argument, NULL, OPTION_ASSERT},
6feb9908 303 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
252b5132 304 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
6feb9908 305 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
252b5132 306 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
6feb9908 307 '\0', NULL, NULL, ONE_DASH },
252b5132 308 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
6feb9908 309 '\0', NULL, NULL, ONE_DASH },
252b5132 310 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
6feb9908 311 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
252b5132 312 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
6feb9908 313 '\0', NULL, NULL, ONE_DASH },
252b5132 314 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
6feb9908 315 '\0', NULL, NULL, ONE_DASH },
252b5132 316 { {"static", no_argument, NULL, OPTION_NON_SHARED},
6feb9908 317 '\0', NULL, NULL, ONE_DASH },
cf893b0e
FS
318 { {"Bno-symbolic", no_argument, NULL, OPTION_NO_SYMBOLIC},
319 '\0', NULL, N_("Don't bind global references locally"), ONE_DASH },
252b5132 320 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
6feb9908 321 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
d8cf8b51 322 { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
40b36307 323 '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
252b5132 324 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
6feb9908
AM
325 '\0', NULL, N_("Check section addresses for overlaps (default)"),
326 TWO_DASHES },
252b5132 327 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
6feb9908
AM
328 '\0', NULL, N_("Do not check section addresses for overlaps"),
329 TWO_DASHES },
ddbb8a31
NC
330 { {"copy-dt-needed-entries", no_argument, NULL,
331 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
332 '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
333 TWO_DASHES },
334 { {"no-copy-dt-needed-entries", no_argument, NULL,
335 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
336 '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
337 TWO_DASHES },
338
252b5132 339 { {"cref", no_argument, NULL, OPTION_CREF},
6feb9908 340 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
252b5132 341 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
6feb9908 342 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
28c309a2 343 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
6feb9908
AM
344 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
345 TWO_DASHES },
3f0a5f17
ME
346 { {"disable-multiple-abs-defs", no_argument, NULL,
347 OPTION_DISABLE_MULTIPLE_DEFS_ABS},
348 '\0', NULL, N_("Do not allow multiple definitions with symbols included\n"
ef913066
MF
349 " in filename invoked by -R "
350 "or --just-symbols"),
3f0a5f17 351 TWO_DASHES},
252b5132 352 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
6feb9908 353 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
8fdd7217
NC
354 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
355 '\0', NULL, N_("Treat warnings as errors"),
356 TWO_DASHES },
0fe58ccd
NC
357 { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL},
358 '\0', NULL, N_("Do not treat warnings as errors (default)"),
359 TWO_DASHES },
3dbf70a2 360 { {"fini", required_argument, NULL, OPTION_FINI},
6feb9908 361 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
252b5132 362 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
6feb9908 363 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
252b5132 364 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
6feb9908
AM
365 '\0', NULL, N_("Remove unused sections (on some targets)"),
366 TWO_DASHES },
252b5132 367 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
6feb9908
AM
368 '\0', NULL, N_("Don't remove unused sections (default)"),
369 TWO_DASHES },
c17d87de
NC
370 { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
371 '\0', NULL, N_("List removed unused sections on stderr"),
372 TWO_DASHES },
373 { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
374 '\0', NULL, N_("Do not list removed unused sections"),
375 TWO_DASHES },
22185505 376 { {"gc-keep-exported", no_argument, NULL, OPTION_GC_KEEP_EXPORTED},
377 '\0', NULL, N_("Keep exported symbols when removing unused sections"),
378 TWO_DASHES },
2d643429 379 { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
6feb9908
AM
380 '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
381 TWO_DASHES },
252b5132 382 { {"help", no_argument, NULL, OPTION_HELP},
6feb9908 383 '\0', NULL, N_("Print option help"), TWO_DASHES },
3dbf70a2 384 { {"init", required_argument, NULL, OPTION_INIT},
6feb9908 385 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
252b5132 386 { {"Map", required_argument, NULL, OPTION_MAP},
72a3b182 387 '\0', N_("FILE/DIR"), N_("Write a linker map to FILE or DIR/<outputname>.map"), ONE_DASH },
4818e05f 388 { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
6feb9908 389 '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
252b5132 390 { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
6feb9908 391 '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
252b5132 392 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
6feb9908 393 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
252b5132 394 { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
6feb9908
AM
395 '\0', NULL, N_("Do not allow unresolved references in object files"),
396 TWO_DASHES },
4b2e7a57
NC
397 { {"no-warnings", no_argument, NULL, OPTION_NO_WARNINGS},
398 'w', NULL, N_("Do not display any warning or error messages"),
399 TWO_DASHES },
b79e8c78 400 { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
cc643b88 401 '\0', NULL, N_("Allow unresolved references in shared libraries"),
6feb9908
AM
402 TWO_DASHES },
403 { {"no-allow-shlib-undefined", no_argument, NULL,
404 OPTION_NO_ALLOW_SHLIB_UNDEFINED},
405 '\0', NULL, N_("Do not allow unresolved references in shared libs"),
406 TWO_DASHES },
407 { {"allow-multiple-definition", no_argument, NULL,
408 OPTION_ALLOW_MULTIPLE_DEFINITION},
409 '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
23ae20f5
NC
410#if SUPPORT_ERROR_HANDLING_SCRIPT
411 { {"error-handling-script", required_argument, NULL,
412 OPTION_ERROR_HANDLING_SCRIPT},
413 '\0', N_("SCRIPT"), N_("Provide a script to help with undefined symbol errors"), TWO_DASHES},
414#endif
27fb6a1a
FS
415 { {"undefined-version", no_argument, NULL, OPTION_UNDEFINED_VERSION},
416 '\0', NULL, N_("Allow undefined version"), EXACTLY_TWO_DASHES },
31941635 417 { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
6feb9908 418 '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
3e3b46e5
PB
419 { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
420 '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
fc0e6df6
PB
421 { {"default-imported-symver", no_argument, NULL,
422 OPTION_DEFAULT_IMPORTED_SYMVER},
423 '\0', NULL, N_("Create default symbol version for imported symbols"),
424 TWO_DASHES },
252b5132 425 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
6feb9908 426 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
fe7929ce
AM
427 { {"no-warn-search-mismatch", no_argument, NULL,
428 OPTION_NO_WARN_SEARCH_MISMATCH},
429 '\0', NULL, N_("Don't warn on finding an incompatible library"),
430 TWO_DASHES},
252b5132 431 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
6feb9908 432 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
252b5132 433 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
6feb9908
AM
434 '\0', NULL, N_("Create an output file even if errors occur"),
435 TWO_DASHES },
252b5132 436 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
6feb9908 437 '\0', NULL, NULL, NO_HELP },
361b220e 438 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
6feb9908 439 '\0', NULL, N_("Only use library directories specified on\n"
c58dea77
AM
440 " the command line"),
441 ONE_DASH },
252b5132 442 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
6feb9908
AM
443 '\0', N_("TARGET"), N_("Specify target of output file"),
444 EXACTLY_TWO_DASHES },
30824704
RM
445 { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
446 '\0', NULL, N_("Print default output format"), TWO_DASHES },
cb9322a8
HPN
447 { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT},
448 '\0', NULL, N_("Print current sysroot"), TWO_DASHES },
252b5132 449 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
6feb9908
AM
450 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
451 { {"reduce-memory-overheads", no_argument, NULL,
452 OPTION_REDUCE_MEMORY_OVERHEADS},
453 '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
454 TWO_DASHES },
a8dde0a2
L
455 { {"max-cache-size=SIZE", required_argument, NULL,
456 OPTION_MAX_CACHE_SIZE},
457 '\0', NULL, N_("Set the maximum cache size to SIZE bytes"),
458 TWO_DASHES },
252b5132 459 { {"relax", no_argument, NULL, OPTION_RELAX},
28d5f677
NC
460 '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
461 { {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
462 '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES },
252b5132 463 { {"retain-symbols-file", required_argument, NULL,
6feb9908
AM
464 OPTION_RETAIN_SYMBOLS_FILE},
465 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
252b5132 466 { {"rpath", required_argument, NULL, OPTION_RPATH},
6feb9908 467 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
252b5132 468 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
6feb9908
AM
469 '\0', N_("PATH"), N_("Set link time shared library search path"),
470 ONE_DASH },
252b5132 471 { {"shared", no_argument, NULL, OPTION_SHARED},
6feb9908 472 '\0', NULL, N_("Create a shared library"), ONE_DASH },
252b5132 473 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
6feb9908 474 '\0', NULL, NULL, ONE_DASH },
36af4a4e 475 { {"pie", no_argument, NULL, OPTION_PIE},
6feb9908 476 '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
36af4a4e 477 { {"pic-executable", no_argument, NULL, OPTION_PIE},
6feb9908 478 '\0', NULL, NULL, TWO_DASHES },
e8f6c2a5
FS
479 { {"no-pie", no_argument, NULL, OPTION_NO_PIE},
480 '\0', NULL, N_("Create a position dependent executable (default)"), ONE_DASH },
de7dd2bd 481 { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
9d5777a3
RM
482 '\0', N_("[=ascending|descending]"),
483 N_("Sort common symbols by alignment [in specified order]"),
de7dd2bd 484 TWO_DASHES },
252b5132 485 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
6feb9908 486 '\0', NULL, NULL, NO_HELP },
bcaa7b3e 487 { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
9d5777a3 488 '\0', N_("name|alignment"),
bcaa7b3e 489 N_("Sort sections by name or maximum alignment"), TWO_DASHES },
6e8376fa
NC
490 { {"section-ordering-file", required_argument, NULL, OPTION_SECTION_ORDERING_FILE},
491 '\0', N_("FILE"),
492 N_("Sort sections by statements in FILE"), TWO_DASHES },
db6751f2 493 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
6feb9908
AM
494 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
495 TWO_DASHES },
a854a4a7 496 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
6feb9908
AM
497 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
498 TWO_DASHES },
a854a4a7 499 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
6feb9908
AM
500 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
501 TWO_DASHES },
252b5132 502 { {"stats", no_argument, NULL, OPTION_STATS},
6feb9908 503 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
ea20a7da 504 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
6feb9908 505 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
252b5132 506 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
6feb9908 507 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
252b5132 508 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
6feb9908 509 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
176355da 510 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
6feb9908
AM
511 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
512 TWO_DASHES },
252b5132 513 { {"Tbss", required_argument, NULL, OPTION_TBSS},
6feb9908 514 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
252b5132 515 { {"Tdata", required_argument, NULL, OPTION_TDATA},
6feb9908 516 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
252b5132 517 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
6feb9908 518 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
258795f5
L
519 { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT},
520 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH },
9d5777a3
RM
521 { {"Trodata-segment", required_argument, NULL, OPTION_TRODATA_SEGMENT},
522 '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH },
0d705e9f
AM
523 { {"Tldata-segment", required_argument, NULL, OPTION_TLDATA_SEGMENT},
524 '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH },
6feb9908
AM
525 { {"unresolved-symbols=<method>", required_argument, NULL,
526 OPTION_UNRESOLVED_SYMBOLS},
527 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n"
c58dea77
AM
528 " ignore-all, report-all, ignore-in-object-files,\n"
529 " ignore-in-shared-libs"),
530 TWO_DASHES },
1715a13c
L
531 { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
532 '\0', N_("[=NUMBER]"),
533 N_("Output lots of information during link"), TWO_DASHES },
252b5132 534 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
6feb9908 535 '\0', NULL, NULL, NO_HELP },
252b5132 536 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
6feb9908 537 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
252b5132
RH
538 { {"version-exports-section", required_argument, NULL,
539 OPTION_VERSION_EXPORTS_SECTION },
6feb9908 540 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
c58dea77
AM
541 " SYMBOL as the version."),
542 TWO_DASHES },
40b36307
L
543 { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
544 '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
545 { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
546 '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
55255dae
L
547 { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
548 '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
549 { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
550 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
37a141bf
FS
551 { {"export-dynamic-symbol", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL},
552 '\0', N_("SYMBOL"), N_("Export the specified symbol"), EXACTLY_TWO_DASHES },
553 { {"export-dynamic-symbol-list", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL_LIST},
554 '\0', N_("FILE"), N_("Read export dynamic symbol list"), EXACTLY_TWO_DASHES },
252b5132 555 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
6feb9908 556 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
252b5132 557 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
6feb9908
AM
558 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
559 TWO_DASHES },
e922d1ea
NC
560
561 { {"error-execstack", no_argument, NULL, OPTION_ERROR_EXECSTACK},
562 '\0', NULL, NULL, TWO_DASHES },
563 { {"no-error-execstack", no_argument, NULL, OPTION_NO_ERROR_EXECSTACK},
564 '\0', NULL, NULL, TWO_DASHES },
565 { {"warn-execstack-objects", no_argument, NULL, OPTION_WARN_EXECSTACK_OBJECTS},
566 '\0', NULL, NULL, TWO_DASHES },
65daf5be 567 { {"warn-execstack", no_argument, NULL, OPTION_WARN_EXECSTACK},
e922d1ea 568 '\0', NULL, NULL, TWO_DASHES },
65daf5be 569 { {"no-warn-execstack", no_argument, NULL, OPTION_NO_WARN_EXECSTACK},
e922d1ea
NC
570 '\0', NULL, NULL, TWO_DASHES },
571
572 { {"error-rwx-segments", no_argument, NULL, OPTION_ERROR_RWX_SEGMENTS},
573 '\0', NULL, NULL, TWO_DASHES },
574 { {"no-error-rwx-segments", no_argument, NULL, OPTION_NO_ERROR_RWX_SEGMENTS},
575 '\0', NULL, NULL, TWO_DASHES },
ba951afb 576 { {"warn-rwx-segments", no_argument, NULL, OPTION_WARN_RWX_SEGMENTS},
e922d1ea 577 '\0', NULL, NULL, TWO_DASHES },
ba951afb 578 { {"no-warn-rwx-segments", no_argument, NULL, OPTION_NO_WARN_RWX_SEGMENTS},
e922d1ea
NC
579 '\0', NULL, NULL, TWO_DASHES },
580
252b5132 581 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
6feb9908 582 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
252b5132 583 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
6feb9908 584 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
252b5132 585 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
6feb9908
AM
586 '\0', NULL, N_("Warn if start of section changes due to alignment"),
587 TWO_DASHES },
a6dbf402 588 { {"warn-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
b32632c4
L
589 '\0', NULL,
590#if DEFAULT_LD_TEXTREL_CHECK_WARNING
ddc73fa9 591 N_("Warn if output has DT_TEXTREL (default)"),
b32632c4 592#else
ddc73fa9 593 N_("Warn if output has DT_TEXTREL"),
b32632c4 594#endif
8fdd7217 595 TWO_DASHES },
a6dbf402
L
596 { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
597 '\0', NULL, NULL, NO_HELP },
a0c402a5
L
598 { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
599 '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
600 TWO_DASHES },
6feb9908
AM
601 { {"warn-unresolved-symbols", no_argument, NULL,
602 OPTION_WARN_UNRESOLVED_SYMBOLS},
560e09e9 603 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
6feb9908
AM
604 { {"error-unresolved-symbols", no_argument, NULL,
605 OPTION_ERROR_UNRESOLVED_SYMBOLS},
560e09e9 606 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
252b5132 607 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
6feb9908
AM
608 '\0', NULL, N_("Include all objects from following archives"),
609 TWO_DASHES },
252b5132 610 { {"wrap", required_argument, NULL, OPTION_WRAP},
6feb9908 611 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
0e86e20e
AM
612 { {"ignore-unresolved-symbol", required_argument, NULL,
613 OPTION_IGNORE_UNRESOLVED_SYMBOL},
614 '\0', N_("SYMBOL"),
615 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
26278bb8
UD
616 { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
617 '\0', NULL, N_("Push state of flags governing input file handling"),
618 TWO_DASHES },
619 { {"pop-state", no_argument, NULL, OPTION_POP_STATE},
620 '\0', NULL, N_("Pop state of flags governing input file handling"),
621 TWO_DASHES },
3604cb1f
TG
622 { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE},
623 '\0', NULL, N_("Report target memory usage"), TWO_DASHES },
c005eb9e
AB
624 { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING},
625 '\0', N_("=MODE"), N_("Control how orphan sections are handled."),
626 TWO_DASHES },
035801ce
FS
627 { {"print-map-discarded", no_argument, NULL, OPTION_PRINT_MAP_DISCARDED},
628 '\0', NULL, N_("Show discarded sections in map file output (default)"),
629 TWO_DASHES },
630 { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISCARDED},
631 '\0', NULL, N_("Do not show discarded sections in map file output"),
632 TWO_DASHES },
496917ce
NC
633 { {"print-map-locals", no_argument, NULL, OPTION_PRINT_MAP_LOCALS},
634 '\0', NULL, N_("Show local symbols in map file output"),
635 TWO_DASHES },
636 { {"no-print-map-locals", no_argument, NULL, OPTION_NO_PRINT_MAP_LOCALS},
637 '\0', NULL, N_("Do not show local symbols in map file output (default)"),
638 TWO_DASHES },
5dba6f05
NA
639 { {"ctf-variables", no_argument, NULL, OPTION_CTF_VARIABLES},
640 '\0', NULL, N_("Emit names and types of static variables in CTF"),
641 TWO_DASHES },
642 { {"no-ctf-variables", no_argument, NULL, OPTION_NO_CTF_VARIABLES},
643 '\0', NULL, N_("Do not emit names and types of static variables in CTF"),
644 TWO_DASHES },
645 { {"ctf-share-types=<method>", required_argument, NULL,
646 OPTION_CTF_SHARE_TYPES},
647 '\0', NULL, N_("How to share CTF types between translation units.\n"
648 " <method> is: share-unconflicted (default),\n"
649 " share-duplicated"),
650 TWO_DASHES },
252b5132
RH
651};
652
e4897a32 653#define OPTION_COUNT ARRAY_SIZE (ld_options)
252b5132 654
252b5132 655void
1579bae1 656parse_args (unsigned argc, char **argv)
252b5132 657{
e4897a32
NC
658 unsigned i;
659 int is, il, irl;
252b5132
RH
660 int ingroup = 0;
661 char *default_dirlist = NULL;
3bcf5557
AM
662 char *shortopts;
663 struct option *longopts;
664 struct option *really_longopts;
252b5132 665 int last_optind;
1914e264
AM
666 enum symbolic_enum
667 {
668 symbolic_unset = 0,
669 symbolic,
670 symbolic_functions,
671 } opt_symbolic = symbolic_unset;
672 enum dynamic_list_enum
673 {
674 dynamic_list_unset = 0,
675 dynamic_list_data,
676 dynamic_list
677 } opt_dynamic_list = dynamic_list_unset;
37a141bf 678 struct bfd_elf_dynamic_list *export_list = NULL;
252b5132 679
1e9cc1c2
NC
680 shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
681 longopts = (struct option *)
682 xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
683 really_longopts = (struct option *)
ee44c2ac 684 xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
3bcf5557 685
252b5132
RH
686 /* Starting the short option string with '-' is for programs that
687 expect options and other ARGV-elements in any order and that care about
688 the ordering of the two. We describe each non-option ARGV-element
689 as if it were the argument of an option with character code 1. */
690 shortopts[0] = '-';
691 is = 1;
692 il = 0;
e4897a32 693 irl = 0;
252b5132
RH
694 for (i = 0; i < OPTION_COUNT; i++)
695 {
696 if (ld_options[i].shortopt != '\0')
697 {
698 shortopts[is] = ld_options[i].shortopt;
699 ++is;
700 if (ld_options[i].opt.has_arg == required_argument
701 || ld_options[i].opt.has_arg == optional_argument)
702 {
703 shortopts[is] = ':';
704 ++is;
705 if (ld_options[i].opt.has_arg == optional_argument)
706 {
707 shortopts[is] = ':';
708 ++is;
709 }
710 }
711 }
712 if (ld_options[i].opt.name != NULL)
713 {
e4897a32
NC
714 if (ld_options[i].control == EXACTLY_TWO_DASHES)
715 {
716 really_longopts[irl] = ld_options[i].opt;
717 ++irl;
718 }
719 else
720 {
721 longopts[il] = ld_options[i].opt;
722 ++il;
723 }
252b5132
RH
724 }
725 }
726 shortopts[is] = '\0';
727 longopts[il].name = NULL;
e4897a32 728 really_longopts[irl].name = NULL;
252b5132 729
3bcf5557
AM
730 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
731
252b5132
RH
732 /* The -G option is ambiguous on different platforms. Sometimes it
733 specifies the largest data size to put into the small data
734 section. Sometimes it is equivalent to --shared. Unfortunately,
735 the first form takes an argument, while the second does not.
736
737 We need to permit the --shared form because on some platforms,
738 such as Solaris, gcc -shared will pass -G to the linker.
739
740 To permit either usage, we look through the argument list. If we
741 find -G not followed by a number, we change it into --shared.
742 This will work for most normal cases. */
743 for (i = 1; i < argc; i++)
744 if (strcmp (argv[i], "-G") == 0
745 && (i + 1 >= argc
3882b010 746 || ! ISDIGIT (argv[i + 1][0])))
252b5132
RH
747 argv[i] = (char *) "--shared";
748
749 /* Because we permit long options to start with a single dash, and
750 we have a --library option, and the -l option is conventionally
751 used with an immediately following argument, we can have bad
752 results if somebody tries to use -l with a library whose name
753 happens to start with "ibrary", as in -li. We avoid problems by
754 simply turning -l into --library. This means that users will
755 have to use two dashes in order to use --library, which is OK
756 since that's how it is documented.
757
758 FIXME: It's possible that this problem can arise for other short
759 options as well, although the user does always have the recourse
760 of adding a space between the option and the argument. */
761 for (i = 1; i < argc; i++)
762 {
763 if (argv[i][0] == '-'
764 && argv[i][1] == 'l'
765 && argv[i][2] != '\0')
766 {
767 char *n;
768
1e9cc1c2 769 n = (char *) xmalloc (strlen (argv[i]) + 20);
252b5132
RH
770 sprintf (n, "--library=%s", argv[i] + 2);
771 argv[i] = n;
772 }
773 }
774
775 last_optind = -1;
776 while (1)
777 {
3991c7ac 778 int longind = 0;
252b5132 779 int optc;
dab69f68 780 static unsigned int defsym_count;
252b5132
RH
781
782 /* Using last_optind lets us avoid calling ldemul_parse_args
783 multiple times on a single option, which would lead to
784 confusion in the internal static variables maintained by
785 getopt. This could otherwise happen for an argument like
786 -nx, in which the -n is parsed as a single option, and we
787 loop around to pick up the -x. */
788 if (optind != last_optind)
89894c62
AM
789 if (ldemul_parse_args (argc, argv))
790 continue;
252b5132
RH
791
792 /* getopt_long_only is like getopt_long, but '-' as well as '--'
793 can indicate a long option. */
0fc3347a 794 opterr = 0;
89894c62 795 last_optind = optind;
252b5132 796 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
0fc3347a
NC
797 if (optc == '?')
798 {
89894c62
AM
799 optind = last_optind;
800 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
0fc3347a 801 }
983d925d
NC
802 /* Attempt to detect grouped short options, eg: "-non-start".
803 Accepting such options is error prone as it is not clear if the user
804 intended "-n -o n-start" or "--non-start". */
805 else if (longind == 0 /* This is a short option. */
806 && optc > 32 /* It is a valid option. */
807 /* The character is not the second character of argv[last_optind]. */
808 && optc != argv[last_optind][1])
809 {
810 if (optarg)
811 einfo (_("%F%P: Error: unable to disambiguate: %s (did you mean -%s ?)\n"),
812 argv[last_optind], argv[last_optind]);
813 else
814 einfo (_("%P: Warning: grouped short command line options are deprecated: %s\n"), argv[last_optind]);
815 }
b7ed8fad 816
3bcf5557
AM
817 if (ldemul_handle_option (optc))
818 continue;
819
252b5132
RH
820 if (optc == -1)
821 break;
0fc3347a 822
252b5132
RH
823 switch (optc)
824 {
0fc3347a 825 case '?':
f82aa165
NC
826 {
827 /* If the last word on the command line is an option that
828 requires an argument, getopt will refuse to recognise it.
829 Try to catch such options here and issue a more helpful
830 error message than just "unrecognized option". */
831 int opt;
832
833 for (opt = ARRAY_SIZE (ld_options); opt--;)
834 if (ld_options[opt].opt.has_arg == required_argument
835 /* FIXME: There are a few short options that do not
836 have long equivalents, but which require arguments.
837 We should handle them too. */
838 && ld_options[opt].opt.name != NULL
839 && strcmp (argv[last_optind] + ld_options[opt].control, ld_options[opt].opt.name) == 0)
840 {
841 einfo (_("%P: %s: missing argument\n"), argv[last_optind]);
842 break;
843 }
844
845 if (opt == -1)
846 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
847 }
058a363d
BE
848 /* Fall through. */
849
252b5132 850 default:
df5f2391 851 einfo (_("%F%P: use the --help option for usage information\n"));
80bb3407 852 break;
210a7bd1 853
252b5132 854 case 1: /* File name. */
1579bae1 855 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
252b5132
RH
856 break;
857
858 case OPTION_IGNORE:
859 break;
860 case 'a':
861 /* For HP/UX compatibility. Actually -a shared should mean
1579bae1
AM
862 ``use only shared libraries'' but, then, we don't
863 currently support shared libraries on HP/UX anyhow. */
252b5132 864 if (strcmp (optarg, "archive") == 0)
f38a2680 865 input_flags.dynamic = false;
252b5132
RH
866 else if (strcmp (optarg, "shared") == 0
867 || strcmp (optarg, "default") == 0)
f38a2680 868 input_flags.dynamic = true;
252b5132 869 else
df5f2391 870 einfo (_("%F%P: unrecognized -a option `%s'\n"), optarg);
252b5132
RH
871 break;
872 case OPTION_ASSERT:
873 /* FIXME: We just ignore these, but we should handle them. */
874 if (strcmp (optarg, "definitions") == 0)
875 ;
876 else if (strcmp (optarg, "nodefinitions") == 0)
877 ;
878 else if (strcmp (optarg, "nosymbolic") == 0)
879 ;
880 else if (strcmp (optarg, "pure-text") == 0)
881 ;
882 else
df5f2391 883 einfo (_("%F%P: unrecognized -assert option `%s'\n"), optarg);
252b5132
RH
884 break;
885 case 'A':
886 ldfile_add_arch (optarg);
887 break;
888 case 'b':
889 lang_add_target (optarg);
890 break;
891 case 'c':
892 ldfile_open_command_file (optarg);
893 parser_input = input_mri_script;
894 yyparse ();
895 break;
896 case OPTION_CALL_SHARED:
f38a2680 897 input_flags.dynamic = true;
252b5132
RH
898 break;
899 case OPTION_NON_SHARED:
f38a2680 900 input_flags.dynamic = false;
252b5132
RH
901 break;
902 case OPTION_CREF:
f38a2680
AM
903 command_line.cref = true;
904 link_info.notice_all = true;
252b5132
RH
905 break;
906 case 'd':
f38a2680 907 command_line.force_common_definition = true;
252b5132 908 break;
6c19b93b 909 case OPTION_FORCE_GROUP_ALLOCATION:
f38a2680 910 command_line.force_group_allocation = true;
6c19b93b 911 break;
252b5132
RH
912 case OPTION_DEFSYM:
913 lex_string = optarg;
dab69f68 914 lex_redirect (optarg, "--defsym", ++defsym_count);
252b5132 915 parser_input = input_defsym;
252b5132 916 yyparse ();
252b5132
RH
917 lex_string = NULL;
918 break;
919 case OPTION_DEMANGLE:
f38a2680 920 demangling = true;
28c309a2
NC
921 if (optarg != NULL)
922 {
923 enum demangling_styles style;
5cc18311 924
28c309a2 925 style = cplus_demangle_name_to_style (optarg);
5cc18311 926 if (style == unknown_demangling)
1d6d1a2c 927 einfo (_("%F%P: unknown demangling style `%s'\n"),
28c309a2 928 optarg);
5cc18311 929
28c309a2 930 cplus_demangle_set_style (style);
e47d05ad 931 }
252b5132 932 break;
506eee22 933 case 'I': /* Used on Solaris. */
252b5132
RH
934 case OPTION_DYNAMIC_LINKER:
935 command_line.interpreter = optarg;
9b8b325a
RF
936 link_info.nointerp = 0;
937 break;
938 case OPTION_NO_DYNAMIC_LINKER:
939 link_info.nointerp = 1;
252b5132 940 break;
e2243057
RS
941 case OPTION_SYSROOT:
942 /* Already handled in ldmain.c. */
943 break;
252b5132
RH
944 case OPTION_EB:
945 command_line.endian = ENDIAN_BIG;
946 break;
947 case OPTION_EL:
948 command_line.endian = ENDIAN_LITTLE;
949 break;
950 case OPTION_EMBEDDED_RELOCS:
f38a2680 951 command_line.embedded_relocs = true;
252b5132
RH
952 break;
953 case OPTION_EXPORT_DYNAMIC:
954 case 'E': /* HP/UX compatibility. */
f38a2680 955 link_info.export_dynamic = true;
252b5132 956 break;
267e2722 957 case OPTION_NO_EXPORT_DYNAMIC:
f38a2680 958 link_info.export_dynamic = false;
267e2722 959 break;
abf874aa 960 case OPTION_NON_CONTIGUOUS_REGIONS:
f38a2680 961 link_info.non_contiguous_regions = true;
abf874aa
CL
962 break;
963 case OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS:
f38a2680 964 link_info.non_contiguous_regions_warnings = true;
abf874aa 965 break;
e922d1ea
NC
966
967 case OPTION_ERROR_EXECSTACK:
968 link_info.error_execstack = 1;
969 break;
970 case OPTION_NO_ERROR_EXECSTACK:
971 link_info.error_execstack = 0;
972 break;
973 case OPTION_WARN_EXECSTACK_OBJECTS:
974 link_info.warn_execstack = 2;
975 break;
65daf5be
NC
976 case OPTION_WARN_EXECSTACK:
977 link_info.warn_execstack = 1;
978 break;
979 case OPTION_NO_WARN_EXECSTACK:
bd7d326d 980 link_info.warn_execstack = 0;
65daf5be 981 break;
e922d1ea
NC
982
983 case OPTION_ERROR_RWX_SEGMENTS:
984 link_info.warn_is_error_for_rwx_segments = 1;
985 break;
986 case OPTION_NO_ERROR_RWX_SEGMENTS:
987 link_info.warn_is_error_for_rwx_segments = 0;
988 break;
ba951afb
NC
989 case OPTION_WARN_RWX_SEGMENTS:
990 link_info.no_warn_rwx_segments = 0;
84789002 991 link_info.user_warn_rwx_segments = 1;
ba951afb
NC
992 break;
993 case OPTION_NO_WARN_RWX_SEGMENTS:
994 link_info.no_warn_rwx_segments = 1;
84789002 995 link_info.user_warn_rwx_segments = 1;
ba951afb 996 break;
e922d1ea 997
252b5132 998 case 'e':
f38a2680 999 lang_add_entry (optarg, true);
252b5132
RH
1000 break;
1001 case 'f':
1002 if (command_line.auxiliary_filters == NULL)
1003 {
1e9cc1c2 1004 command_line.auxiliary_filters = (char **)
6c19b93b 1005 xmalloc (2 * sizeof (char *));
252b5132
RH
1006 command_line.auxiliary_filters[0] = optarg;
1007 command_line.auxiliary_filters[1] = NULL;
1008 }
1009 else
1010 {
1011 int c;
1012 char **p;
1013
1014 c = 0;
1015 for (p = command_line.auxiliary_filters; *p != NULL; p++)
1016 ++c;
1e9cc1c2 1017 command_line.auxiliary_filters = (char **)
6c19b93b
AM
1018 xrealloc (command_line.auxiliary_filters,
1019 (c + 2) * sizeof (char *));
252b5132
RH
1020 command_line.auxiliary_filters[c] = optarg;
1021 command_line.auxiliary_filters[c + 1] = NULL;
1022 }
1023 break;
1024 case 'F':
1025 command_line.filter_shlib = optarg;
1026 break;
1027 case OPTION_FORCE_EXE_SUFFIX:
f38a2680 1028 command_line.force_exe_suffix = true;
252b5132
RH
1029 break;
1030 case 'G':
1031 {
1032 char *end;
1033 g_switch_value = strtoul (optarg, &end, 0);
1034 if (*end)
df5f2391 1035 einfo (_("%F%P: invalid number `%s'\n"), optarg);
252b5132
RH
1036 }
1037 break;
1038 case 'g':
1039 /* Ignore. */
1040 break;
1041 case OPTION_GC_SECTIONS:
f38a2680 1042 link_info.gc_sections = true;
252b5132 1043 break;
c17d87de 1044 case OPTION_PRINT_GC_SECTIONS:
f38a2680 1045 link_info.print_gc_sections = true;
c17d87de 1046 break;
22185505 1047 case OPTION_GC_KEEP_EXPORTED:
f38a2680 1048 link_info.gc_keep_exported = true;
22185505 1049 break;
252b5132
RH
1050 case OPTION_HELP:
1051 help ();
1052 xexit (0);
1053 break;
1054 case 'L':
f38a2680 1055 ldfile_add_library_path (optarg, true);
252b5132
RH
1056 break;
1057 case 'l':
1579bae1 1058 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
252b5132
RH
1059 break;
1060 case 'M':
1061 config.map_filename = "-";
1062 break;
1063 case 'm':
1064 /* Ignore. Was handled in a pre-parse. */
1065 break;
1066 case OPTION_MAP:
1067 config.map_filename = optarg;
1068 break;
1069 case 'N':
f38a2680
AM
1070 config.text_read_only = false;
1071 config.magic_demand_paged = false;
1072 input_flags.dynamic = false;
252b5132 1073 break;
63fd3b82 1074 case OPTION_NO_OMAGIC:
f38a2680
AM
1075 config.text_read_only = true;
1076 config.magic_demand_paged = true;
66be1055 1077 /* NB/ Does not set input_flags.dynamic to TRUE.
63fd3b82
NC
1078 Use --call-shared or -Bdynamic for this. */
1079 break;
252b5132 1080 case 'n':
f38a2680
AM
1081 config.text_read_only = true;
1082 config.magic_demand_paged = false;
1083 input_flags.dynamic = false;
252b5132 1084 break;
4818e05f 1085 case OPTION_NO_DEFINE_COMMON:
f38a2680 1086 link_info.inhibit_common_definition = true;
4818e05f 1087 break;
252b5132 1088 case OPTION_NO_DEMANGLE:
f38a2680 1089 demangling = false;
252b5132
RH
1090 break;
1091 case OPTION_NO_GC_SECTIONS:
f38a2680 1092 link_info.gc_sections = false;
252b5132 1093 break;
c17d87de 1094 case OPTION_NO_PRINT_GC_SECTIONS:
f38a2680 1095 link_info.print_gc_sections = false;
c17d87de 1096 break;
252b5132 1097 case OPTION_NO_KEEP_MEMORY:
f38a2680 1098 link_info.keep_memory = false;
252b5132
RH
1099 break;
1100 case OPTION_NO_UNDEFINED:
95a51568 1101 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
252b5132 1102 break;
b79e8c78 1103 case OPTION_ALLOW_SHLIB_UNDEFINED:
560e09e9 1104 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
b79e8c78 1105 break;
ae9a127f 1106 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
95a51568 1107 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
ae9a127f 1108 break;
560e09e9
NC
1109 case OPTION_UNRESOLVED_SYMBOLS:
1110 if (strcmp (optarg, "ignore-all") == 0)
1111 {
1112 link_info.unresolved_syms_in_objects = RM_IGNORE;
1113 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1114 }
1115 else if (strcmp (optarg, "report-all") == 0)
1116 {
95a51568
FS
1117 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
1118 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
560e09e9
NC
1119 }
1120 else if (strcmp (optarg, "ignore-in-object-files") == 0)
1121 {
1122 link_info.unresolved_syms_in_objects = RM_IGNORE;
95a51568 1123 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
560e09e9 1124 }
6c19b93b 1125 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
560e09e9 1126 {
95a51568 1127 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
560e09e9
NC
1128 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1129 }
1130 else
df5f2391 1131 einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg);
560e09e9
NC
1132 break;
1133 case OPTION_WARN_UNRESOLVED_SYMBOLS:
f38a2680 1134 link_info.warn_unresolved_syms = true;
560e09e9 1135 break;
560e09e9 1136 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
f38a2680 1137 link_info.warn_unresolved_syms = false;
6feb9908 1138 break;
aa713662 1139 case OPTION_ALLOW_MULTIPLE_DEFINITION:
f38a2680 1140 link_info.allow_multiple_definition = true;
aa713662 1141 break;
23ae20f5
NC
1142
1143#if SUPPORT_ERROR_HANDLING_SCRIPT
1144 case OPTION_ERROR_HANDLING_SCRIPT:
1145 /* FIXME: Should we warn if the script is being overridden by another ?
1146 Or maybe they should be chained together ? */
1147 error_handling_script = optarg;
1148 break;
1149#endif
1150
2d5783fa
NC
1151 case OPTION_ENABLE_LINKER_VERSION:
1152 enable_linker_version = true;
1153 break;
1154 case OPTION_DISABLE_LINKER_VERSION:
1155 enable_linker_version = false;
1156 break;
1157
27fb6a1a
FS
1158 case OPTION_UNDEFINED_VERSION:
1159 link_info.allow_undefined_version = true;
1160 break;
31941635 1161 case OPTION_NO_UNDEFINED_VERSION:
f38a2680 1162 link_info.allow_undefined_version = false;
31941635 1163 break;
3e3b46e5 1164 case OPTION_DEFAULT_SYMVER:
f38a2680 1165 link_info.create_default_symver = true;
3e3b46e5 1166 break;
fc0e6df6 1167 case OPTION_DEFAULT_IMPORTED_SYMVER:
f38a2680 1168 link_info.default_imported_symver = true;
fc0e6df6 1169 break;
252b5132 1170 case OPTION_NO_WARN_MISMATCH:
f38a2680 1171 command_line.warn_mismatch = false;
252b5132 1172 break;
fe7929ce 1173 case OPTION_NO_WARN_SEARCH_MISMATCH:
f38a2680 1174 command_line.warn_search_mismatch = false;
fe7929ce 1175 break;
252b5132 1176 case OPTION_NOINHIBIT_EXEC:
f38a2680 1177 force_make_executable = true;
252b5132 1178 break;
361b220e 1179 case OPTION_NOSTDLIB:
f38a2680 1180 config.only_cmd_line_lib_dirs = true;
361b220e 1181 break;
252b5132 1182 case OPTION_NO_WHOLE_ARCHIVE:
f38a2680 1183 input_flags.whole_archive = false;
252b5132
RH
1184 break;
1185 case 'O':
1186 /* FIXME "-O<non-digits> <value>" used to set the address of
1187 section <non-digits>. Was this for compatibility with
1188 something, or can we create a new option to do that
1189 (with a syntax similar to -defsym)?
1190 getopt can't handle two args to an option without kludges. */
1191
1192 /* Enable optimizations of output files. */
63b4cc53 1193 link_info.optimize = strtoul (optarg, NULL, 0) != 0;
252b5132
RH
1194 break;
1195 case 'o':
5cc18311 1196 lang_add_output (optarg, 0);
252b5132
RH
1197 break;
1198 case OPTION_OFORMAT:
1579bae1 1199 lang_add_output_format (optarg, NULL, NULL, 0);
252b5132 1200 break;
76359541
TP
1201 case OPTION_OUT_IMPLIB:
1202 command_line.out_implib_filename = xstrdup (optarg);
1203 break;
cb9322a8
HPN
1204 case OPTION_PRINT_SYSROOT:
1205 if (*ld_sysroot)
1206 puts (ld_sysroot);
1207 xexit (0);
1208 break;
30824704 1209 case OPTION_PRINT_OUTPUT_FORMAT:
f38a2680 1210 command_line.print_output_format = true;
30824704 1211 break;
0381901e 1212#if BFD_SUPPORTS_PLUGINS
5d3236ee 1213 case OPTION_PLUGIN:
d82184d7 1214 plugin_opt_plugin (optarg);
5d3236ee
DK
1215 break;
1216 case OPTION_PLUGIN_OPT:
1217 if (plugin_opt_plugin_arg (optarg))
df5f2391 1218 einfo (_("%F%P: bad -plugin-opt option\n"));
5d3236ee 1219 break;
d9511b64
L
1220 case OPTION_PLUGIN_SAVE_TEMPS:
1221 config.plugin_save_temps = true;
1222 break;
0381901e 1223#endif /* BFD_SUPPORTS_PLUGINS */
a712da20 1224 case 'q':
f38a2680 1225 link_info.emitrelocations = true;
a712da20 1226 break;
8c5ff972 1227 case 'i':
252b5132 1228 case 'r':
210a7bd1
NC
1229 if (optind == last_optind)
1230 /* This can happen if the user put "-rpath,a" on the command
1231 line. (Or something similar. The comma is important).
1232 Getopt becomes confused and thinks that this is a -r option
1233 but it cannot parse the text after the -r so it refuses to
1234 increment the optind counter. Detect this case and issue
1235 an error message here. We cannot just make this a warning,
1236 increment optind, and continue because getopt is too confused
1237 and will seg-fault the next time around. */
df5f2391 1238 einfo(_("%F%P: unrecognised option: %s\n"), argv[optind]);
b7a26f91 1239
0e1862bb 1240 if (bfd_link_pic (&link_info))
df5f2391 1241 einfo (_("%F%P: -r and %s may not be used together\n"),
0e1862bb
L
1242 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1243
1244 link_info.type = type_relocatable;
f38a2680
AM
1245 config.build_constructors = false;
1246 config.magic_demand_paged = false;
1247 config.text_read_only = false;
1248 input_flags.dynamic = false;
252b5132
RH
1249 break;
1250 case 'R':
1251 /* The GNU linker traditionally uses -R to mean to include
1252 only the symbols from a file. The Solaris linker uses -R
1253 to set the path used by the runtime linker to find
1254 libraries. This is the GNU linker -rpath argument. We
1255 try to support both simultaneously by checking the file
1256 named. If it is a directory, rather than a regular file,
1257 we assume -rpath was meant. */
1258 {
1259 struct stat s;
1260
1261 if (stat (optarg, &s) >= 0
1262 && ! S_ISDIR (s.st_mode))
1263 {
1264 lang_add_input_file (optarg,
1265 lang_input_file_is_symbols_only_enum,
1579bae1 1266 NULL);
252b5132
RH
1267 break;
1268 }
1269 }
1270 /* Fall through. */
1271 case OPTION_RPATH:
1272 if (command_line.rpath == NULL)
d1b2b2dc 1273 command_line.rpath = xstrdup (optarg);
252b5132
RH
1274 else
1275 {
1276 size_t rpath_len = strlen (command_line.rpath);
1277 size_t optarg_len = strlen (optarg);
1278 char *buf;
1279 char *cp = command_line.rpath;
1280
1281 /* First see whether OPTARG is already in the path. */
1282 do
1283 {
c76308d2
RS
1284 if (strncmp (optarg, cp, optarg_len) == 0
1285 && (cp[optarg_len] == 0
1286 || cp[optarg_len] == config.rpath_separator))
252b5132
RH
1287 /* We found it. */
1288 break;
1289
1290 /* Not yet found. */
c76308d2 1291 cp = strchr (cp, config.rpath_separator);
252b5132
RH
1292 if (cp != NULL)
1293 ++cp;
1294 }
1295 while (cp != NULL);
1296
1297 if (cp == NULL)
1298 {
1e9cc1c2 1299 buf = (char *) xmalloc (rpath_len + optarg_len + 2);
c76308d2
RS
1300 sprintf (buf, "%s%c%s", command_line.rpath,
1301 config.rpath_separator, optarg);
252b5132
RH
1302 free (command_line.rpath);
1303 command_line.rpath = buf;
1304 }
1305 }
1306 break;
1307 case OPTION_RPATH_LINK:
1308 if (command_line.rpath_link == NULL)
d1b2b2dc 1309 command_line.rpath_link = xstrdup (optarg);
252b5132
RH
1310 else
1311 {
1312 char *buf;
1313
1e9cc1c2 1314 buf = (char *) xmalloc (strlen (command_line.rpath_link)
6c19b93b
AM
1315 + strlen (optarg)
1316 + 2);
c76308d2
RS
1317 sprintf (buf, "%s%c%s", command_line.rpath_link,
1318 config.rpath_separator, optarg);
252b5132
RH
1319 free (command_line.rpath_link);
1320 command_line.rpath_link = buf;
1321 }
1322 break;
28d5f677
NC
1323 case OPTION_NO_RELAX:
1324 DISABLE_RELAXATION;
1325 break;
252b5132 1326 case OPTION_RELAX:
28d5f677 1327 ENABLE_RELAXATION;
252b5132
RH
1328 break;
1329 case OPTION_RETAIN_SYMBOLS_FILE:
1330 add_keepsyms_file (optarg);
1331 break;
1332 case 'S':
1333 link_info.strip = strip_debugger;
1334 break;
1335 case 's':
1336 link_info.strip = strip_all;
1337 break;
d5cd3933 1338 case OPTION_STRIP_DISCARDED:
f38a2680 1339 link_info.strip_discarded = true;
d5cd3933
AM
1340 break;
1341 case OPTION_NO_STRIP_DISCARDED:
f38a2680 1342 link_info.strip_discarded = false;
d5cd3933 1343 break;
3f0a5f17 1344 case OPTION_DISABLE_MULTIPLE_DEFS_ABS:
f38a2680 1345 link_info.prohibit_multiple_definition_absolute = true;
3f0a5f17 1346 break;
252b5132
RH
1347 case OPTION_SHARED:
1348 if (config.has_shared)
560e09e9 1349 {
0e1862bb 1350 if (bfd_link_relocatable (&link_info))
df5f2391
AM
1351 einfo (_("%F%P: -r and %s may not be used together\n"),
1352 "-shared");
0e1862bb
L
1353
1354 link_info.type = type_dll;
560e09e9
NC
1355 /* When creating a shared library, the default
1356 behaviour is to ignore any unresolved references. */
1357 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1358 link_info.unresolved_syms_in_objects = RM_IGNORE;
1359 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1360 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1361 }
252b5132 1362 else
df5f2391 1363 einfo (_("%F%P: -shared not supported\n"));
252b5132 1364 break;
e8f6c2a5
FS
1365 case OPTION_NO_PIE:
1366 link_info.type = type_pde;
1367 break;
36af4a4e
JJ
1368 case OPTION_PIE:
1369 if (config.has_shared)
1370 {
0e1862bb 1371 if (bfd_link_relocatable (&link_info))
df5f2391 1372 einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
0e1862bb 1373
64d94ba0 1374 link_info.type = type_pie;
36af4a4e
JJ
1375 }
1376 else
df5f2391 1377 einfo (_("%F%P: -pie not supported\n"));
36af4a4e 1378 break;
252b5132
RH
1379 case 'h': /* Used on Solaris. */
1380 case OPTION_SONAME:
b0054819
UD
1381 if (optarg[0] == '\0' && command_line.soname
1382 && command_line.soname[0])
1383 einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
1384 else
1385 command_line.soname = optarg;
252b5132
RH
1386 break;
1387 case OPTION_SORT_COMMON:
de7dd2bd
NC
1388 if (optarg == NULL
1389 || strcmp (optarg, N_("descending")) == 0)
6c19b93b
AM
1390 config.sort_common = sort_descending;
1391 else if (strcmp (optarg, N_("ascending")) == 0)
de7dd2bd
NC
1392 config.sort_common = sort_ascending;
1393 else
df5f2391 1394 einfo (_("%F%P: invalid common section sorting option: %s\n"),
de7dd2bd 1395 optarg);
252b5132 1396 break;
bcaa7b3e
L
1397 case OPTION_SORT_SECTION:
1398 if (strcmp (optarg, N_("name")) == 0)
1399 sort_section = by_name;
1400 else if (strcmp (optarg, N_("alignment")) == 0)
1401 sort_section = by_alignment;
1402 else
df5f2391 1403 einfo (_("%F%P: invalid section sorting option: %s\n"),
bcaa7b3e
L
1404 optarg);
1405 break;
6e8376fa
NC
1406 case OPTION_SECTION_ORDERING_FILE:
1407 if (command_line.section_ordering_file != NULL
1408 && strcmp (optarg, command_line.section_ordering_file) != 0)
1409 einfo (_("%P: warning: section ordering file changed. Ignoring earlier definition\n"));
1410 command_line.section_ordering_file = optarg;
1411 break;
252b5132 1412 case OPTION_STATS:
f38a2680 1413 config.stats = true;
252b5132 1414 break;
cf893b0e
FS
1415 case OPTION_NO_SYMBOLIC:
1416 opt_symbolic = symbolic_unset;
1417 break;
252b5132 1418 case OPTION_SYMBOLIC:
1914e264 1419 opt_symbolic = symbolic;
d8cf8b51
L
1420 break;
1421 case OPTION_SYMBOLIC_FUNCTIONS:
1914e264 1422 opt_symbolic = symbolic_functions;
252b5132
RH
1423 break;
1424 case 't':
727a29ba 1425 ++trace_files;
252b5132
RH
1426 break;
1427 case 'T':
53d25da6 1428 previous_script_handle = saved_script_handle;
6ec6968b 1429 ldfile_open_script_file (optarg);
252b5132
RH
1430 parser_input = input_script;
1431 yyparse ();
53d25da6 1432 previous_script_handle = NULL;
252b5132 1433 break;
14be8564
L
1434 case OPTION_DEFAULT_SCRIPT:
1435 command_line.default_script = optarg;
1436 break;
176355da
NC
1437 case OPTION_SECTION_START:
1438 {
1439 char *optarg2;
227aeb07
AM
1440 char *sec_name;
1441 int len;
176355da
NC
1442
1443 /* Check for <something>=<somthing>... */
1444 optarg2 = strchr (optarg, '=');
1445 if (optarg2 == NULL)
df5f2391 1446 einfo (_("%F%P: invalid argument to option"
6feb9908 1447 " \"--section-start\"\n"));
176355da 1448
e47d05ad 1449 optarg2++;
5cc18311 1450
176355da
NC
1451 /* So far so good. Are all the args present? */
1452 if ((*optarg == '\0') || (*optarg2 == '\0'))
df5f2391 1453 einfo (_("%F%P: missing argument(s) to option"
6feb9908 1454 " \"--section-start\"\n"));
176355da 1455
227aeb07
AM
1456 /* We must copy the section name as set_section_start
1457 doesn't do it for us. */
1458 len = optarg2 - optarg;
1e9cc1c2 1459 sec_name = (char *) xmalloc (len);
227aeb07
AM
1460 memcpy (sec_name, optarg, len - 1);
1461 sec_name[len - 1] = 0;
176355da
NC
1462
1463 /* Then set it... */
227aeb07 1464 set_section_start (sec_name, optarg2);
176355da
NC
1465 }
1466 break;
ea20a7da
CC
1467 case OPTION_TARGET_HELP:
1468 /* Mention any target specific options. */
b7a26f91
KH
1469 ldemul_list_emulation_options (stdout);
1470 exit (0);
252b5132 1471 case OPTION_TBSS:
ba916c8a 1472 set_segment_start (".bss", optarg);
252b5132
RH
1473 break;
1474 case OPTION_TDATA:
ba916c8a 1475 set_segment_start (".data", optarg);
252b5132
RH
1476 break;
1477 case OPTION_TTEXT:
ba916c8a 1478 set_segment_start (".text", optarg);
252b5132 1479 break;
258795f5
L
1480 case OPTION_TTEXT_SEGMENT:
1481 set_segment_start (".text-segment", optarg);
1482 break;
9d5777a3
RM
1483 case OPTION_TRODATA_SEGMENT:
1484 set_segment_start (".rodata-segment", optarg);
1485 break;
0d705e9f
AM
1486 case OPTION_TLDATA_SEGMENT:
1487 set_segment_start (".ldata-segment", optarg);
1488 break;
252b5132 1489 case OPTION_TRADITIONAL_FORMAT:
f38a2680 1490 link_info.traditional_format = true;
252b5132
RH
1491 break;
1492 case OPTION_TASK_LINK:
f38a2680 1493 link_info.task_link = true;
1a0670f3 1494 /* Fall through. */
252b5132 1495 case OPTION_UR:
0e1862bb 1496 if (bfd_link_pic (&link_info))
df5f2391 1497 einfo (_("%F%P: -r and %s may not be used together\n"),
0e1862bb
L
1498 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1499
1500 link_info.type = type_relocatable;
f38a2680
AM
1501 config.build_constructors = true;
1502 config.magic_demand_paged = false;
1503 config.text_read_only = false;
1504 input_flags.dynamic = false;
252b5132
RH
1505 break;
1506 case 'u':
f38a2680 1507 ldlang_add_undef (optarg, true);
252b5132 1508 break;
6c19b93b
AM
1509 case OPTION_REQUIRE_DEFINED_SYMBOL:
1510 ldlang_add_require_defined (optarg);
0a618243 1511 break;
a854a4a7 1512 case OPTION_UNIQUE:
577a0623
AM
1513 if (optarg != NULL)
1514 lang_add_unique (optarg);
1515 else
f38a2680 1516 config.unique_orphan_sections = true;
a854a4a7 1517 break;
252b5132
RH
1518 case OPTION_VERBOSE:
1519 ldversion (1);
f38a2680
AM
1520 version_printed = true;
1521 verbose = true;
8aae64e6 1522 overflow_cutoff_limit = -2;
1715a13c
L
1523 if (optarg != NULL)
1524 {
1525 char *end;
d436a15e 1526 int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
1715a13c 1527 if (*end)
df5f2391 1528 einfo (_("%F%P: invalid number `%s'\n"), optarg);
0381901e 1529#if BFD_SUPPORTS_PLUGINS
1715a13c 1530 report_plugin_symbols = level > 1;
0381901e 1531#endif /* BFD_SUPPORTS_PLUGINS */
1715a13c 1532 }
252b5132
RH
1533 break;
1534 case 'v':
1535 ldversion (0);
f38a2680 1536 version_printed = true;
252b5132
RH
1537 break;
1538 case 'V':
1539 ldversion (1);
f38a2680 1540 version_printed = true;
252b5132
RH
1541 break;
1542 case OPTION_VERSION:
d32820f2 1543 ldversion (2);
252b5132
RH
1544 xexit (0);
1545 break;
1546 case OPTION_VERSION_SCRIPT:
1547 /* This option indicates a small script that only specifies
1579bae1
AM
1548 version information. Read it, but don't assume that
1549 we've seen a linker script. */
252b5132 1550 {
b7a26f91 1551 FILE *hold_script_handle;
252b5132 1552
b9a8de1e 1553 hold_script_handle = saved_script_handle;
252b5132 1554 ldfile_open_command_file (optarg);
b9a8de1e 1555 saved_script_handle = hold_script_handle;
252b5132
RH
1556 parser_input = input_version_script;
1557 yyparse ();
1558 }
1559 break;
1560 case OPTION_VERSION_EXPORTS_SECTION:
1561 /* This option records a version symbol to be applied to the
1562 symbols listed for export to be found in the object files
1563 .exports sections. */
1564 command_line.version_exports_section = optarg;
1565 break;
40b36307 1566 case OPTION_DYNAMIC_LIST_DATA:
1914e264 1567 opt_dynamic_list = dynamic_list_data;
40b36307 1568 break;
55255dae
L
1569 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1570 lang_append_dynamic_list_cpp_typeinfo ();
1914e264
AM
1571 if (opt_dynamic_list != dynamic_list_data)
1572 opt_dynamic_list = dynamic_list;
40b36307
L
1573 break;
1574 case OPTION_DYNAMIC_LIST_CPP_NEW:
1575 lang_append_dynamic_list_cpp_new ();
1914e264
AM
1576 if (opt_dynamic_list != dynamic_list_data)
1577 opt_dynamic_list = dynamic_list;
55255dae
L
1578 break;
1579 case OPTION_DYNAMIC_LIST:
1580 /* This option indicates a small script that only specifies
1581 a dynamic list. Read it, but don't assume that we've
1582 seen a linker script. */
1583 {
1584 FILE *hold_script_handle;
1585
1586 hold_script_handle = saved_script_handle;
1587 ldfile_open_command_file (optarg);
1588 saved_script_handle = hold_script_handle;
1589 parser_input = input_dynamic_list;
37a141bf 1590 current_dynamic_list_p = &link_info.dynamic_list;
55255dae
L
1591 yyparse ();
1592 }
1914e264
AM
1593 if (opt_dynamic_list != dynamic_list_data)
1594 opt_dynamic_list = dynamic_list;
55255dae 1595 break;
37a141bf
FS
1596 case OPTION_EXPORT_DYNAMIC_SYMBOL:
1597 {
1598 struct bfd_elf_version_expr *expr
1599 = lang_new_vers_pattern (NULL, xstrdup (optarg), NULL,
f38a2680 1600 false);
37a141bf 1601 lang_append_dynamic_list (&export_list, expr);
f37b21b4 1602 }
37a141bf
FS
1603 break;
1604 case OPTION_EXPORT_DYNAMIC_SYMBOL_LIST:
1605 /* This option indicates a small script that only specifies
1606 an export list. Read it, but don't assume that we've
1607 seen a linker script. */
1608 {
1609 FILE *hold_script_handle;
1610
1611 hold_script_handle = saved_script_handle;
1612 ldfile_open_command_file (optarg);
1613 saved_script_handle = hold_script_handle;
1614 parser_input = input_dynamic_list;
1615 current_dynamic_list_p = &export_list;
1616 yyparse ();
1617 }
1618 break;
252b5132 1619 case OPTION_WARN_COMMON:
f38a2680 1620 config.warn_common = true;
252b5132
RH
1621 break;
1622 case OPTION_WARN_CONSTRUCTORS:
f38a2680 1623 config.warn_constructors = true;
252b5132 1624 break;
7ce691ae 1625 case OPTION_WARN_FATAL:
f38a2680 1626 config.fatal_warnings = true;
7ce691ae 1627 break;
0fe58ccd 1628 case OPTION_NO_WARN_FATAL:
f38a2680 1629 config.fatal_warnings = false;
0fe58ccd 1630 break;
4b2e7a57
NC
1631 case OPTION_NO_WARNINGS:
1632 case 'w':
1633 config.no_warnings = true;
1634 config.fatal_warnings = false;
1635 break;
252b5132 1636 case OPTION_WARN_MULTIPLE_GP:
f38a2680 1637 config.warn_multiple_gp = true;
252b5132
RH
1638 break;
1639 case OPTION_WARN_ONCE:
f38a2680 1640 config.warn_once = true;
252b5132
RH
1641 break;
1642 case OPTION_WARN_SECTION_ALIGN:
f38a2680 1643 config.warn_section_align = true;
252b5132 1644 break;
a6dbf402
L
1645 case OPTION_WARN_TEXTREL:
1646 link_info.textrel_check = textrel_check_warning;
8fdd7217 1647 break;
a0c402a5 1648 case OPTION_WARN_ALTERNATE_EM:
f38a2680 1649 link_info.warn_alternate_em = true;
a0c402a5 1650 break;
252b5132 1651 case OPTION_WHOLE_ARCHIVE:
f38a2680 1652 input_flags.whole_archive = true;
252b5132 1653 break;
ddbb8a31 1654 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
f38a2680 1655 input_flags.add_DT_NEEDED_for_dynamic = true;
e56f61be 1656 break;
ddbb8a31 1657 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
f38a2680 1658 input_flags.add_DT_NEEDED_for_dynamic = false;
e56f61be 1659 break;
ddbb8a31 1660 case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
f38a2680 1661 input_flags.add_DT_NEEDED_for_regular = true;
4a43e768 1662 break;
ddbb8a31 1663 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
f38a2680 1664 input_flags.add_DT_NEEDED_for_regular = false;
4a43e768 1665 break;
252b5132
RH
1666 case OPTION_WRAP:
1667 add_wrap (optarg);
1668 break;
0e86e20e
AM
1669 case OPTION_IGNORE_UNRESOLVED_SYMBOL:
1670 add_ignoresym (&link_info, optarg);
1671 break;
f5fa8ca2
JJ
1672 case OPTION_DISCARD_NONE:
1673 link_info.discard = discard_none;
1674 break;
252b5132
RH
1675 case 'X':
1676 link_info.discard = discard_l;
1677 break;
1678 case 'x':
1679 link_info.discard = discard_all;
1680 break;
1681 case 'Y':
08dedd66 1682 if (startswith (optarg, "P,"))
252b5132 1683 optarg += 2;
5e2ab612 1684 free (default_dirlist);
252b5132
RH
1685 default_dirlist = xstrdup (optarg);
1686 break;
1687 case 'y':
1688 add_ysym (optarg);
1689 break;
db6751f2
JJ
1690 case OPTION_SPARE_DYNAMIC_TAGS:
1691 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1692 break;
252b5132 1693 case OPTION_SPLIT_BY_RELOC:
a854a4a7
AM
1694 if (optarg != NULL)
1695 config.split_by_reloc = strtoul (optarg, NULL, 0);
1696 else
1697 config.split_by_reloc = 32768;
5cc18311 1698 break;
252b5132 1699 case OPTION_SPLIT_BY_FILE:
a854a4a7
AM
1700 if (optarg != NULL)
1701 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1702 else
1703 config.split_by_file = 1;
5cc18311 1704 break;
252b5132 1705 case OPTION_CHECK_SECTIONS:
02b0b1aa 1706 command_line.check_section_addresses = 1;
252b5132
RH
1707 break;
1708 case OPTION_NO_CHECK_SECTIONS:
02b0b1aa 1709 command_line.check_section_addresses = 0;
252b5132 1710 break;
312b768e 1711 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
f38a2680 1712 command_line.accept_unknown_input_arch = true;
312b768e
NC
1713 break;
1714 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
f38a2680 1715 command_line.accept_unknown_input_arch = false;
312b768e 1716 break;
252b5132 1717 case '(':
252b5132 1718 lang_enter_group ();
20f3d0d6 1719 ingroup++;
252b5132
RH
1720 break;
1721 case ')':
1722 if (! ingroup)
df5f2391 1723 einfo (_("%F%P: group ended before it began (--help for usage)\n"));
210a7bd1 1724
252b5132 1725 lang_leave_group ();
20f3d0d6 1726 ingroup--;
252b5132 1727 break;
3dbf70a2
MM
1728
1729 case OPTION_INIT:
1730 link_info.init_function = optarg;
1731 break;
5cc18311 1732
3dbf70a2
MM
1733 case OPTION_FINI:
1734 link_info.fini_function = optarg;
1735 break;
2d643429 1736
fb221fba
NC
1737 case OPTION_REMAP_INPUTS_FILE:
1738 if (! ldfile_add_remap_file (optarg))
1739 einfo (_("%F%P: failed to add remap file %s\n"), optarg);
1740 break;
1741
1742 case OPTION_REMAP_INPUTS:
1743 {
1744 char *optarg2 = strchr (optarg, '=');
1745 if (optarg2 == NULL)
1746 /* FIXME: Should we allow --remap-inputs=@myfile as a synonym
1747 for --remap-inputs-file=myfile ? */
1748 einfo (_("%F%P: invalid argument to option --remap-inputs\n"));
1749 size_t len = optarg2 - optarg;
1750 char * pattern = xmalloc (len + 1);
1751 memcpy (pattern, optarg, len);
1752 pattern[len] = 0;
1753 ldfile_add_remap (pattern, optarg2 + 1);
1754 free (pattern);
1755 }
1756 break;
1757
35835446 1758 case OPTION_REDUCE_MEMORY_OVERHEADS:
f38a2680 1759 link_info.reduce_memory_overheads = true;
2d643429
NC
1760 if (config.hash_table_size == 0)
1761 config.hash_table_size = 1021;
35835446 1762 break;
2d643429 1763
a8dde0a2
L
1764 case OPTION_MAX_CACHE_SIZE:
1765 {
1766 char *end;
1767 bfd_size_type cache_size = strtoul (optarg, &end, 0);
1768 if (*end != '\0')
1769 einfo (_("%F%P: invalid cache memory size: %s\n"),
1770 optarg);
1771 link_info.max_cache_size = cache_size;
1772 }
1773 break;
1774
6c19b93b 1775 case OPTION_HASH_SIZE:
2d643429
NC
1776 {
1777 bfd_size_type new_size;
1778
6c19b93b
AM
1779 new_size = strtoul (optarg, NULL, 0);
1780 if (new_size)
1781 config.hash_table_size = new_size;
1782 else
df5f2391 1783 einfo (_("%X%P: --hash-size needs a numeric argument\n"));
6c19b93b
AM
1784 }
1785 break;
26278bb8
UD
1786
1787 case OPTION_PUSH_STATE:
1788 input_flags.pushed = xmemdup (&input_flags,
1789 sizeof (input_flags),
1790 sizeof (input_flags));
1791 break;
1792
1793 case OPTION_POP_STATE:
1794 if (input_flags.pushed == NULL)
df5f2391 1795 einfo (_("%F%P: no state pushed before popping\n"));
26278bb8
UD
1796 else
1797 {
1798 struct lang_input_statement_flags *oldp = input_flags.pushed;
1799 memcpy (&input_flags, oldp, sizeof (input_flags));
1800 free (oldp);
1801 }
1802 break;
3604cb1f
TG
1803
1804 case OPTION_PRINT_MEMORY_USAGE:
f38a2680 1805 command_line.print_memory_usage = true;
3604cb1f 1806 break;
c005eb9e
AB
1807
1808 case OPTION_ORPHAN_HANDLING:
1809 if (strcasecmp (optarg, "place") == 0)
1810 config.orphan_handling = orphan_handling_place;
1811 else if (strcasecmp (optarg, "warn") == 0)
1812 config.orphan_handling = orphan_handling_warn;
1813 else if (strcasecmp (optarg, "error") == 0)
1814 config.orphan_handling = orphan_handling_error;
1815 else if (strcasecmp (optarg, "discard") == 0)
1816 config.orphan_handling = orphan_handling_discard;
1817 else
df5f2391 1818 einfo (_("%F%P: invalid argument to option"
c005eb9e
AB
1819 " \"--orphan-handling\"\n"));
1820 break;
035801ce
FS
1821
1822 case OPTION_NO_PRINT_MAP_DISCARDED:
f38a2680 1823 config.print_map_discarded = false;
035801ce
FS
1824 break;
1825
1826 case OPTION_PRINT_MAP_DISCARDED:
f38a2680 1827 config.print_map_discarded = true;
035801ce 1828 break;
f37b21b4 1829
496917ce
NC
1830 case OPTION_NO_PRINT_MAP_LOCALS:
1831 config.print_map_locals = false;
1832 break;
1833
1834 case OPTION_PRINT_MAP_LOCALS:
1835 config.print_map_locals = true;
1836 break;
1837
f37b21b4
RM
1838 case OPTION_DEPENDENCY_FILE:
1839 config.dependency_file = optarg;
1840 break;
5dba6f05
NA
1841
1842 case OPTION_CTF_VARIABLES:
f38a2680 1843 config.ctf_variables = true;
5dba6f05
NA
1844 break;
1845
1846 case OPTION_NO_CTF_VARIABLES:
f38a2680 1847 config.ctf_variables = false;
5dba6f05
NA
1848 break;
1849
1850 case OPTION_CTF_SHARE_TYPES:
1851 if (strcmp (optarg, "share-unconflicted") == 0)
f38a2680 1852 config.ctf_share_duplicated = false;
5dba6f05 1853 else if (strcmp (optarg, "share-duplicated") == 0)
f38a2680 1854 config.ctf_share_duplicated = true;
5dba6f05
NA
1855 else
1856 einfo (_("%F%P: bad --ctf-share-types option: %s\n"), optarg);
1857 break;
252b5132
RH
1858 }
1859 }
1860
8da4f428
AM
1861 free (really_longopts);
1862 free (longopts);
1863 free (shortopts);
1864
198204a7
NC
1865 /* Run a couple of checks on the map filename. */
1866 if (config.map_filename)
1867 {
2c72361c
NC
1868 char * new_name = NULL;
1869 char * percent;
1870 int res = 0;
1871
198204a7
NC
1872 if (config.map_filename[0] == 0)
1873 {
72a3b182
NC
1874 einfo (_("%P: no file/directory name provided for map output; ignored\n"));
1875 config.map_filename = NULL;
198204a7 1876 }
2c72361c
NC
1877 else if (strcmp (config.map_filename, "-") == 0)
1878 ; /* Write to stdout. Handled in main(). */
1879 else if ((percent = strchr (config.map_filename, '%')) != NULL)
1880 {
1881 /* FIXME: Check for a second % character and issue an error ? */
1882
1883 /* Construct a map file by replacing the % character with the (full)
1884 output filename. If the % character was the last character in
1885 the original map filename then add a .map extension. */
1886 percent[0] = 0;
1887 res = asprintf (&new_name, "%s%s%s", config.map_filename,
1888 output_filename,
1889 percent[1] ? percent + 1 : ".map");
1890
1891 /* FIXME: Should we ensure that any directory components in new_name exist ? */
1892 }
198204a7
NC
1893 else
1894 {
1895 struct stat s;
1896
1897 /* If the map filename is actually a directory then create
72a3b182 1898 a file inside it, based upon the output filename. */
2c72361c 1899 if (stat (config.map_filename, &s) < 0)
198204a7 1900 {
2c72361c
NC
1901 if (errno != ENOENT)
1902 einfo (_("%P: cannot stat linker map file: %E\n"));
198204a7 1903 }
2c72361c
NC
1904 else if (S_ISDIR (s.st_mode))
1905 {
1906 char lastc = config.map_filename[strlen (config.map_filename) - 1];
1907 res = asprintf (&new_name, "%s%s%s.map",
1908 config.map_filename,
1909 IS_DIR_SEPARATOR (lastc) ? "" : "/",
1910 lbasename (output_filename));
1911 }
1912 else if (! S_ISREG (s.st_mode))
1913 {
1914 einfo (_("%P: linker map file is not a regular file\n"));
1915 config.map_filename = NULL;
1916 }
1917 /* else FIXME: Check write permission ? */
1918 }
1919
1920 if (res < 0)
1921 {
1922 /* If the asprintf failed then something is probably very
1923 wrong. Better to halt now rather than continue on
1924 into more problems. */
1925 einfo (_("%P%F: cannot create name for linker map file: %E\n"));
1926 }
1927 else if (new_name != NULL)
1928 {
1929 /* This is a trivial memory leak. */
1930 config.map_filename = new_name;
198204a7
NC
1931 }
1932 }
1933
b0054819
UD
1934 if (command_line.soname && command_line.soname[0] == '\0')
1935 {
1936 einfo (_("%P: SONAME must not be empty string; ignored\n"));
1937 command_line.soname = NULL;
1938 }
1939
20f3d0d6
AM
1940 while (ingroup)
1941 {
776ab89f 1942 einfo (_("%P: missing --end-group; added as last command line option\n"));
20f3d0d6
AM
1943 lang_leave_group ();
1944 ingroup--;
1945 }
252b5132
RH
1946
1947 if (default_dirlist != NULL)
5ed6aba4
NC
1948 {
1949 set_default_dirlist (default_dirlist);
1950 free (default_dirlist);
1951 }
560e09e9
NC
1952
1953 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1954 /* FIXME: Should we allow emulations a chance to set this ? */
95a51568 1955 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
6feb9908 1956
560e09e9
NC
1957 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1958 /* FIXME: Should we allow emulations a chance to set this ? */
95a51568 1959 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
5d3236ee 1960
0e1862bb
L
1961 if (bfd_link_relocatable (&link_info)
1962 && command_line.check_section_addresses < 0)
1963 command_line.check_section_addresses = 0;
9bbc1a67 1964
37a141bf
FS
1965 if (export_list)
1966 {
1967 struct bfd_elf_version_expr *head = export_list->head.list;
1968 struct bfd_elf_version_expr *next;
1969
1970 /* For --export-dynamic-symbol[-list]:
1971 1. When building executable, treat like --dynamic-list.
1972 2. When building shared object:
1973 a. If -Bsymbolic or --dynamic-list are used, treat like
1974 --dynamic-list.
1975 b. Otherwise, ignored.
1976 */
1977 if (!bfd_link_relocatable (&link_info)
1978 && (bfd_link_executable (&link_info)
1979 || opt_symbolic != symbolic_unset
1980 || opt_dynamic_list != dynamic_list_unset))
1981 {
1982 /* Append the export list to link_info.dynamic_list. */
1983 if (link_info.dynamic_list)
1984 {
1985 for (next = head; next->next != NULL; next = next->next)
1986 ;
1987 next->next = link_info.dynamic_list->head.list;
1988 link_info.dynamic_list->head.list = head;
1989 }
1990 else
1991 link_info.dynamic_list = export_list;
1992
1993 if (opt_dynamic_list != dynamic_list_data)
1994 opt_dynamic_list = dynamic_list;
1995 }
1996 else
1997 {
1998 /* Free the export list. */
1999 for (; head->next != NULL; head = next)
2000 {
2001 next = head->next;
2002 free (head);
2003 }
2004 free (export_list);
2005 }
2006 }
2007
bb68f22c
FS
2008 switch (opt_dynamic_list)
2009 {
2010 case dynamic_list_unset:
2011 break;
2012 case dynamic_list_data:
f38a2680 2013 link_info.dynamic_data = true;
bb68f22c
FS
2014 /* Fall through. */
2015 case dynamic_list:
f38a2680 2016 link_info.dynamic = true;
bb68f22c
FS
2017 opt_symbolic = symbolic_unset;
2018 break;
2019 }
2020
1914e264
AM
2021 /* -Bsymbolic and -Bsymbols-functions are for shared library output. */
2022 if (bfd_link_dll (&link_info))
2023 switch (opt_symbolic)
2024 {
2025 case symbolic_unset:
2026 break;
2027 case symbolic:
f38a2680 2028 link_info.symbolic = true;
1914e264
AM
2029 if (link_info.dynamic_list)
2030 {
2031 struct bfd_elf_version_expr *ent, *next;
2032 for (ent = link_info.dynamic_list->head.list; ent; ent = next)
2033 {
2034 next = ent->next;
2035 free (ent);
2036 }
2037 free (link_info.dynamic_list);
2038 link_info.dynamic_list = NULL;
2039 }
1914e264
AM
2040 break;
2041 case symbolic_functions:
f38a2680
AM
2042 link_info.dynamic = true;
2043 link_info.dynamic_data = true;
1914e264
AM
2044 break;
2045 }
9bbc1a67 2046
96cc7918
KB
2047 /* -z nosectionheader implies --strip-all. */
2048 if (config.no_section_header)
2049 {
2050 if (bfd_link_relocatable (&link_info))
2051 einfo (_("%F%P: -r and -z nosectionheader may not be used together\n"));
2052
2053 link_info.strip = strip_all;
2054 }
2055
0e1862bb 2056 if (!bfd_link_dll (&link_info))
9bbc1a67
AM
2057 {
2058 if (command_line.filter_shlib)
df5f2391 2059 einfo (_("%F%P: -F may not be used without -shared\n"));
9bbc1a67 2060 if (command_line.auxiliary_filters)
df5f2391 2061 einfo (_("%F%P: -f may not be used without -shared\n"));
9bbc1a67
AM
2062 }
2063
9bbc1a67
AM
2064 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
2065 don't see how else this can be handled, since in this case we
2066 must preserve all externally visible symbols. */
0e1862bb 2067 if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all)
9bbc1a67
AM
2068 {
2069 link_info.strip = strip_debugger;
2070 if (link_info.discard == discard_sec_merge)
2071 link_info.discard = discard_all;
2072 }
252b5132
RH
2073}
2074
2075/* Add the (colon-separated) elements of DIRLIST_PTR to the
2076 library search path. */
2077
2078static void
1579bae1 2079set_default_dirlist (char *dirlist_ptr)
252b5132
RH
2080{
2081 char *p;
2082
2083 while (1)
2084 {
2085 p = strchr (dirlist_ptr, PATH_SEPARATOR);
2086 if (p != NULL)
2087 *p = '\0';
2088 if (*dirlist_ptr != '\0')
f38a2680 2089 ldfile_add_library_path (dirlist_ptr, true);
252b5132
RH
2090 if (p == NULL)
2091 break;
2092 dirlist_ptr = p + 1;
2093 }
2094}
2095
2096static void
1579bae1 2097set_section_start (char *sect, char *valstr)
252b5132 2098{
93697284
AM
2099 const char *end;
2100 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
252b5132 2101 if (*end)
df5f2391 2102 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
ba916c8a 2103 lang_section_start (sect, exp_intop (val), NULL);
252b5132 2104}
ba916c8a
MM
2105
2106static void
2107set_segment_start (const char *section, char *valstr)
2108{
2109 const char *name;
2110 const char *end;
2111 segment_type *seg;
2112
2113 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
2114 if (*end)
df5f2391 2115 einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
ba916c8a
MM
2116 /* If we already have an entry for this segment, update the existing
2117 value. */
2118 name = section + 1;
2119 for (seg = segments; seg; seg = seg->next)
2120 if (strcmp (seg->name, name) == 0)
2121 {
2122 seg->value = val;
42b7a39b 2123 lang_section_start (section, exp_intop (val), seg);
ba916c8a
MM
2124 return;
2125 }
2126 /* There was no existing value so we must create a new segment
2127 entry. */
988de25b 2128 seg = stat_alloc (sizeof (*seg));
ba916c8a
MM
2129 seg->name = name;
2130 seg->value = val;
f38a2680 2131 seg->used = false;
ba916c8a
MM
2132 /* Add it to the linked list of segments. */
2133 seg->next = segments;
2134 segments = seg;
2135 /* Historically, -Ttext and friends set the base address of a
2136 particular section. For backwards compatibility, we still do
2137 that. If a SEGMENT_START directive is seen, the section address
2138 assignment will be disabled. */
2139 lang_section_start (section, exp_intop (val), seg);
2140}
2141
c58212ea
L
2142static void
2143elf_shlib_list_options (FILE *file)
2144{
2145 fprintf (file, _("\
2146 --audit=AUDITLIB Specify a library to use for auditing\n"));
2147 fprintf (file, _("\
2148 -Bgroup Selects group name lookup rules for DSO\n"));
2149 fprintf (file, _("\
2150 --disable-new-dtags Disable new dynamic tags\n"));
2151 fprintf (file, _("\
2152 --enable-new-dtags Enable new dynamic tags\n"));
2153 fprintf (file, _("\
2154 --eh-frame-hdr Create .eh_frame_hdr section\n"));
29063f8b
NC
2155 fprintf (file, _("\
2156 --no-eh-frame-hdr Do not create .eh_frame_hdr section\n"));
c58212ea
L
2157 fprintf (file, _("\
2158 --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
2159 fprintf (file, _("\
ba311c5b
NC
2160 --hash-style=STYLE Set hash style to sysv/gnu/both. Default: "));
2161 if (DEFAULT_EMIT_SYSV_HASH)
2162 {
2163 /* Note - these strings are not translated as
2164 they are keywords not descriptive text. */
2165 if (DEFAULT_EMIT_GNU_HASH)
2166 fprintf (file, "both\n");
2167 else
2168 fprintf (file, "sysv\n");
2169 }
2170 else
2171 {
2172 if (DEFAULT_EMIT_GNU_HASH)
2173 fprintf (file, "gnu\n");
2174 else
2175 /* FIXME: Can this happen ? */
2176 fprintf (file, "none\n");
2177 }
c58212ea
L
2178 fprintf (file, _("\
2179 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
a5aae508 2180 Specify a library to use for auditing dependencies\n"));
c58212ea
L
2181 fprintf (file, _("\
2182 -z combreloc Merge dynamic relocs into one section and sort\n"));
2183 fprintf (file, _("\
2184 -z nocombreloc Don't merge dynamic relocs into one section\n"));
2185 fprintf (file, _("\
2186 -z global Make symbols in DSO available for subsequently\n\
a5aae508 2187 loaded objects\n"));
c58212ea
L
2188 fprintf (file, _("\
2189 -z initfirst Mark DSO to be initialized first at runtime\n"));
2190 fprintf (file, _("\
2191 -z interpose Mark object to interpose all DSOs but executable\n"));
2192 fprintf (file, _("\
c3805e4c
VDM
2193 -z unique Mark DSO to be loaded at most once by default, and only in the main namespace\n"));
2194 fprintf (file, _("\
2195 -z nounique Don't mark DSO as a loadable at most once\n"));
2196 fprintf (file, _("\
c58212ea
L
2197 -z lazy Mark object lazy runtime binding (default)\n"));
2198 fprintf (file, _("\
2199 -z loadfltr Mark object requiring immediate process\n"));
2200 fprintf (file, _("\
2201 -z nocopyreloc Don't create copy relocs\n"));
2202 fprintf (file, _("\
2203 -z nodefaultlib Mark object not to use default search paths\n"));
2204 fprintf (file, _("\
2205 -z nodelete Mark DSO non-deletable at runtime\n"));
2206 fprintf (file, _("\
2207 -z nodlopen Mark DSO not available to dlopen\n"));
2208 fprintf (file, _("\
2209 -z nodump Mark DSO not available to dldump\n"));
2210 fprintf (file, _("\
2211 -z now Mark object non-lazy runtime binding\n"));
2212 fprintf (file, _("\
2213 -z origin Mark object requiring immediate $ORIGIN\n\
a5aae508 2214 processing at runtime\n"));
da4463c7 2215#if DEFAULT_LD_Z_RELRO
c58212ea 2216 fprintf (file, _("\
da4463c7 2217 -z relro Create RELRO program header (default)\n"));
c58212ea
L
2218 fprintf (file, _("\
2219 -z norelro Don't create RELRO program header\n"));
da4463c7
L
2220#else
2221 fprintf (file, _("\
2222 -z relro Create RELRO program header\n"));
2223 fprintf (file, _("\
2224 -z norelro Don't create RELRO program header (default)\n"));
2225#endif
b14b7ff1
L
2226#if DEFAULT_LD_Z_SEPARATE_CODE
2227 fprintf (file, _("\
2228 -z separate-code Create separate code program header (default)\n"));
2229 fprintf (file, _("\
2230 -z noseparate-code Don't create separate code program header\n"));
2231#else
47acac12
L
2232 fprintf (file, _("\
2233 -z separate-code Create separate code program header\n"));
2234 fprintf (file, _("\
2235 -z noseparate-code Don't create separate code program header (default)\n"));
b14b7ff1 2236#endif
c58212ea 2237 fprintf (file, _("\
b8871f35
L
2238 -z common Generate common symbols with STT_COMMON type\n"));
2239 fprintf (file, _("\
2240 -z nocommon Generate common symbols with STT_OBJECT type\n"));
a6dbf402
L
2241 if (link_info.textrel_check == textrel_check_error)
2242 fprintf (file, _("\
2243 -z text Treat DT_TEXTREL in output as error (default)\n"));
2244 else
2245 fprintf (file, _("\
2246 -z text Treat DT_TEXTREL in output as error\n"));
2247 if (link_info.textrel_check == textrel_check_none)
2248 {
2249 fprintf (file, _("\
2250 -z notext Don't treat DT_TEXTREL in output as error (default)\n"));
2251 fprintf (file, _("\
2252 -z textoff Don't treat DT_TEXTREL in output as error (default)\n"));
2253 }
2254 else
2255 {
2256 fprintf (file, _("\
2257 -z notext Don't treat DT_TEXTREL in output as error\n"));
2258 fprintf (file, _("\
2259 -z textoff Don't treat DT_TEXTREL in output as error\n"));
2260 }
c58212ea
L
2261}
2262
2263static void
2264elf_static_list_options (FILE *file)
2265{
2266 fprintf (file, _("\
2267 --build-id[=STYLE] Generate build ID note\n"));
2268 fprintf (file, _("\
9e2bb0cb
LB
2269 --package-metadata[=JSON] Generate package metadata note\n"));
2270 fprintf (file, _("\
2cac01e3
FS
2271 --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi|zstd]\n\
2272 Compress DWARF debug sections\n"));
6c3bc0f8 2273 fprintf (file, _("\
857bddbe 2274 Default: %s\n"),
c3620d6d 2275 bfd_get_compression_algorithm_name (config.compress_debug));
0ce398f1 2276 fprintf (file, _("\
c58212ea
L
2277 -z common-page-size=SIZE Set common page size to SIZE\n"));
2278 fprintf (file, _("\
2279 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
2280 fprintf (file, _("\
df5f2391 2281 -z defs Report unresolved symbols in object files\n"));
c58212ea 2282 fprintf (file, _("\
8ee10e86
AM
2283 -z undefs Ignore unresolved symbols in object files\n"));
2284 fprintf (file, _("\
c58212ea
L
2285 -z muldefs Allow multiple definitions\n"));
2286 fprintf (file, _("\
8ee10e86 2287 -z stack-size=SIZE Set size of stack segment\n"));
e922d1ea 2288
8ee10e86 2289 fprintf (file, _("\
c58212ea
L
2290 -z execstack Mark executable as requiring executable stack\n"));
2291 fprintf (file, _("\
e922d1ea 2292 -z noexecstack Mark executable as not requiring executable stack\n"));
ba951afb 2293 fprintf (file, _("\
e922d1ea
NC
2294 --warn-execstack-objects Generate a warning if an object file requests an executable stack\n"));
2295#if DEFAULT_LD_WARN_EXECSTACK == 0
2296 fprintf (file, _("\
2297 --warn-execstack Generate a warning if creating an executable stack\n"));
ba951afb 2298#else
93ab9c0d 2299 fprintf (file, _("\
e922d1ea 2300 --warn-execstack Generate a warning if creating an executable stack (default)\n"));
ba951afb 2301#endif
bd7d326d 2302#if DEFAULT_LD_WARN_EXECSTACK == 0
ba951afb 2303 fprintf (file, _("\
e922d1ea 2304 --no-warn-execstack Do not generate a warning if creating an executable stack (default)\n"));
ba951afb 2305#else
65daf5be 2306 fprintf (file, _("\
e922d1ea 2307 --no-warn-execstack Do not generate a warning if creating an executable stack\n"));
ba951afb 2308#endif
e922d1ea
NC
2309 fprintf (file, _("\
2310 --error-execstack Turn warnings about executable stacks into errors\n"));
2311 fprintf (file, _("\
2312 --no-error-execstack Do not turn warnings about executable stacks into errors\n"));
2313
ba951afb
NC
2314#if DEFAULT_LD_WARN_RWX_SEGMENTS
2315 fprintf (file, _("\
2316 --warn-rwx-segments Generate a warning if a LOAD segment has RWX permissions (default)\n"));
2317 fprintf (file, _("\
2318 --no-warn-rwx-segments Do not generate a warning if a LOAD segments has RWX permissions\n"));
2319#else
2320 fprintf (file, _("\
2321 --warn-rwx-segments Generate a warning if a LOAD segment has RWX permissions\n"));
2322 fprintf (file, _("\
2323 --no-warn-rwx-segments Do not generate a warning if a LOAD segments has RWX permissions (default)\n"));
2324#endif
e922d1ea
NC
2325 fprintf (file, _("\
2326 --error-rwx-segments Turn warnings about loadable RWX segments into errors\n"));
2327 fprintf (file, _("\
2328 --no-error-rwx-segments Do not turn warnings about loadable RWX segments into errors\n"));
2329
65daf5be 2330 fprintf (file, _("\
496afd17
L
2331 -z unique-symbol Avoid duplicated local symbol names\n"));
2332 fprintf (file, _("\
2333 -z nounique-symbol Keep duplicated local symbol names (default)\n"));
2334 fprintf (file, _("\
93ab9c0d 2335 -z globalaudit Mark executable requiring global auditing\n"));
8ee10e86
AM
2336 fprintf (file, _("\
2337 -z start-stop-gc Enable garbage collection on __start/__stop\n"));
2338 fprintf (file, _("\
2339 -z nostart-stop-gc Don't garbage collect __start/__stop (default)\n"));
2340 fprintf (file, _("\
2341 -z start-stop-visibility=V Set visibility of built-in __start/__stop symbols\n\
2342 to DEFAULT, PROTECTED, HIDDEN or INTERNAL\n"));
96cc7918
KB
2343 fprintf (file, _("\
2344 -z sectionheader Generate section header (default)\n"));
2345 fprintf (file, _("\
2346 -z nosectionheader Do not generate section header\n"));
c58212ea
L
2347}
2348
2349static void
2350elf_plt_unwind_list_options (FILE *file)
2351{
2352 fprintf (file, _("\
df5f2391
AM
2353 --ld-generated-unwind-info Generate exception handling info for PLT\n"));
2354 fprintf (file, _("\
c58212ea 2355 --no-ld-generated-unwind-info\n\
a5aae508 2356 Don't generate exception handling info for PLT\n"));
c58212ea
L
2357}
2358
2359static void
f38a2680 2360ld_list_options (FILE *file, bool elf, bool shlib, bool plt_unwind)
c58212ea
L
2361{
2362 if (!elf)
2363 return;
2364 printf (_("ELF emulations:\n"));
2365 if (plt_unwind)
2366 elf_plt_unwind_list_options (file);
2367 elf_static_list_options (file);
2368 if (shlib)
2369 elf_shlib_list_options (file);
2370}
2371
252b5132
RH
2372\f
2373/* Print help messages for the options. */
2374
2375static void
1579bae1 2376help (void)
252b5132 2377{
e4897a32 2378 unsigned i;
252b5132 2379 const char **targets, **pp;
a55ff675 2380 int len;
252b5132
RH
2381
2382 printf (_("Usage: %s [options] file...\n"), program_name);
2383
2384 printf (_("Options:\n"));
2385 for (i = 0; i < OPTION_COUNT; i++)
2386 {
2387 if (ld_options[i].doc != NULL)
2388 {
f38a2680 2389 bool comma;
e4897a32 2390 unsigned j;
252b5132
RH
2391
2392 printf (" ");
2393
f38a2680 2394 comma = false;
252b5132
RH
2395 len = 2;
2396
2397 j = i;
2398 do
2399 {
2400 if (ld_options[j].shortopt != '\0'
2401 && ld_options[j].control != NO_HELP)
2402 {
2403 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
2404 len += (comma ? 2 : 0) + 2;
2405 if (ld_options[j].arg != NULL)
2406 {
2407 if (ld_options[j].opt.has_arg != optional_argument)
2408 {
2409 printf (" ");
2410 ++len;
2411 }
2412 printf ("%s", _(ld_options[j].arg));
2413 len += strlen (_(ld_options[j].arg));
2414 }
f38a2680 2415 comma = true;
252b5132
RH
2416 }
2417 ++j;
2418 }
2419 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
2420
2421 j = i;
2422 do
2423 {
2424 if (ld_options[j].opt.name != NULL
2425 && ld_options[j].control != NO_HELP)
2426 {
e4897a32
NC
2427 int two_dashes =
2428 (ld_options[j].control == TWO_DASHES
2429 || ld_options[j].control == EXACTLY_TWO_DASHES);
b7a26f91 2430
252b5132
RH
2431 printf ("%s-%s%s",
2432 comma ? ", " : "",
e4897a32 2433 two_dashes ? "-" : "",
252b5132
RH
2434 ld_options[j].opt.name);
2435 len += ((comma ? 2 : 0)
2436 + 1
e4897a32 2437 + (two_dashes ? 1 : 0)
252b5132
RH
2438 + strlen (ld_options[j].opt.name));
2439 if (ld_options[j].arg != NULL)
2440 {
2441 printf (" %s", _(ld_options[j].arg));
2442 len += 1 + strlen (_(ld_options[j].arg));
2443 }
f38a2680 2444 comma = true;
252b5132
RH
2445 }
2446 ++j;
2447 }
2448 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
2449
2450 if (len >= 30)
2451 {
2452 printf ("\n");
2453 len = 0;
2454 }
2455
2456 for (; len < 30; len++)
2457 putchar (' ');
2458
2459 printf ("%s\n", _(ld_options[i].doc));
2460 }
2461 }
a55ff675
MM
2462 printf (_(" @FILE"));
2463 for (len = strlen (" @FILE"); len < 30; len++)
2464 putchar (' ');
2465 printf (_("Read options from FILE\n"));
252b5132 2466
f75692fe
NC
2467 /* Note: Various tools (such as libtool) depend upon the
2468 format of the listings below - do not change them. */
252b5132 2469 /* xgettext:c-format */
f75692fe 2470 printf (_("%s: supported targets:"), program_name);
252b5132
RH
2471 targets = bfd_target_list ();
2472 for (pp = targets; *pp != NULL; pp++)
2473 printf (" %s", *pp);
2474 free (targets);
2475 printf ("\n");
2476
2477 /* xgettext:c-format */
f75692fe 2478 printf (_("%s: supported emulations: "), program_name);
252b5132
RH
2479 ldemul_list_emulations (stdout);
2480 printf ("\n");
2481
2482 /* xgettext:c-format */
2483 printf (_("%s: emulation specific options:\n"), program_name);
c58212ea
L
2484 ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
2485 ELF_PLT_UNWIND_LIST_OPTIONS);
252b5132
RH
2486 ldemul_list_emulation_options (stdout);
2487 printf ("\n");
c20f4f8c 2488
92f01d61
JM
2489 if (REPORT_BUGS_TO[0])
2490 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
252b5132 2491}