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