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