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