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