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