1 // options.h -- handle command line options for gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 // General_options (from Command_line::options())
24 // All the options (a.k.a. command-line flags)
25 // Input_argument (from Command_line::inputs())
26 // The list of input files, including -l options.
28 // Everything we get from the command line -- the General_options
29 // plus the Input_arguments.
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).
36 #ifndef GOLD_OPTIONS_H
37 #define GOLD_OPTIONS_H
53 class General_options
;
54 class Search_directory
;
55 class Input_file_group
;
57 class Position_dependent_options
;
62 // Incremental build action for a specific file, as selected by the user.
64 enum Incremental_disposition
66 // Determine the status from the timestamp (default).
68 // Assume the file changed from the previous build.
70 // Assume the file didn't change from the previous build.
74 // The nested namespace is to contain all the global variables and
75 // structs that need to be defined in the .h file, but do not need to
76 // be used outside this class.
79 typedef std::vector
<Search_directory
> Dir_list
;
80 typedef Unordered_set
<std::string
> String_set
;
82 // These routines convert from a string option to various types.
83 // Each gives a fatal error if it cannot parse the argument.
86 parse_bool(const char* option_name
, const char* arg
, bool* retval
);
89 parse_int(const char* option_name
, const char* arg
, int* retval
);
92 parse_uint(const char* option_name
, const char* arg
, int* retval
);
95 parse_uint64(const char* option_name
, const char* arg
, uint64_t* retval
);
98 parse_double(const char* option_name
, const char* arg
, double* retval
);
101 parse_percent(const char* option_name
, const char* arg
, double* retval
);
104 parse_string(const char* option_name
, const char* arg
, const char** retval
);
107 parse_optional_string(const char* option_name
, const char* arg
,
108 const char** retval
);
111 parse_dirlist(const char* option_name
, const char* arg
, Dir_list
* retval
);
114 parse_set(const char* option_name
, const char* arg
, String_set
* retval
);
117 parse_choices(const char* option_name
, const char* arg
, const char** retval
,
118 const char* choices
[], int num_choices
);
122 // Most options have both a shortname (one letter) and a longname.
123 // This enum controls how many dashes are expected for longname access
124 // -- shortnames always use one dash. Most longnames will accept
125 // either one dash or two; the only difference between ONE_DASH and
126 // TWO_DASHES is how we print the option in --help. However, some
127 // longnames require two dashes, and some require only one. The
128 // special value DASH_Z means that the option is preceded by "-z".
131 ONE_DASH
, TWO_DASHES
, EXACTLY_ONE_DASH
, EXACTLY_TWO_DASHES
, DASH_Z
134 // LONGNAME is the long-name of the option with dashes converted to
135 // underscores, or else the short-name if the option has no long-name.
136 // It is never the empty string.
137 // DASHES is an instance of the Dashes enum: ONE_DASH, TWO_DASHES, etc.
138 // SHORTNAME is the short-name of the option, as a char, or '\0' if the
139 // option has no short-name. If the option has no long-name, you
140 // should specify the short-name in *both* VARNAME and here.
141 // DEFAULT_VALUE is the value of the option if not specified on the
142 // commandline, as a string.
143 // HELPSTRING is the descriptive text used with the option via --help
144 // HELPARG is how you define the argument to the option.
145 // --help output is "-shortname HELPARG, --longname HELPARG: HELPSTRING"
146 // HELPARG should be NULL iff the option is a bool and takes no arg.
147 // OPTIONAL_ARG is true if this option takes an optional argument. An
148 // optional argument must be specifid as --OPTION=VALUE, not
150 // READER provides parse_to_value, which is a function that will convert
151 // a char* argument into the proper type and store it in some variable.
152 // A One_option struct initializes itself with the global list of options
153 // at constructor time, so be careful making one of these.
156 std::string longname
;
159 const char* default_value
;
160 const char* helpstring
;
165 One_option(const char* ln
, Dashes d
, char sn
, const char* dv
,
166 const char* hs
, const char* ha
, bool oa
, Struct_var
* r
)
167 : longname(ln
), dashes(d
), shortname(sn
), default_value(dv
? dv
: ""),
168 helpstring(hs
), helparg(ha
), optional_arg(oa
), reader(r
)
170 // In longname, we convert all underscores to dashes, since GNU
171 // style uses dashes in option names. longname is likely to have
172 // underscores in it because it's also used to declare a C++
174 const char* pos
= strchr(this->longname
.c_str(), '_');
175 for (; pos
; pos
= strchr(pos
, '_'))
176 this->longname
[pos
- this->longname
.c_str()] = '-';
178 // We only register ourselves if our helpstring is not NULL. This
179 // is to support the "no-VAR" boolean variables, which we
180 // conditionally turn on by defining "no-VAR" help text.
181 if (this->helpstring
)
182 this->register_option();
185 // This option takes an argument iff helparg is not NULL.
187 takes_argument() const
188 { return this->helparg
!= NULL
; }
190 // Whether the argument is optional.
192 takes_optional_argument() const
193 { return this->optional_arg
; }
195 // Register this option with the global list of options.
199 // Print this option to stdout (used with --help).
204 // All options have a Struct_##varname that inherits from this and
205 // actually implements parse_to_value for that option.
208 // OPTION: the name of the option as specified on the commandline,
209 // including leading dashes, and any text following the option:
210 // "-O", "--defsym=mysym=0x1000", etc.
211 // ARG: the arg associated with this option, or NULL if the option
212 // takes no argument: "2", "mysym=0x1000", etc.
213 // CMDLINE: the global Command_line object. Used by DEFINE_special.
214 // OPTIONS: the global General_options object. Used by DEFINE_special.
216 parse_to_value(const char* option
, const char* arg
,
217 Command_line
* cmdline
, General_options
* options
) = 0;
219 ~Struct_var() // To make gcc happy.
223 // This is for "special" options that aren't of any predefined type.
224 struct Struct_special
: public Struct_var
226 // If you change this, change the parse-fn in DEFINE_special as well.
227 typedef void (General_options::*Parse_function
)(const char*, const char*,
229 Struct_special(const char* varname
, Dashes dashes
, char shortname
,
230 Parse_function parse_function
,
231 const char* helpstring
, const char* helparg
)
232 : option(varname
, dashes
, shortname
, "", helpstring
, helparg
, false, this),
233 parse(parse_function
)
236 void parse_to_value(const char* option
, const char* arg
,
237 Command_line
* cmdline
, General_options
* options
)
238 { (options
->*(this->parse
))(option
, arg
, cmdline
); }
241 Parse_function parse
;
244 } // End namespace options.
247 // These are helper macros use by DEFINE_uint64/etc below.
248 // This macro is used inside the General_options_ class, so defines
249 // var() and set_var() as General_options methods. Arguments as are
250 // for the constructor for One_option. param_type__ is the same as
251 // type__ for built-in types, and "const type__ &" otherwise.
253 // When we define the linker command option "assert", the macro argument
254 // varname__ of DEFINE_var below will be replaced by "assert". On Mac OSX
255 // assert.h is included implicitly by one of the library headers we use. To
256 // avoid unintended macro substitution of "assert()", we need to enclose
257 // varname__ with parenthese.
258 #define DEFINE_var(varname__, dashes__, shortname__, default_value__, \
259 default_value_as_string__, helpstring__, helparg__, \
260 optional_arg__, type__, param_type__, parse_fn__) \
263 (varname__)() const \
264 { return this->varname__##_.value; } \
267 user_set_##varname__() const \
268 { return this->varname__##_.user_set_via_option; } \
271 set_user_set_##varname__() \
272 { this->varname__##_.user_set_via_option = true; } \
275 struct Struct_##varname__ : public options::Struct_var \
277 Struct_##varname__() \
278 : option(#varname__, dashes__, shortname__, default_value_as_string__, \
279 helpstring__, helparg__, optional_arg__, this), \
280 user_set_via_option(false), value(default_value__) \
284 parse_to_value(const char* option_name, const char* arg, \
285 Command_line*, General_options*) \
287 parse_fn__(option_name, arg, &this->value); \
288 this->user_set_via_option = true; \
291 options::One_option option; \
292 bool user_set_via_option; \
295 Struct_##varname__ varname__##_; \
297 set_##varname__(param_type__ value) \
298 { this->varname__##_.value = value; }
300 // These macros allow for easy addition of a new commandline option.
302 // If no_helpstring__ is not NULL, then in addition to creating
303 // VARNAME, we also create an option called no-VARNAME (or, for a -z
304 // option, noVARNAME).
305 #define DEFINE_bool(varname__, dashes__, shortname__, default_value__, \
306 helpstring__, no_helpstring__) \
307 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
308 default_value__ ? "true" : "false", helpstring__, NULL, \
309 false, bool, bool, options::parse_bool) \
310 struct Struct_no_##varname__ : public options::Struct_var \
312 Struct_no_##varname__() : option((dashes__ == options::DASH_Z \
314 : "no-" #varname__), \
316 default_value__ ? "false" : "true", \
317 no_helpstring__, NULL, false, this) \
321 parse_to_value(const char*, const char*, \
322 Command_line*, General_options* options) \
324 options->set_##varname__(false); \
325 options->set_user_set_##varname__(); \
328 options::One_option option; \
330 Struct_no_##varname__ no_##varname__##_initializer_
332 #define DEFINE_enable(varname__, dashes__, shortname__, default_value__, \
333 helpstring__, no_helpstring__) \
334 DEFINE_var(enable_##varname__, dashes__, shortname__, default_value__, \
335 default_value__ ? "true" : "false", helpstring__, NULL, \
336 false, bool, bool, options::parse_bool) \
337 struct Struct_disable_##varname__ : public options::Struct_var \
339 Struct_disable_##varname__() : option("disable-" #varname__, \
341 default_value__ ? "false" : "true", \
342 no_helpstring__, NULL, false, this) \
346 parse_to_value(const char*, const char*, \
347 Command_line*, General_options* options) \
348 { options->set_enable_##varname__(false); } \
350 options::One_option option; \
352 Struct_disable_##varname__ disable_##varname__##_initializer_
354 #define DEFINE_int(varname__, dashes__, shortname__, default_value__, \
355 helpstring__, helparg__) \
356 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
357 #default_value__, helpstring__, helparg__, false, \
358 int, int, options::parse_int)
360 #define DEFINE_uint(varname__, dashes__, shortname__, default_value__, \
361 helpstring__, helparg__) \
362 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
363 #default_value__, helpstring__, helparg__, false, \
364 int, int, options::parse_uint)
366 #define DEFINE_uint64(varname__, dashes__, shortname__, default_value__, \
367 helpstring__, helparg__) \
368 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
369 #default_value__, helpstring__, helparg__, false, \
370 uint64_t, uint64_t, options::parse_uint64)
372 #define DEFINE_double(varname__, dashes__, shortname__, default_value__, \
373 helpstring__, helparg__) \
374 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
375 #default_value__, helpstring__, helparg__, false, \
376 double, double, options::parse_double)
378 #define DEFINE_percent(varname__, dashes__, shortname__, default_value__, \
379 helpstring__, helparg__) \
380 DEFINE_var(varname__, dashes__, shortname__, default_value__ / 100.0, \
381 #default_value__, helpstring__, helparg__, false, \
382 double, double, options::parse_percent)
384 #define DEFINE_string(varname__, dashes__, shortname__, default_value__, \
385 helpstring__, helparg__) \
386 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
387 default_value__, helpstring__, helparg__, false, \
388 const char*, const char*, options::parse_string)
390 // This is like DEFINE_string, but we convert each occurrence to a
391 // Search_directory and store it in a vector. Thus we also have the
392 // add_to_VARNAME() method, to append to the vector.
393 #define DEFINE_dirlist(varname__, dashes__, shortname__, \
394 helpstring__, helparg__) \
395 DEFINE_var(varname__, dashes__, shortname__, , \
396 "", helpstring__, helparg__, false, options::Dir_list, \
397 const options::Dir_list&, options::parse_dirlist) \
399 add_to_##varname__(const char* new_value) \
400 { options::parse_dirlist(NULL, new_value, &this->varname__##_.value); } \
402 add_search_directory_to_##varname__(const Search_directory& dir) \
403 { this->varname__##_.value.push_back(dir); }
405 // This is like DEFINE_string, but we store a set of strings.
406 #define DEFINE_set(varname__, dashes__, shortname__, \
407 helpstring__, helparg__) \
408 DEFINE_var(varname__, dashes__, shortname__, , \
409 "", helpstring__, helparg__, false, options::String_set, \
410 const options::String_set&, options::parse_set) \
413 any_##varname__() const \
414 { return !this->varname__##_.value.empty(); } \
417 is_##varname__(const char* symbol) const \
419 return (!this->varname__##_.value.empty() \
420 && (this->varname__##_.value.find(std::string(symbol)) \
421 != this->varname__##_.value.end())); \
424 options::String_set::const_iterator \
425 varname__##_begin() const \
426 { return this->varname__##_.value.begin(); } \
428 options::String_set::const_iterator \
429 varname__##_end() const \
430 { return this->varname__##_.value.end(); }
432 // When you have a list of possible values (expressed as string)
433 // After helparg__ should come an initializer list, like
434 // {"foo", "bar", "baz"}
435 #define DEFINE_enum(varname__, dashes__, shortname__, default_value__, \
436 helpstring__, helparg__, ...) \
437 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
438 default_value__, helpstring__, helparg__, false, \
439 const char*, const char*, parse_choices_##varname__) \
441 static void parse_choices_##varname__(const char* option_name, \
443 const char** retval) { \
444 const char* choices[] = __VA_ARGS__; \
445 options::parse_choices(option_name, arg, retval, \
446 choices, sizeof(choices) / sizeof(*choices)); \
449 // This is like DEFINE_bool, but VARNAME is the name of a different
450 // option. This option becomes an alias for that one. INVERT is true
451 // if this option is an inversion of the other one.
452 #define DEFINE_bool_alias(option__, varname__, dashes__, shortname__, \
453 helpstring__, no_helpstring__, invert__) \
455 struct Struct_##option__ : public options::Struct_var \
457 Struct_##option__() \
458 : option(#option__, dashes__, shortname__, "", helpstring__, \
463 parse_to_value(const char*, const char*, \
464 Command_line*, General_options* options) \
466 options->set_##varname__(!invert__); \
467 options->set_user_set_##varname__(); \
470 options::One_option option; \
472 Struct_##option__ option__##_; \
474 struct Struct_no_##option__ : public options::Struct_var \
476 Struct_no_##option__() \
477 : option((dashes__ == options::DASH_Z \
479 : "no-" #option__), \
480 dashes__, '\0', "", no_helpstring__, \
485 parse_to_value(const char*, const char*, \
486 Command_line*, General_options* options) \
488 options->set_##varname__(invert__); \
489 options->set_user_set_##varname__(); \
492 options::One_option option; \
494 Struct_no_##option__ no_##option__##_initializer_
496 // This is used for non-standard flags. It defines no functions; it
497 // just calls General_options::parse_VARNAME whenever the flag is
498 // seen. We declare parse_VARNAME as a static member of
499 // General_options; you are responsible for defining it there.
500 // helparg__ should be NULL iff this special-option is a boolean.
501 #define DEFINE_special(varname__, dashes__, shortname__, \
502 helpstring__, helparg__) \
504 void parse_##varname__(const char* option, const char* arg, \
505 Command_line* inputs); \
506 struct Struct_##varname__ : public options::Struct_special \
508 Struct_##varname__() \
509 : options::Struct_special(#varname__, dashes__, shortname__, \
510 &General_options::parse_##varname__, \
511 helpstring__, helparg__) \
514 Struct_##varname__ varname__##_initializer_
516 // An option that takes an optional string argument. If the option is
517 // used with no argument, the value will be the default, and
518 // user_set_via_option will be true.
519 #define DEFINE_optional_string(varname__, dashes__, shortname__, \
521 helpstring__, helparg__) \
522 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
523 default_value__, helpstring__, helparg__, true, \
524 const char*, const char*, options::parse_optional_string)
526 // A directory to search. For each directory we record whether it is
527 // in the sysroot. We need to know this so that, if a linker script
528 // is found within the sysroot, we will apply the sysroot to any files
529 // named by that script.
531 class Search_directory
534 // We need a default constructor because we put this in a
537 : name_(NULL
), put_in_sysroot_(false), is_in_sysroot_(false)
540 // This is the usual constructor.
541 Search_directory(const char* name
, bool put_in_sysroot
)
542 : name_(name
), put_in_sysroot_(put_in_sysroot
), is_in_sysroot_(false)
544 if (this->name_
.empty())
548 // This is called if we have a sysroot. The sysroot is prefixed to
549 // any entries for which put_in_sysroot_ is true. is_in_sysroot_ is
550 // set to true for any enries which are in the sysroot (this will
551 // naturally include any entries for which put_in_sysroot_ is true).
552 // SYSROOT is the sysroot, CANONICAL_SYSROOT is the result of
553 // passing SYSROOT to lrealpath.
555 add_sysroot(const char* sysroot
, const char* canonical_sysroot
);
557 // Get the directory name.
560 { return this->name_
; }
562 // Return whether this directory is in the sysroot.
564 is_in_sysroot() const
565 { return this->is_in_sysroot_
; }
567 // Return whether this is considered a system directory.
569 is_system_directory() const
570 { return this->put_in_sysroot_
|| this->is_in_sysroot_
; }
573 // The directory name.
575 // True if the sysroot should be added as a prefix for this
576 // directory (if there is a sysroot). This is true for system
577 // directories that we search by default.
578 bool put_in_sysroot_
;
579 // True if this directory is in the sysroot (if there is a sysroot).
580 // This is true if there is a sysroot and either 1) put_in_sysroot_
581 // is true, or 2) the directory happens to be in the sysroot based
582 // on a pathname comparison.
586 class General_options
589 // NOTE: For every option that you add here, also consider if you
590 // should add it to Position_dependent_options.
591 DEFINE_special(help
, options::TWO_DASHES
, '\0',
592 N_("Report usage information"), NULL
);
593 DEFINE_special(version
, options::TWO_DASHES
, 'v',
594 N_("Report version information"), NULL
);
595 DEFINE_special(V
, options::EXACTLY_ONE_DASH
, '\0',
596 N_("Report version and target information"), NULL
);
598 // These options are sorted approximately so that for each letter in
599 // the alphabet, we show the option whose shortname is that letter
600 // (if any) and then every longname that starts with that letter (in
601 // alphabetical order). For both, lowercase sorts before uppercase.
602 // The -z options come last.
604 DEFINE_bool(add_needed
, options::TWO_DASHES
, '\0', false,
606 N_("Do not copy DT_NEEDED tags from shared libraries"));
608 DEFINE_bool_alias(allow_multiple_definition
, muldefs
, options::TWO_DASHES
,
609 '\0', N_("Allow multiple definitions of symbols"),
610 N_("Do not allow multiple definitions"), false);
612 DEFINE_bool(allow_shlib_undefined
, options::TWO_DASHES
, '\0', false,
613 N_("Allow unresolved references in shared libraries"),
614 N_("Do not allow unresolved references in shared libraries"));
616 DEFINE_bool(as_needed
, options::TWO_DASHES
, '\0', false,
617 N_("Only set DT_NEEDED for shared libraries if used"),
618 N_("Always DT_NEEDED for shared libraries"));
620 DEFINE_enum(assert, options::ONE_DASH
, '\0', NULL
,
621 N_("Ignored"), N_("[ignored]"),
622 {"definitions", "nodefinitions", "nosymbolic", "pure-text"});
624 // This should really be an "enum", but it's too easy for folks to
625 // forget to update the list as they add new targets. So we just
626 // accept any string. We'll fail later (when the string is parsed),
627 // if the target isn't actually supported.
628 DEFINE_string(format
, options::TWO_DASHES
, 'b', "elf",
629 N_("Set input format"), ("[elf,binary]"));
631 DEFINE_bool(Bdynamic
, options::ONE_DASH
, '\0', true,
632 N_("-l searches for shared libraries"), NULL
);
633 DEFINE_bool_alias(Bstatic
, Bdynamic
, options::ONE_DASH
, '\0',
634 N_("-l does not search for shared libraries"), NULL
,
636 DEFINE_bool_alias(dy
, Bdynamic
, options::ONE_DASH
, '\0',
637 N_("alias for -Bdynamic"), NULL
, false);
638 DEFINE_bool_alias(dn
, Bdynamic
, options::ONE_DASH
, '\0',
639 N_("alias for -Bstatic"), NULL
, true);
641 DEFINE_bool(Bsymbolic
, options::ONE_DASH
, '\0', false,
642 N_("Bind defined symbols locally"), NULL
);
644 DEFINE_bool(Bsymbolic_functions
, options::ONE_DASH
, '\0', false,
645 N_("Bind defined function symbols locally"), NULL
);
647 DEFINE_optional_string(build_id
, options::TWO_DASHES
, '\0', "sha1",
648 N_("Generate build ID note"),
651 DEFINE_bool(check_sections
, options::TWO_DASHES
, '\0', true,
652 N_("Check segment addresses for overlaps (default)"),
653 N_("Do not check segment addresses for overlaps"));
656 DEFINE_enum(compress_debug_sections
, options::TWO_DASHES
, '\0', "none",
657 N_("Compress .debug_* sections in the output file"),
661 DEFINE_enum(compress_debug_sections
, options::TWO_DASHES
, '\0', "none",
662 N_("Compress .debug_* sections in the output file"),
667 DEFINE_bool(copy_dt_needed_entries
, options::TWO_DASHES
, '\0', false,
669 N_("Do not copy DT_NEEDED tags from shared libraries"));
671 DEFINE_bool(cref
, options::TWO_DASHES
, '\0', false,
672 N_("Output cross reference table"),
673 N_("Do not output cross reference table"));
675 DEFINE_bool(ctors_in_init_array
, options::TWO_DASHES
, '\0', true,
676 N_("Use DT_INIT_ARRAY for all constructors (default)"),
677 N_("Handle constructors as directed by compiler"));
679 DEFINE_bool(define_common
, options::TWO_DASHES
, 'd', false,
680 N_("Define common symbols"),
681 N_("Do not define common symbols"));
682 DEFINE_bool(dc
, options::ONE_DASH
, '\0', false,
683 N_("Alias for -d"), NULL
);
684 DEFINE_bool(dp
, options::ONE_DASH
, '\0', false,
685 N_("Alias for -d"), NULL
);
687 DEFINE_string(debug
, options::TWO_DASHES
, '\0', "",
688 N_("Turn on debugging"),
689 N_("[all,files,script,task][,...]"));
691 DEFINE_special(defsym
, options::TWO_DASHES
, '\0',
692 N_("Define a symbol"), N_("SYMBOL=EXPRESSION"));
694 DEFINE_optional_string(demangle
, options::TWO_DASHES
, '\0', NULL
,
695 N_("Demangle C++ symbols in log messages"),
698 DEFINE_bool(no_demangle
, options::TWO_DASHES
, '\0', false,
699 N_("Do not demangle C++ symbols in log messages"),
702 DEFINE_bool(detect_odr_violations
, options::TWO_DASHES
, '\0', false,
703 N_("Look for violations of the C++ One Definition Rule"),
704 N_("Do not look for violations of the C++ One Definition Rule"));
706 DEFINE_bool(discard_all
, options::TWO_DASHES
, 'x', false,
707 N_("Delete all local symbols"), NULL
);
708 DEFINE_bool(discard_locals
, options::TWO_DASHES
, 'X', false,
709 N_("Delete all temporary local symbols"), NULL
);
711 DEFINE_bool(dynamic_list_data
, options::TWO_DASHES
, '\0', false,
712 N_("Add data symbols to dynamic symbols"), NULL
);
714 DEFINE_bool(dynamic_list_cpp_new
, options::TWO_DASHES
, '\0', false,
715 N_("Add C++ operator new/delete to dynamic symbols"), NULL
);
717 DEFINE_bool(dynamic_list_cpp_typeinfo
, options::TWO_DASHES
, '\0', false,
718 N_("Add C++ typeinfo to dynamic symbols"), NULL
);
720 DEFINE_special(dynamic_list
, options::TWO_DASHES
, '\0',
721 N_("Read a list of dynamic symbols"), N_("FILE"));
723 DEFINE_string(entry
, options::TWO_DASHES
, 'e', NULL
,
724 N_("Set program start address"), N_("ADDRESS"));
726 DEFINE_special(exclude_libs
, options::TWO_DASHES
, '\0',
727 N_("Exclude libraries from automatic export"),
728 N_(("lib,lib ...")));
730 DEFINE_bool(export_dynamic
, options::TWO_DASHES
, 'E', false,
731 N_("Export all dynamic symbols"),
732 N_("Do not export all dynamic symbols (default)"));
734 DEFINE_special(EB
, options::ONE_DASH
, '\0',
735 N_("Link big-endian objects."), NULL
);
737 DEFINE_bool(eh_frame_hdr
, options::TWO_DASHES
, '\0', false,
738 N_("Create exception frame header"), NULL
);
740 DEFINE_special(EL
, options::ONE_DASH
, '\0',
741 N_("Link little-endian objects."), NULL
);
743 DEFINE_bool(enum_size_warning
, options::TWO_DASHES
, '\0', true, NULL
,
744 N_("(ARM only) Do not warn about objects with incompatible "
747 DEFINE_set(auxiliary
, options::TWO_DASHES
, 'f',
748 N_("Auxiliary filter for shared object symbol table"),
751 DEFINE_string(filter
, options::TWO_DASHES
, 'F', NULL
,
752 N_("Filter for shared object symbol table"),
755 DEFINE_bool(fatal_warnings
, options::TWO_DASHES
, '\0', false,
756 N_("Treat warnings as errors"),
757 N_("Do not treat warnings as errors"));
759 DEFINE_string(fini
, options::ONE_DASH
, '\0', "_fini",
760 N_("Call SYMBOL at unload-time"), N_("SYMBOL"));
762 DEFINE_bool(fix_cortex_a8
, options::TWO_DASHES
, '\0', false,
763 N_("(ARM only) Fix binaries for Cortex-A8 erratum."),
764 N_("(ARM only) Do not fix binaries for Cortex-A8 erratum."));
766 DEFINE_bool(merge_exidx_entries
, options::TWO_DASHES
, '\0', true,
767 N_("(ARM only) Merge exidx entries in debuginfo."),
768 N_("(ARM only) Do not merge exidx entries in debuginfo."));
770 DEFINE_special(fix_v4bx
, options::TWO_DASHES
, '\0',
771 N_("(ARM only) Rewrite BX rn as MOV pc, rn for ARMv4"),
774 DEFINE_special(fix_v4bx_interworking
, options::TWO_DASHES
, '\0',
775 N_("(ARM only) Rewrite BX rn branch to ARMv4 interworking "
779 DEFINE_bool(g
, options::EXACTLY_ONE_DASH
, '\0', false,
780 N_("Ignored"), NULL
);
782 DEFINE_string(soname
, options::ONE_DASH
, 'h', NULL
,
783 N_("Set shared library name"), N_("FILENAME"));
785 DEFINE_double(hash_bucket_empty_fraction
, options::TWO_DASHES
, '\0', 0.0,
786 N_("Min fraction of empty buckets in dynamic hash"),
789 DEFINE_enum(hash_style
, options::TWO_DASHES
, '\0', "sysv",
790 N_("Dynamic hash style"), N_("[sysv,gnu,both]"),
791 {"sysv", "gnu", "both"});
793 DEFINE_string(dynamic_linker
, options::TWO_DASHES
, 'I', NULL
,
794 N_("Set dynamic linker path"), N_("PROGRAM"));
796 DEFINE_special(incremental
, options::TWO_DASHES
, '\0',
797 N_("Do an incremental link if possible; "
798 "otherwise, do a full link and prepare output "
799 "for incremental linking"), NULL
);
801 DEFINE_special(no_incremental
, options::TWO_DASHES
, '\0',
802 N_("Do a full link (default)"), NULL
);
804 DEFINE_special(incremental_full
, options::TWO_DASHES
, '\0',
805 N_("Do a full link and "
806 "prepare output for incremental linking"), NULL
);
808 DEFINE_special(incremental_update
, options::TWO_DASHES
, '\0',
809 N_("Do an incremental link; exit if not possible"), NULL
);
811 DEFINE_string(incremental_base
, options::TWO_DASHES
, '\0', NULL
,
812 N_("Set base file for incremental linking"
813 " (default is output file)"),
816 DEFINE_special(incremental_changed
, options::TWO_DASHES
, '\0',
817 N_("Assume files changed"), NULL
);
819 DEFINE_special(incremental_unchanged
, options::TWO_DASHES
, '\0',
820 N_("Assume files didn't change"), NULL
);
822 DEFINE_special(incremental_unknown
, options::TWO_DASHES
, '\0',
823 N_("Use timestamps to check files (default)"), NULL
);
825 DEFINE_percent(incremental_patch
, options::TWO_DASHES
, '\0', 10,
826 N_("Amount of extra space to allocate for patches"),
829 DEFINE_string(init
, options::ONE_DASH
, '\0', "_init",
830 N_("Call SYMBOL at load-time"), N_("SYMBOL"));
832 DEFINE_special(just_symbols
, options::TWO_DASHES
, '\0',
833 N_("Read only symbol values from FILE"), N_("FILE"));
835 DEFINE_bool(map_whole_files
, options::TWO_DASHES
, '\0',
837 N_("Map whole files to memory (default on 64-bit hosts)"),
838 N_("Map relevant file parts to memory (default on 32-bit "
840 DEFINE_bool(keep_files_mapped
, options::TWO_DASHES
, '\0', true,
841 N_("Keep files mapped across passes (default)"),
842 N_("Release mapped files after each pass"));
844 DEFINE_bool(ld_generated_unwind_info
, options::TWO_DASHES
, '\0', true,
845 N_("Generate unwind information for PLT (default)"),
846 N_("Do not generate unwind information for PLT"));
848 DEFINE_special(library
, options::TWO_DASHES
, 'l',
849 N_("Search for library LIBNAME"), N_("LIBNAME"));
851 DEFINE_dirlist(library_path
, options::TWO_DASHES
, 'L',
852 N_("Add directory to search path"), N_("DIR"));
854 DEFINE_bool(nostdlib
, options::ONE_DASH
, '\0', false,
855 N_(" Only search directories specified on the command line."),
858 DEFINE_bool(rosegment
, options::TWO_DASHES
, '\0', false,
859 N_(" Put read-only non-executable sections in their own segment"),
862 DEFINE_string(m
, options::EXACTLY_ONE_DASH
, 'm', "",
863 N_("Set GNU linker emulation; obsolete"), N_("EMULATION"));
865 DEFINE_bool(print_map
, options::TWO_DASHES
, 'M', false,
866 N_("Write map file on standard output"), NULL
);
867 DEFINE_string(Map
, options::ONE_DASH
, '\0', NULL
, N_("Write map file"),
870 DEFINE_bool(nmagic
, options::TWO_DASHES
, 'n', false,
871 N_("Do not page align data"), NULL
);
872 DEFINE_bool(omagic
, options::EXACTLY_TWO_DASHES
, 'N', false,
873 N_("Do not page align data, do not make text readonly"),
874 N_("Page align data, make text readonly"));
876 DEFINE_enable(new_dtags
, options::EXACTLY_TWO_DASHES
, '\0', false,
877 N_("Enable use of DT_RUNPATH and DT_FLAGS"),
878 N_("Disable use of DT_RUNPATH and DT_FLAGS"));
880 DEFINE_bool(noinhibit_exec
, options::TWO_DASHES
, '\0', false,
881 N_("Create an output file even if errors occur"), NULL
);
883 DEFINE_bool_alias(no_undefined
, defs
, options::TWO_DASHES
, '\0',
884 N_("Report undefined symbols (even with --shared)"),
887 DEFINE_string(output
, options::TWO_DASHES
, 'o', "a.out",
888 N_("Set output file name"), N_("FILE"));
890 DEFINE_uint(optimize
, options::EXACTLY_ONE_DASH
, 'O', 0,
891 N_("Optimize output file size"), N_("LEVEL"));
893 DEFINE_string(oformat
, options::EXACTLY_TWO_DASHES
, '\0', "elf",
894 N_("Set output format"), N_("[binary]"));
896 DEFINE_bool(p
, options::ONE_DASH
, '\0', false,
897 N_("(ARM only) Ignore for backward compatibility"), NULL
);
899 DEFINE_bool(pie
, options::ONE_DASH
, '\0', false,
900 N_("Create a position independent executable"), NULL
);
901 DEFINE_bool_alias(pic_executable
, pie
, options::TWO_DASHES
, '\0',
902 N_("Create a position independent executable"), NULL
,
905 DEFINE_bool(pipeline_knowledge
, options::ONE_DASH
, '\0', false,
906 NULL
, N_("(ARM only) Ignore for backward compatibility"));
908 #ifdef ENABLE_PLUGINS
909 DEFINE_special(plugin
, options::TWO_DASHES
, '\0',
910 N_("Load a plugin library"), N_("PLUGIN"));
911 DEFINE_special(plugin_opt
, options::TWO_DASHES
, '\0',
912 N_("Pass an option to the plugin"), N_("OPTION"));
915 DEFINE_bool(preread_archive_symbols
, options::TWO_DASHES
, '\0', false,
916 N_("Preread archive symbols when multi-threaded"), NULL
);
918 DEFINE_string(print_symbol_counts
, options::TWO_DASHES
, '\0', NULL
,
919 N_("Print symbols defined and used for each input"),
922 DEFINE_bool(Qy
, options::EXACTLY_ONE_DASH
, '\0', false,
923 N_("Ignored for SVR4 compatibility"), NULL
);
925 DEFINE_bool(emit_relocs
, options::TWO_DASHES
, 'q', false,
926 N_("Generate relocations in output"), NULL
);
928 DEFINE_bool(relocatable
, options::EXACTLY_ONE_DASH
, 'r', false,
929 N_("Generate relocatable output"), NULL
);
930 DEFINE_bool_alias(i
, relocatable
, options::EXACTLY_ONE_DASH
, '\0',
931 N_("Synonym for -r"), NULL
, false);
933 DEFINE_bool(relax
, options::TWO_DASHES
, '\0', false,
934 N_("Relax branches on certain targets"), NULL
);
936 DEFINE_string(retain_symbols_file
, options::TWO_DASHES
, '\0', NULL
,
937 N_("keep only symbols listed in this file"), N_("FILE"));
939 // -R really means -rpath, but can mean --just-symbols for
940 // compatibility with GNU ld. -rpath is always -rpath, so we list
942 DEFINE_special(R
, options::EXACTLY_ONE_DASH
, 'R',
943 N_("Add DIR to runtime search path"), N_("DIR"));
945 DEFINE_dirlist(rpath
, options::ONE_DASH
, '\0',
946 N_("Add DIR to runtime search path"), N_("DIR"));
948 DEFINE_dirlist(rpath_link
, options::TWO_DASHES
, '\0',
949 N_("Add DIR to link time shared library search path"),
952 DEFINE_string(section_ordering_file
, options::TWO_DASHES
, '\0', NULL
,
953 N_("Layout sections in the order specified."),
956 DEFINE_special(section_start
, options::TWO_DASHES
, '\0',
957 N_("Set address of section"), N_("SECTION=ADDRESS"));
959 DEFINE_optional_string(sort_common
, options::TWO_DASHES
, '\0', NULL
,
960 N_("Sort common symbols by alignment"),
961 N_("[={ascending,descending}]"));
963 DEFINE_uint(spare_dynamic_tags
, options::TWO_DASHES
, '\0', 5,
964 N_("Dynamic tag slots to reserve (default 5)"),
967 DEFINE_bool(strip_all
, options::TWO_DASHES
, 's', false,
968 N_("Strip all symbols"), NULL
);
969 DEFINE_bool(strip_debug
, options::TWO_DASHES
, 'S', false,
970 N_("Strip debugging information"), NULL
);
971 DEFINE_bool(strip_debug_non_line
, options::TWO_DASHES
, '\0', false,
972 N_("Emit only debug line number information"), NULL
);
973 DEFINE_bool(strip_debug_gdb
, options::TWO_DASHES
, '\0', false,
974 N_("Strip debug symbols that are unused by gdb "
975 "(at least versions <= 6.7)"), NULL
);
976 DEFINE_bool(strip_lto_sections
, options::TWO_DASHES
, '\0', true,
977 N_("Strip LTO intermediate code sections"), NULL
);
979 DEFINE_int(stub_group_size
, options::TWO_DASHES
, '\0', 1,
980 N_("(ARM only) The maximum distance from instructions in a group "
981 "of sections to their stubs. Negative values mean stubs "
982 "are always after the group. 1 means using default size.\n"),
985 DEFINE_bool(no_keep_memory
, options::TWO_DASHES
, '\0', false,
986 N_("Use less memory and more disk I/O "
987 "(included only for compatibility with GNU ld)"), NULL
);
989 DEFINE_bool(shared
, options::ONE_DASH
, 'G', false,
990 N_("Generate shared library"), NULL
);
992 DEFINE_bool(Bshareable
, options::ONE_DASH
, '\0', false,
993 N_("Generate shared library"), NULL
);
995 DEFINE_uint(split_stack_adjust_size
, options::TWO_DASHES
, '\0', 0x4000,
996 N_("Stack size when -fsplit-stack function calls non-split"),
999 // This is not actually special in any way, but I need to give it
1000 // a non-standard accessor-function name because 'static' is a keyword.
1001 DEFINE_special(static, options::ONE_DASH
, '\0',
1002 N_("Do not link against shared libraries"), NULL
);
1004 DEFINE_enum(icf
, options::TWO_DASHES
, '\0', "none",
1005 N_("Identical Code Folding. "
1006 "\'--icf=safe\' Folds ctors, dtors and functions whose"
1007 " pointers are definitely not taken."),
1008 ("[none,all,safe]"),
1009 {"none", "all", "safe"});
1011 DEFINE_uint(icf_iterations
, options::TWO_DASHES
, '\0', 0,
1012 N_("Number of iterations of ICF (default 2)"), N_("COUNT"));
1014 DEFINE_bool(print_icf_sections
, options::TWO_DASHES
, '\0', false,
1015 N_("List folded identical sections on stderr"),
1016 N_("Do not list folded identical sections"));
1018 DEFINE_set(keep_unique
, options::TWO_DASHES
, '\0',
1019 N_("Do not fold this symbol during ICF"), N_("SYMBOL"));
1021 DEFINE_bool(gc_sections
, options::TWO_DASHES
, '\0', false,
1022 N_("Remove unused sections"),
1023 N_("Don't remove unused sections (default)"));
1025 DEFINE_bool(print_gc_sections
, options::TWO_DASHES
, '\0', false,
1026 N_("List removed unused sections on stderr"),
1027 N_("Do not list removed unused sections"));
1029 DEFINE_bool(stats
, options::TWO_DASHES
, '\0', false,
1030 N_("Print resource usage statistics"), NULL
);
1032 DEFINE_string(sysroot
, options::TWO_DASHES
, '\0', "",
1033 N_("Set target system root directory"), N_("DIR"));
1035 DEFINE_bool(trace
, options::TWO_DASHES
, 't', false,
1036 N_("Print the name of each input file"), NULL
);
1038 DEFINE_special(script
, options::TWO_DASHES
, 'T',
1039 N_("Read linker script"), N_("FILE"));
1041 DEFINE_bool(threads
, options::TWO_DASHES
, '\0', false,
1042 N_("Run the linker multi-threaded"),
1043 N_("Do not run the linker multi-threaded"));
1044 DEFINE_uint(thread_count
, options::TWO_DASHES
, '\0', 0,
1045 N_("Number of threads to use"), N_("COUNT"));
1046 DEFINE_uint(thread_count_initial
, options::TWO_DASHES
, '\0', 0,
1047 N_("Number of threads to use in initial pass"), N_("COUNT"));
1048 DEFINE_uint(thread_count_middle
, options::TWO_DASHES
, '\0', 0,
1049 N_("Number of threads to use in middle pass"), N_("COUNT"));
1050 DEFINE_uint(thread_count_final
, options::TWO_DASHES
, '\0', 0,
1051 N_("Number of threads to use in final pass"), N_("COUNT"));
1053 DEFINE_uint64(Tbss
, options::ONE_DASH
, '\0', -1U,
1054 N_("Set the address of the bss segment"), N_("ADDRESS"));
1055 DEFINE_uint64(Tdata
, options::ONE_DASH
, '\0', -1U,
1056 N_("Set the address of the data segment"), N_("ADDRESS"));
1057 DEFINE_uint64(Ttext
, options::ONE_DASH
, '\0', -1U,
1058 N_("Set the address of the text segment"), N_("ADDRESS"));
1060 DEFINE_set(undefined
, options::TWO_DASHES
, 'u',
1061 N_("Create undefined reference to SYMBOL"), N_("SYMBOL"));
1063 DEFINE_bool(verbose
, options::TWO_DASHES
, '\0', false,
1064 N_("Synonym for --debug=files"), NULL
);
1066 DEFINE_special(version_script
, options::TWO_DASHES
, '\0',
1067 N_("Read version script"), N_("FILE"));
1069 DEFINE_bool(warn_common
, options::TWO_DASHES
, '\0', false,
1070 N_("Warn about duplicate common symbols"),
1071 N_("Do not warn about duplicate common symbols (default)"));
1073 DEFINE_bool(warn_constructors
, options::TWO_DASHES
, '\0', false,
1074 N_("Ignored"), N_("Ignored"));
1076 DEFINE_bool(warn_execstack
, options::TWO_DASHES
, '\0', false,
1077 N_("Warn if the stack is executable"),
1078 N_("Do not warn if the stack is executable (default)"));
1080 DEFINE_bool(warn_mismatch
, options::TWO_DASHES
, '\0', true,
1081 NULL
, N_("Don't warn about mismatched input files"));
1083 DEFINE_bool(warn_multiple_gp
, options::TWO_DASHES
, '\0', false,
1084 N_("Ignored"), NULL
);
1086 DEFINE_bool(warn_search_mismatch
, options::TWO_DASHES
, '\0', true,
1087 N_("Warn when skipping an incompatible library"),
1088 N_("Don't warn when skipping an incompatible library"));
1090 DEFINE_bool(warn_shared_textrel
, options::TWO_DASHES
, '\0', false,
1091 N_("Warn if text segment is not shareable"),
1092 N_("Do not warn if text segment is not shareable (default)"));
1094 DEFINE_bool(warn_unresolved_symbols
, options::TWO_DASHES
, '\0', false,
1095 N_("Report unresolved symbols as warnings"),
1097 DEFINE_bool_alias(error_unresolved_symbols
, warn_unresolved_symbols
,
1098 options::TWO_DASHES
, '\0',
1099 N_("Report unresolved symbols as errors"),
1102 DEFINE_bool(wchar_size_warning
, options::TWO_DASHES
, '\0', true, NULL
,
1103 N_("(ARM only) Do not warn about objects with incompatible "
1106 DEFINE_bool(whole_archive
, options::TWO_DASHES
, '\0', false,
1107 N_("Include all archive contents"),
1108 N_("Include only needed archive contents"));
1110 DEFINE_set(wrap
, options::TWO_DASHES
, '\0',
1111 N_("Use wrapper functions for SYMBOL"), N_("SYMBOL"));
1113 DEFINE_set(trace_symbol
, options::TWO_DASHES
, 'y',
1114 N_("Trace references to symbol"), N_("SYMBOL"));
1116 DEFINE_bool(undefined_version
, options::TWO_DASHES
, '\0', true,
1117 N_("Allow unused version in script (default)"),
1118 N_("Do not allow unused version in script"));
1120 DEFINE_string(Y
, options::EXACTLY_ONE_DASH
, 'Y', "",
1121 N_("Default search path for Solaris compatibility"),
1124 DEFINE_special(start_group
, options::TWO_DASHES
, '(',
1125 N_("Start a library search group"), NULL
);
1126 DEFINE_special(end_group
, options::TWO_DASHES
, ')',
1127 N_("End a library search group"), NULL
);
1130 DEFINE_special(start_lib
, options::TWO_DASHES
, '\0',
1131 N_("Start a library"), NULL
);
1132 DEFINE_special(end_lib
, options::TWO_DASHES
, '\0',
1133 N_("End a library "), NULL
);
1137 DEFINE_bool(combreloc
, options::DASH_Z
, '\0', true,
1138 N_("Sort dynamic relocs"),
1139 N_("Do not sort dynamic relocs"));
1140 DEFINE_uint64(common_page_size
, options::DASH_Z
, '\0', 0,
1141 N_("Set common page size to SIZE"), N_("SIZE"));
1142 DEFINE_bool(defs
, options::DASH_Z
, '\0', false,
1143 N_("Report undefined symbols (even with --shared)"),
1145 DEFINE_bool(execstack
, options::DASH_Z
, '\0', false,
1146 N_("Mark output as requiring executable stack"), NULL
);
1147 DEFINE_bool(initfirst
, options::DASH_Z
, '\0', false,
1148 N_("Mark DSO to be initialized first at runtime"),
1150 DEFINE_bool(interpose
, options::DASH_Z
, '\0', false,
1151 N_("Mark object to interpose all DSOs but executable"),
1153 DEFINE_bool_alias(lazy
, now
, options::DASH_Z
, '\0',
1154 N_("Mark object for lazy runtime binding (default)"),
1156 DEFINE_bool(loadfltr
, options::DASH_Z
, '\0', false,
1157 N_("Mark object requiring immediate process"),
1159 DEFINE_uint64(max_page_size
, options::DASH_Z
, '\0', 0,
1160 N_("Set maximum page size to SIZE"), N_("SIZE"));
1161 DEFINE_bool(muldefs
, options::DASH_Z
, '\0', false,
1162 N_("Allow multiple definitions of symbols"),
1164 // copyreloc is here in the list because there is only -z
1165 // nocopyreloc, not -z copyreloc.
1166 DEFINE_bool(copyreloc
, options::DASH_Z
, '\0', true,
1168 N_("Do not create copy relocs"));
1169 DEFINE_bool(nodefaultlib
, options::DASH_Z
, '\0', false,
1170 N_("Mark object not to use default search paths"),
1172 DEFINE_bool(nodelete
, options::DASH_Z
, '\0', false,
1173 N_("Mark DSO non-deletable at runtime"),
1175 DEFINE_bool(nodlopen
, options::DASH_Z
, '\0', false,
1176 N_("Mark DSO not available to dlopen"),
1178 DEFINE_bool(nodump
, options::DASH_Z
, '\0', false,
1179 N_("Mark DSO not available to dldump"),
1181 DEFINE_bool(noexecstack
, options::DASH_Z
, '\0', false,
1182 N_("Mark output as not requiring executable stack"), NULL
);
1183 DEFINE_bool(now
, options::DASH_Z
, '\0', false,
1184 N_("Mark object for immediate function binding"),
1186 DEFINE_bool(origin
, options::DASH_Z
, '\0', false,
1187 N_("Mark DSO to indicate that needs immediate $ORIGIN "
1188 "processing at runtime"), NULL
);
1189 DEFINE_bool(relro
, options::DASH_Z
, '\0', false,
1190 N_("Where possible mark variables read-only after relocation"),
1191 N_("Don't mark variables read-only after relocation"));
1192 DEFINE_bool(text
, options::DASH_Z
, '\0', false,
1193 N_("Do not permit relocations in read-only segments"),
1194 N_("Permit relocations in read-only segments (default)"));
1195 DEFINE_bool_alias(textoff
, text
, options::DASH_Z
, '\0',
1196 N_("Permit relocations in read-only segments (default)"),
1200 typedef options::Dir_list Dir_list
;
1204 // Does post-processing on flags, making sure they all have
1205 // non-conflicting values. Also converts some flags from their
1206 // "standard" types (string, etc), to another type (enum, DirList),
1207 // which can be accessed via a separate method. Dies if it notices
1211 // True if we printed the version information.
1213 printed_version() const
1214 { return this->printed_version_
; }
1216 // The macro defines output() (based on --output), but that's a
1217 // generic name. Provide this alternative name, which is clearer.
1219 output_file_name() const
1220 { return this->output(); }
1222 // This is not defined via a flag, but combines flags to say whether
1223 // the output is position-independent or not.
1225 output_is_position_independent() const
1226 { return this->shared() || this->pie(); }
1228 // Return true if the output is something that can be exec()ed, such
1229 // as a static executable, or a position-dependent or
1230 // position-independent executable, but not a dynamic library or an
1233 output_is_executable() const
1234 { return !this->shared() && !this->relocatable(); }
1236 // This would normally be static(), and defined automatically, but
1237 // since static is a keyword, we need to come up with our own name.
1242 // In addition to getting the input and output formats as a string
1243 // (via format() and oformat()), we also give access as an enum.
1248 // Straight binary format.
1249 OBJECT_FORMAT_BINARY
1252 // Convert a string to an Object_format. Gives an error if the
1253 // string is not recognized.
1254 static Object_format
1255 string_to_object_format(const char* arg
);
1257 // Note: these functions are not very fast.
1258 Object_format
format_enum() const;
1259 Object_format
oformat_enum() const;
1261 // Return whether FILENAME is in a system directory.
1263 is_in_system_directory(const std::string
& name
) const;
1265 // RETURN whether SYMBOL_NAME should be kept, according to symbols_to_retain_.
1267 should_retain_symbol(const char* symbol_name
) const
1269 if (symbols_to_retain_
.empty()) // means flag wasn't specified
1271 return symbols_to_retain_
.find(symbol_name
) != symbols_to_retain_
.end();
1274 // These are the best way to get access to the execstack state,
1275 // not execstack() and noexecstack() which are hard to use properly.
1277 is_execstack_set() const
1278 { return this->execstack_status_
!= EXECSTACK_FROM_INPUT
; }
1281 is_stack_executable() const
1282 { return this->execstack_status_
== EXECSTACK_YES
; }
1286 { return this->icf_status_
!= ICF_NONE
; }
1289 icf_safe_folding() const
1290 { return this->icf_status_
== ICF_SAFE
; }
1292 // The --demangle option takes an optional string, and there is also
1293 // a --no-demangle option. This is the best way to decide whether
1294 // to demangle or not.
1297 { return this->do_demangle_
; }
1299 // Returns TRUE if any plugin libraries have been loaded.
1302 { return this->plugins_
!= NULL
; }
1304 // Return a pointer to the plugin manager.
1307 { return this->plugins_
; }
1309 // True iff SYMBOL was found in the file specified by dynamic-list.
1311 in_dynamic_list(const char* symbol
) const
1312 { return this->dynamic_list_
.version_script_info()->symbol_is_local(symbol
); }
1314 // Finalize the dynamic list.
1316 finalize_dynamic_list()
1317 { this->dynamic_list_
.version_script_info()->finalize(); }
1319 // The mode selected by the --incremental options.
1320 enum Incremental_mode
1322 // No incremental linking (--no-incremental).
1324 // Incremental update only (--incremental-update).
1326 // Force a full link, but prepare for subsequent incremental link
1327 // (--incremental-full).
1329 // Incremental update if possible, fallback to full link (--incremental).
1333 // The incremental linking mode.
1335 incremental_mode() const
1336 { return this->incremental_mode_
; }
1338 // The disposition given by the --incremental-changed,
1339 // --incremental-unchanged or --incremental-unknown option. The
1340 // value may change as we proceed parsing the command line flags.
1341 Incremental_disposition
1342 incremental_disposition() const
1343 { return this->incremental_disposition_
; }
1345 // Return true if S is the name of a library excluded from automatic
1348 check_excluded_libs(const std::string
&s
) const;
1350 // If an explicit start address was given for section SECNAME with
1351 // the --section-start option, return true and set *PADDR to the
1352 // address. Otherwise return false.
1354 section_start(const char* secname
, uint64_t* paddr
) const;
1358 // Leave original instruction.
1360 // Replace instruction.
1362 // Generate an interworking veneer.
1363 FIX_V4BX_INTERWORKING
1368 { return (this->fix_v4bx_
); }
1379 { return this->endianness_
; }
1382 // Don't copy this structure.
1383 General_options(const General_options
&);
1384 General_options
& operator=(const General_options
&);
1386 // Whether to mark the stack as executable.
1389 // Not set on command line.
1390 EXECSTACK_FROM_INPUT
,
1391 // Mark the stack as executable (-z execstack).
1393 // Mark the stack as not executable (-z noexecstack).
1399 // Do not fold any functions (Default or --icf=none).
1401 // All functions are candidates for folding. (--icf=all).
1403 // Only ctors and dtors are candidates for folding. (--icf=safe).
1408 set_icf_status(Icf_status value
)
1409 { this->icf_status_
= value
; }
1412 set_execstack_status(Execstack value
)
1413 { this->execstack_status_
= value
; }
1416 set_do_demangle(bool value
)
1417 { this->do_demangle_
= value
; }
1420 set_static(bool value
)
1421 { static_
= value
; }
1423 // These are called by finalize() to set up the search-path correctly.
1425 add_to_library_path_with_sysroot(const char* arg
)
1426 { this->add_search_directory_to_library_path(Search_directory(arg
, true)); }
1428 // Apply any sysroot to the directory lists.
1432 // Add a plugin and its arguments to the list of plugins.
1434 add_plugin(const char* filename
);
1436 // Add a plugin option.
1438 add_plugin_option(const char* opt
);
1440 // Whether we printed version information.
1441 bool printed_version_
;
1442 // Whether to mark the stack as executable.
1443 Execstack execstack_status_
;
1444 // Whether to do code folding.
1445 Icf_status icf_status_
;
1446 // Whether to do a static link.
1448 // Whether to do demangling.
1450 // List of plugin libraries.
1451 Plugin_manager
* plugins_
;
1452 // The parsed output of --dynamic-list files. For convenience in
1453 // script.cc, we store this as a Script_options object, even though
1454 // we only use a single Version_tree from it.
1455 Script_options dynamic_list_
;
1456 // The incremental linking mode.
1457 Incremental_mode incremental_mode_
;
1458 // The disposition given by the --incremental-changed,
1459 // --incremental-unchanged or --incremental-unknown option. The
1460 // value may change as we proceed parsing the command line flags.
1461 Incremental_disposition incremental_disposition_
;
1462 // Whether we have seen one of the options that require incremental
1463 // build (--incremental-changed, --incremental-unchanged or
1464 // --incremental-unknown)
1465 bool implicit_incremental_
;
1466 // Libraries excluded from automatic export, via --exclude-libs.
1467 Unordered_set
<std::string
> excluded_libs_
;
1468 // List of symbol-names to keep, via -retain-symbol-info.
1469 Unordered_set
<std::string
> symbols_to_retain_
;
1470 // Map from section name to address from --section-start.
1471 std::map
<std::string
, uint64_t> section_starts_
;
1472 // Whether to process armv4 bx instruction relocation.
1475 Endianness endianness_
;
1478 // The position-dependent options. We use this to store the state of
1479 // the commandline at a particular point in parsing for later
1480 // reference. For instance, if we see "ld --whole-archive foo.a
1481 // --no-whole-archive," we want to store the whole-archive option with
1482 // foo.a, so when the time comes to parse foo.a we know we should do
1483 // it in whole-archive mode. We could store all of General_options,
1484 // but that's big, so we just pick the subset of flags that actually
1485 // change in a position-dependent way.
1487 #define DEFINE_posdep(varname__, type__) \
1491 { return this->varname__##_; } \
1494 set_##varname__(type__ value) \
1495 { this->varname__##_ = value; } \
1499 class Position_dependent_options
1502 Position_dependent_options(const General_options
& options
1503 = Position_dependent_options::default_options_
)
1504 { copy_from_options(options
); }
1506 void copy_from_options(const General_options
& options
)
1508 this->set_as_needed(options
.as_needed());
1509 this->set_Bdynamic(options
.Bdynamic());
1510 this->set_format_enum(options
.format_enum());
1511 this->set_whole_archive(options
.whole_archive());
1512 this->set_incremental_disposition(options
.incremental_disposition());
1515 DEFINE_posdep(as_needed
, bool);
1516 DEFINE_posdep(Bdynamic
, bool);
1517 DEFINE_posdep(format_enum
, General_options::Object_format
);
1518 DEFINE_posdep(whole_archive
, bool);
1519 DEFINE_posdep(incremental_disposition
, Incremental_disposition
);
1522 // This is a General_options with everything set to its default
1523 // value. A Position_dependent_options created with no argument
1524 // will take its values from here.
1525 static General_options default_options_
;
1529 // A single file or library argument from the command line.
1531 class Input_file_argument
1534 enum Input_file_type
1536 // A regular file, name used as-is, not searched.
1537 INPUT_FILE_TYPE_FILE
,
1538 // A library name. When used, "lib" will be prepended and ".so" or
1539 // ".a" appended to make a filename, and that filename will be searched
1540 // for using the -L paths.
1541 INPUT_FILE_TYPE_LIBRARY
,
1542 // A regular file, name used as-is, but searched using the -L paths.
1543 INPUT_FILE_TYPE_SEARCHED_FILE
1546 // name: file name or library name
1547 // type: the type of this input file.
1548 // extra_search_path: an extra directory to look for the file, prior
1549 // to checking the normal library search path. If this is "",
1550 // then no extra directory is added.
1551 // just_symbols: whether this file only defines symbols.
1552 // options: The position dependent options at this point in the
1553 // command line, such as --whole-archive.
1554 Input_file_argument()
1555 : name_(), type_(INPUT_FILE_TYPE_FILE
), extra_search_path_(""),
1556 just_symbols_(false), options_(), arg_serial_(0)
1559 Input_file_argument(const char* name
, Input_file_type type
,
1560 const char* extra_search_path
,
1562 const Position_dependent_options
& options
)
1563 : name_(name
), type_(type
), extra_search_path_(extra_search_path
),
1564 just_symbols_(just_symbols
), options_(options
), arg_serial_(0)
1567 // You can also pass in a General_options instance instead of a
1568 // Position_dependent_options. In that case, we extract the
1569 // position-independent vars from the General_options and only store
1571 Input_file_argument(const char* name
, Input_file_type type
,
1572 const char* extra_search_path
,
1574 const General_options
& options
)
1575 : name_(name
), type_(type
), extra_search_path_(extra_search_path
),
1576 just_symbols_(just_symbols
), options_(options
), arg_serial_(0)
1581 { return this->name_
.c_str(); }
1583 const Position_dependent_options
&
1585 { return this->options_
; }
1589 { return type_
== INPUT_FILE_TYPE_LIBRARY
; }
1592 is_searched_file() const
1593 { return type_
== INPUT_FILE_TYPE_SEARCHED_FILE
; }
1596 extra_search_path() const
1598 return (this->extra_search_path_
.empty()
1600 : this->extra_search_path_
.c_str());
1603 // Return whether we should only read symbols from this file.
1605 just_symbols() const
1606 { return this->just_symbols_
; }
1608 // Return whether this file may require a search using the -L
1611 may_need_search() const
1613 return (this->is_lib()
1614 || this->is_searched_file()
1615 || !this->extra_search_path_
.empty());
1618 // Set the serial number for this argument.
1620 set_arg_serial(unsigned int arg_serial
)
1621 { this->arg_serial_
= arg_serial
; }
1623 // Get the serial number.
1626 { return this->arg_serial_
; }
1629 // We use std::string, not const char*, here for convenience when
1630 // using script files, so that we do not have to preserve the string
1633 Input_file_type type_
;
1634 std::string extra_search_path_
;
1636 Position_dependent_options options_
;
1637 // A unique index for this file argument in the argument list.
1638 unsigned int arg_serial_
;
1641 // A file or library, or a group, from the command line.
1643 class Input_argument
1646 // Create a file or library argument.
1647 explicit Input_argument(Input_file_argument file
)
1648 : is_file_(true), file_(file
), group_(NULL
), lib_(NULL
), script_info_(NULL
)
1651 // Create a group argument.
1652 explicit Input_argument(Input_file_group
* group
)
1653 : is_file_(false), group_(group
), lib_(NULL
), script_info_(NULL
)
1656 // Create a lib argument.
1657 explicit Input_argument(Input_file_lib
* lib
)
1658 : is_file_(false), group_(NULL
), lib_(lib
), script_info_(NULL
)
1661 // Return whether this is a file.
1664 { return this->is_file_
; }
1666 // Return whether this is a group.
1669 { return !this->is_file_
&& this->lib_
== NULL
; }
1671 // Return whether this is a lib.
1674 { return this->lib_
!= NULL
; }
1676 // Return the information about the file.
1677 const Input_file_argument
&
1680 gold_assert(this->is_file_
);
1684 // Return the information about the group.
1685 const Input_file_group
*
1688 gold_assert(!this->is_file_
);
1689 return this->group_
;
1695 gold_assert(!this->is_file_
);
1696 return this->group_
;
1699 // Return the information about the lib.
1700 const Input_file_lib
*
1703 gold_assert(!this->is_file_
);
1704 gold_assert(this->lib_
);
1711 gold_assert(!this->is_file_
);
1712 gold_assert(this->lib_
);
1716 // If a script generated this argument, store a pointer to the script info.
1717 // Currently used only for recording incremental link information.
1719 set_script_info(Script_info
* info
)
1720 { this->script_info_
= info
; }
1724 { return this->script_info_
; }
1728 Input_file_argument file_
;
1729 Input_file_group
* group_
;
1730 Input_file_lib
* lib_
;
1731 Script_info
* script_info_
;
1734 typedef std::vector
<Input_argument
> Input_argument_list
;
1736 // A group from the command line. This is a set of arguments within
1737 // --start-group ... --end-group.
1739 class Input_file_group
1742 typedef Input_argument_list::const_iterator const_iterator
;
1748 // Add a file to the end of the group.
1750 add_file(const Input_file_argument
& arg
)
1752 this->files_
.push_back(Input_argument(arg
));
1753 return this->files_
.back();
1756 // Iterators to iterate over the group contents.
1760 { return this->files_
.begin(); }
1764 { return this->files_
.end(); }
1767 Input_argument_list files_
;
1770 // A lib from the command line. This is a set of arguments within
1771 // --start-lib ... --end-lib.
1773 class Input_file_lib
1776 typedef Input_argument_list::const_iterator const_iterator
;
1778 Input_file_lib(const Position_dependent_options
& options
)
1779 : files_(), options_(options
)
1782 // Add a file to the end of the lib.
1784 add_file(const Input_file_argument
& arg
)
1786 this->files_
.push_back(Input_argument(arg
));
1787 return this->files_
.back();
1790 const Position_dependent_options
&
1792 { return this->options_
; }
1794 // Iterators to iterate over the lib contents.
1798 { return this->files_
.begin(); }
1802 { return this->files_
.end(); }
1806 { return this->files_
.size(); }
1809 Input_argument_list files_
;
1810 Position_dependent_options options_
;
1813 // A list of files from the command line or a script.
1815 class Input_arguments
1818 typedef Input_argument_list::const_iterator const_iterator
;
1821 : input_argument_list_(), in_group_(false), in_lib_(false), file_count_(0)
1826 add_file(Input_file_argument
& arg
);
1828 // Start a group (the --start-group option).
1832 // End a group (the --end-group option).
1836 // Start a lib (the --start-lib option).
1838 start_lib(const Position_dependent_options
&);
1840 // End a lib (the --end-lib option).
1844 // Return whether we are currently in a group.
1847 { return this->in_group_
; }
1849 // Return whether we are currently in a lib.
1852 { return this->in_lib_
; }
1854 // The number of entries in the list.
1857 { return this->input_argument_list_
.size(); }
1859 // Iterators to iterate over the list of input files.
1863 { return this->input_argument_list_
.begin(); }
1867 { return this->input_argument_list_
.end(); }
1869 // Return whether the list is empty.
1872 { return this->input_argument_list_
.empty(); }
1874 // Return the number of input files. This may be larger than
1875 // input_argument_list_.size(), because of files that are part
1876 // of groups or libs.
1878 number_of_input_files() const
1879 { return this->file_count_
; }
1882 Input_argument_list input_argument_list_
;
1885 unsigned int file_count_
;
1889 // All the information read from the command line. These are held in
1890 // three separate structs: one to hold the options (--foo), one to
1891 // hold the filenames listed on the commandline, and one to hold
1892 // linker script information. This third is not a subset of the other
1893 // two because linker scripts can be specified either as options (via
1894 // -T) or as a file.
1899 typedef Input_arguments::const_iterator const_iterator
;
1903 // Process the command line options. This will exit with an
1904 // appropriate error message if an unrecognized option is seen.
1906 process(int argc
, const char** argv
);
1908 // Process one command-line option. This takes the index of argv to
1909 // process, and returns the index for the next option. no_more_options
1910 // is set to true if argv[i] is "--".
1912 process_one_option(int argc
, const char** argv
, int i
,
1913 bool* no_more_options
);
1915 // Get the general options.
1916 const General_options
&
1918 { return this->options_
; }
1920 // Get the position dependent options.
1921 const Position_dependent_options
&
1922 position_dependent_options() const
1923 { return this->position_options_
; }
1925 // Get the linker-script options.
1928 { return this->script_options_
; }
1930 // Finalize the version-script options and return them.
1931 const Version_script_info
&
1934 // Get the input files.
1937 { return this->inputs_
; }
1939 // The number of input files.
1941 number_of_input_files() const
1942 { return this->inputs_
.number_of_input_files(); }
1944 // Iterators to iterate over the list of input files.
1948 { return this->inputs_
.begin(); }
1952 { return this->inputs_
.end(); }
1955 Command_line(const Command_line
&);
1956 Command_line
& operator=(const Command_line
&);
1958 // This is a dummy class to provide a constructor that runs before
1959 // the constructor for the General_options. The Pre_options constructor
1960 // is used as a hook to set the flag enabling the options to register
1962 struct Pre_options
{
1966 // This must come before options_!
1967 Pre_options pre_options_
;
1968 General_options options_
;
1969 Position_dependent_options position_options_
;
1970 Script_options script_options_
;
1971 Input_arguments inputs_
;
1974 } // End namespace gold.
1976 #endif // !defined(GOLD_OPTIONS_H)