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