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