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