]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gold/options.h
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gold / options.h
CommitLineData
bae7f79e
ILT
1// options.h -- handle command line options for gold -*- C++ -*-
2
d87bef3a 3// Copyright (C) 2006-2023 Free Software Foundation, Inc.
6cb15b7f
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21// MA 02110-1301, USA.
22
bae7f79e 23// General_options (from Command_line::options())
ee1fe73e 24// All the options (a.k.a. command-line flags)
bae7f79e
ILT
25// Input_argument (from Command_line::inputs())
26// The list of input files, including -l options.
ee1fe73e
ILT
27// Command_line
28// Everything we get from the command line -- the General_options
29// plus the Input_arguments.
30//
31// There are also some smaller classes, such as
32// Position_dependent_options which hold a subset of General_options
33// that change as options are parsed (as opposed to the usual behavior
34// of the last instance of that option specified on the commandline wins).
bae7f79e
ILT
35
36#ifndef GOLD_OPTIONS_H
37#define GOLD_OPTIONS_H
38
ca3a67a5 39#include <cstdlib>
cbb93e63 40#include <cstring>
bae7f79e 41#include <list>
a192ba05 42#include <map>
61ba1cf9 43#include <string>
92e059d8 44#include <vector>
bae7f79e 45
0daa6f62 46#include "elfcpp.h"
3c2fafa5
ILT
47#include "script.h"
48
bae7f79e
ILT
49namespace gold
50{
51
52class Command_line;
ee1fe73e
ILT
53class General_options;
54class Search_directory;
ead1e424 55class Input_file_group;
b0193076 56class Input_file_lib;
3c2fafa5 57class Position_dependent_options;
0daa6f62 58class Target;
89fc3421 59class Plugin_manager;
cdc29364 60class Script_info;
bae7f79e 61
266d0a74
ILT
62// Incremental build action for a specific file, as selected by the user.
63
64enum Incremental_disposition
65{
221597a5
CC
66 // Startup files that appear before the first disposition option.
67 // These will default to INCREMENTAL_CHECK unless the
68 // --incremental-startup-unchanged option is given.
69 // (For files added implicitly by gcc before any user options.)
70 INCREMENTAL_STARTUP,
266d0a74
ILT
71 // Determine the status from the timestamp (default).
72 INCREMENTAL_CHECK,
73 // Assume the file changed from the previous build.
74 INCREMENTAL_CHANGED,
75 // Assume the file didn't change from the previous build.
76 INCREMENTAL_UNCHANGED
77};
78
ee1fe73e
ILT
79// The nested namespace is to contain all the global variables and
80// structs that need to be defined in the .h file, but do not need to
81// be used outside this class.
c7912668
ILT
82namespace options
83{
ee1fe73e 84typedef std::vector<Search_directory> Dir_list;
c5818ff1 85typedef Unordered_set<std::string> String_set;
ee1fe73e
ILT
86
87// These routines convert from a string option to various types.
88// Each gives a fatal error if it cannot parse the argument.
89
90extern void
91parse_bool(const char* option_name, const char* arg, bool* retval);
92
c0a62865
DK
93extern void
94parse_int(const char* option_name, const char* arg, int* retval);
95
ee1fe73e
ILT
96extern void
97parse_uint(const char* option_name, const char* arg, int* retval);
98
99extern void
c18476e7
ILT
100parse_uint64(const char* option_name, const char* arg, uint64_t* retval);
101
102extern void
103parse_double(const char* option_name, const char* arg, double* retval);
ee1fe73e 104
9fbd3822
CC
105extern void
106parse_percent(const char* option_name, const char* arg, double* retval);
107
ee1fe73e
ILT
108extern void
109parse_string(const char* option_name, const char* arg, const char** retval);
110
086a1841
ILT
111extern void
112parse_optional_string(const char* option_name, const char* arg,
113 const char** retval);
114
ee1fe73e
ILT
115extern void
116parse_dirlist(const char* option_name, const char* arg, Dir_list* retval);
117
c5818ff1
CC
118extern void
119parse_set(const char* option_name, const char* arg, String_set* retval);
120
ee1fe73e
ILT
121extern void
122parse_choices(const char* option_name, const char* arg, const char** retval,
0c6e6c39 123 const char* choices[], int num_choices);
ee1fe73e
ILT
124
125struct Struct_var;
126
127// Most options have both a shortname (one letter) and a longname.
128// This enum controls how many dashes are expected for longname access
129// -- shortnames always use one dash. Most longnames will accept
130// either one dash or two; the only difference between ONE_DASH and
131// TWO_DASHES is how we print the option in --help. However, some
132// longnames require two dashes, and some require only one. The
133// special value DASH_Z means that the option is preceded by "-z".
134enum Dashes
135{
136 ONE_DASH, TWO_DASHES, EXACTLY_ONE_DASH, EXACTLY_TWO_DASHES, DASH_Z
137};
138
139// LONGNAME is the long-name of the option with dashes converted to
140// underscores, or else the short-name if the option has no long-name.
141// It is never the empty string.
142// DASHES is an instance of the Dashes enum: ONE_DASH, TWO_DASHES, etc.
143// SHORTNAME is the short-name of the option, as a char, or '\0' if the
144// option has no short-name. If the option has no long-name, you
145// should specify the short-name in *both* VARNAME and here.
146// DEFAULT_VALUE is the value of the option if not specified on the
147// commandline, as a string.
148// HELPSTRING is the descriptive text used with the option via --help
149// HELPARG is how you define the argument to the option.
150// --help output is "-shortname HELPARG, --longname HELPARG: HELPSTRING"
151// HELPARG should be NULL iff the option is a bool and takes no arg.
086a1841
ILT
152// OPTIONAL_ARG is true if this option takes an optional argument. An
153// optional argument must be specifid as --OPTION=VALUE, not
154// --OPTION VALUE.
ee1fe73e
ILT
155// READER provides parse_to_value, which is a function that will convert
156// a char* argument into the proper type and store it in some variable.
358a9718
CC
157// IS_DEFAULT is true for boolean options that are on by default,
158// and thus should have "(default)" printed with the helpstring.
ee1fe73e
ILT
159// A One_option struct initializes itself with the global list of options
160// at constructor time, so be careful making one of these.
161struct One_option
162{
163 std::string longname;
164 Dashes dashes;
165 char shortname;
166 const char* default_value;
167 const char* helpstring;
168 const char* helparg;
086a1841 169 bool optional_arg;
ee1fe73e 170 Struct_var* reader;
358a9718 171 bool is_default;
ee1fe73e
ILT
172
173 One_option(const char* ln, Dashes d, char sn, const char* dv,
358a9718
CC
174 const char* hs, const char* ha, bool oa, Struct_var* r,
175 bool id)
ee1fe73e 176 : longname(ln), dashes(d), shortname(sn), default_value(dv ? dv : ""),
358a9718
CC
177 helpstring(hs), helparg(ha), optional_arg(oa), reader(r),
178 is_default(id)
ee1fe73e
ILT
179 {
180 // In longname, we convert all underscores to dashes, since GNU
181 // style uses dashes in option names. longname is likely to have
182 // underscores in it because it's also used to declare a C++
183 // function.
184 const char* pos = strchr(this->longname.c_str(), '_');
185 for (; pos; pos = strchr(pos, '_'))
186 this->longname[pos - this->longname.c_str()] = '-';
187
188 // We only register ourselves if our helpstring is not NULL. This
189 // is to support the "no-VAR" boolean variables, which we
190 // conditionally turn on by defining "no-VAR" help text.
191 if (this->helpstring)
192 this->register_option();
193 }
194
195 // This option takes an argument iff helparg is not NULL.
196 bool
197 takes_argument() const
198 { return this->helparg != NULL; }
199
086a1841
ILT
200 // Whether the argument is optional.
201 bool
202 takes_optional_argument() const
203 { return this->optional_arg; }
204
ee1fe73e
ILT
205 // Register this option with the global list of options.
206 void
207 register_option();
208
209 // Print this option to stdout (used with --help).
210 void
211 print() const;
212};
213
214// All options have a Struct_##varname that inherits from this and
215// actually implements parse_to_value for that option.
216struct Struct_var
217{
218 // OPTION: the name of the option as specified on the commandline,
219 // including leading dashes, and any text following the option:
220 // "-O", "--defsym=mysym=0x1000", etc.
221 // ARG: the arg associated with this option, or NULL if the option
222 // takes no argument: "2", "mysym=0x1000", etc.
223 // CMDLINE: the global Command_line object. Used by DEFINE_special.
224 // OPTIONS: the global General_options object. Used by DEFINE_special.
225 virtual void
226 parse_to_value(const char* option, const char* arg,
0c6e6c39 227 Command_line* cmdline, General_options* options) = 0;
ee1fe73e
ILT
228 virtual
229 ~Struct_var() // To make gcc happy.
230 { }
231};
bae7f79e 232
ee1fe73e
ILT
233// This is for "special" options that aren't of any predefined type.
234struct Struct_special : public Struct_var
235{
236 // If you change this, change the parse-fn in DEFINE_special as well.
237 typedef void (General_options::*Parse_function)(const char*, const char*,
0c6e6c39 238 Command_line*);
ee1fe73e 239 Struct_special(const char* varname, Dashes dashes, char shortname,
0c6e6c39
RM
240 Parse_function parse_function,
241 const char* helpstring, const char* helparg)
358a9718
CC
242 : option(varname, dashes, shortname, "", helpstring, helparg, false, this,
243 false),
ee1fe73e
ILT
244 parse(parse_function)
245 { }
246
2ea97941 247 void parse_to_value(const char* option, const char* arg,
0c6e6c39 248 Command_line* cmdline, General_options* options)
2ea97941 249 { (options->*(this->parse))(option, arg, cmdline); }
ee1fe73e
ILT
250
251 One_option option;
252 Parse_function parse;
253};
254
255} // End namespace options.
256
257
258// These are helper macros use by DEFINE_uint64/etc below.
259// This macro is used inside the General_options_ class, so defines
260// var() and set_var() as General_options methods. Arguments as are
261// for the constructor for One_option. param_type__ is the same as
262// type__ for built-in types, and "const type__ &" otherwise.
e96c574b
DK
263//
264// When we define the linker command option "assert", the macro argument
265// varname__ of DEFINE_var below will be replaced by "assert". On Mac OSX
266// assert.h is included implicitly by one of the library headers we use. To
267// avoid unintended macro substitution of "assert()", we need to enclose
268// varname__ with parenthese.
ee1fe73e 269#define DEFINE_var(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 270 default_value_as_string__, helpstring__, helparg__, \
358a9718
CC
271 optional_arg__, type__, param_type__, parse_fn__, \
272 is_default__) \
ee1fe73e
ILT
273 public: \
274 param_type__ \
e96c574b 275 (varname__)() const \
ee1fe73e 276 { return this->varname__##_.value; } \
0c6e6c39 277 \
ee1fe73e
ILT
278 bool \
279 user_set_##varname__() const \
280 { return this->varname__##_.user_set_via_option; } \
0c6e6c39 281 \
2b706932
ILT
282 void \
283 set_user_set_##varname__() \
284 { this->varname__##_.user_set_via_option = true; } \
285 \
358a9718
CC
286 static const bool varname__##is_default = is_default__; \
287 \
ee1fe73e
ILT
288 private: \
289 struct Struct_##varname__ : public options::Struct_var \
290 { \
291 Struct_##varname__() \
292 : option(#varname__, dashes__, shortname__, default_value_as_string__, \
358a9718 293 helpstring__, helparg__, optional_arg__, this, is_default__), \
0c6e6c39 294 user_set_via_option(false), value(default_value__) \
ee1fe73e 295 { } \
0c6e6c39 296 \
ee1fe73e
ILT
297 void \
298 parse_to_value(const char* option_name, const char* arg, \
0c6e6c39 299 Command_line*, General_options*) \
ee1fe73e
ILT
300 { \
301 parse_fn__(option_name, arg, &this->value); \
302 this->user_set_via_option = true; \
303 } \
0c6e6c39 304 \
ee1fe73e
ILT
305 options::One_option option; \
306 bool user_set_via_option; \
307 type__ value; \
308 }; \
309 Struct_##varname__ varname__##_; \
310 void \
311 set_##varname__(param_type__ value) \
312 { this->varname__##_.value = value; }
313
314// These macros allow for easy addition of a new commandline option.
315
316// If no_helpstring__ is not NULL, then in addition to creating
d98bc257
ILT
317// VARNAME, we also create an option called no-VARNAME (or, for a -z
318// option, noVARNAME).
ee1fe73e 319#define DEFINE_bool(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 320 helpstring__, no_helpstring__) \
ee1fe73e 321 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 322 default_value__ ? "true" : "false", helpstring__, NULL, \
358a9718 323 false, bool, bool, options::parse_bool, default_value__) \
ee1fe73e
ILT
324 struct Struct_no_##varname__ : public options::Struct_var \
325 { \
d98bc257
ILT
326 Struct_no_##varname__() : option((dashes__ == options::DASH_Z \
327 ? "no" #varname__ \
328 : "no-" #varname__), \
329 dashes__, '\0', \
0c6e6c39 330 default_value__ ? "false" : "true", \
358a9718
CC
331 no_helpstring__, NULL, false, this, \
332 !(default_value__)) \
333 { } \
334 \
335 void \
336 parse_to_value(const char*, const char*, \
337 Command_line*, General_options* options) \
338 { \
339 options->set_##varname__(false); \
340 options->set_user_set_##varname__(); \
341 } \
342 \
343 options::One_option option; \
344 }; \
345 Struct_no_##varname__ no_##varname__##_initializer_
346
347#define DEFINE_bool_ignore(varname__, dashes__, shortname__, \
348 helpstring__, no_helpstring__) \
349 DEFINE_var(varname__, dashes__, shortname__, false, \
350 "false", helpstring__, NULL, \
351 false, bool, bool, options::parse_bool, false) \
352 struct Struct_no_##varname__ : public options::Struct_var \
353 { \
354 Struct_no_##varname__() : option((dashes__ == options::DASH_Z \
355 ? "no" #varname__ \
356 : "no-" #varname__), \
357 dashes__, '\0', \
358 "false", \
359 no_helpstring__, NULL, false, this, \
360 false) \
ee1fe73e 361 { } \
0c6e6c39 362 \
ee1fe73e
ILT
363 void \
364 parse_to_value(const char*, const char*, \
0c6e6c39 365 Command_line*, General_options* options) \
41263c05
DK
366 { \
367 options->set_##varname__(false); \
368 options->set_user_set_##varname__(); \
369 } \
0c6e6c39 370 \
ee1fe73e
ILT
371 options::One_option option; \
372 }; \
373 Struct_no_##varname__ no_##varname__##_initializer_
374
7c414435 375#define DEFINE_enable(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 376 helpstring__, no_helpstring__) \
7c414435 377 DEFINE_var(enable_##varname__, dashes__, shortname__, default_value__, \
0c6e6c39 378 default_value__ ? "true" : "false", helpstring__, NULL, \
358a9718 379 false, bool, bool, options::parse_bool, default_value__) \
7c414435
DM
380 struct Struct_disable_##varname__ : public options::Struct_var \
381 { \
382 Struct_disable_##varname__() : option("disable-" #varname__, \
0c6e6c39
RM
383 dashes__, '\0', \
384 default_value__ ? "false" : "true", \
358a9718
CC
385 no_helpstring__, NULL, false, this, \
386 !default_value__) \
7c414435 387 { } \
0c6e6c39 388 \
7c414435
DM
389 void \
390 parse_to_value(const char*, const char*, \
0c6e6c39 391 Command_line*, General_options* options) \
7c414435 392 { options->set_enable_##varname__(false); } \
0c6e6c39 393 \
7c414435
DM
394 options::One_option option; \
395 }; \
396 Struct_disable_##varname__ disable_##varname__##_initializer_
397
c0a62865 398#define DEFINE_int(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 399 helpstring__, helparg__) \
c0a62865 400 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 401 #default_value__, helpstring__, helparg__, false, \
358a9718 402 int, int, options::parse_int, false)
c0a62865 403
ee1fe73e 404#define DEFINE_uint(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 405 helpstring__, helparg__) \
ee1fe73e 406 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 407 #default_value__, helpstring__, helparg__, false, \
358a9718 408 int, int, options::parse_uint, false)
ee1fe73e
ILT
409
410#define DEFINE_uint64(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 411 helpstring__, helparg__) \
ee1fe73e 412 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 413 #default_value__, helpstring__, helparg__, false, \
358a9718 414 uint64_t, uint64_t, options::parse_uint64, false)
ee1fe73e 415
c18476e7
ILT
416#define DEFINE_double(varname__, dashes__, shortname__, default_value__, \
417 helpstring__, helparg__) \
418 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
086a1841 419 #default_value__, helpstring__, helparg__, false, \
358a9718 420 double, double, options::parse_double, false)
c18476e7 421
9fbd3822
CC
422#define DEFINE_percent(varname__, dashes__, shortname__, default_value__, \
423 helpstring__, helparg__) \
424 DEFINE_var(varname__, dashes__, shortname__, default_value__ / 100.0, \
425 #default_value__, helpstring__, helparg__, false, \
358a9718 426 double, double, options::parse_percent, false)
9fbd3822 427
ee1fe73e 428#define DEFINE_string(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 429 helpstring__, helparg__) \
ee1fe73e 430 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 431 default_value__, helpstring__, helparg__, false, \
358a9718 432 const char*, const char*, options::parse_string, false)
ee1fe73e
ILT
433
434// This is like DEFINE_string, but we convert each occurrence to a
435// Search_directory and store it in a vector. Thus we also have the
436// add_to_VARNAME() method, to append to the vector.
437#define DEFINE_dirlist(varname__, dashes__, shortname__, \
0c6e6c39 438 helpstring__, helparg__) \
ee1fe73e 439 DEFINE_var(varname__, dashes__, shortname__, , \
0c6e6c39 440 "", helpstring__, helparg__, false, options::Dir_list, \
358a9718 441 const options::Dir_list&, options::parse_dirlist, false) \
ee1fe73e
ILT
442 void \
443 add_to_##varname__(const char* new_value) \
444 { options::parse_dirlist(NULL, new_value, &this->varname__##_.value); } \
445 void \
446 add_search_directory_to_##varname__(const Search_directory& dir) \
447 { this->varname__##_.value.push_back(dir); }
448
c5818ff1
CC
449// This is like DEFINE_string, but we store a set of strings.
450#define DEFINE_set(varname__, dashes__, shortname__, \
0c6e6c39 451 helpstring__, helparg__) \
c5818ff1 452 DEFINE_var(varname__, dashes__, shortname__, , \
0c6e6c39 453 "", helpstring__, helparg__, false, options::String_set, \
358a9718 454 const options::String_set&, options::parse_set, false) \
c5818ff1
CC
455 public: \
456 bool \
457 any_##varname__() const \
458 { return !this->varname__##_.value.empty(); } \
f3e9c5c5 459 \
c5818ff1
CC
460 bool \
461 is_##varname__(const char* symbol) const \
462 { \
463 return (!this->varname__##_.value.empty() \
0c6e6c39
RM
464 && (this->varname__##_.value.find(std::string(symbol)) \
465 != this->varname__##_.value.end())); \
f3e9c5c5
ILT
466 } \
467 \
468 options::String_set::const_iterator \
469 varname__##_begin() const \
470 { return this->varname__##_.value.begin(); } \
471 \
472 options::String_set::const_iterator \
473 varname__##_end() const \
0b65c07b 474 { return this->varname__##_.value.end(); } \
f37b21b4 475 \
0b65c07b
ST
476 options::String_set::size_type \
477 varname__##_size() const \
478 { return this->varname__##_.value.size(); } \
c5818ff1 479
ee1fe73e
ILT
480// When you have a list of possible values (expressed as string)
481// After helparg__ should come an initializer list, like
482// {"foo", "bar", "baz"}
483#define DEFINE_enum(varname__, dashes__, shortname__, default_value__, \
afd2ea23 484 helpstring__, helparg__, optional_arg__, ...) \
ee1fe73e 485 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
afd2ea23 486 default_value__, helpstring__, helparg__, optional_arg__, \
358a9718 487 const char*, const char*, parse_choices_##varname__, false) \
ee1fe73e
ILT
488 private: \
489 static void parse_choices_##varname__(const char* option_name, \
0c6e6c39
RM
490 const char* arg, \
491 const char** retval) { \
ee1fe73e
ILT
492 const char* choices[] = __VA_ARGS__; \
493 options::parse_choices(option_name, arg, retval, \
0c6e6c39 494 choices, sizeof(choices) / sizeof(*choices)); \
ee1fe73e
ILT
495 }
496
2b706932
ILT
497// This is like DEFINE_bool, but VARNAME is the name of a different
498// option. This option becomes an alias for that one. INVERT is true
499// if this option is an inversion of the other one.
500#define DEFINE_bool_alias(option__, varname__, dashes__, shortname__, \
501 helpstring__, no_helpstring__, invert__) \
502 private: \
503 struct Struct_##option__ : public options::Struct_var \
504 { \
505 Struct_##option__() \
506 : option(#option__, dashes__, shortname__, "", helpstring__, \
358a9718
CC
507 NULL, false, this, \
508 General_options::varname__##is_default ^ invert__) \
2b706932
ILT
509 { } \
510 \
511 void \
512 parse_to_value(const char*, const char*, \
513 Command_line*, General_options* options) \
514 { \
515 options->set_##varname__(!invert__); \
516 options->set_user_set_##varname__(); \
517 } \
518 \
519 options::One_option option; \
520 }; \
521 Struct_##option__ option__##_; \
522 \
523 struct Struct_no_##option__ : public options::Struct_var \
524 { \
525 Struct_no_##option__() \
526 : option((dashes__ == options::DASH_Z \
527 ? "no" #option__ \
528 : "no-" #option__), \
529 dashes__, '\0', "", no_helpstring__, \
358a9718
CC
530 NULL, false, this, \
531 !General_options::varname__##is_default ^ invert__) \
2b706932
ILT
532 { } \
533 \
534 void \
535 parse_to_value(const char*, const char*, \
536 Command_line*, General_options* options) \
537 { \
538 options->set_##varname__(invert__); \
539 options->set_user_set_##varname__(); \
540 } \
541 \
542 options::One_option option; \
543 }; \
544 Struct_no_##option__ no_##option__##_initializer_
545
214383dd
ILT
546// This is like DEFINE_uint64, but VARNAME is the name of a different
547// option. This option becomes an alias for that one.
548#define DEFINE_uint64_alias(option__, varname__, dashes__, shortname__, \
549 helpstring__, helparg__) \
550 private: \
551 struct Struct_##option__ : public options::Struct_var \
552 { \
553 Struct_##option__() \
554 : option(#option__, dashes__, shortname__, "", helpstring__, \
358a9718 555 helparg__, false, this, false) \
214383dd
ILT
556 { } \
557 \
558 void \
559 parse_to_value(const char* option_name, const char* arg, \
560 Command_line*, General_options* options) \
561 { \
562 uint64_t value; \
563 options::parse_uint64(option_name, arg, &value); \
564 options->set_##varname__(value); \
565 options->set_user_set_##varname__(); \
566 } \
567 \
568 options::One_option option; \
569 }; \
570 Struct_##option__ option__##_;
571
ee1fe73e
ILT
572// This is used for non-standard flags. It defines no functions; it
573// just calls General_options::parse_VARNAME whenever the flag is
574// seen. We declare parse_VARNAME as a static member of
575// General_options; you are responsible for defining it there.
576// helparg__ should be NULL iff this special-option is a boolean.
577#define DEFINE_special(varname__, dashes__, shortname__, \
0c6e6c39 578 helpstring__, helparg__) \
ee1fe73e
ILT
579 private: \
580 void parse_##varname__(const char* option, const char* arg, \
0c6e6c39 581 Command_line* inputs); \
ee1fe73e
ILT
582 struct Struct_##varname__ : public options::Struct_special \
583 { \
584 Struct_##varname__() \
585 : options::Struct_special(#varname__, dashes__, shortname__, \
0c6e6c39
RM
586 &General_options::parse_##varname__, \
587 helpstring__, helparg__) \
ee1fe73e
ILT
588 { } \
589 }; \
590 Struct_##varname__ varname__##_initializer_
bae7f79e 591
086a1841
ILT
592// An option that takes an optional string argument. If the option is
593// used with no argument, the value will be the default, and
594// user_set_via_option will be true.
595#define DEFINE_optional_string(varname__, dashes__, shortname__, \
596 default_value__, \
597 helpstring__, helparg__) \
598 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
0c6e6c39 599 default_value__, helpstring__, helparg__, true, \
358a9718
CC
600 const char*, const char*, options::parse_optional_string, \
601 false)
bae7f79e 602
ad2d6943
ILT
603// A directory to search. For each directory we record whether it is
604// in the sysroot. We need to know this so that, if a linker script
605// is found within the sysroot, we will apply the sysroot to any files
606// named by that script.
607
608class Search_directory
609{
610 public:
611 // We need a default constructor because we put this in a
612 // std::vector.
613 Search_directory()
068a039b 614 : name_(), put_in_sysroot_(false), is_in_sysroot_(false)
ad2d6943
ILT
615 { }
616
617 // This is the usual constructor.
3f3cddf1 618 Search_directory(const std::string& name, bool put_in_sysroot)
2ea97941 619 : name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false)
15893b88
ILT
620 {
621 if (this->name_.empty())
622 this->name_ = ".";
623 }
ad2d6943
ILT
624
625 // This is called if we have a sysroot. The sysroot is prefixed to
626 // any entries for which put_in_sysroot_ is true. is_in_sysroot_ is
627 // set to true for any enries which are in the sysroot (this will
628 // naturally include any entries for which put_in_sysroot_ is true).
629 // SYSROOT is the sysroot, CANONICAL_SYSROOT is the result of
630 // passing SYSROOT to lrealpath.
631 void
632 add_sysroot(const char* sysroot, const char* canonical_sysroot);
633
634 // Get the directory name.
635 const std::string&
636 name() const
637 { return this->name_; }
638
639 // Return whether this directory is in the sysroot.
640 bool
641 is_in_sysroot() const
642 { return this->is_in_sysroot_; }
643
fd9d194f
ILT
644 // Return whether this is considered a system directory.
645 bool
646 is_system_directory() const
647 { return this->put_in_sysroot_ || this->is_in_sysroot_; }
648
ad2d6943 649 private:
fd9d194f 650 // The directory name.
ad2d6943 651 std::string name_;
fd9d194f
ILT
652 // True if the sysroot should be added as a prefix for this
653 // directory (if there is a sysroot). This is true for system
654 // directories that we search by default.
ad2d6943 655 bool put_in_sysroot_;
fd9d194f
ILT
656 // True if this directory is in the sysroot (if there is a sysroot).
657 // This is true if there is a sysroot and either 1) put_in_sysroot_
658 // is true, or 2) the directory happens to be in the sysroot based
659 // on a pathname comparison.
ad2d6943
ILT
660 bool is_in_sysroot_;
661};
662
bae7f79e
ILT
663class General_options
664{
ee1fe73e
ILT
665 private:
666 // NOTE: For every option that you add here, also consider if you
667 // should add it to Position_dependent_options.
668 DEFINE_special(help, options::TWO_DASHES, '\0',
0c6e6c39 669 N_("Report usage information"), NULL);
ee1fe73e 670 DEFINE_special(version, options::TWO_DASHES, 'v',
0c6e6c39 671 N_("Report version information"), NULL);
b5be4a7c 672 DEFINE_special(V, options::EXACTLY_ONE_DASH, '\0',
0c6e6c39 673 N_("Report version and target information"), NULL);
ee1fe73e 674
fee2edb1
ILT
675 // These options are sorted approximately so that for each letter in
676 // the alphabet, we show the option whose shortname is that letter
677 // (if any) and then every longname that starts with that letter (in
678 // alphabetical order). For both, lowercase sorts before uppercase.
679 // The -z options come last.
680
358a9718
CC
681 // a
682
7eaea549
ILT
683 DEFINE_bool(add_needed, options::TWO_DASHES, '\0', false,
684 N_("Not supported"),
685 N_("Do not copy DT_NEEDED tags from shared libraries"));
686
9c4ae156 687 DEFINE_bool_alias(allow_multiple_definition, muldefs, options::TWO_DASHES,
358a9718
CC
688 '\0',
689 N_("Allow multiple definitions of symbols"),
9c4ae156 690 N_("Do not allow multiple definitions"), false);
30bc8c46 691
ee1fe73e 692 DEFINE_bool(allow_shlib_undefined, options::TWO_DASHES, '\0', false,
0c6e6c39
RM
693 N_("Allow unresolved references in shared libraries"),
694 N_("Do not allow unresolved references in shared libraries"));
ee1fe73e 695
0eccf19f 696 DEFINE_bool(apply_dynamic_relocs, options::TWO_DASHES, '\0', true,
358a9718 697 N_("Apply link-time values for dynamic relocations"),
0eccf19f 698 N_("(aarch64 only) Do not apply link-time values "
1130c90e 699 "for dynamic relocations"));
0eccf19f 700
ee1fe73e 701 DEFINE_bool(as_needed, options::TWO_DASHES, '\0', false,
358a9718
CC
702 N_("Use DT_NEEDED only for shared libraries that are used"),
703 N_("Use DT_NEEDED for all shared libraries"));
ee1fe73e 704
fe35d28d 705 DEFINE_enum(assert, options::ONE_DASH, '\0', NULL,
afd2ea23 706 N_("Ignored"), N_("[ignored]"), false,
fe35d28d
ILT
707 {"definitions", "nodefinitions", "nosymbolic", "pure-text"});
708
358a9718
CC
709 // b
710
fee2edb1
ILT
711 // This should really be an "enum", but it's too easy for folks to
712 // forget to update the list as they add new targets. So we just
713 // accept any string. We'll fail later (when the string is parsed),
714 // if the target isn't actually supported.
715 DEFINE_string(format, options::TWO_DASHES, 'b', "elf",
0c6e6c39 716 N_("Set input format"), ("[elf,binary]"));
fee2edb1 717
36862fc0 718 DEFINE_bool(be8, options::TWO_DASHES, '\0', false,
358a9718
CC
719 N_("Output BE8 format image"), NULL);
720
721 DEFINE_optional_string(build_id, options::TWO_DASHES, '\0', "tree",
722 N_("Generate build ID note"),
723 N_("[=STYLE]"));
724
725 DEFINE_uint64(build_id_chunk_size_for_treehash,
726 options::TWO_DASHES, '\0', 2 << 20,
727 N_("Chunk size for '--build-id=tree'"), N_("SIZE"));
728
729 DEFINE_uint64(build_id_min_file_size_for_treehash, options::TWO_DASHES,
730 '\0', 40 << 20,
731 N_("Minimum output file size for '--build-id=tree' to work"
732 " differently than '--build-id=sha1'"), N_("SIZE"));
733
ee1fe73e 734 DEFINE_bool(Bdynamic, options::ONE_DASH, '\0', true,
0c6e6c39 735 N_("-l searches for shared libraries"), NULL);
2b706932
ILT
736 DEFINE_bool_alias(Bstatic, Bdynamic, options::ONE_DASH, '\0',
737 N_("-l does not search for shared libraries"), NULL,
738 true);
b821d13c
ILT
739 DEFINE_bool_alias(dy, Bdynamic, options::ONE_DASH, '\0',
740 N_("alias for -Bdynamic"), NULL, false);
741 DEFINE_bool_alias(dn, Bdynamic, options::ONE_DASH, '\0',
742 N_("alias for -Bstatic"), NULL, true);
ee1fe73e 743
e2153196
ILT
744 DEFINE_bool(Bgroup, options::ONE_DASH, '\0', false,
745 N_("Use group name lookup rules for shared library"), NULL);
746
358a9718
CC
747 DEFINE_bool(Bshareable, options::ONE_DASH, '\0', false,
748 N_("Generate shared library (alias for -G/-shared)"), NULL);
749
823241a2
FS
750 DEFINE_special (Bno_symbolic, options::ONE_DASH, '\0',
751 N_ ("Don't bind default visibility defined symbols locally "
752 "for -shared (default)"),
753 NULL);
ee1fe73e 754
823241a2
FS
755 DEFINE_special (Bsymbolic_functions, options::ONE_DASH, '\0',
756 N_ ("Bind default visibility defined function symbols "
757 "locally for -shared"),
758 NULL);
759
760 DEFINE_special (
761 Bsymbolic, options::ONE_DASH, '\0',
762 N_ ("Bind default visibility defined symbols locally for -shared"),
763 NULL);
f1f70eae 764
358a9718 765 // c
e7c5ea40 766
34810851 767 DEFINE_bool(check_sections, options::TWO_DASHES, '\0', true,
358a9718 768 N_("Check segment addresses for overlaps"),
34810851
ILT
769 N_("Do not check segment addresses for overlaps"));
770
ee1fe73e 771 DEFINE_enum(compress_debug_sections, options::TWO_DASHES, '\0', "none",
0c6e6c39 772 N_("Compress .debug_* sections in the output file"),
8b2d02cb
FS
773 ("[none,zlib,zlib-gnu,zlib-gabi,zstd]"), false,
774 {"none", "zlib", "zlib-gnu", "zlib-gabi", "zstd"});
0dfbdef4 775
7eaea549
ILT
776 DEFINE_bool(copy_dt_needed_entries, options::TWO_DASHES, '\0', false,
777 N_("Not supported"),
778 N_("Do not copy DT_NEEDED tags from shared libraries"));
779
dde3f402
ILT
780 DEFINE_bool(cref, options::TWO_DASHES, '\0', false,
781 N_("Output cross reference table"),
782 N_("Do not output cross reference table"));
783
5393d741 784 DEFINE_bool(ctors_in_init_array, options::TWO_DASHES, '\0', true,
358a9718 785 N_("Use DT_INIT_ARRAY for all constructors"),
5393d741
ILT
786 N_("Handle constructors as directed by compiler"));
787
358a9718
CC
788 // d
789
ee1fe73e 790 DEFINE_bool(define_common, options::TWO_DASHES, 'd', false,
0c6e6c39 791 N_("Define common symbols"),
358a9718 792 N_("Do not define common symbols in relocatable output"));
ee1fe73e 793 DEFINE_bool(dc, options::ONE_DASH, '\0', false,
0c6e6c39 794 N_("Alias for -d"), NULL);
ee1fe73e 795 DEFINE_bool(dp, options::ONE_DASH, '\0', false,
0c6e6c39 796 N_("Alias for -d"), NULL);
d391083d 797
fee2edb1 798 DEFINE_string(debug, options::TWO_DASHES, '\0', "",
0c6e6c39
RM
799 N_("Turn on debugging"),
800 N_("[all,files,script,task][,...]"));
fee2edb1 801
ee1fe73e 802 DEFINE_special(defsym, options::TWO_DASHES, '\0',
0c6e6c39 803 N_("Define a symbol"), N_("SYMBOL=EXPRESSION"));
a6badf5a 804
086a1841
ILT
805 DEFINE_optional_string(demangle, options::TWO_DASHES, '\0', NULL,
806 N_("Demangle C++ symbols in log messages"),
807 N_("[=STYLE]"));
086a1841
ILT
808 DEFINE_bool(no_demangle, options::TWO_DASHES, '\0', false,
809 N_("Do not demangle C++ symbols in log messages"),
810 NULL);
fced7afd 811
f37b21b4
RM
812 DEFINE_string(dependency_file, options::TWO_DASHES, '\0', NULL,
813 N_("Write a dependency file listing all files read"),
814 N_("FILE"));
815
ee1fe73e 816 DEFINE_bool(detect_odr_violations, options::TWO_DASHES, '\0', false,
0c6e6c39 817 N_("Look for violations of the C++ One Definition Rule"),
f30f86fa 818 N_("Do not look for violations of the C++ One Definition Rule"));
ee1fe73e 819
c82fbeee 820 DEFINE_bool(dynamic_list_data, options::TWO_DASHES, '\0', false,
0c6e6c39 821 N_("Add data symbols to dynamic symbols"), NULL);
c82fbeee
CS
822
823 DEFINE_bool(dynamic_list_cpp_new, options::TWO_DASHES, '\0', false,
0c6e6c39 824 N_("Add C++ operator new/delete to dynamic symbols"), NULL);
c82fbeee
CS
825
826 DEFINE_bool(dynamic_list_cpp_typeinfo, options::TWO_DASHES, '\0', false,
0c6e6c39 827 N_("Add C++ typeinfo to dynamic symbols"), NULL);
c82fbeee
CS
828
829 DEFINE_special(dynamic_list, options::TWO_DASHES, '\0',
0c6e6c39 830 N_("Read a list of dynamic symbols"), N_("FILE"));
c82fbeee 831
358a9718
CC
832 // e
833
590b87ff
AM
834 DEFINE_bool(emit_stub_syms, options::TWO_DASHES, '\0', true,
835 N_("(PowerPC only) Label linker stubs with a symbol"),
836 N_("(PowerPC only) Do not label linker stubs with a symbol"));
837
ee1fe73e 838 DEFINE_string(entry, options::TWO_DASHES, 'e', NULL,
0c6e6c39 839 N_("Set program start address"), N_("ADDRESS"));
ee1fe73e 840
358a9718
CC
841 DEFINE_bool(eh_frame_hdr, options::TWO_DASHES, '\0', false,
842 N_("Create exception frame header"),
843 N_("Do not create exception frame header"));
844
845 // Alphabetized under 'e' because the option is spelled --enable-new-dtags.
846 DEFINE_enable(new_dtags, options::EXACTLY_TWO_DASHES, '\0', true,
847 N_("Enable use of DT_RUNPATH"),
848 N_("Disable use of DT_RUNPATH"));
849
850 DEFINE_bool(enum_size_warning, options::TWO_DASHES, '\0', true, NULL,
851 N_("(ARM only) Do not warn about objects with incompatible "
852 "enum sizes"));
853
65514900
CC
854 DEFINE_special(exclude_libs, options::TWO_DASHES, '\0',
855 N_("Exclude libraries from automatic export"),
856 N_(("lib,lib ...")));
857
ee1fe73e 858 DEFINE_bool(export_dynamic, options::TWO_DASHES, 'E', false,
0c6e6c39 859 N_("Export all dynamic symbols"),
358a9718 860 N_("Do not export all dynamic symbols"));
dbe717ef 861
31821be0
CC
862 DEFINE_set(export_dynamic_symbol, options::TWO_DASHES, '\0',
863 N_("Export SYMBOL to dynamic symbol table"), N_("SYMBOL"));
864
7296d933
DK
865 DEFINE_special(EB, options::ONE_DASH, '\0',
866 N_("Link big-endian objects."), NULL);
7296d933
DK
867 DEFINE_special(EL, options::ONE_DASH, '\0',
868 N_("Link little-endian objects."), NULL);
869
358a9718 870 // f
ce0d1972 871
886288f1
ILT
872 DEFINE_set(auxiliary, options::TWO_DASHES, 'f',
873 N_("Auxiliary filter for shared object symbol table"),
874 N_("SHLIB"));
875
876 DEFINE_string(filter, options::TWO_DASHES, 'F', NULL,
877 N_("Filter for shared object symbol table"),
878 N_("SHLIB"));
879
d82a5bcc
ILT
880 DEFINE_bool(fatal_warnings, options::TWO_DASHES, '\0', false,
881 N_("Treat warnings as errors"),
882 N_("Do not treat warnings as errors"));
883
c6585162 884 DEFINE_string(fini, options::ONE_DASH, '\0', "_fini",
0c6e6c39 885 N_("Call SYMBOL at unload-time"), N_("SYMBOL"));
c6585162 886
358a9718
CC
887 DEFINE_bool(fix_arm1176, options::TWO_DASHES, '\0', true,
888 N_("(ARM only) Fix binaries for ARM1176 erratum"),
889 N_("(ARM only) Do not fix binaries for ARM1176 erratum"));
890
41263c05 891 DEFINE_bool(fix_cortex_a8, options::TWO_DASHES, '\0', false,
358a9718
CC
892 N_("(ARM only) Fix binaries for Cortex-A8 erratum"),
893 N_("(ARM only) Do not fix binaries for Cortex-A8 erratum"));
41263c05 894
7a2a1c79 895 DEFINE_bool(fix_cortex_a53_843419, options::TWO_DASHES, '\0', false,
358a9718
CC
896 N_("(AArch64 only) Fix Cortex-A53 erratum 843419"),
897 N_("(AArch64 only) Do not fix Cortex-A53 erratum 843419"));
2f0c79aa
HS
898
899 DEFINE_bool(fix_cortex_a53_835769, options::TWO_DASHES, '\0', false,
358a9718
CC
900 N_("(AArch64 only) Fix Cortex-A53 erratum 835769"),
901 N_("(AArch64 only) Do not fix Cortex-A53 erratum 835769"));
85fdf906 902
9b2fd367 903 DEFINE_special(fix_v4bx, options::TWO_DASHES, '\0',
0c6e6c39
RM
904 N_("(ARM only) Rewrite BX rn as MOV pc, rn for ARMv4"),
905 NULL);
9b2fd367
DK
906
907 DEFINE_special(fix_v4bx_interworking, options::TWO_DASHES, '\0',
0c6e6c39
RM
908 N_("(ARM only) Rewrite BX rn branch to ARMv4 interworking "
909 "veneer"),
910 NULL);
9b2fd367 911
358a9718
CC
912 DEFINE_string(fuse_ld, options::ONE_DASH, '\0', "",
913 N_("Ignored for GCC linker option compatibility"),
930b5f8b 914 N_("[gold,bfd]"));
358a9718
CC
915
916 // g
ce3e4980 917
fe35d28d
ILT
918 DEFINE_bool(g, options::EXACTLY_ONE_DASH, '\0', false,
919 N_("Ignored"), NULL);
920
358a9718
CC
921 DEFINE_bool(gc_sections, options::TWO_DASHES, '\0', false,
922 N_("Remove unused sections"),
923 N_("Don't remove unused sections"));
924
c1027032
CC
925 DEFINE_bool(gdb_index, options::TWO_DASHES, '\0', false,
926 N_("Generate .gdb_index section"),
927 N_("Do not generate .gdb_index section"));
928
9634ed06 929 DEFINE_bool(gnu_unique, options::TWO_DASHES, '\0', true,
358a9718 930 N_("Enable STB_GNU_UNIQUE symbol binding"),
9634ed06
CC
931 N_("Disable STB_GNU_UNIQUE symbol binding"));
932
358a9718
CC
933 DEFINE_bool(shared, options::ONE_DASH, 'G', false,
934 N_("Generate shared library"), NULL);
935
936 // h
937
ee1fe73e 938 DEFINE_string(soname, options::ONE_DASH, 'h', NULL,
0c6e6c39 939 N_("Set shared library name"), N_("FILENAME"));
ee1fe73e 940
c18476e7
ILT
941 DEFINE_double(hash_bucket_empty_fraction, options::TWO_DASHES, '\0', 0.0,
942 N_("Min fraction of empty buckets in dynamic hash"),
943 N_("FRACTION"));
944
2760f24c 945 DEFINE_enum(hash_style, options::TWO_DASHES, '\0', DEFAULT_HASH_STYLE,
afd2ea23 946 N_("Dynamic hash style"), N_("[sysv,gnu,both]"), false,
13670ee6
ILT
947 {"sysv", "gnu", "both"});
948
358a9718
CC
949 // i
950
951 DEFINE_bool_alias(i, relocatable, options::EXACTLY_ONE_DASH, '\0',
952 N_("Alias for -r"), NULL, false);
953
954 DEFINE_enum(icf, options::TWO_DASHES, '\0', "none",
955 N_("Identical Code Folding. "
956 "\'--icf=safe\' Folds ctors, dtors and functions whose"
957 " pointers are definitely not taken"),
afd2ea23 958 ("[none,all,safe]"), false,
358a9718
CC
959 {"none", "all", "safe"});
960
961 DEFINE_uint(icf_iterations, options::TWO_DASHES , '\0', 0,
e173ea00 962 N_("Number of iterations of ICF (default 3)"), N_("COUNT"));
ee1fe73e 963
8c21d9d3
CC
964 DEFINE_special(incremental, options::TWO_DASHES, '\0',
965 N_("Do an incremental link if possible; "
966 "otherwise, do a full link and prepare output "
967 "for incremental linking"), NULL);
968
969 DEFINE_special(no_incremental, options::TWO_DASHES, '\0',
970 N_("Do a full link (default)"), NULL);
971
972 DEFINE_special(incremental_full, options::TWO_DASHES, '\0',
973 N_("Do a full link and "
974 "prepare output for incremental linking"), NULL);
975
976 DEFINE_special(incremental_update, options::TWO_DASHES, '\0',
977 N_("Do an incremental link; exit if not possible"), NULL);
266d0a74 978
aa92d6ed 979 DEFINE_string(incremental_base, options::TWO_DASHES, '\0', NULL,
0c6e6c39
RM
980 N_("Set base file for incremental linking"
981 " (default is output file)"),
982 N_("FILE"));
aa92d6ed 983
266d0a74 984 DEFINE_special(incremental_changed, options::TWO_DASHES, '\0',
0c6e6c39 985 N_("Assume files changed"), NULL);
266d0a74
ILT
986
987 DEFINE_special(incremental_unchanged, options::TWO_DASHES, '\0',
0c6e6c39 988 N_("Assume files didn't change"), NULL);
266d0a74
ILT
989
990 DEFINE_special(incremental_unknown, options::TWO_DASHES, '\0',
0c6e6c39 991 N_("Use timestamps to check files (default)"), NULL);
266d0a74 992
221597a5 993 DEFINE_special(incremental_startup_unchanged, options::TWO_DASHES, '\0',
0c6e6c39 994 N_("Assume startup files unchanged "
221597a5
CC
995 "(files preceding this option)"), NULL);
996
9fbd3822 997 DEFINE_percent(incremental_patch, options::TWO_DASHES, '\0', 10,
358a9718
CC
998 N_("Amount of extra space to allocate for patches "
999 "(default 10)"),
9fbd3822
CC
1000 N_("PERCENT"));
1001
c6585162 1002 DEFINE_string(init, options::ONE_DASH, '\0', "_init",
0c6e6c39 1003 N_("Call SYMBOL at load-time"), N_("SYMBOL"));
c6585162 1004
358a9718
CC
1005 DEFINE_string(dynamic_linker, options::TWO_DASHES, 'I', NULL,
1006 N_("Set dynamic linker path"), N_("PROGRAM"));
1007
1008 // j
1009
fee2edb1 1010 DEFINE_special(just_symbols, options::TWO_DASHES, '\0',
0c6e6c39 1011 N_("Read only symbol values from FILE"), N_("FILE"));
fee2edb1 1012
358a9718
CC
1013 // k
1014
a2a5469e 1015 DEFINE_bool(keep_files_mapped, options::TWO_DASHES, '\0', true,
358a9718 1016 N_("Keep files mapped across passes"),
0c6e6c39 1017 N_("Release mapped files after each pass"));
2c849493 1018
358a9718
CC
1019 DEFINE_set(keep_unique, options::TWO_DASHES, '\0',
1020 N_("Do not fold this symbol during ICF"), N_("SYMBOL"));
1021
1022 // l
07a60597 1023
ee1fe73e 1024 DEFINE_special(library, options::TWO_DASHES, 'l',
0c6e6c39 1025 N_("Search for library LIBNAME"), N_("LIBNAME"));
bae7f79e 1026
358a9718
CC
1027 DEFINE_bool(ld_generated_unwind_info, options::TWO_DASHES, '\0', true,
1028 N_("Generate unwind information for PLT"),
1029 N_("Do not generate unwind information for PLT"));
1030
ee1fe73e 1031 DEFINE_dirlist(library_path, options::TWO_DASHES, 'L',
0c6e6c39 1032 N_("Add directory to search path"), N_("DIR"));
ee1fe73e 1033
358a9718
CC
1034 DEFINE_bool(long_plt, options::TWO_DASHES, '\0', false,
1035 N_("(ARM only) Generate long PLT entries"),
1036 N_("(ARM only) Do not generate long PLT entries"));
0f72bf6f 1037
358a9718 1038 // m
bbc5ae17 1039
ee1fe73e 1040 DEFINE_string(m, options::EXACTLY_ONE_DASH, 'm', "",
96f9814d 1041 N_("Set GNU linker emulation; obsolete"), N_("EMULATION"));
ee1fe73e 1042
358a9718
CC
1043 DEFINE_bool(map_whole_files, options::TWO_DASHES, '\0',
1044 sizeof(void*) >= 8,
1045 N_("Map whole files to memory"),
1046 N_("Map relevant file parts to memory"));
1047
1048 DEFINE_bool(merge_exidx_entries, options::TWO_DASHES, '\0', true,
1049 N_("(ARM only) Merge exidx entries in debuginfo"),
1050 N_("(ARM only) Do not merge exidx entries in debuginfo"));
1051
7c0640fa 1052 DEFINE_bool(mmap_output_file, options::TWO_DASHES, '\0', true,
358a9718
CC
1053 N_("Map the output file for writing"),
1054 N_("Do not map the output file for writing"));
7c0640fa 1055
7d9e3d98
ILT
1056 DEFINE_bool(print_map, options::TWO_DASHES, 'M', false,
1057 N_("Write map file on standard output"), NULL);
358a9718 1058
7d9e3d98
ILT
1059 DEFINE_string(Map, options::ONE_DASH, '\0', NULL, N_("Write map file"),
1060 N_("MAPFILENAME"));
1061
358a9718
CC
1062 // n
1063
af6156ef
ILT
1064 DEFINE_bool(nmagic, options::TWO_DASHES, 'n', false,
1065 N_("Do not page align data"), NULL);
1066 DEFINE_bool(omagic, options::EXACTLY_TWO_DASHES, 'N', false,
1067 N_("Do not page align data, do not make text readonly"),
1068 N_("Page align data, make text readonly"));
1069
358a9718
CC
1070 DEFINE_bool(no_keep_memory, options::TWO_DASHES, '\0', false,
1071 N_("Use less memory and more disk I/O "
1072 "(included only for compatibility with GNU ld)"), NULL);
cdb0b8f5 1073
f3e9c5c5
ILT
1074 DEFINE_bool_alias(no_undefined, defs, options::TWO_DASHES, '\0',
1075 N_("Report undefined symbols (even with --shared)"),
1076 NULL, false);
1077
358a9718
CC
1078 DEFINE_bool(noinhibit_exec, options::TWO_DASHES, '\0', false,
1079 N_("Create an output file even if errors occur"), NULL);
1080
1081 DEFINE_bool(nostdlib, options::ONE_DASH, '\0', false,
1082 N_("Only search directories specified on the command line"),
1083 NULL);
1084
1085 // o
1086
ee1fe73e 1087 DEFINE_string(output, options::TWO_DASHES, 'o', "a.out",
0c6e6c39 1088 N_("Set output file name"), N_("FILE"));
ee1fe73e 1089
358a9718
CC
1090 DEFINE_string(oformat, options::EXACTLY_TWO_DASHES, '\0', "elf",
1091 N_("Set output format"), N_("[binary]"));
1092
ee1fe73e 1093 DEFINE_uint(optimize, options::EXACTLY_ONE_DASH, 'O', 0,
0c6e6c39 1094 N_("Optimize output file size"), N_("LEVEL"));
ee1fe73e 1095
591be3e4
CC
1096 DEFINE_enum(orphan_handling, options::TWO_DASHES, '\0', "place",
1097 N_("Orphan section handling"), N_("[place,discard,warn,error]"),
afd2ea23 1098 false, {"place", "discard", "warn", "error"});
591be3e4 1099
358a9718 1100 // p
ee1fe73e 1101
358a9718
CC
1102 DEFINE_bool(p, options::ONE_DASH, 'p', false,
1103 N_("Ignored for ARM compatibility"), NULL);
7296d933 1104
70182115
LB
1105 DEFINE_optional_string(package_metadata, options::TWO_DASHES, '\0', NULL,
1106 N_("Generate package metadata note"),
1107 N_("[=JSON]"));
1108
374ad285 1109 DEFINE_bool(pie, options::ONE_DASH, '\0', false,
81233653
ST
1110 N_("Create a position independent executable"),
1111 N_("Do not create a position independent executable"));
374ad285 1112 DEFINE_bool_alias(pic_executable, pie, options::TWO_DASHES, '\0',
5f772412
ST
1113 N_("Create a position independent executable"),
1114 N_("Do not create a position independent executable"),
374ad285
ILT
1115 false);
1116
cdb06167
HS
1117 DEFINE_bool(pic_veneer, options::TWO_DASHES, '\0', false,
1118 N_("Force PIC sequences for ARM/Thumb interworking veneers"),
1119 NULL);
1120
7296d933
DK
1121 DEFINE_bool(pipeline_knowledge, options::ONE_DASH, '\0', false,
1122 NULL, N_("(ARM only) Ignore for backward compatibility"));
1123
9e69ed50 1124 DEFINE_var(plt_align, options::TWO_DASHES, '\0', 0, "5",
9e390558 1125 N_("(PowerPC only) Align PLT call stubs to fit cache lines"),
358a9718 1126 N_("[=P2ALIGN]"), true, int, int, options::parse_uint, false);
9e69ed50 1127
7ee7ff70
AM
1128 DEFINE_bool(plt_localentry, options::TWO_DASHES, '\0', false,
1129 N_("(PowerPC64 only) Optimize calls to ELFv2 localentry:0 functions"),
1130 N_("(PowerPC64 only) Don't optimize ELFv2 calls"));
1131
9e69ed50
AM
1132 DEFINE_bool(plt_static_chain, options::TWO_DASHES, '\0', false,
1133 N_("(PowerPC64 only) PLT call stubs should load r11"),
1134 N_("(PowerPC64 only) PLT call stubs should not load r11"));
1135
1136 DEFINE_bool(plt_thread_safe, options::TWO_DASHES, '\0', false,
1137 N_("(PowerPC64 only) PLT call stubs with load-load barrier"),
1138 N_("(PowerPC64 only) PLT call stubs without barrier"));
1139
89fc3421
CC
1140#ifdef ENABLE_PLUGINS
1141 DEFINE_special(plugin, options::TWO_DASHES, '\0',
0c6e6c39 1142 N_("Load a plugin library"), N_("PLUGIN"));
4674ecfc 1143 DEFINE_special(plugin_opt, options::TWO_DASHES, '\0',
0c6e6c39 1144 N_("Pass an option to the plugin"), N_("OPTION"));
24538276
CC
1145#else
1146 DEFINE_special(plugin, options::TWO_DASHES, '\0',
1147 N_("Load a plugin library (not supported)"), N_("PLUGIN"));
1148 DEFINE_special(plugin_opt, options::TWO_DASHES, '\0',
1149 N_("Pass an option to the plugin (not supported)"),
1150 N_("OPTION"));
89fc3421
CC
1151#endif
1152
7c0640fa 1153 DEFINE_bool(posix_fallocate, options::TWO_DASHES, '\0', true,
358a9718
CC
1154 N_("Use posix_fallocate to reserve space in the output file"),
1155 N_("Use fallocate or ftruncate to reserve space"));
7c0640fa 1156
afd2ea23
AM
1157 DEFINE_enum(power10_stubs, options::TWO_DASHES, '\0', "yes",
1158 N_("(PowerPC64 only) stubs use power10 insns"),
1159 N_("[=auto,no,yes]"), true, {"auto", "no", "yes"});
1160 DEFINE_special(no_power10_stubs, options::TWO_DASHES, '\0',
1161 N_("(PowerPC64 only) stubs do not use power10 insns"), NULL);
1162
ac45a351 1163 DEFINE_bool(preread_archive_symbols, options::TWO_DASHES, '\0', false,
0c6e6c39 1164 N_("Preread archive symbols when multi-threaded"), NULL);
89fc3421 1165
358a9718
CC
1166 DEFINE_bool(print_gc_sections, options::TWO_DASHES, '\0', false,
1167 N_("List removed unused sections on stderr"),
1168 N_("Do not list removed unused sections"));
1169
1170 DEFINE_bool(print_icf_sections, options::TWO_DASHES, '\0', false,
1171 N_("List folded identical sections on stderr"),
1172 N_("Do not list folded identical sections"));
1173
f1ddb600
ILT
1174 DEFINE_bool(print_output_format, options::TWO_DASHES, '\0', false,
1175 N_("Print default output format"), NULL);
1176
92de84a6
ILT
1177 DEFINE_string(print_symbol_counts, options::TWO_DASHES, '\0', NULL,
1178 N_("Print symbols defined and used for each input"),
1179 N_("FILENAME"));
1180
376c3ecd
CC
1181 DEFINE_special(push_state, options::TWO_DASHES, '\0',
1182 N_("Save the state of flags related to input files"), NULL);
1183 DEFINE_special(pop_state, options::TWO_DASHES, '\0',
1184 N_("Restore the state of flags related to input files"), NULL);
1185
358a9718 1186 // q
b5be4a7c 1187
ee1fe73e 1188 DEFINE_bool(emit_relocs, options::TWO_DASHES, 'q', false,
0c6e6c39 1189 N_("Generate relocations in output"), NULL);
ee1fe73e 1190
358a9718
CC
1191 DEFINE_bool(Qy, options::EXACTLY_ONE_DASH, '\0', false,
1192 N_("Ignored for SVR4 compatibility"), NULL);
1193
1194 // r
1195
ee1fe73e 1196 DEFINE_bool(relocatable, options::EXACTLY_ONE_DASH, 'r', false,
0c6e6c39 1197 N_("Generate relocatable output"), NULL);
ee1fe73e 1198
706e1f5e 1199 DEFINE_bool(relax, options::TWO_DASHES, '\0', false,
223b97ba
JC
1200 N_("Relax branches on certain targets"),
1201 N_("Do not relax branches"));
706e1f5e 1202
719328e1 1203 DEFINE_string(retain_symbols_file, options::TWO_DASHES, '\0', NULL,
0c6e6c39 1204 N_("keep only symbols listed in this file"), N_("FILE"));
8c604651 1205
358a9718
CC
1206 DEFINE_bool(rosegment, options::TWO_DASHES, '\0', false,
1207 N_("Put read-only non-executable sections in their own segment"),
9a6c68ca 1208 N_("Do not put read-only non-executable sections in their own segment"));
358a9718
CC
1209
1210 DEFINE_uint64(rosegment_gap, options::TWO_DASHES, '\0', -1U,
1211 N_("Set offset between executable and read-only segments"),
1212 N_("OFFSET"));
1213
ee1fe73e
ILT
1214 // -R really means -rpath, but can mean --just-symbols for
1215 // compatibility with GNU ld. -rpath is always -rpath, so we list
1216 // it separately.
1217 DEFINE_special(R, options::EXACTLY_ONE_DASH, 'R',
0c6e6c39 1218 N_("Add DIR to runtime search path"), N_("DIR"));
ee1fe73e
ILT
1219
1220 DEFINE_dirlist(rpath, options::ONE_DASH, '\0',
0c6e6c39 1221 N_("Add DIR to runtime search path"), N_("DIR"));
ee1fe73e 1222
ee1fe73e 1223 DEFINE_dirlist(rpath_link, options::TWO_DASHES, '\0',
0c6e6c39
RM
1224 N_("Add DIR to link time shared library search path"),
1225 N_("DIR"));
ee1fe73e 1226
358a9718
CC
1227 // s
1228
1229 DEFINE_bool(strip_all, options::TWO_DASHES, 's', false,
1230 N_("Strip all symbols"), NULL);
1231 DEFINE_bool(strip_debug, options::TWO_DASHES, 'S', false,
1232 N_("Strip debugging information"), NULL);
1233 DEFINE_bool(strip_debug_non_line, options::TWO_DASHES, '\0', false,
1234 N_("Emit only debug line number information"), NULL);
1235 DEFINE_bool(strip_debug_gdb, options::TWO_DASHES, '\0', false,
1236 N_("Strip debug symbols that are unused by gdb "
1237 "(at least versions <= 7.4)"), NULL);
1238 DEFINE_bool(strip_lto_sections, options::TWO_DASHES, '\0', true,
1239 N_("Strip LTO intermediate code sections"), NULL);
1240
6e9ba2ca 1241 DEFINE_string(section_ordering_file, options::TWO_DASHES, '\0', NULL,
358a9718 1242 N_("Layout sections in the order specified"),
6e9ba2ca
ST
1243 N_("FILENAME"));
1244
a192ba05
ILT
1245 DEFINE_special(section_start, options::TWO_DASHES, '\0',
1246 N_("Set address of section"), N_("SECTION=ADDRESS"));
1247
f159cdb6
AM
1248 DEFINE_bool(secure_plt, options::TWO_DASHES , '\0', true,
1249 N_("(PowerPC only) Use new-style PLT"), NULL);
1250
fc59c572
ILT
1251 DEFINE_optional_string(sort_common, options::TWO_DASHES, '\0', NULL,
1252 N_("Sort common symbols by alignment"),
1253 N_("[={ascending,descending}]"));
1254
6934001a
CC
1255 DEFINE_enum(sort_section, options::TWO_DASHES, '\0', "none",
1256 N_("Sort sections by name. \'--no-text-reorder\'"
1257 " will override \'--sort-section=name\' for .text"),
afd2ea23 1258 N_("[none,name]"), false,
6934001a
CC
1259 {"none", "name"});
1260
9e9e071b
ILT
1261 DEFINE_uint(spare_dynamic_tags, options::TWO_DASHES, '\0', 5,
1262 N_("Dynamic tag slots to reserve (default 5)"),
1263 N_("COUNT"));
1264
c0a62865 1265 DEFINE_int(stub_group_size, options::TWO_DASHES , '\0', 1,
0c6e6c39 1266 N_("(ARM, PowerPC only) The maximum distance from instructions "
358a9718 1267 "in a group of sections to their stubs. Negative values mean "
a5018ae5 1268 "stubs are always after the group. 1 means use default size"),
c0a62865
DK
1269 N_("SIZE"));
1270
ab502e63 1271 DEFINE_bool(stub_group_multi, options::TWO_DASHES, '\0', true,
69a2af10 1272 N_("(PowerPC only) Allow a group of stubs to serve multiple "
ab502e63
AM
1273 "output sections"),
1274 N_("(PowerPC only) Each output section has its own stubs"));
1c3a5fbe 1275
f9ff65d4 1276 DEFINE_uint(split_stack_adjust_size, options::TWO_DASHES, '\0', 0x100000,
364c7fa5
ILT
1277 N_("Stack size when -fsplit-stack function calls non-split"),
1278 N_("SIZE"));
1279
ee1fe73e
ILT
1280 // This is not actually special in any way, but I need to give it
1281 // a non-standard accessor-function name because 'static' is a keyword.
1282 DEFINE_special(static, options::ONE_DASH, '\0',
0c6e6c39 1283 N_("Do not link against shared libraries"), NULL);
ee1fe73e 1284
358a9718
CC
1285 DEFINE_special(start_lib, options::TWO_DASHES, '\0',
1286 N_("Start a library"), NULL);
1287 DEFINE_special(end_lib, options::TWO_DASHES, '\0',
1288 N_("End a library "), NULL);
6d03d481 1289
ee1fe73e 1290 DEFINE_bool(stats, options::TWO_DASHES, '\0', false,
0c6e6c39 1291 N_("Print resource usage statistics"), NULL);
ee1fe73e
ILT
1292
1293 DEFINE_string(sysroot, options::TWO_DASHES, '\0', "",
0c6e6c39 1294 N_("Set target system root directory"), N_("DIR"));
ee1fe73e 1295
358a9718
CC
1296 // t
1297
1298 DEFINE_bool(trace, options::TWO_DASHES, 't', false,
1299 N_("Print the name of each input file"), NULL);
1300
bc99685c
DK
1301 DEFINE_bool(target1_abs, options::TWO_DASHES, '\0', false,
1302 N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_ABS32"),
1303 NULL);
358a9718
CC
1304 DEFINE_bool(target1_rel, options::TWO_DASHES, '\0', false,
1305 N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_REL32"),
1306 NULL);
bc99685c
DK
1307 DEFINE_enum(target2, options::TWO_DASHES, '\0', NULL,
1308 N_("(ARM only) Set R_ARM_TARGET2 relocation type"),
afd2ea23 1309 N_("[rel, abs, got-rel"), false,
bc99685c
DK
1310 {"rel", "abs", "got-rel"});
1311
358a9718
CC
1312 DEFINE_bool(text_reorder, options::TWO_DASHES, '\0', true,
1313 N_("Enable text section reordering for GCC section names"),
1314 N_("Disable text section reordering for GCC section names"));
ee1fe73e
ILT
1315
1316 DEFINE_bool(threads, options::TWO_DASHES, '\0', false,
0c6e6c39
RM
1317 N_("Run the linker multi-threaded"),
1318 N_("Do not run the linker multi-threaded"));
ee1fe73e 1319 DEFINE_uint(thread_count, options::TWO_DASHES, '\0', 0,
0c6e6c39 1320 N_("Number of threads to use"), N_("COUNT"));
ee1fe73e 1321 DEFINE_uint(thread_count_initial, options::TWO_DASHES, '\0', 0,
0c6e6c39 1322 N_("Number of threads to use in initial pass"), N_("COUNT"));
ee1fe73e 1323 DEFINE_uint(thread_count_middle, options::TWO_DASHES, '\0', 0,
0c6e6c39 1324 N_("Number of threads to use in middle pass"), N_("COUNT"));
ee1fe73e 1325 DEFINE_uint(thread_count_final, options::TWO_DASHES, '\0', 0,
0c6e6c39 1326 N_("Number of threads to use in final pass"), N_("COUNT"));
ee1fe73e 1327
aacb3b6d
AM
1328 DEFINE_bool(tls_optimize, options::TWO_DASHES, '\0', true,
1329 N_("(PowerPC/64 only) Optimize GD/LD/IE code to IE/LE"),
1330 N_("(PowerPC/64 only) Don'\''t try to optimize TLS accesses"));
34e0882b
AM
1331 DEFINE_bool(tls_get_addr_optimize, options::TWO_DASHES, '\0', true,
1332 N_("(PowerPC/64 only) Use a special __tls_get_addr call"),
1333 N_("(PowerPC/64 only) Don't use a special __tls_get_addr call"));
aacb3b6d 1334
358a9718
CC
1335 DEFINE_bool(toc_optimize, options::TWO_DASHES, '\0', true,
1336 N_("(PowerPC64 only) Optimize TOC code sequences"),
1337 N_("(PowerPC64 only) Don't optimize TOC code sequences"));
1338
1339 DEFINE_bool(toc_sort, options::TWO_DASHES, '\0', true,
1340 N_("(PowerPC64 only) Sort TOC and GOT sections"),
1341 N_("(PowerPC64 only) Don't sort TOC and GOT sections"));
1342
1343 DEFINE_special(script, options::TWO_DASHES, 'T',
1344 N_("Read linker script"), N_("FILE"));
1345
fee2edb1 1346 DEFINE_uint64(Tbss, options::ONE_DASH, '\0', -1U,
0c6e6c39 1347 N_("Set the address of the bss segment"), N_("ADDRESS"));
fee2edb1 1348 DEFINE_uint64(Tdata, options::ONE_DASH, '\0', -1U,
0c6e6c39 1349 N_("Set the address of the data segment"), N_("ADDRESS"));
fee2edb1 1350 DEFINE_uint64(Ttext, options::ONE_DASH, '\0', -1U,
0c6e6c39 1351 N_("Set the address of the text segment"), N_("ADDRESS"));
214383dd
ILT
1352 DEFINE_uint64_alias(Ttext_segment, Ttext, options::ONE_DASH, '\0',
1353 N_("Set the address of the text segment"),
1354 N_("ADDRESS"));
a3ed37d8
RM
1355 DEFINE_uint64(Trodata_segment, options::ONE_DASH, '\0', -1U,
1356 N_("Set the address of the rodata segment"), N_("ADDRESS"));
fee2edb1 1357
358a9718 1358 // u
aba6bc71 1359
f3e9c5c5
ILT
1360 DEFINE_set(undefined, options::TWO_DASHES, 'u',
1361 N_("Create undefined reference to SYMBOL"), N_("SYMBOL"));
2b706932 1362
beabb2c6
ILT
1363 DEFINE_enum(unresolved_symbols, options::TWO_DASHES, '\0', NULL,
1364 N_("How to handle unresolved symbols"),
1365 ("ignore-all,report-all,ignore-in-object-files,"
afd2ea23 1366 "ignore-in-shared-libs"), false,
beabb2c6
ILT
1367 {"ignore-all", "report-all", "ignore-in-object-files",
1368 "ignore-in-shared-libs"});
1369
358a9718
CC
1370 // v
1371
2285a610 1372 DEFINE_bool(verbose, options::TWO_DASHES, '\0', false,
358a9718 1373 N_("Alias for --debug=files"), NULL);
2285a610 1374
fee2edb1 1375 DEFINE_special(version_script, options::TWO_DASHES, '\0',
0c6e6c39 1376 N_("Read version script"), N_("FILE"));
fee2edb1 1377
358a9718
CC
1378 // w
1379
1ae4d23b
ILT
1380 DEFINE_bool(warn_common, options::TWO_DASHES, '\0', false,
1381 N_("Warn about duplicate common symbols"),
358a9718 1382 N_("Do not warn about duplicate common symbols"));
1ae4d23b 1383
358a9718
CC
1384 DEFINE_bool_ignore(warn_constructors, options::TWO_DASHES, '\0',
1385 N_("Ignored"), N_("Ignored"));
37a9ac43 1386
3a12c78d
CC
1387 DEFINE_bool(warn_drop_version, options::TWO_DASHES, '\0', false,
1388 N_("Warn when discarding version information"),
1389 N_("Do not warn when discarding version information"));
1390
83e17bd5
CC
1391 DEFINE_bool(warn_execstack, options::TWO_DASHES, '\0', false,
1392 N_("Warn if the stack is executable"),
358a9718 1393 N_("Do not warn if the stack is executable"));
83e17bd5 1394
7296d933
DK
1395 DEFINE_bool(warn_mismatch, options::TWO_DASHES, '\0', true,
1396 NULL, N_("Don't warn about mismatched input files"));
1397
6eda8c29
ILT
1398 DEFINE_bool(warn_multiple_gp, options::TWO_DASHES, '\0', false,
1399 N_("Ignored"), NULL);
1400
15f8229b
ILT
1401 DEFINE_bool(warn_search_mismatch, options::TWO_DASHES, '\0', true,
1402 N_("Warn when skipping an incompatible library"),
1403 N_("Don't warn when skipping an incompatible library"));
1404
b9674e17
ILT
1405 DEFINE_bool(warn_shared_textrel, options::TWO_DASHES, '\0', false,
1406 N_("Warn if text segment is not shareable"),
358a9718 1407 N_("Do not warn if text segment is not shareable"));
b9674e17 1408
dc3f80fe
ILT
1409 DEFINE_bool(warn_unresolved_symbols, options::TWO_DASHES, '\0', false,
1410 N_("Report unresolved symbols as warnings"),
1411 NULL);
1412 DEFINE_bool_alias(error_unresolved_symbols, warn_unresolved_symbols,
1413 options::TWO_DASHES, '\0',
1414 N_("Report unresolved symbols as errors"),
1415 NULL, true);
1416
ce0d1972
DK
1417 DEFINE_bool(wchar_size_warning, options::TWO_DASHES, '\0', true, NULL,
1418 N_("(ARM only) Do not warn about objects with incompatible "
1419 "wchar_t sizes"));
1420
358a9718
CC
1421 DEFINE_bool(weak_unresolved_symbols, options::TWO_DASHES, '\0', false,
1422 N_("Convert unresolved symbols to weak references"),
1423 NULL);
1424
ee1fe73e 1425 DEFINE_bool(whole_archive, options::TWO_DASHES, '\0', false,
0c6e6c39
RM
1426 N_("Include all archive contents"),
1427 N_("Include only needed archive contents"));
ee1fe73e 1428
c5818ff1
CC
1429 DEFINE_set(wrap, options::TWO_DASHES, '\0',
1430 N_("Use wrapper functions for SYMBOL"), N_("SYMBOL"));
1431
358a9718
CC
1432 // x
1433
1434 DEFINE_special(discard_all, options::TWO_DASHES, 'x',
1435 N_("Delete all local symbols"), NULL);
1436 DEFINE_special(discard_locals, options::TWO_DASHES, 'X',
1437 N_("Delete all temporary local symbols"), NULL);
1438 DEFINE_special(discard_none, options::TWO_DASHES, '\0',
1439 N_("Keep all local symbols"), NULL);
1440
1441 // y
1442
c5818ff1 1443 DEFINE_set(trace_symbol, options::TWO_DASHES, 'y',
0c6e6c39 1444 N_("Trace references to symbol"), N_("SYMBOL"));
0864d551 1445
62dfdd4d 1446 DEFINE_bool(undefined_version, options::TWO_DASHES, '\0', true,
358a9718 1447 N_("Allow unused version in script"),
62dfdd4d
ILT
1448 N_("Do not allow unused version in script"));
1449
706e1f5e
ILT
1450 DEFINE_string(Y, options::EXACTLY_ONE_DASH, 'Y', "",
1451 N_("Default search path for Solaris compatibility"),
1452 N_("PATH"));
1453
358a9718
CC
1454 // special characters
1455
ee1fe73e 1456 DEFINE_special(start_group, options::TWO_DASHES, '(',
0c6e6c39 1457 N_("Start a library search group"), NULL);
ee1fe73e 1458 DEFINE_special(end_group, options::TWO_DASHES, ')',
0c6e6c39 1459 N_("End a library search group"), NULL);
ee1fe73e 1460
fee2edb1 1461 // The -z options.
ee1fe73e 1462
d98bc257
ILT
1463 DEFINE_bool(combreloc, options::DASH_Z, '\0', true,
1464 N_("Sort dynamic relocs"),
1465 N_("Do not sort dynamic relocs"));
fee2edb1 1466 DEFINE_uint64(common_page_size, options::DASH_Z, '\0', 0,
0c6e6c39 1467 N_("Set common page size to SIZE"), N_("SIZE"));
eb42429a 1468 DEFINE_bool(defs, options::DASH_Z, '\0', false,
0c6e6c39
RM
1469 N_("Report undefined symbols (even with --shared)"),
1470 NULL);
ee1fe73e 1471 DEFINE_bool(execstack, options::DASH_Z, '\0', false,
0c6e6c39 1472 N_("Mark output as requiring executable stack"), NULL);
fb257835
DI
1473 DEFINE_bool(global, options::DASH_Z, '\0', false,
1474 N_("Make symbols in DSO available for subsequently loaded "
1130c90e 1475 "objects"), NULL);
7c414435
DM
1476 DEFINE_bool(initfirst, options::DASH_Z, '\0', false,
1477 N_("Mark DSO to be initialized first at runtime"),
1478 NULL);
1479 DEFINE_bool(interpose, options::DASH_Z, '\0', false,
1480 N_("Mark object to interpose all DSOs but executable"),
1481 NULL);
8a87b279
VDM
1482 DEFINE_bool(unique, options::DASH_Z, '\0', false,
1483 N_("Mark DSO to be loaded at most once, and only in the main namespace"),
1484 N_("Do not mark the DSO as one to be loaded only in the main namespace"));
6a9da32a 1485 DEFINE_bool_alias(lazy, now, options::DASH_Z, '\0',
358a9718 1486 N_("Mark object for lazy runtime binding"),
6a9da32a 1487 NULL, true);
7c414435
DM
1488 DEFINE_bool(loadfltr, options::DASH_Z, '\0', false,
1489 N_("Mark object requiring immediate process"),
1490 NULL);
e1c74d60 1491 DEFINE_uint64(max_page_size, options::DASH_Z, '\0', 0,
0c6e6c39 1492 N_("Set maximum page size to SIZE"), N_("SIZE"));
30bc8c46
ILT
1493 DEFINE_bool(muldefs, options::DASH_Z, '\0', false,
1494 N_("Allow multiple definitions of symbols"),
1495 NULL);
1496 // copyreloc is here in the list because there is only -z
1497 // nocopyreloc, not -z copyreloc.
966d4097
DK
1498 DEFINE_bool(copyreloc, options::DASH_Z, '\0', true,
1499 NULL,
1500 N_("Do not create copy relocs"));
7c414435
DM
1501 DEFINE_bool(nodefaultlib, options::DASH_Z, '\0', false,
1502 N_("Mark object not to use default search paths"),
1503 NULL);
1504 DEFINE_bool(nodelete, options::DASH_Z, '\0', false,
1505 N_("Mark DSO non-deletable at runtime"),
1506 NULL);
1507 DEFINE_bool(nodlopen, options::DASH_Z, '\0', false,
1508 N_("Mark DSO not available to dlopen"),
1509 NULL);
1510 DEFINE_bool(nodump, options::DASH_Z, '\0', false,
1511 N_("Mark DSO not available to dldump"),
1512 NULL);
e1c74d60 1513 DEFINE_bool(noexecstack, options::DASH_Z, '\0', false,
0c6e6c39 1514 N_("Mark output as not requiring executable stack"), NULL);
e1c74d60
ILT
1515 DEFINE_bool(now, options::DASH_Z, '\0', false,
1516 N_("Mark object for immediate function binding"),
1517 NULL);
7be8330a
CD
1518 DEFINE_bool(origin, options::DASH_Z, '\0', false,
1519 N_("Mark DSO to indicate that needs immediate $ORIGIN "
0c6e6c39 1520 "processing at runtime"), NULL);
6b1edb94 1521 DEFINE_bool(relro, options::DASH_Z, '\0', DEFAULT_LD_Z_RELRO,
e1c74d60
ILT
1522 N_("Where possible mark variables read-only after relocation"),
1523 N_("Don't mark variables read-only after relocation"));
1130c90e
RM
1524 DEFINE_uint64(stack_size, options::DASH_Z, '\0', 0,
1525 N_("Set PT_GNU_STACK segment p_memsz to SIZE"), N_("SIZE"));
cae64165 1526 DEFINE_enum(start_stop_visibility, options::DASH_Z, '\0', "protected",
f37b21b4
RM
1527 N_("ELF symbol visibility for synthesized "
1528 "__start_* and __stop_* symbols"),
afd2ea23 1529 ("[default,internal,hidden,protected]"), false,
f37b21b4 1530 {"default", "internal", "hidden", "protected"});
ffeef7df
ILT
1531 DEFINE_bool(text, options::DASH_Z, '\0', false,
1532 N_("Do not permit relocations in read-only segments"),
358a9718 1533 N_("Permit relocations in read-only segments"));
ffeef7df 1534 DEFINE_bool_alias(textoff, text, options::DASH_Z, '\0',
358a9718 1535 N_("Permit relocations in read-only segments"),
ffeef7df 1536 NULL, true);
3b4190cc
ST
1537 DEFINE_bool(text_unlikely_segment, options::DASH_Z, '\0', false,
1538 N_("Move .text.unlikely sections to a separate segment."),
1539 N_("Do not move .text.unlikely sections to a separate "
1540 "segment."));
779bdadb
ST
1541 DEFINE_bool(keep_text_section_prefix, options::DASH_Z, '\0', false,
1542 N_("Keep .text.hot, .text.startup, .text.exit and .text.unlikely "
1543 "as separate sections in the final binary."),
1544 N_("Merge all .text.* prefix sections."));
3b4190cc 1545
bae7f79e 1546
ee1fe73e
ILT
1547 public:
1548 typedef options::Dir_list Dir_list;
ca3a67a5 1549
ee1fe73e 1550 General_options();
61ba1cf9 1551
ee1fe73e
ILT
1552 // Does post-processing on flags, making sure they all have
1553 // non-conflicting values. Also converts some flags from their
1554 // "standard" types (string, etc), to another type (enum, DirList),
1555 // which can be accessed via a separate method. Dies if it notices
1556 // any problems.
1557 void finalize();
516cb3d0 1558
459c9f1c
ILT
1559 // True if we printed the version information.
1560 bool
1561 printed_version() const
1562 { return this->printed_version_; }
1563
ee1fe73e
ILT
1564 // The macro defines output() (based on --output), but that's a
1565 // generic name. Provide this alternative name, which is clearer.
8851ecca 1566 const char*
ee1fe73e
ILT
1567 output_file_name() const
1568 { return this->output(); }
92e059d8 1569
8851ecca
ILT
1570 // This is not defined via a flag, but combines flags to say whether
1571 // the output is position-independent or not.
1572 bool
1573 output_is_position_independent() const
374ad285 1574 { return this->shared() || this->pie(); }
8851ecca 1575
183fd0e3
AO
1576 // Return true if the output is something that can be exec()ed, such
1577 // as a static executable, or a position-dependent or
1578 // position-independent executable, but not a dynamic library or an
1579 // object file.
1580 bool
1581 output_is_executable() const
374ad285 1582 { return !this->shared() && !this->relocatable(); }
183fd0e3 1583
ee1fe73e
ILT
1584 // This would normally be static(), and defined automatically, but
1585 // since static is a keyword, we need to come up with our own name.
bae7f79e
ILT
1586 bool
1587 is_static() const
ee1fe73e 1588 { return static_; }
756ac4a8 1589
ee1fe73e
ILT
1590 // In addition to getting the input and output formats as a string
1591 // (via format() and oformat()), we also give access as an enum.
1592 enum Object_format
1593 {
1594 // Ordinary ELF.
1595 OBJECT_FORMAT_ELF,
1596 // Straight binary format.
1597 OBJECT_FORMAT_BINARY
1598 };
fe9a4c12 1599
e6a307ba
ILT
1600 // Convert a string to an Object_format. Gives an error if the
1601 // string is not recognized.
1602 static Object_format
1603 string_to_object_format(const char* arg);
1604
376c3ecd
CC
1605 // Convert an Object_format to string.
1606 static const char*
1607 object_format_to_string(Object_format);
1608
ee1fe73e
ILT
1609 // Note: these functions are not very fast.
1610 Object_format format_enum() const;
1611 Object_format oformat_enum() const;
fe9a4c12 1612
fd9d194f
ILT
1613 // Return whether FILENAME is in a system directory.
1614 bool
1615 is_in_system_directory(const std::string& name) const;
1616
8c604651
CS
1617 // RETURN whether SYMBOL_NAME should be kept, according to symbols_to_retain_.
1618 bool
1619 should_retain_symbol(const char* symbol_name) const
1620 {
1621 if (symbols_to_retain_.empty()) // means flag wasn't specified
0c6e6c39 1622 return true;
8c604651
CS
1623 return symbols_to_retain_.find(symbol_name) != symbols_to_retain_.end();
1624 }
1625
ee1fe73e
ILT
1626 // These are the best way to get access to the execstack state,
1627 // not execstack() and noexecstack() which are hard to use properly.
35cdfc9a
ILT
1628 bool
1629 is_execstack_set() const
ee1fe73e 1630 { return this->execstack_status_ != EXECSTACK_FROM_INPUT; }
35cdfc9a
ILT
1631
1632 bool
1633 is_stack_executable() const
ee1fe73e 1634 { return this->execstack_status_ == EXECSTACK_YES; }
c7912668 1635
032ce4e9
ST
1636 bool
1637 icf_enabled() const
1638 { return this->icf_status_ != ICF_NONE; }
1639
1640 bool
1641 icf_safe_folding() const
1642 { return this->icf_status_ == ICF_SAFE; }
1643
086a1841
ILT
1644 // The --demangle option takes an optional string, and there is also
1645 // a --no-demangle option. This is the best way to decide whether
1646 // to demangle or not.
1647 bool
1648 do_demangle() const
1649 { return this->do_demangle_; }
1650
89fc3421
CC
1651 // Returns TRUE if any plugin libraries have been loaded.
1652 bool
1653 has_plugins() const
1654 { return this->plugins_ != NULL; }
1655
1656 // Return a pointer to the plugin manager.
1657 Plugin_manager*
1658 plugins() const
1659 { return this->plugins_; }
1660
c82fbeee
CS
1661 // True iff SYMBOL was found in the file specified by dynamic-list.
1662 bool
1663 in_dynamic_list(const char* symbol) const
1664 { return this->dynamic_list_.version_script_info()->symbol_is_local(symbol); }
1665
fd834e57
CC
1666 // True if a --dynamic-list script was provided.
1667 bool
1668 have_dynamic_list() const
1669 { return this->have_dynamic_list_; }
1670
6affe781
ILT
1671 // Finalize the dynamic list.
1672 void
1673 finalize_dynamic_list()
1674 { this->dynamic_list_.version_script_info()->finalize(); }
1675
8c21d9d3
CC
1676 // The mode selected by the --incremental options.
1677 enum Incremental_mode
1678 {
1679 // No incremental linking (--no-incremental).
1680 INCREMENTAL_OFF,
1681 // Incremental update only (--incremental-update).
1682 INCREMENTAL_UPDATE,
1683 // Force a full link, but prepare for subsequent incremental link
1684 // (--incremental-full).
1685 INCREMENTAL_FULL,
1686 // Incremental update if possible, fallback to full link (--incremental).
1687 INCREMENTAL_AUTO
1688 };
1689
1690 // The incremental linking mode.
1691 Incremental_mode
1692 incremental_mode() const
1693 { return this->incremental_mode_; }
1694
266d0a74
ILT
1695 // The disposition given by the --incremental-changed,
1696 // --incremental-unchanged or --incremental-unknown option. The
1697 // value may change as we proceed parsing the command line flags.
1698 Incremental_disposition
1699 incremental_disposition() const
1700 { return this->incremental_disposition_; }
1701
376c3ecd
CC
1702 void
1703 set_incremental_disposition(Incremental_disposition disp)
1704 { this->incremental_disposition_ = disp; }
1705
221597a5
CC
1706 // The disposition to use for startup files (those that precede the
1707 // first --incremental-changed, etc. option).
1708 Incremental_disposition
1709 incremental_startup_disposition() const
1710 { return this->incremental_startup_disposition_; }
1711
65514900
CC
1712 // Return true if S is the name of a library excluded from automatic
1713 // symbol export.
1714 bool
ca09d69a 1715 check_excluded_libs(const std::string &s) const;
65514900 1716
a192ba05
ILT
1717 // If an explicit start address was given for section SECNAME with
1718 // the --section-start option, return true and set *PADDR to the
1719 // address. Otherwise return false.
1720 bool
1721 section_start(const char* secname, uint64_t* paddr) const;
1722
ea0d8c47
ILT
1723 // Return whether any --section-start option was used.
1724 bool
1725 any_section_start() const
1726 { return !this->section_starts_.empty(); }
1727
9b2fd367
DK
1728 enum Fix_v4bx
1729 {
1730 // Leave original instruction.
1731 FIX_V4BX_NONE,
1732 // Replace instruction.
1733 FIX_V4BX_REPLACE,
1734 // Generate an interworking veneer.
1735 FIX_V4BX_INTERWORKING
1736 };
1737
1738 Fix_v4bx
1739 fix_v4bx() const
1740 { return (this->fix_v4bx_); }
1741
7296d933
DK
1742 enum Endianness
1743 {
1744 ENDIANNESS_NOT_SET,
1745 ENDIANNESS_BIG,
1746 ENDIANNESS_LITTLE
1747 };
1748
1749 Endianness
1750 endianness() const
1751 { return this->endianness_; }
1752
823241a2
FS
1753 enum Bsymbolic_kind
1754 {
1755 BSYMBOLIC_NONE,
1756 BSYMBOLIC_FUNCTIONS,
1757 BSYMBOLIC_ALL,
1758 };
1759
1760 bool
1761 Bsymbolic() const
1762 { return this->bsymbolic_ == BSYMBOLIC_ALL; }
1763
1764 bool
1765 Bsymbolic_functions() const
1766 { return this->bsymbolic_ == BSYMBOLIC_FUNCTIONS; }
1767
cd3c333f
CC
1768 bool
1769 discard_all() const
1770 { return this->discard_locals_ == DISCARD_ALL; }
1771
1772 bool
1773 discard_locals() const
1774 { return this->discard_locals_ == DISCARD_LOCALS; }
1775
1776 bool
1777 discard_sec_merge() const
1778 { return this->discard_locals_ == DISCARD_SEC_MERGE; }
1779
591be3e4
CC
1780 enum Orphan_handling
1781 {
1782 // Place orphan sections normally (default).
1783 ORPHAN_PLACE,
1784 // Discard all orphan sections.
1785 ORPHAN_DISCARD,
1786 // Warn when placing orphan sections.
1787 ORPHAN_WARN,
1788 // Issue error for orphan sections.
1789 ORPHAN_ERROR
1790 };
1791
1792 Orphan_handling
1793 orphan_handling_enum() const
1794 { return this->orphan_handling_enum_; }
1795
cae64165
RM
1796 elfcpp::STV
1797 start_stop_visibility_enum() const
1798 { return this->start_stop_visibility_enum_; }
1799
afd2ea23
AM
1800 enum Power10_stubs
1801 {
1802 // Use Power10 insns on @notoc calls/branches, non-Power10 elsewhere.
1803 POWER10_STUBS_AUTO,
1804 // Don't use Power10 insns
1805 POWER10_STUBS_NO,
1806 // Always use Power10 insns
1807 POWER10_STUBS_YES
1808 };
1809
1810 Power10_stubs
1811 power10_stubs_enum() const
1812 { return this->power10_stubs_enum_; }
1813
bae7f79e 1814 private:
dbe717ef
ILT
1815 // Don't copy this structure.
1816 General_options(const General_options&);
1817 General_options& operator=(const General_options&);
1818
cd3c333f
CC
1819 // What local symbols to discard.
1820 enum Discard_locals
1821 {
1822 // Locals in merge sections (default).
1823 DISCARD_SEC_MERGE,
1824 // None (--discard-none).
1825 DISCARD_NONE,
1826 // Temporary locals (--discard-locals/-X).
1827 DISCARD_LOCALS,
1828 // All locals (--discard-all/-x).
1829 DISCARD_ALL
1830 };
1831
35cdfc9a
ILT
1832 // Whether to mark the stack as executable.
1833 enum Execstack
1834 {
1835 // Not set on command line.
1836 EXECSTACK_FROM_INPUT,
ee1fe73e 1837 // Mark the stack as executable (-z execstack).
35cdfc9a 1838 EXECSTACK_YES,
ee1fe73e 1839 // Mark the stack as not executable (-z noexecstack).
35cdfc9a
ILT
1840 EXECSTACK_NO
1841 };
1842
032ce4e9
ST
1843 enum Icf_status
1844 {
1845 // Do not fold any functions (Default or --icf=none).
1846 ICF_NONE,
1847 // All functions are candidates for folding. (--icf=all).
0c6e6c39 1848 ICF_ALL,
032ce4e9
ST
1849 // Only ctors and dtors are candidates for folding. (--icf=safe).
1850 ICF_SAFE
1851 };
1852
1853 void
1854 set_icf_status(Icf_status value)
1855 { this->icf_status_ = value; }
1856
92e059d8 1857 void
ee1fe73e 1858 set_execstack_status(Execstack value)
086a1841
ILT
1859 { this->execstack_status_ = value; }
1860
1861 void
1862 set_do_demangle(bool value)
1863 { this->do_demangle_ = value; }
92e059d8 1864
bae7f79e 1865 void
45aa233b 1866 set_static(bool value)
ee1fe73e 1867 { static_ = value; }
652ec9bd 1868
591be3e4
CC
1869 void
1870 set_orphan_handling_enum(Orphan_handling value)
1871 { this->orphan_handling_enum_ = value; }
1872
cae64165
RM
1873 void
1874 set_start_stop_visibility_enum(elfcpp::STV value)
1875 { this->start_stop_visibility_enum_ = value; }
1876
afd2ea23
AM
1877 void
1878 set_power10_stubs_enum(Power10_stubs value)
1879 { this->power10_stubs_enum_ = value; }
1880
ee1fe73e 1881 // These are called by finalize() to set up the search-path correctly.
35cdfc9a 1882 void
3f3cddf1 1883 add_to_library_path_with_sysroot(const std::string& arg)
ee1fe73e 1884 { this->add_search_directory_to_library_path(Search_directory(arg, true)); }
c7912668 1885
ad2d6943
ILT
1886 // Apply any sysroot to the directory lists.
1887 void
1888 add_sysroot();
086a1841 1889
89fc3421
CC
1890 // Add a plugin and its arguments to the list of plugins.
1891 void
ca09d69a 1892 add_plugin(const char* filename);
4674ecfc
CC
1893
1894 // Add a plugin option.
1895 void
1896 add_plugin_option(const char* opt);
89fc3421 1897
376c3ecd
CC
1898 void
1899 copy_from_posdep_options(const Position_dependent_options&);
1900
823241a2
FS
1901 // Whether we bind default visibility defined symbols locally for -shared.
1902 Bsymbolic_kind bsymbolic_;
459c9f1c
ILT
1903 // Whether we printed version information.
1904 bool printed_version_;
086a1841
ILT
1905 // Whether to mark the stack as executable.
1906 Execstack execstack_status_;
032ce4e9
ST
1907 // Whether to do code folding.
1908 Icf_status icf_status_;
086a1841
ILT
1909 // Whether to do a static link.
1910 bool static_;
1911 // Whether to do demangling.
1912 bool do_demangle_;
89fc3421
CC
1913 // List of plugin libraries.
1914 Plugin_manager* plugins_;
c82fbeee
CS
1915 // The parsed output of --dynamic-list files. For convenience in
1916 // script.cc, we store this as a Script_options object, even though
1917 // we only use a single Version_tree from it.
1918 Script_options dynamic_list_;
fd834e57
CC
1919 // Whether a --dynamic-list file was provided.
1920 bool have_dynamic_list_;
8c21d9d3
CC
1921 // The incremental linking mode.
1922 Incremental_mode incremental_mode_;
266d0a74
ILT
1923 // The disposition given by the --incremental-changed,
1924 // --incremental-unchanged or --incremental-unknown option. The
1925 // value may change as we proceed parsing the command line flags.
1926 Incremental_disposition incremental_disposition_;
221597a5
CC
1927 // The disposition to use for startup files (those marked
1928 // INCREMENTAL_STARTUP).
1929 Incremental_disposition incremental_startup_disposition_;
459c9f1c 1930 // Whether we have seen one of the options that require incremental
221597a5
CC
1931 // build (--incremental-changed, --incremental-unchanged,
1932 // --incremental-unknown, or --incremental-startup-unchanged).
266d0a74 1933 bool implicit_incremental_;
8c604651 1934 // Libraries excluded from automatic export, via --exclude-libs.
65514900 1935 Unordered_set<std::string> excluded_libs_;
8c604651
CS
1936 // List of symbol-names to keep, via -retain-symbol-info.
1937 Unordered_set<std::string> symbols_to_retain_;
a192ba05
ILT
1938 // Map from section name to address from --section-start.
1939 std::map<std::string, uint64_t> section_starts_;
9b2fd367
DK
1940 // Whether to process armv4 bx instruction relocation.
1941 Fix_v4bx fix_v4bx_;
7296d933
DK
1942 // Endianness.
1943 Endianness endianness_;
cd3c333f
CC
1944 // What local symbols to discard.
1945 Discard_locals discard_locals_;
376c3ecd
CC
1946 // Stack of saved options for --push-state/--pop-state.
1947 std::vector<Position_dependent_options*> options_stack_;
591be3e4
CC
1948 // Orphan handling option, decoded to an enum value.
1949 Orphan_handling orphan_handling_enum_;
cae64165
RM
1950 // Symbol visibility for __start_* / __stop_* magic symbols.
1951 elfcpp::STV start_stop_visibility_enum_;
afd2ea23
AM
1952 // Power10 stubs option
1953 Power10_stubs power10_stubs_enum_;
bae7f79e
ILT
1954};
1955
ee1fe73e
ILT
1956// The position-dependent options. We use this to store the state of
1957// the commandline at a particular point in parsing for later
1958// reference. For instance, if we see "ld --whole-archive foo.a
1959// --no-whole-archive," we want to store the whole-archive option with
1960// foo.a, so when the time comes to parse foo.a we know we should do
1961// it in whole-archive mode. We could store all of General_options,
1962// but that's big, so we just pick the subset of flags that actually
1963// change in a position-dependent way.
1964
1965#define DEFINE_posdep(varname__, type__) \
1966 public: \
1967 type__ \
1968 varname__() const \
1969 { return this->varname__##_; } \
0c6e6c39 1970 \
ee1fe73e
ILT
1971 void \
1972 set_##varname__(type__ value) \
1973 { this->varname__##_ = value; } \
1974 private: \
1975 type__ varname__##_
bae7f79e
ILT
1976
1977class Position_dependent_options
1978{
1979 public:
ee1fe73e 1980 Position_dependent_options(const General_options& options
0c6e6c39 1981 = Position_dependent_options::default_options_)
ee1fe73e 1982 { copy_from_options(options); }
bae7f79e 1983
376c3ecd
CC
1984 void
1985 copy_from_options(const General_options& options)
ee1fe73e
ILT
1986 {
1987 this->set_as_needed(options.as_needed());
1988 this->set_Bdynamic(options.Bdynamic());
1989 this->set_format_enum(options.format_enum());
1990 this->set_whole_archive(options.whole_archive());
266d0a74 1991 this->set_incremental_disposition(options.incremental_disposition());
ee1fe73e 1992 }
bc644c6c 1993
ee1fe73e
ILT
1994 DEFINE_posdep(as_needed, bool);
1995 DEFINE_posdep(Bdynamic, bool);
1996 DEFINE_posdep(format_enum, General_options::Object_format);
1997 DEFINE_posdep(whole_archive, bool);
266d0a74 1998 DEFINE_posdep(incremental_disposition, Incremental_disposition);
7cc619c3 1999
dbe717ef 2000 private:
ee1fe73e
ILT
2001 // This is a General_options with everything set to its default
2002 // value. A Position_dependent_options created with no argument
2003 // will take its values from here.
2004 static General_options default_options_;
bae7f79e
ILT
2005};
2006
ee1fe73e 2007
bae7f79e
ILT
2008// A single file or library argument from the command line.
2009
ead1e424 2010class Input_file_argument
bae7f79e
ILT
2011{
2012 public:
ae3b5189
CD
2013 enum Input_file_type
2014 {
2015 // A regular file, name used as-is, not searched.
2016 INPUT_FILE_TYPE_FILE,
2017 // A library name. When used, "lib" will be prepended and ".so" or
2018 // ".a" appended to make a filename, and that filename will be searched
2019 // for using the -L paths.
2020 INPUT_FILE_TYPE_LIBRARY,
2021 // A regular file, name used as-is, but searched using the -L paths.
2022 INPUT_FILE_TYPE_SEARCHED_FILE
2023 };
2024
51dee2fe 2025 // name: file name or library name
ae3b5189 2026 // type: the type of this input file.
51dee2fe
ILT
2027 // extra_search_path: an extra directory to look for the file, prior
2028 // to checking the normal library search path. If this is "",
2029 // then no extra directory is added.
88dd47ac 2030 // just_symbols: whether this file only defines symbols.
51dee2fe 2031 // options: The position dependent options at this point in the
ad2d6943 2032 // command line, such as --whole-archive.
ead1e424 2033 Input_file_argument()
ae3b5189 2034 : name_(), type_(INPUT_FILE_TYPE_FILE), extra_search_path_(""),
cdc29364 2035 just_symbols_(false), options_(), arg_serial_(0)
ead1e424
ILT
2036 { }
2037
2ea97941 2038 Input_file_argument(const char* name, Input_file_type type,
0c6e6c39
RM
2039 const char* extra_search_path,
2040 bool just_symbols,
2041 const Position_dependent_options& options)
2ea97941 2042 : name_(name), type_(type), extra_search_path_(extra_search_path),
cdc29364 2043 just_symbols_(just_symbols), options_(options), arg_serial_(0)
ee1fe73e
ILT
2044 { }
2045
2046 // You can also pass in a General_options instance instead of a
2047 // Position_dependent_options. In that case, we extract the
2048 // position-independent vars from the General_options and only store
2049 // those.
2ea97941 2050 Input_file_argument(const char* name, Input_file_type type,
0c6e6c39
RM
2051 const char* extra_search_path,
2052 bool just_symbols,
2053 const General_options& options)
2ea97941 2054 : name_(name), type_(type), extra_search_path_(extra_search_path),
cdc29364 2055 just_symbols_(just_symbols), options_(options), arg_serial_(0)
bae7f79e
ILT
2056 { }
2057
2058 const char*
2059 name() const
dbe717ef 2060 { return this->name_.c_str(); }
bae7f79e
ILT
2061
2062 const Position_dependent_options&
2063 options() const
2064 { return this->options_; }
2065
2066 bool
2067 is_lib() const
ae3b5189
CD
2068 { return type_ == INPUT_FILE_TYPE_LIBRARY; }
2069
2070 bool
2071 is_searched_file() const
2072 { return type_ == INPUT_FILE_TYPE_SEARCHED_FILE; }
bae7f79e 2073
51dee2fe
ILT
2074 const char*
2075 extra_search_path() const
2076 {
2077 return (this->extra_search_path_.empty()
0c6e6c39
RM
2078 ? NULL
2079 : this->extra_search_path_.c_str());
51dee2fe
ILT
2080 }
2081
88dd47ac
ILT
2082 // Return whether we should only read symbols from this file.
2083 bool
2084 just_symbols() const
2085 { return this->just_symbols_; }
2086
51dee2fe
ILT
2087 // Return whether this file may require a search using the -L
2088 // options.
2089 bool
2090 may_need_search() const
ae3b5189
CD
2091 {
2092 return (this->is_lib()
2093 || this->is_searched_file()
2094 || !this->extra_search_path_.empty());
2095 }
51dee2fe 2096
cdc29364
CC
2097 // Set the serial number for this argument.
2098 void
2099 set_arg_serial(unsigned int arg_serial)
2100 { this->arg_serial_ = arg_serial; }
2101
2102 // Get the serial number.
2103 unsigned int
2104 arg_serial() const
2105 { return this->arg_serial_; }
2106
bae7f79e 2107 private:
dbe717ef
ILT
2108 // We use std::string, not const char*, here for convenience when
2109 // using script files, so that we do not have to preserve the string
2110 // in that case.
2111 std::string name_;
ae3b5189 2112 Input_file_type type_;
51dee2fe 2113 std::string extra_search_path_;
88dd47ac 2114 bool just_symbols_;
bae7f79e 2115 Position_dependent_options options_;
cdc29364
CC
2116 // A unique index for this file argument in the argument list.
2117 unsigned int arg_serial_;
bae7f79e
ILT
2118};
2119
ead1e424
ILT
2120// A file or library, or a group, from the command line.
2121
2122class Input_argument
2123{
2124 public:
2125 // Create a file or library argument.
2ea97941 2126 explicit Input_argument(Input_file_argument file)
c7975edd 2127 : is_file_(true), file_(file), group_(NULL), lib_(NULL), script_info_(NULL)
ead1e424
ILT
2128 { }
2129
2130 // Create a group argument.
2ea97941 2131 explicit Input_argument(Input_file_group* group)
c7975edd 2132 : is_file_(false), group_(group), lib_(NULL), script_info_(NULL)
b0193076
RÁE
2133 { }
2134
2135 // Create a lib argument.
2136 explicit Input_argument(Input_file_lib* lib)
c7975edd 2137 : is_file_(false), group_(NULL), lib_(lib), script_info_(NULL)
ead1e424
ILT
2138 { }
2139
2140 // Return whether this is a file.
2141 bool
2142 is_file() const
2143 { return this->is_file_; }
2144
2145 // Return whether this is a group.
2146 bool
2147 is_group() const
b0193076
RÁE
2148 { return !this->is_file_ && this->lib_ == NULL; }
2149
2150 // Return whether this is a lib.
2151 bool
2152 is_lib() const
2153 { return this->lib_ != NULL; }
ead1e424
ILT
2154
2155 // Return the information about the file.
2156 const Input_file_argument&
2157 file() const
2158 {
a3ad94ed 2159 gold_assert(this->is_file_);
ead1e424
ILT
2160 return this->file_;
2161 }
2162
2163 // Return the information about the group.
2164 const Input_file_group*
2165 group() const
2166 {
a3ad94ed 2167 gold_assert(!this->is_file_);
ead1e424
ILT
2168 return this->group_;
2169 }
2170
2171 Input_file_group*
2172 group()
2173 {
a3ad94ed 2174 gold_assert(!this->is_file_);
ead1e424
ILT
2175 return this->group_;
2176 }
2177
b0193076
RÁE
2178 // Return the information about the lib.
2179 const Input_file_lib*
2180 lib() const
2181 {
2182 gold_assert(!this->is_file_);
2183 gold_assert(this->lib_);
2184 return this->lib_;
2185 }
2186
2187 Input_file_lib*
2188 lib()
2189 {
2190 gold_assert(!this->is_file_);
2191 gold_assert(this->lib_);
2192 return this->lib_;
2193 }
2194
c7975edd
CC
2195 // If a script generated this argument, store a pointer to the script info.
2196 // Currently used only for recording incremental link information.
2197 void
2198 set_script_info(Script_info* info)
2199 { this->script_info_ = info; }
2200
2201 Script_info*
2202 script_info() const
2203 { return this->script_info_; }
2204
ead1e424
ILT
2205 private:
2206 bool is_file_;
2207 Input_file_argument file_;
2208 Input_file_group* group_;
b0193076 2209 Input_file_lib* lib_;
c7975edd 2210 Script_info* script_info_;
ead1e424
ILT
2211};
2212
072fe7ce
ILT
2213typedef std::vector<Input_argument> Input_argument_list;
2214
ead1e424
ILT
2215// A group from the command line. This is a set of arguments within
2216// --start-group ... --end-group.
2217
2218class Input_file_group
92e059d8 2219{
ead1e424 2220 public:
072fe7ce 2221 typedef Input_argument_list::const_iterator const_iterator;
ead1e424
ILT
2222
2223 Input_file_group()
2224 : files_()
2225 { }
2226
2227 // Add a file to the end of the group.
c7975edd 2228 Input_argument&
ead1e424 2229 add_file(const Input_file_argument& arg)
c7975edd
CC
2230 {
2231 this->files_.push_back(Input_argument(arg));
2232 return this->files_.back();
2233 }
ead1e424
ILT
2234
2235 // Iterators to iterate over the group contents.
2236
2237 const_iterator
2238 begin() const
2239 { return this->files_.begin(); }
2240
2241 const_iterator
2242 end() const
2243 { return this->files_.end(); }
2244
2245 private:
072fe7ce 2246 Input_argument_list files_;
92e059d8
ILT
2247};
2248
b0193076
RÁE
2249// A lib from the command line. This is a set of arguments within
2250// --start-lib ... --end-lib.
2251
2252class Input_file_lib
2253{
2254 public:
2255 typedef Input_argument_list::const_iterator const_iterator;
2256
2257 Input_file_lib(const Position_dependent_options& options)
2258 : files_(), options_(options)
2259 { }
2260
2261 // Add a file to the end of the lib.
c7975edd 2262 Input_argument&
b0193076 2263 add_file(const Input_file_argument& arg)
c7975edd
CC
2264 {
2265 this->files_.push_back(Input_argument(arg));
2266 return this->files_.back();
2267 }
b0193076
RÁE
2268
2269 const Position_dependent_options&
2270 options() const
2271 { return this->options_; }
2272
2273 // Iterators to iterate over the lib contents.
2274
2275 const_iterator
2276 begin() const
2277 { return this->files_.begin(); }
2278
2279 const_iterator
2280 end() const
2281 { return this->files_.end(); }
2282
2283 size_t
2284 size() const
2285 { return this->files_.size(); }
2286
2287 private:
2288 Input_argument_list files_;
2289 Position_dependent_options options_;
2290};
2291
dbe717ef
ILT
2292// A list of files from the command line or a script.
2293
2294class Input_arguments
2295{
2296 public:
dbe717ef
ILT
2297 typedef Input_argument_list::const_iterator const_iterator;
2298
2299 Input_arguments()
cdc29364 2300 : input_argument_list_(), in_group_(false), in_lib_(false), file_count_(0)
dbe717ef
ILT
2301 { }
2302
2303 // Add a file.
c7975edd 2304 Input_argument&
cdc29364 2305 add_file(Input_file_argument& arg);
dbe717ef
ILT
2306
2307 // Start a group (the --start-group option).
2308 void
2309 start_group();
2310
2311 // End a group (the --end-group option).
2312 void
2313 end_group();
2314
b0193076
RÁE
2315 // Start a lib (the --start-lib option).
2316 void
2317 start_lib(const Position_dependent_options&);
2318
2319 // End a lib (the --end-lib option).
2320 void
2321 end_lib();
2322
dbe717ef
ILT
2323 // Return whether we are currently in a group.
2324 bool
2325 in_group() const
2326 { return this->in_group_; }
2327
b0193076
RÁE
2328 // Return whether we are currently in a lib.
2329 bool
2330 in_lib() const
2331 { return this->in_lib_; }
2332
fe9a4c12
ILT
2333 // The number of entries in the list.
2334 int
2335 size() const
2336 { return this->input_argument_list_.size(); }
2337
dbe717ef
ILT
2338 // Iterators to iterate over the list of input files.
2339
2340 const_iterator
2341 begin() const
2342 { return this->input_argument_list_.begin(); }
2343
2344 const_iterator
2345 end() const
2346 { return this->input_argument_list_.end(); }
2347
2348 // Return whether the list is empty.
2349 bool
2350 empty() const
2351 { return this->input_argument_list_.empty(); }
2352
cdc29364
CC
2353 // Return the number of input files. This may be larger than
2354 // input_argument_list_.size(), because of files that are part
2355 // of groups or libs.
2356 int
2357 number_of_input_files() const
2358 { return this->file_count_; }
2359
dbe717ef
ILT
2360 private:
2361 Input_argument_list input_argument_list_;
2362 bool in_group_;
b0193076 2363 bool in_lib_;
cdc29364 2364 unsigned int file_count_;
dbe717ef
ILT
2365};
2366
ee1fe73e
ILT
2367
2368// All the information read from the command line. These are held in
2369// three separate structs: one to hold the options (--foo), one to
2370// hold the filenames listed on the commandline, and one to hold
2371// linker script information. This third is not a subset of the other
2372// two because linker scripts can be specified either as options (via
2373// -T) or as a file.
bae7f79e
ILT
2374
2375class Command_line
2376{
2377 public:
ead1e424
ILT
2378 typedef Input_arguments::const_iterator const_iterator;
2379
a5dc0706 2380 Command_line();
bae7f79e
ILT
2381
2382 // Process the command line options. This will exit with an
2383 // appropriate error message if an unrecognized option is seen.
2384 void
ee1fe73e 2385 process(int argc, const char** argv);
bae7f79e 2386
a0451b38 2387 // Process one command-line option. This takes the index of argv to
ee1fe73e
ILT
2388 // process, and returns the index for the next option. no_more_options
2389 // is set to true if argv[i] is "--".
61ba1cf9 2390 int
ee1fe73e 2391 process_one_option(int argc, const char** argv, int i,
0c6e6c39 2392 bool* no_more_options);
3c2fafa5 2393
61ba1cf9 2394 // Get the general options.
bae7f79e
ILT
2395 const General_options&
2396 options() const
2397 { return this->options_; }
2398
3c2fafa5
ILT
2399 // Get the position dependent options.
2400 const Position_dependent_options&
2401 position_dependent_options() const
2402 { return this->position_options_; }
2403
a5dc0706
ILT
2404 // Get the linker-script options.
2405 Script_options&
e5756efb 2406 script_options()
a5dc0706 2407 { return this->script_options_; }
e5756efb 2408
6affe781 2409 // Finalize the version-script options and return them.
a5dc0706 2410 const Version_script_info&
6affe781 2411 version_script();
e5756efb 2412
ee1fe73e
ILT
2413 // Get the input files.
2414 Input_arguments&
2415 inputs()
2416 { return this->inputs_; }
2417
fe9a4c12
ILT
2418 // The number of input files.
2419 int
2420 number_of_input_files() const
cdc29364 2421 { return this->inputs_.number_of_input_files(); }
fe9a4c12 2422
ead1e424
ILT
2423 // Iterators to iterate over the list of input files.
2424
2425 const_iterator
2426 begin() const
2427 { return this->inputs_.begin(); }
2428
2429 const_iterator
2430 end() const
2431 { return this->inputs_.end(); }
bae7f79e
ILT
2432
2433 private:
ead1e424
ILT
2434 Command_line(const Command_line&);
2435 Command_line& operator=(const Command_line&);
2436
293c1386
CC
2437 // This is a dummy class to provide a constructor that runs before
2438 // the constructor for the General_options. The Pre_options constructor
2439 // is used as a hook to set the flag enabling the options to register
2440 // themselves.
2441 struct Pre_options {
2442 Pre_options();
2443 };
2444
2445 // This must come before options_!
2446 Pre_options pre_options_;
bae7f79e
ILT
2447 General_options options_;
2448 Position_dependent_options position_options_;
a5dc0706 2449 Script_options script_options_;
ead1e424 2450 Input_arguments inputs_;
bae7f79e
ILT
2451};
2452
2453} // End namespace gold.
2454
2455#endif // !defined(GOLD_OPTIONS_H)