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