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