1 // options.h -- handle command line options for gold -*- C++ -*-
3 // Copyright (C) 2006-2017 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 // Startup files that appear before the first disposition option.
67 // These will default to INCREMENTAL_CHECK unless the
68 // --incremental-startup-unchanged option is given.
69 // (For files added implicitly by gcc before any user options.)
71 // Determine the status from the timestamp (default).
73 // Assume the file changed from the previous build.
75 // Assume the file didn't change from the previous build.
79 // The nested namespace is to contain all the global variables and
80 // structs that need to be defined in the .h file, but do not need to
81 // be used outside this class.
84 typedef std::vector
<Search_directory
> Dir_list
;
85 typedef Unordered_set
<std::string
> String_set
;
87 // These routines convert from a string option to various types.
88 // Each gives a fatal error if it cannot parse the argument.
91 parse_bool(const char* option_name
, const char* arg
, bool* retval
);
94 parse_int(const char* option_name
, const char* arg
, int* retval
);
97 parse_uint(const char* option_name
, const char* arg
, int* retval
);
100 parse_uint64(const char* option_name
, const char* arg
, uint64_t* retval
);
103 parse_double(const char* option_name
, const char* arg
, double* retval
);
106 parse_percent(const char* option_name
, const char* arg
, double* retval
);
109 parse_string(const char* option_name
, const char* arg
, const char** retval
);
112 parse_optional_string(const char* option_name
, const char* arg
,
113 const char** retval
);
116 parse_dirlist(const char* option_name
, const char* arg
, Dir_list
* retval
);
119 parse_set(const char* option_name
, const char* arg
, String_set
* retval
);
122 parse_choices(const char* option_name
, const char* arg
, const char** retval
,
123 const char* choices
[], int num_choices
);
127 // Most options have both a shortname (one letter) and a longname.
128 // This enum controls how many dashes are expected for longname access
129 // -- shortnames always use one dash. Most longnames will accept
130 // either one dash or two; the only difference between ONE_DASH and
131 // TWO_DASHES is how we print the option in --help. However, some
132 // longnames require two dashes, and some require only one. The
133 // special value DASH_Z means that the option is preceded by "-z".
136 ONE_DASH
, TWO_DASHES
, EXACTLY_ONE_DASH
, EXACTLY_TWO_DASHES
, DASH_Z
139 // LONGNAME is the long-name of the option with dashes converted to
140 // underscores, or else the short-name if the option has no long-name.
141 // It is never the empty string.
142 // DASHES is an instance of the Dashes enum: ONE_DASH, TWO_DASHES, etc.
143 // SHORTNAME is the short-name of the option, as a char, or '\0' if the
144 // option has no short-name. If the option has no long-name, you
145 // should specify the short-name in *both* VARNAME and here.
146 // DEFAULT_VALUE is the value of the option if not specified on the
147 // commandline, as a string.
148 // HELPSTRING is the descriptive text used with the option via --help
149 // HELPARG is how you define the argument to the option.
150 // --help output is "-shortname HELPARG, --longname HELPARG: HELPSTRING"
151 // HELPARG should be NULL iff the option is a bool and takes no arg.
152 // OPTIONAL_ARG is true if this option takes an optional argument. An
153 // optional argument must be specifid as --OPTION=VALUE, not
155 // READER provides parse_to_value, which is a function that will convert
156 // a char* argument into the proper type and store it in some variable.
157 // IS_DEFAULT is true for boolean options that are on by default,
158 // and thus should have "(default)" printed with the helpstring.
159 // A One_option struct initializes itself with the global list of options
160 // at constructor time, so be careful making one of these.
163 std::string longname
;
166 const char* default_value
;
167 const char* helpstring
;
173 One_option(const char* ln
, Dashes d
, char sn
, const char* dv
,
174 const char* hs
, const char* ha
, bool oa
, Struct_var
* r
,
176 : longname(ln
), dashes(d
), shortname(sn
), default_value(dv
? dv
: ""),
177 helpstring(hs
), helparg(ha
), optional_arg(oa
), reader(r
),
180 // In longname, we convert all underscores to dashes, since GNU
181 // style uses dashes in option names. longname is likely to have
182 // underscores in it because it's also used to declare a C++
184 const char* pos
= strchr(this->longname
.c_str(), '_');
185 for (; pos
; pos
= strchr(pos
, '_'))
186 this->longname
[pos
- this->longname
.c_str()] = '-';
188 // We only register ourselves if our helpstring is not NULL. This
189 // is to support the "no-VAR" boolean variables, which we
190 // conditionally turn on by defining "no-VAR" help text.
191 if (this->helpstring
)
192 this->register_option();
195 // This option takes an argument iff helparg is not NULL.
197 takes_argument() const
198 { return this->helparg
!= NULL
; }
200 // Whether the argument is optional.
202 takes_optional_argument() const
203 { return this->optional_arg
; }
205 // Register this option with the global list of options.
209 // Print this option to stdout (used with --help).
214 // All options have a Struct_##varname that inherits from this and
215 // actually implements parse_to_value for that option.
218 // OPTION: the name of the option as specified on the commandline,
219 // including leading dashes, and any text following the option:
220 // "-O", "--defsym=mysym=0x1000", etc.
221 // ARG: the arg associated with this option, or NULL if the option
222 // takes no argument: "2", "mysym=0x1000", etc.
223 // CMDLINE: the global Command_line object. Used by DEFINE_special.
224 // OPTIONS: the global General_options object. Used by DEFINE_special.
226 parse_to_value(const char* option
, const char* arg
,
227 Command_line
* cmdline
, General_options
* options
) = 0;
229 ~Struct_var() // To make gcc happy.
233 // This is for "special" options that aren't of any predefined type.
234 struct Struct_special
: public Struct_var
236 // If you change this, change the parse-fn in DEFINE_special as well.
237 typedef void (General_options::*Parse_function
)(const char*, const char*,
239 Struct_special(const char* varname
, Dashes dashes
, char shortname
,
240 Parse_function parse_function
,
241 const char* helpstring
, const char* helparg
)
242 : option(varname
, dashes
, shortname
, "", helpstring
, helparg
, false, this,
244 parse(parse_function
)
247 void parse_to_value(const char* option
, const char* arg
,
248 Command_line
* cmdline
, General_options
* options
)
249 { (options
->*(this->parse
))(option
, arg
, cmdline
); }
252 Parse_function parse
;
255 } // End namespace options.
258 // These are helper macros use by DEFINE_uint64/etc below.
259 // This macro is used inside the General_options_ class, so defines
260 // var() and set_var() as General_options methods. Arguments as are
261 // for the constructor for One_option. param_type__ is the same as
262 // type__ for built-in types, and "const type__ &" otherwise.
264 // When we define the linker command option "assert", the macro argument
265 // varname__ of DEFINE_var below will be replaced by "assert". On Mac OSX
266 // assert.h is included implicitly by one of the library headers we use. To
267 // avoid unintended macro substitution of "assert()", we need to enclose
268 // varname__ with parenthese.
269 #define DEFINE_var(varname__, dashes__, shortname__, default_value__, \
270 default_value_as_string__, helpstring__, helparg__, \
271 optional_arg__, type__, param_type__, parse_fn__, \
275 (varname__)() const \
276 { return this->varname__##_.value; } \
279 user_set_##varname__() const \
280 { return this->varname__##_.user_set_via_option; } \
283 set_user_set_##varname__() \
284 { this->varname__##_.user_set_via_option = true; } \
286 static const bool varname__##is_default = is_default__; \
289 struct Struct_##varname__ : public options::Struct_var \
291 Struct_##varname__() \
292 : option(#varname__, dashes__, shortname__, default_value_as_string__, \
293 helpstring__, helparg__, optional_arg__, this, is_default__), \
294 user_set_via_option(false), value(default_value__) \
298 parse_to_value(const char* option_name, const char* arg, \
299 Command_line*, General_options*) \
301 parse_fn__(option_name, arg, &this->value); \
302 this->user_set_via_option = true; \
305 options::One_option option; \
306 bool user_set_via_option; \
309 Struct_##varname__ varname__##_; \
311 set_##varname__(param_type__ value) \
312 { this->varname__##_.value = value; }
314 // These macros allow for easy addition of a new commandline option.
316 // If no_helpstring__ is not NULL, then in addition to creating
317 // VARNAME, we also create an option called no-VARNAME (or, for a -z
318 // option, noVARNAME).
319 #define DEFINE_bool(varname__, dashes__, shortname__, default_value__, \
320 helpstring__, no_helpstring__) \
321 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
322 default_value__ ? "true" : "false", helpstring__, NULL, \
323 false, bool, bool, options::parse_bool, default_value__) \
324 struct Struct_no_##varname__ : public options::Struct_var \
326 Struct_no_##varname__() : option((dashes__ == options::DASH_Z \
328 : "no-" #varname__), \
330 default_value__ ? "false" : "true", \
331 no_helpstring__, NULL, false, this, \
332 !(default_value__)) \
336 parse_to_value(const char*, const char*, \
337 Command_line*, General_options* options) \
339 options->set_##varname__(false); \
340 options->set_user_set_##varname__(); \
343 options::One_option option; \
345 Struct_no_##varname__ no_##varname__##_initializer_
347 #define DEFINE_bool_ignore(varname__, dashes__, shortname__, \
348 helpstring__, no_helpstring__) \
349 DEFINE_var(varname__, dashes__, shortname__, false, \
350 "false", helpstring__, NULL, \
351 false, bool, bool, options::parse_bool, false) \
352 struct Struct_no_##varname__ : public options::Struct_var \
354 Struct_no_##varname__() : option((dashes__ == options::DASH_Z \
356 : "no-" #varname__), \
359 no_helpstring__, NULL, false, this, \
364 parse_to_value(const char*, const char*, \
365 Command_line*, General_options* options) \
367 options->set_##varname__(false); \
368 options->set_user_set_##varname__(); \
371 options::One_option option; \
373 Struct_no_##varname__ no_##varname__##_initializer_
375 #define DEFINE_enable(varname__, dashes__, shortname__, default_value__, \
376 helpstring__, no_helpstring__) \
377 DEFINE_var(enable_##varname__, dashes__, shortname__, default_value__, \
378 default_value__ ? "true" : "false", helpstring__, NULL, \
379 false, bool, bool, options::parse_bool, default_value__) \
380 struct Struct_disable_##varname__ : public options::Struct_var \
382 Struct_disable_##varname__() : option("disable-" #varname__, \
384 default_value__ ? "false" : "true", \
385 no_helpstring__, NULL, false, this, \
390 parse_to_value(const char*, const char*, \
391 Command_line*, General_options* options) \
392 { options->set_enable_##varname__(false); } \
394 options::One_option option; \
396 Struct_disable_##varname__ disable_##varname__##_initializer_
398 #define DEFINE_int(varname__, dashes__, shortname__, default_value__, \
399 helpstring__, helparg__) \
400 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
401 #default_value__, helpstring__, helparg__, false, \
402 int, int, options::parse_int, false)
404 #define DEFINE_uint(varname__, dashes__, shortname__, default_value__, \
405 helpstring__, helparg__) \
406 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
407 #default_value__, helpstring__, helparg__, false, \
408 int, int, options::parse_uint, false)
410 #define DEFINE_uint64(varname__, dashes__, shortname__, default_value__, \
411 helpstring__, helparg__) \
412 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
413 #default_value__, helpstring__, helparg__, false, \
414 uint64_t, uint64_t, options::parse_uint64, false)
416 #define DEFINE_double(varname__, dashes__, shortname__, default_value__, \
417 helpstring__, helparg__) \
418 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
419 #default_value__, helpstring__, helparg__, false, \
420 double, double, options::parse_double, false)
422 #define DEFINE_percent(varname__, dashes__, shortname__, default_value__, \
423 helpstring__, helparg__) \
424 DEFINE_var(varname__, dashes__, shortname__, default_value__ / 100.0, \
425 #default_value__, helpstring__, helparg__, false, \
426 double, double, options::parse_percent, false)
428 #define DEFINE_string(varname__, dashes__, shortname__, default_value__, \
429 helpstring__, helparg__) \
430 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
431 default_value__, helpstring__, helparg__, false, \
432 const char*, const char*, options::parse_string, false)
434 // This is like DEFINE_string, but we convert each occurrence to a
435 // Search_directory and store it in a vector. Thus we also have the
436 // add_to_VARNAME() method, to append to the vector.
437 #define DEFINE_dirlist(varname__, dashes__, shortname__, \
438 helpstring__, helparg__) \
439 DEFINE_var(varname__, dashes__, shortname__, , \
440 "", helpstring__, helparg__, false, options::Dir_list, \
441 const options::Dir_list&, options::parse_dirlist, false) \
443 add_to_##varname__(const char* new_value) \
444 { options::parse_dirlist(NULL, new_value, &this->varname__##_.value); } \
446 add_search_directory_to_##varname__(const Search_directory& dir) \
447 { this->varname__##_.value.push_back(dir); }
449 // This is like DEFINE_string, but we store a set of strings.
450 #define DEFINE_set(varname__, dashes__, shortname__, \
451 helpstring__, helparg__) \
452 DEFINE_var(varname__, dashes__, shortname__, , \
453 "", helpstring__, helparg__, false, options::String_set, \
454 const options::String_set&, options::parse_set, false) \
457 any_##varname__() const \
458 { return !this->varname__##_.value.empty(); } \
461 is_##varname__(const char* symbol) const \
463 return (!this->varname__##_.value.empty() \
464 && (this->varname__##_.value.find(std::string(symbol)) \
465 != this->varname__##_.value.end())); \
468 options::String_set::const_iterator \
469 varname__##_begin() const \
470 { return this->varname__##_.value.begin(); } \
472 options::String_set::const_iterator \
473 varname__##_end() const \
474 { return this->varname__##_.value.end(); }
476 // When you have a list of possible values (expressed as string)
477 // After helparg__ should come an initializer list, like
478 // {"foo", "bar", "baz"}
479 #define DEFINE_enum(varname__, dashes__, shortname__, default_value__, \
480 helpstring__, helparg__, ...) \
481 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
482 default_value__, helpstring__, helparg__, false, \
483 const char*, const char*, parse_choices_##varname__, false) \
485 static void parse_choices_##varname__(const char* option_name, \
487 const char** retval) { \
488 const char* choices[] = __VA_ARGS__; \
489 options::parse_choices(option_name, arg, retval, \
490 choices, sizeof(choices) / sizeof(*choices)); \
493 // This is like DEFINE_bool, but VARNAME is the name of a different
494 // option. This option becomes an alias for that one. INVERT is true
495 // if this option is an inversion of the other one.
496 #define DEFINE_bool_alias(option__, varname__, dashes__, shortname__, \
497 helpstring__, no_helpstring__, invert__) \
499 struct Struct_##option__ : public options::Struct_var \
501 Struct_##option__() \
502 : option(#option__, dashes__, shortname__, "", helpstring__, \
504 General_options::varname__##is_default ^ invert__) \
508 parse_to_value(const char*, const char*, \
509 Command_line*, General_options* options) \
511 options->set_##varname__(!invert__); \
512 options->set_user_set_##varname__(); \
515 options::One_option option; \
517 Struct_##option__ option__##_; \
519 struct Struct_no_##option__ : public options::Struct_var \
521 Struct_no_##option__() \
522 : option((dashes__ == options::DASH_Z \
524 : "no-" #option__), \
525 dashes__, '\0', "", no_helpstring__, \
527 !General_options::varname__##is_default ^ invert__) \
531 parse_to_value(const char*, const char*, \
532 Command_line*, General_options* options) \
534 options->set_##varname__(invert__); \
535 options->set_user_set_##varname__(); \
538 options::One_option option; \
540 Struct_no_##option__ no_##option__##_initializer_
542 // This is like DEFINE_uint64, but VARNAME is the name of a different
543 // option. This option becomes an alias for that one.
544 #define DEFINE_uint64_alias(option__, varname__, dashes__, shortname__, \
545 helpstring__, helparg__) \
547 struct Struct_##option__ : public options::Struct_var \
549 Struct_##option__() \
550 : option(#option__, dashes__, shortname__, "", helpstring__, \
551 helparg__, false, this, false) \
555 parse_to_value(const char* option_name, const char* arg, \
556 Command_line*, General_options* options) \
559 options::parse_uint64(option_name, arg, &value); \
560 options->set_##varname__(value); \
561 options->set_user_set_##varname__(); \
564 options::One_option option; \
566 Struct_##option__ option__##_;
568 // This is used for non-standard flags. It defines no functions; it
569 // just calls General_options::parse_VARNAME whenever the flag is
570 // seen. We declare parse_VARNAME as a static member of
571 // General_options; you are responsible for defining it there.
572 // helparg__ should be NULL iff this special-option is a boolean.
573 #define DEFINE_special(varname__, dashes__, shortname__, \
574 helpstring__, helparg__) \
576 void parse_##varname__(const char* option, const char* arg, \
577 Command_line* inputs); \
578 struct Struct_##varname__ : public options::Struct_special \
580 Struct_##varname__() \
581 : options::Struct_special(#varname__, dashes__, shortname__, \
582 &General_options::parse_##varname__, \
583 helpstring__, helparg__) \
586 Struct_##varname__ varname__##_initializer_
588 // An option that takes an optional string argument. If the option is
589 // used with no argument, the value will be the default, and
590 // user_set_via_option will be true.
591 #define DEFINE_optional_string(varname__, dashes__, shortname__, \
593 helpstring__, helparg__) \
594 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
595 default_value__, helpstring__, helparg__, true, \
596 const char*, const char*, options::parse_optional_string, \
599 // A directory to search. For each directory we record whether it is
600 // in the sysroot. We need to know this so that, if a linker script
601 // is found within the sysroot, we will apply the sysroot to any files
602 // named by that script.
604 class Search_directory
607 // We need a default constructor because we put this in a
610 : name_(NULL
), put_in_sysroot_(false), is_in_sysroot_(false)
613 // This is the usual constructor.
614 Search_directory(const std::string
& name
, bool put_in_sysroot
)
615 : name_(name
), put_in_sysroot_(put_in_sysroot
), is_in_sysroot_(false)
617 if (this->name_
.empty())
621 // This is called if we have a sysroot. The sysroot is prefixed to
622 // any entries for which put_in_sysroot_ is true. is_in_sysroot_ is
623 // set to true for any enries which are in the sysroot (this will
624 // naturally include any entries for which put_in_sysroot_ is true).
625 // SYSROOT is the sysroot, CANONICAL_SYSROOT is the result of
626 // passing SYSROOT to lrealpath.
628 add_sysroot(const char* sysroot
, const char* canonical_sysroot
);
630 // Get the directory name.
633 { return this->name_
; }
635 // Return whether this directory is in the sysroot.
637 is_in_sysroot() const
638 { return this->is_in_sysroot_
; }
640 // Return whether this is considered a system directory.
642 is_system_directory() const
643 { return this->put_in_sysroot_
|| this->is_in_sysroot_
; }
646 // The directory name.
648 // True if the sysroot should be added as a prefix for this
649 // directory (if there is a sysroot). This is true for system
650 // directories that we search by default.
651 bool put_in_sysroot_
;
652 // True if this directory is in the sysroot (if there is a sysroot).
653 // This is true if there is a sysroot and either 1) put_in_sysroot_
654 // is true, or 2) the directory happens to be in the sysroot based
655 // on a pathname comparison.
659 class General_options
662 // NOTE: For every option that you add here, also consider if you
663 // should add it to Position_dependent_options.
664 DEFINE_special(help
, options::TWO_DASHES
, '\0',
665 N_("Report usage information"), NULL
);
666 DEFINE_special(version
, options::TWO_DASHES
, 'v',
667 N_("Report version information"), NULL
);
668 DEFINE_special(V
, options::EXACTLY_ONE_DASH
, '\0',
669 N_("Report version and target information"), NULL
);
671 // These options are sorted approximately so that for each letter in
672 // the alphabet, we show the option whose shortname is that letter
673 // (if any) and then every longname that starts with that letter (in
674 // alphabetical order). For both, lowercase sorts before uppercase.
675 // The -z options come last.
679 DEFINE_bool(add_needed
, options::TWO_DASHES
, '\0', false,
681 N_("Do not copy DT_NEEDED tags from shared libraries"));
683 DEFINE_bool_alias(allow_multiple_definition
, muldefs
, options::TWO_DASHES
,
685 N_("Allow multiple definitions of symbols"),
686 N_("Do not allow multiple definitions"), false);
688 DEFINE_bool(allow_shlib_undefined
, options::TWO_DASHES
, '\0', false,
689 N_("Allow unresolved references in shared libraries"),
690 N_("Do not allow unresolved references in shared libraries"));
692 DEFINE_bool(apply_dynamic_relocs
, options::TWO_DASHES
, '\0', true,
693 N_("Apply link-time values for dynamic relocations"),
694 N_("(aarch64 only) Do not apply link-time values "
695 "for dynamic relocations"));
697 DEFINE_bool(as_needed
, options::TWO_DASHES
, '\0', false,
698 N_("Use DT_NEEDED only for shared libraries that are used"),
699 N_("Use DT_NEEDED for all shared libraries"));
701 DEFINE_enum(assert, options::ONE_DASH
, '\0', NULL
,
702 N_("Ignored"), N_("[ignored]"),
703 {"definitions", "nodefinitions", "nosymbolic", "pure-text"});
707 // This should really be an "enum", but it's too easy for folks to
708 // forget to update the list as they add new targets. So we just
709 // accept any string. We'll fail later (when the string is parsed),
710 // if the target isn't actually supported.
711 DEFINE_string(format
, options::TWO_DASHES
, 'b', "elf",
712 N_("Set input format"), ("[elf,binary]"));
714 DEFINE_bool(be8
,options::TWO_DASHES
, '\0', false,
715 N_("Output BE8 format image"), NULL
);
717 DEFINE_optional_string(build_id
, options::TWO_DASHES
, '\0', "tree",
718 N_("Generate build ID note"),
721 DEFINE_uint64(build_id_chunk_size_for_treehash
,
722 options::TWO_DASHES
, '\0', 2 << 20,
723 N_("Chunk size for '--build-id=tree'"), N_("SIZE"));
725 DEFINE_uint64(build_id_min_file_size_for_treehash
, options::TWO_DASHES
,
727 N_("Minimum output file size for '--build-id=tree' to work"
728 " differently than '--build-id=sha1'"), N_("SIZE"));
730 DEFINE_bool(Bdynamic
, options::ONE_DASH
, '\0', true,
731 N_("-l searches for shared libraries"), NULL
);
732 DEFINE_bool_alias(Bstatic
, Bdynamic
, options::ONE_DASH
, '\0',
733 N_("-l does not search for shared libraries"), NULL
,
735 DEFINE_bool_alias(dy
, Bdynamic
, options::ONE_DASH
, '\0',
736 N_("alias for -Bdynamic"), NULL
, false);
737 DEFINE_bool_alias(dn
, Bdynamic
, options::ONE_DASH
, '\0',
738 N_("alias for -Bstatic"), NULL
, true);
740 DEFINE_bool(Bgroup
, options::ONE_DASH
, '\0', false,
741 N_("Use group name lookup rules for shared library"), NULL
);
743 DEFINE_bool(Bshareable
, options::ONE_DASH
, '\0', false,
744 N_("Generate shared library (alias for -G/-shared)"), NULL
);
746 DEFINE_bool(Bsymbolic
, options::ONE_DASH
, '\0', false,
747 N_("Bind defined symbols locally"), NULL
);
749 DEFINE_bool(Bsymbolic_functions
, options::ONE_DASH
, '\0', false,
750 N_("Bind defined function symbols locally"), NULL
);
754 DEFINE_bool(check_sections
, options::TWO_DASHES
, '\0', true,
755 N_("Check segment addresses for overlaps"),
756 N_("Do not check segment addresses for overlaps"));
758 DEFINE_enum(compress_debug_sections
, options::TWO_DASHES
, '\0', "none",
759 N_("Compress .debug_* sections in the output file"),
760 ("[none,zlib,zlib-gnu,zlib-gabi]"),
761 {"none", "zlib", "zlib-gnu", "zlib-gabi"});
763 DEFINE_bool(copy_dt_needed_entries
, options::TWO_DASHES
, '\0', false,
765 N_("Do not copy DT_NEEDED tags from shared libraries"));
767 DEFINE_bool(cref
, options::TWO_DASHES
, '\0', false,
768 N_("Output cross reference table"),
769 N_("Do not output cross reference table"));
771 DEFINE_bool(ctors_in_init_array
, options::TWO_DASHES
, '\0', true,
772 N_("Use DT_INIT_ARRAY for all constructors"),
773 N_("Handle constructors as directed by compiler"));
777 DEFINE_bool(define_common
, options::TWO_DASHES
, 'd', false,
778 N_("Define common symbols"),
779 N_("Do not define common symbols in relocatable output"));
780 DEFINE_bool(dc
, options::ONE_DASH
, '\0', false,
781 N_("Alias for -d"), NULL
);
782 DEFINE_bool(dp
, options::ONE_DASH
, '\0', false,
783 N_("Alias for -d"), NULL
);
785 DEFINE_string(debug
, options::TWO_DASHES
, '\0', "",
786 N_("Turn on debugging"),
787 N_("[all,files,script,task][,...]"));
789 DEFINE_special(defsym
, options::TWO_DASHES
, '\0',
790 N_("Define a symbol"), N_("SYMBOL=EXPRESSION"));
792 DEFINE_optional_string(demangle
, options::TWO_DASHES
, '\0', NULL
,
793 N_("Demangle C++ symbols in log messages"),
795 DEFINE_bool(no_demangle
, options::TWO_DASHES
, '\0', false,
796 N_("Do not demangle C++ symbols in log messages"),
799 DEFINE_bool(detect_odr_violations
, options::TWO_DASHES
, '\0', false,
800 N_("Look for violations of the C++ One Definition Rule"),
801 N_("Do not look for violations of the C++ One Definition Rule"));
803 DEFINE_bool(dynamic_list_data
, options::TWO_DASHES
, '\0', false,
804 N_("Add data symbols to dynamic symbols"), NULL
);
806 DEFINE_bool(dynamic_list_cpp_new
, options::TWO_DASHES
, '\0', false,
807 N_("Add C++ operator new/delete to dynamic symbols"), NULL
);
809 DEFINE_bool(dynamic_list_cpp_typeinfo
, options::TWO_DASHES
, '\0', false,
810 N_("Add C++ typeinfo to dynamic symbols"), NULL
);
812 DEFINE_special(dynamic_list
, options::TWO_DASHES
, '\0',
813 N_("Read a list of dynamic symbols"), N_("FILE"));
817 DEFINE_bool(emit_stub_syms
, options::TWO_DASHES
, '\0', true,
818 N_("(PowerPC only) Label linker stubs with a symbol"),
819 N_("(PowerPC only) Do not label linker stubs with a symbol"));
821 DEFINE_string(entry
, options::TWO_DASHES
, 'e', NULL
,
822 N_("Set program start address"), N_("ADDRESS"));
824 DEFINE_bool(eh_frame_hdr
, options::TWO_DASHES
, '\0', false,
825 N_("Create exception frame header"),
826 N_("Do not create exception frame header"));
828 // Alphabetized under 'e' because the option is spelled --enable-new-dtags.
829 DEFINE_enable(new_dtags
, options::EXACTLY_TWO_DASHES
, '\0', true,
830 N_("Enable use of DT_RUNPATH"),
831 N_("Disable use of DT_RUNPATH"));
833 DEFINE_bool(enum_size_warning
, options::TWO_DASHES
, '\0', true, NULL
,
834 N_("(ARM only) Do not warn about objects with incompatible "
837 DEFINE_special(exclude_libs
, options::TWO_DASHES
, '\0',
838 N_("Exclude libraries from automatic export"),
839 N_(("lib,lib ...")));
841 DEFINE_bool(export_dynamic
, options::TWO_DASHES
, 'E', false,
842 N_("Export all dynamic symbols"),
843 N_("Do not export all dynamic symbols"));
845 DEFINE_set(export_dynamic_symbol
, options::TWO_DASHES
, '\0',
846 N_("Export SYMBOL to dynamic symbol table"), N_("SYMBOL"));
848 DEFINE_special(EB
, options::ONE_DASH
, '\0',
849 N_("Link big-endian objects."), NULL
);
850 DEFINE_special(EL
, options::ONE_DASH
, '\0',
851 N_("Link little-endian objects."), NULL
);
855 DEFINE_set(auxiliary
, options::TWO_DASHES
, 'f',
856 N_("Auxiliary filter for shared object symbol table"),
859 DEFINE_string(filter
, options::TWO_DASHES
, 'F', NULL
,
860 N_("Filter for shared object symbol table"),
863 DEFINE_bool(fatal_warnings
, options::TWO_DASHES
, '\0', false,
864 N_("Treat warnings as errors"),
865 N_("Do not treat warnings as errors"));
867 DEFINE_string(fini
, options::ONE_DASH
, '\0', "_fini",
868 N_("Call SYMBOL at unload-time"), N_("SYMBOL"));
870 DEFINE_bool(fix_arm1176
, options::TWO_DASHES
, '\0', true,
871 N_("(ARM only) Fix binaries for ARM1176 erratum"),
872 N_("(ARM only) Do not fix binaries for ARM1176 erratum"));
874 DEFINE_bool(fix_cortex_a8
, options::TWO_DASHES
, '\0', false,
875 N_("(ARM only) Fix binaries for Cortex-A8 erratum"),
876 N_("(ARM only) Do not fix binaries for Cortex-A8 erratum"));
878 DEFINE_bool(fix_cortex_a53_843419
, options::TWO_DASHES
, '\0', false,
879 N_("(AArch64 only) Fix Cortex-A53 erratum 843419"),
880 N_("(AArch64 only) Do not fix Cortex-A53 erratum 843419"));
882 DEFINE_bool(fix_cortex_a53_835769
, options::TWO_DASHES
, '\0', false,
883 N_("(AArch64 only) Fix Cortex-A53 erratum 835769"),
884 N_("(AArch64 only) Do not fix Cortex-A53 erratum 835769"));
886 DEFINE_special(fix_v4bx
, options::TWO_DASHES
, '\0',
887 N_("(ARM only) Rewrite BX rn as MOV pc, rn for ARMv4"),
890 DEFINE_special(fix_v4bx_interworking
, options::TWO_DASHES
, '\0',
891 N_("(ARM only) Rewrite BX rn branch to ARMv4 interworking "
895 DEFINE_string(fuse_ld
, options::ONE_DASH
, '\0', "",
896 N_("Ignored for GCC linker option compatibility"),
901 DEFINE_bool(g
, options::EXACTLY_ONE_DASH
, '\0', false,
902 N_("Ignored"), NULL
);
904 DEFINE_bool(gc_sections
, options::TWO_DASHES
, '\0', false,
905 N_("Remove unused sections"),
906 N_("Don't remove unused sections"));
908 DEFINE_bool(gdb_index
, options::TWO_DASHES
, '\0', false,
909 N_("Generate .gdb_index section"),
910 N_("Do not generate .gdb_index section"));
912 DEFINE_bool(gnu_unique
, options::TWO_DASHES
, '\0', true,
913 N_("Enable STB_GNU_UNIQUE symbol binding"),
914 N_("Disable STB_GNU_UNIQUE symbol binding"));
916 DEFINE_bool(shared
, options::ONE_DASH
, 'G', false,
917 N_("Generate shared library"), NULL
);
921 DEFINE_string(soname
, options::ONE_DASH
, 'h', NULL
,
922 N_("Set shared library name"), N_("FILENAME"));
924 DEFINE_double(hash_bucket_empty_fraction
, options::TWO_DASHES
, '\0', 0.0,
925 N_("Min fraction of empty buckets in dynamic hash"),
928 DEFINE_enum(hash_style
, options::TWO_DASHES
, '\0', "sysv",
929 N_("Dynamic hash style"), N_("[sysv,gnu,both]"),
930 {"sysv", "gnu", "both"});
934 DEFINE_bool_alias(i
, relocatable
, options::EXACTLY_ONE_DASH
, '\0',
935 N_("Alias for -r"), NULL
, false);
937 DEFINE_enum(icf
, options::TWO_DASHES
, '\0', "none",
938 N_("Identical Code Folding. "
939 "\'--icf=safe\' Folds ctors, dtors and functions whose"
940 " pointers are definitely not taken"),
942 {"none", "all", "safe"});
944 DEFINE_uint(icf_iterations
, options::TWO_DASHES
, '\0', 0,
945 N_("Number of iterations of ICF (default 2)"), N_("COUNT"));
947 DEFINE_special(incremental
, options::TWO_DASHES
, '\0',
948 N_("Do an incremental link if possible; "
949 "otherwise, do a full link and prepare output "
950 "for incremental linking"), NULL
);
952 DEFINE_special(no_incremental
, options::TWO_DASHES
, '\0',
953 N_("Do a full link (default)"), NULL
);
955 DEFINE_special(incremental_full
, options::TWO_DASHES
, '\0',
956 N_("Do a full link and "
957 "prepare output for incremental linking"), NULL
);
959 DEFINE_special(incremental_update
, options::TWO_DASHES
, '\0',
960 N_("Do an incremental link; exit if not possible"), NULL
);
962 DEFINE_string(incremental_base
, options::TWO_DASHES
, '\0', NULL
,
963 N_("Set base file for incremental linking"
964 " (default is output file)"),
967 DEFINE_special(incremental_changed
, options::TWO_DASHES
, '\0',
968 N_("Assume files changed"), NULL
);
970 DEFINE_special(incremental_unchanged
, options::TWO_DASHES
, '\0',
971 N_("Assume files didn't change"), NULL
);
973 DEFINE_special(incremental_unknown
, options::TWO_DASHES
, '\0',
974 N_("Use timestamps to check files (default)"), NULL
);
976 DEFINE_special(incremental_startup_unchanged
, options::TWO_DASHES
, '\0',
977 N_("Assume startup files unchanged "
978 "(files preceding this option)"), NULL
);
980 DEFINE_percent(incremental_patch
, options::TWO_DASHES
, '\0', 10,
981 N_("Amount of extra space to allocate for patches "
985 DEFINE_string(init
, options::ONE_DASH
, '\0', "_init",
986 N_("Call SYMBOL at load-time"), N_("SYMBOL"));
988 DEFINE_string(dynamic_linker
, options::TWO_DASHES
, 'I', NULL
,
989 N_("Set dynamic linker path"), N_("PROGRAM"));
993 DEFINE_special(just_symbols
, options::TWO_DASHES
, '\0',
994 N_("Read only symbol values from FILE"), N_("FILE"));
998 DEFINE_bool(keep_files_mapped
, options::TWO_DASHES
, '\0', true,
999 N_("Keep files mapped across passes"),
1000 N_("Release mapped files after each pass"));
1002 DEFINE_set(keep_unique
, options::TWO_DASHES
, '\0',
1003 N_("Do not fold this symbol during ICF"), N_("SYMBOL"));
1007 DEFINE_special(library
, options::TWO_DASHES
, 'l',
1008 N_("Search for library LIBNAME"), N_("LIBNAME"));
1010 DEFINE_bool(ld_generated_unwind_info
, options::TWO_DASHES
, '\0', true,
1011 N_("Generate unwind information for PLT"),
1012 N_("Do not generate unwind information for PLT"));
1014 DEFINE_dirlist(library_path
, options::TWO_DASHES
, 'L',
1015 N_("Add directory to search path"), N_("DIR"));
1017 DEFINE_bool(long_plt
, options::TWO_DASHES
, '\0', false,
1018 N_("(ARM only) Generate long PLT entries"),
1019 N_("(ARM only) Do not generate long PLT entries"));
1023 DEFINE_string(m
, options::EXACTLY_ONE_DASH
, 'm', "",
1024 N_("Set GNU linker emulation; obsolete"), N_("EMULATION"));
1026 DEFINE_bool(map_whole_files
, options::TWO_DASHES
, '\0',
1028 N_("Map whole files to memory"),
1029 N_("Map relevant file parts to memory"));
1031 DEFINE_bool(merge_exidx_entries
, options::TWO_DASHES
, '\0', true,
1032 N_("(ARM only) Merge exidx entries in debuginfo"),
1033 N_("(ARM only) Do not merge exidx entries in debuginfo"));
1035 DEFINE_bool(mmap_output_file
, options::TWO_DASHES
, '\0', true,
1036 N_("Map the output file for writing"),
1037 N_("Do not map the output file for writing"));
1039 DEFINE_bool(print_map
, options::TWO_DASHES
, 'M', false,
1040 N_("Write map file on standard output"), NULL
);
1042 DEFINE_string(Map
, options::ONE_DASH
, '\0', NULL
, N_("Write map file"),
1047 DEFINE_bool(nmagic
, options::TWO_DASHES
, 'n', false,
1048 N_("Do not page align data"), NULL
);
1049 DEFINE_bool(omagic
, options::EXACTLY_TWO_DASHES
, 'N', false,
1050 N_("Do not page align data, do not make text readonly"),
1051 N_("Page align data, make text readonly"));
1053 DEFINE_bool(no_keep_memory
, options::TWO_DASHES
, '\0', false,
1054 N_("Use less memory and more disk I/O "
1055 "(included only for compatibility with GNU ld)"), NULL
);
1057 DEFINE_bool_alias(no_undefined
, defs
, options::TWO_DASHES
, '\0',
1058 N_("Report undefined symbols (even with --shared)"),
1061 DEFINE_bool(noinhibit_exec
, options::TWO_DASHES
, '\0', false,
1062 N_("Create an output file even if errors occur"), NULL
);
1064 DEFINE_bool(nostdlib
, options::ONE_DASH
, '\0', false,
1065 N_("Only search directories specified on the command line"),
1070 DEFINE_string(output
, options::TWO_DASHES
, 'o', "a.out",
1071 N_("Set output file name"), N_("FILE"));
1073 DEFINE_string(oformat
, options::EXACTLY_TWO_DASHES
, '\0', "elf",
1074 N_("Set output format"), N_("[binary]"));
1076 DEFINE_uint(optimize
, options::EXACTLY_ONE_DASH
, 'O', 0,
1077 N_("Optimize output file size"), N_("LEVEL"));
1079 DEFINE_enum(orphan_handling
, options::TWO_DASHES
, '\0', "place",
1080 N_("Orphan section handling"), N_("[place,discard,warn,error]"),
1081 {"place", "discard", "warn", "error"});
1085 DEFINE_bool(p
, options::ONE_DASH
, 'p', false,
1086 N_("Ignored for ARM compatibility"), NULL
);
1088 DEFINE_bool(pie
, options::ONE_DASH
, '\0', false,
1089 N_("Create a position independent executable"),
1090 N_("Do not create a position independent executable"));
1091 DEFINE_bool_alias(pic_executable
, pie
, options::TWO_DASHES
, '\0',
1092 N_("Create a position independent executable"),
1093 N_("Do not create a position independent executable"),
1096 DEFINE_bool(pic_veneer
, options::TWO_DASHES
, '\0', false,
1097 N_("Force PIC sequences for ARM/Thumb interworking veneers"),
1100 DEFINE_bool(pipeline_knowledge
, options::ONE_DASH
, '\0', false,
1101 NULL
, N_("(ARM only) Ignore for backward compatibility"));
1103 DEFINE_var(plt_align
, options::TWO_DASHES
, '\0', 0, "5",
1104 N_("(PowerPC64 only) Align PLT call stubs to fit cache lines"),
1105 N_("[=P2ALIGN]"), true, int, int, options::parse_uint
, false);
1107 DEFINE_bool(plt_localentry
, options::TWO_DASHES
, '\0', false,
1108 N_("(PowerPC64 only) Optimize calls to ELFv2 localentry:0 functions"),
1109 N_("(PowerPC64 only) Don't optimize ELFv2 calls"));
1111 DEFINE_bool(plt_static_chain
, options::TWO_DASHES
, '\0', false,
1112 N_("(PowerPC64 only) PLT call stubs should load r11"),
1113 N_("(PowerPC64 only) PLT call stubs should not load r11"));
1115 DEFINE_bool(plt_thread_safe
, options::TWO_DASHES
, '\0', false,
1116 N_("(PowerPC64 only) PLT call stubs with load-load barrier"),
1117 N_("(PowerPC64 only) PLT call stubs without barrier"));
1119 #ifdef ENABLE_PLUGINS
1120 DEFINE_special(plugin
, options::TWO_DASHES
, '\0',
1121 N_("Load a plugin library"), N_("PLUGIN"));
1122 DEFINE_special(plugin_opt
, options::TWO_DASHES
, '\0',
1123 N_("Pass an option to the plugin"), N_("OPTION"));
1126 DEFINE_bool(posix_fallocate
, options::TWO_DASHES
, '\0', true,
1127 N_("Use posix_fallocate to reserve space in the output file"),
1128 N_("Use fallocate or ftruncate to reserve space"));
1130 DEFINE_bool(preread_archive_symbols
, options::TWO_DASHES
, '\0', false,
1131 N_("Preread archive symbols when multi-threaded"), NULL
);
1133 DEFINE_bool(print_gc_sections
, options::TWO_DASHES
, '\0', false,
1134 N_("List removed unused sections on stderr"),
1135 N_("Do not list removed unused sections"));
1137 DEFINE_bool(print_icf_sections
, options::TWO_DASHES
, '\0', false,
1138 N_("List folded identical sections on stderr"),
1139 N_("Do not list folded identical sections"));
1141 DEFINE_bool(print_output_format
, options::TWO_DASHES
, '\0', false,
1142 N_("Print default output format"), NULL
);
1144 DEFINE_string(print_symbol_counts
, options::TWO_DASHES
, '\0', NULL
,
1145 N_("Print symbols defined and used for each input"),
1148 DEFINE_special(push_state
, options::TWO_DASHES
, '\0',
1149 N_("Save the state of flags related to input files"), NULL
);
1150 DEFINE_special(pop_state
, options::TWO_DASHES
, '\0',
1151 N_("Restore the state of flags related to input files"), NULL
);
1155 DEFINE_bool(emit_relocs
, options::TWO_DASHES
, 'q', false,
1156 N_("Generate relocations in output"), NULL
);
1158 DEFINE_bool(Qy
, options::EXACTLY_ONE_DASH
, '\0', false,
1159 N_("Ignored for SVR4 compatibility"), NULL
);
1163 DEFINE_bool(relocatable
, options::EXACTLY_ONE_DASH
, 'r', false,
1164 N_("Generate relocatable output"), NULL
);
1166 DEFINE_bool(relax
, options::TWO_DASHES
, '\0', false,
1167 N_("Relax branches on certain targets"), NULL
);
1169 DEFINE_string(retain_symbols_file
, options::TWO_DASHES
, '\0', NULL
,
1170 N_("keep only symbols listed in this file"), N_("FILE"));
1172 DEFINE_bool(rosegment
, options::TWO_DASHES
, '\0', false,
1173 N_("Put read-only non-executable sections in their own segment"),
1176 DEFINE_uint64(rosegment_gap
, options::TWO_DASHES
, '\0', -1U,
1177 N_("Set offset between executable and read-only segments"),
1180 // -R really means -rpath, but can mean --just-symbols for
1181 // compatibility with GNU ld. -rpath is always -rpath, so we list
1183 DEFINE_special(R
, options::EXACTLY_ONE_DASH
, 'R',
1184 N_("Add DIR to runtime search path"), N_("DIR"));
1186 DEFINE_dirlist(rpath
, options::ONE_DASH
, '\0',
1187 N_("Add DIR to runtime search path"), N_("DIR"));
1189 DEFINE_dirlist(rpath_link
, options::TWO_DASHES
, '\0',
1190 N_("Add DIR to link time shared library search path"),
1195 DEFINE_bool(strip_all
, options::TWO_DASHES
, 's', false,
1196 N_("Strip all symbols"), NULL
);
1197 DEFINE_bool(strip_debug
, options::TWO_DASHES
, 'S', false,
1198 N_("Strip debugging information"), NULL
);
1199 DEFINE_bool(strip_debug_non_line
, options::TWO_DASHES
, '\0', false,
1200 N_("Emit only debug line number information"), NULL
);
1201 DEFINE_bool(strip_debug_gdb
, options::TWO_DASHES
, '\0', false,
1202 N_("Strip debug symbols that are unused by gdb "
1203 "(at least versions <= 7.4)"), NULL
);
1204 DEFINE_bool(strip_lto_sections
, options::TWO_DASHES
, '\0', true,
1205 N_("Strip LTO intermediate code sections"), NULL
);
1207 DEFINE_string(section_ordering_file
, options::TWO_DASHES
, '\0', NULL
,
1208 N_("Layout sections in the order specified"),
1211 DEFINE_special(section_start
, options::TWO_DASHES
, '\0',
1212 N_("Set address of section"), N_("SECTION=ADDRESS"));
1214 DEFINE_bool(secure_plt
, options::TWO_DASHES
, '\0', true,
1215 N_("(PowerPC only) Use new-style PLT"), NULL
);
1217 DEFINE_optional_string(sort_common
, options::TWO_DASHES
, '\0', NULL
,
1218 N_("Sort common symbols by alignment"),
1219 N_("[={ascending,descending}]"));
1221 DEFINE_enum(sort_section
, options::TWO_DASHES
, '\0', "none",
1222 N_("Sort sections by name. \'--no-text-reorder\'"
1223 " will override \'--sort-section=name\' for .text"),
1227 DEFINE_uint(spare_dynamic_tags
, options::TWO_DASHES
, '\0', 5,
1228 N_("Dynamic tag slots to reserve (default 5)"),
1231 DEFINE_int(stub_group_size
, options::TWO_DASHES
, '\0', 1,
1232 N_("(ARM, PowerPC only) The maximum distance from instructions "
1233 "in a group of sections to their stubs. Negative values mean "
1234 "stubs are always after the group. 1 means use default size"),
1237 DEFINE_bool(stub_group_multi
, options::TWO_DASHES
, '\0', false,
1238 N_("(PowerPC only) Allow a group of stubs to serve multiple "
1239 "output sections"), NULL
);
1241 DEFINE_uint(split_stack_adjust_size
, options::TWO_DASHES
, '\0', 0x4000,
1242 N_("Stack size when -fsplit-stack function calls non-split"),
1245 // This is not actually special in any way, but I need to give it
1246 // a non-standard accessor-function name because 'static' is a keyword.
1247 DEFINE_special(static, options::ONE_DASH
, '\0',
1248 N_("Do not link against shared libraries"), NULL
);
1250 DEFINE_special(start_lib
, options::TWO_DASHES
, '\0',
1251 N_("Start a library"), NULL
);
1252 DEFINE_special(end_lib
, options::TWO_DASHES
, '\0',
1253 N_("End a library "), NULL
);
1255 DEFINE_bool(stats
, options::TWO_DASHES
, '\0', false,
1256 N_("Print resource usage statistics"), NULL
);
1258 DEFINE_string(sysroot
, options::TWO_DASHES
, '\0', "",
1259 N_("Set target system root directory"), N_("DIR"));
1263 DEFINE_bool(trace
, options::TWO_DASHES
, 't', false,
1264 N_("Print the name of each input file"), NULL
);
1266 DEFINE_bool(target1_abs
, options::TWO_DASHES
, '\0', false,
1267 N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_ABS32"),
1269 DEFINE_bool(target1_rel
, options::TWO_DASHES
, '\0', false,
1270 N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_REL32"),
1272 DEFINE_enum(target2
, options::TWO_DASHES
, '\0', NULL
,
1273 N_("(ARM only) Set R_ARM_TARGET2 relocation type"),
1274 N_("[rel, abs, got-rel"),
1275 {"rel", "abs", "got-rel"});
1277 DEFINE_bool(text_reorder
, options::TWO_DASHES
, '\0', true,
1278 N_("Enable text section reordering for GCC section names"),
1279 N_("Disable text section reordering for GCC section names"));
1281 DEFINE_bool(threads
, options::TWO_DASHES
, '\0', false,
1282 N_("Run the linker multi-threaded"),
1283 N_("Do not run the linker multi-threaded"));
1284 DEFINE_uint(thread_count
, options::TWO_DASHES
, '\0', 0,
1285 N_("Number of threads to use"), N_("COUNT"));
1286 DEFINE_uint(thread_count_initial
, options::TWO_DASHES
, '\0', 0,
1287 N_("Number of threads to use in initial pass"), N_("COUNT"));
1288 DEFINE_uint(thread_count_middle
, options::TWO_DASHES
, '\0', 0,
1289 N_("Number of threads to use in middle pass"), N_("COUNT"));
1290 DEFINE_uint(thread_count_final
, options::TWO_DASHES
, '\0', 0,
1291 N_("Number of threads to use in final pass"), N_("COUNT"));
1293 DEFINE_bool(toc_optimize
, options::TWO_DASHES
, '\0', true,
1294 N_("(PowerPC64 only) Optimize TOC code sequences"),
1295 N_("(PowerPC64 only) Don't optimize TOC code sequences"));
1297 DEFINE_bool(toc_sort
, options::TWO_DASHES
, '\0', true,
1298 N_("(PowerPC64 only) Sort TOC and GOT sections"),
1299 N_("(PowerPC64 only) Don't sort TOC and GOT sections"));
1301 DEFINE_special(script
, options::TWO_DASHES
, 'T',
1302 N_("Read linker script"), N_("FILE"));
1304 DEFINE_uint64(Tbss
, options::ONE_DASH
, '\0', -1U,
1305 N_("Set the address of the bss segment"), N_("ADDRESS"));
1306 DEFINE_uint64(Tdata
, options::ONE_DASH
, '\0', -1U,
1307 N_("Set the address of the data segment"), N_("ADDRESS"));
1308 DEFINE_uint64(Ttext
, options::ONE_DASH
, '\0', -1U,
1309 N_("Set the address of the text segment"), N_("ADDRESS"));
1310 DEFINE_uint64_alias(Ttext_segment
, Ttext
, options::ONE_DASH
, '\0',
1311 N_("Set the address of the text segment"),
1313 DEFINE_uint64(Trodata_segment
, options::ONE_DASH
, '\0', -1U,
1314 N_("Set the address of the rodata segment"), N_("ADDRESS"));
1318 DEFINE_set(undefined
, options::TWO_DASHES
, 'u',
1319 N_("Create undefined reference to SYMBOL"), N_("SYMBOL"));
1321 DEFINE_enum(unresolved_symbols
, options::TWO_DASHES
, '\0', NULL
,
1322 N_("How to handle unresolved symbols"),
1323 ("ignore-all,report-all,ignore-in-object-files,"
1324 "ignore-in-shared-libs"),
1325 {"ignore-all", "report-all", "ignore-in-object-files",
1326 "ignore-in-shared-libs"});
1330 DEFINE_bool(verbose
, options::TWO_DASHES
, '\0', false,
1331 N_("Alias for --debug=files"), NULL
);
1333 DEFINE_special(version_script
, options::TWO_DASHES
, '\0',
1334 N_("Read version script"), N_("FILE"));
1338 DEFINE_bool(warn_common
, options::TWO_DASHES
, '\0', false,
1339 N_("Warn about duplicate common symbols"),
1340 N_("Do not warn about duplicate common symbols"));
1342 DEFINE_bool_ignore(warn_constructors
, options::TWO_DASHES
, '\0',
1343 N_("Ignored"), N_("Ignored"));
1345 DEFINE_bool(warn_execstack
, options::TWO_DASHES
, '\0', false,
1346 N_("Warn if the stack is executable"),
1347 N_("Do not warn if the stack is executable"));
1349 DEFINE_bool(warn_mismatch
, options::TWO_DASHES
, '\0', true,
1350 NULL
, N_("Don't warn about mismatched input files"));
1352 DEFINE_bool(warn_multiple_gp
, options::TWO_DASHES
, '\0', false,
1353 N_("Ignored"), NULL
);
1355 DEFINE_bool(warn_search_mismatch
, options::TWO_DASHES
, '\0', true,
1356 N_("Warn when skipping an incompatible library"),
1357 N_("Don't warn when skipping an incompatible library"));
1359 DEFINE_bool(warn_shared_textrel
, options::TWO_DASHES
, '\0', false,
1360 N_("Warn if text segment is not shareable"),
1361 N_("Do not warn if text segment is not shareable"));
1363 DEFINE_bool(warn_unresolved_symbols
, options::TWO_DASHES
, '\0', false,
1364 N_("Report unresolved symbols as warnings"),
1366 DEFINE_bool_alias(error_unresolved_symbols
, warn_unresolved_symbols
,
1367 options::TWO_DASHES
, '\0',
1368 N_("Report unresolved symbols as errors"),
1371 DEFINE_bool(wchar_size_warning
, options::TWO_DASHES
, '\0', true, NULL
,
1372 N_("(ARM only) Do not warn about objects with incompatible "
1375 DEFINE_bool(weak_unresolved_symbols
, options::TWO_DASHES
, '\0', false,
1376 N_("Convert unresolved symbols to weak references"),
1379 DEFINE_bool(whole_archive
, options::TWO_DASHES
, '\0', false,
1380 N_("Include all archive contents"),
1381 N_("Include only needed archive contents"));
1383 DEFINE_set(wrap
, options::TWO_DASHES
, '\0',
1384 N_("Use wrapper functions for SYMBOL"), N_("SYMBOL"));
1388 DEFINE_special(discard_all
, options::TWO_DASHES
, 'x',
1389 N_("Delete all local symbols"), NULL
);
1390 DEFINE_special(discard_locals
, options::TWO_DASHES
, 'X',
1391 N_("Delete all temporary local symbols"), NULL
);
1392 DEFINE_special(discard_none
, options::TWO_DASHES
, '\0',
1393 N_("Keep all local symbols"), NULL
);
1397 DEFINE_set(trace_symbol
, options::TWO_DASHES
, 'y',
1398 N_("Trace references to symbol"), N_("SYMBOL"));
1400 DEFINE_bool(undefined_version
, options::TWO_DASHES
, '\0', true,
1401 N_("Allow unused version in script"),
1402 N_("Do not allow unused version in script"));
1404 DEFINE_string(Y
, options::EXACTLY_ONE_DASH
, 'Y', "",
1405 N_("Default search path for Solaris compatibility"),
1408 // special characters
1410 DEFINE_special(start_group
, options::TWO_DASHES
, '(',
1411 N_("Start a library search group"), NULL
);
1412 DEFINE_special(end_group
, options::TWO_DASHES
, ')',
1413 N_("End a library search group"), NULL
);
1417 DEFINE_bool(bndplt
, options::DASH_Z
, '\0', false,
1418 N_("(x86-64 only) Generate a BND PLT for Intel MPX"),
1419 N_("Generate a regular PLT"));
1420 DEFINE_bool(combreloc
, options::DASH_Z
, '\0', true,
1421 N_("Sort dynamic relocs"),
1422 N_("Do not sort dynamic relocs"));
1423 DEFINE_uint64(common_page_size
, options::DASH_Z
, '\0', 0,
1424 N_("Set common page size to SIZE"), N_("SIZE"));
1425 DEFINE_bool(defs
, options::DASH_Z
, '\0', false,
1426 N_("Report undefined symbols (even with --shared)"),
1428 DEFINE_bool(execstack
, options::DASH_Z
, '\0', false,
1429 N_("Mark output as requiring executable stack"), NULL
);
1430 DEFINE_bool(global
, options::DASH_Z
, '\0', false,
1431 N_("Make symbols in DSO available for subsequently loaded "
1433 DEFINE_bool(initfirst
, options::DASH_Z
, '\0', false,
1434 N_("Mark DSO to be initialized first at runtime"),
1436 DEFINE_bool(interpose
, options::DASH_Z
, '\0', false,
1437 N_("Mark object to interpose all DSOs but executable"),
1439 DEFINE_bool_alias(lazy
, now
, options::DASH_Z
, '\0',
1440 N_("Mark object for lazy runtime binding"),
1442 DEFINE_bool(loadfltr
, options::DASH_Z
, '\0', false,
1443 N_("Mark object requiring immediate process"),
1445 DEFINE_uint64(max_page_size
, options::DASH_Z
, '\0', 0,
1446 N_("Set maximum page size to SIZE"), N_("SIZE"));
1447 DEFINE_bool(muldefs
, options::DASH_Z
, '\0', false,
1448 N_("Allow multiple definitions of symbols"),
1450 // copyreloc is here in the list because there is only -z
1451 // nocopyreloc, not -z copyreloc.
1452 DEFINE_bool(copyreloc
, options::DASH_Z
, '\0', true,
1454 N_("Do not create copy relocs"));
1455 DEFINE_bool(nodefaultlib
, options::DASH_Z
, '\0', false,
1456 N_("Mark object not to use default search paths"),
1458 DEFINE_bool(nodelete
, options::DASH_Z
, '\0', false,
1459 N_("Mark DSO non-deletable at runtime"),
1461 DEFINE_bool(nodlopen
, options::DASH_Z
, '\0', false,
1462 N_("Mark DSO not available to dlopen"),
1464 DEFINE_bool(nodump
, options::DASH_Z
, '\0', false,
1465 N_("Mark DSO not available to dldump"),
1467 DEFINE_bool(noexecstack
, options::DASH_Z
, '\0', false,
1468 N_("Mark output as not requiring executable stack"), NULL
);
1469 DEFINE_bool(now
, options::DASH_Z
, '\0', false,
1470 N_("Mark object for immediate function binding"),
1472 DEFINE_bool(origin
, options::DASH_Z
, '\0', false,
1473 N_("Mark DSO to indicate that needs immediate $ORIGIN "
1474 "processing at runtime"), NULL
);
1475 DEFINE_bool(relro
, options::DASH_Z
, '\0', DEFAULT_LD_Z_RELRO
,
1476 N_("Where possible mark variables read-only after relocation"),
1477 N_("Don't mark variables read-only after relocation"));
1478 DEFINE_uint64(stack_size
, options::DASH_Z
, '\0', 0,
1479 N_("Set PT_GNU_STACK segment p_memsz to SIZE"), N_("SIZE"));
1480 DEFINE_bool(text
, options::DASH_Z
, '\0', false,
1481 N_("Do not permit relocations in read-only segments"),
1482 N_("Permit relocations in read-only segments"));
1483 DEFINE_bool_alias(textoff
, text
, options::DASH_Z
, '\0',
1484 N_("Permit relocations in read-only segments"),
1488 typedef options::Dir_list Dir_list
;
1492 // Does post-processing on flags, making sure they all have
1493 // non-conflicting values. Also converts some flags from their
1494 // "standard" types (string, etc), to another type (enum, DirList),
1495 // which can be accessed via a separate method. Dies if it notices
1499 // True if we printed the version information.
1501 printed_version() const
1502 { return this->printed_version_
; }
1504 // The macro defines output() (based on --output), but that's a
1505 // generic name. Provide this alternative name, which is clearer.
1507 output_file_name() const
1508 { return this->output(); }
1510 // This is not defined via a flag, but combines flags to say whether
1511 // the output is position-independent or not.
1513 output_is_position_independent() const
1514 { return this->shared() || this->pie(); }
1516 // Return true if the output is something that can be exec()ed, such
1517 // as a static executable, or a position-dependent or
1518 // position-independent executable, but not a dynamic library or an
1521 output_is_executable() const
1522 { return !this->shared() && !this->relocatable(); }
1524 // This would normally be static(), and defined automatically, but
1525 // since static is a keyword, we need to come up with our own name.
1530 // In addition to getting the input and output formats as a string
1531 // (via format() and oformat()), we also give access as an enum.
1536 // Straight binary format.
1537 OBJECT_FORMAT_BINARY
1540 // Convert a string to an Object_format. Gives an error if the
1541 // string is not recognized.
1542 static Object_format
1543 string_to_object_format(const char* arg
);
1545 // Convert an Object_format to string.
1547 object_format_to_string(Object_format
);
1549 // Note: these functions are not very fast.
1550 Object_format
format_enum() const;
1551 Object_format
oformat_enum() const;
1553 // Return whether FILENAME is in a system directory.
1555 is_in_system_directory(const std::string
& name
) const;
1557 // RETURN whether SYMBOL_NAME should be kept, according to symbols_to_retain_.
1559 should_retain_symbol(const char* symbol_name
) const
1561 if (symbols_to_retain_
.empty()) // means flag wasn't specified
1563 return symbols_to_retain_
.find(symbol_name
) != symbols_to_retain_
.end();
1566 // These are the best way to get access to the execstack state,
1567 // not execstack() and noexecstack() which are hard to use properly.
1569 is_execstack_set() const
1570 { return this->execstack_status_
!= EXECSTACK_FROM_INPUT
; }
1573 is_stack_executable() const
1574 { return this->execstack_status_
== EXECSTACK_YES
; }
1578 { return this->icf_status_
!= ICF_NONE
; }
1581 icf_safe_folding() const
1582 { return this->icf_status_
== ICF_SAFE
; }
1584 // The --demangle option takes an optional string, and there is also
1585 // a --no-demangle option. This is the best way to decide whether
1586 // to demangle or not.
1589 { return this->do_demangle_
; }
1591 // Returns TRUE if any plugin libraries have been loaded.
1594 { return this->plugins_
!= NULL
; }
1596 // Return a pointer to the plugin manager.
1599 { return this->plugins_
; }
1601 // True iff SYMBOL was found in the file specified by dynamic-list.
1603 in_dynamic_list(const char* symbol
) const
1604 { return this->dynamic_list_
.version_script_info()->symbol_is_local(symbol
); }
1606 // True if a --dynamic-list script was provided.
1608 have_dynamic_list() const
1609 { return this->have_dynamic_list_
; }
1611 // Finalize the dynamic list.
1613 finalize_dynamic_list()
1614 { this->dynamic_list_
.version_script_info()->finalize(); }
1616 // The mode selected by the --incremental options.
1617 enum Incremental_mode
1619 // No incremental linking (--no-incremental).
1621 // Incremental update only (--incremental-update).
1623 // Force a full link, but prepare for subsequent incremental link
1624 // (--incremental-full).
1626 // Incremental update if possible, fallback to full link (--incremental).
1630 // The incremental linking mode.
1632 incremental_mode() const
1633 { return this->incremental_mode_
; }
1635 // The disposition given by the --incremental-changed,
1636 // --incremental-unchanged or --incremental-unknown option. The
1637 // value may change as we proceed parsing the command line flags.
1638 Incremental_disposition
1639 incremental_disposition() const
1640 { return this->incremental_disposition_
; }
1643 set_incremental_disposition(Incremental_disposition disp
)
1644 { this->incremental_disposition_
= disp
; }
1646 // The disposition to use for startup files (those that precede the
1647 // first --incremental-changed, etc. option).
1648 Incremental_disposition
1649 incremental_startup_disposition() const
1650 { return this->incremental_startup_disposition_
; }
1652 // Return true if S is the name of a library excluded from automatic
1655 check_excluded_libs(const std::string
&s
) const;
1657 // If an explicit start address was given for section SECNAME with
1658 // the --section-start option, return true and set *PADDR to the
1659 // address. Otherwise return false.
1661 section_start(const char* secname
, uint64_t* paddr
) const;
1663 // Return whether any --section-start option was used.
1665 any_section_start() const
1666 { return !this->section_starts_
.empty(); }
1670 // Leave original instruction.
1672 // Replace instruction.
1674 // Generate an interworking veneer.
1675 FIX_V4BX_INTERWORKING
1680 { return (this->fix_v4bx_
); }
1691 { return this->endianness_
; }
1695 { return this->discard_locals_
== DISCARD_ALL
; }
1698 discard_locals() const
1699 { return this->discard_locals_
== DISCARD_LOCALS
; }
1702 discard_sec_merge() const
1703 { return this->discard_locals_
== DISCARD_SEC_MERGE
; }
1705 enum Orphan_handling
1707 // Place orphan sections normally (default).
1709 // Discard all orphan sections.
1711 // Warn when placing orphan sections.
1713 // Issue error for orphan sections.
1718 orphan_handling_enum() const
1719 { return this->orphan_handling_enum_
; }
1722 // Don't copy this structure.
1723 General_options(const General_options
&);
1724 General_options
& operator=(const General_options
&);
1726 // What local symbols to discard.
1729 // Locals in merge sections (default).
1731 // None (--discard-none).
1733 // Temporary locals (--discard-locals/-X).
1735 // All locals (--discard-all/-x).
1739 // Whether to mark the stack as executable.
1742 // Not set on command line.
1743 EXECSTACK_FROM_INPUT
,
1744 // Mark the stack as executable (-z execstack).
1746 // Mark the stack as not executable (-z noexecstack).
1752 // Do not fold any functions (Default or --icf=none).
1754 // All functions are candidates for folding. (--icf=all).
1756 // Only ctors and dtors are candidates for folding. (--icf=safe).
1761 set_icf_status(Icf_status value
)
1762 { this->icf_status_
= value
; }
1765 set_execstack_status(Execstack value
)
1766 { this->execstack_status_
= value
; }
1769 set_do_demangle(bool value
)
1770 { this->do_demangle_
= value
; }
1773 set_static(bool value
)
1774 { static_
= value
; }
1777 set_orphan_handling_enum(Orphan_handling value
)
1778 { this->orphan_handling_enum_
= value
; }
1780 // These are called by finalize() to set up the search-path correctly.
1782 add_to_library_path_with_sysroot(const std::string
& arg
)
1783 { this->add_search_directory_to_library_path(Search_directory(arg
, true)); }
1785 // Apply any sysroot to the directory lists.
1789 // Add a plugin and its arguments to the list of plugins.
1791 add_plugin(const char* filename
);
1793 // Add a plugin option.
1795 add_plugin_option(const char* opt
);
1798 copy_from_posdep_options(const Position_dependent_options
&);
1800 // Whether we printed version information.
1801 bool printed_version_
;
1802 // Whether to mark the stack as executable.
1803 Execstack execstack_status_
;
1804 // Whether to do code folding.
1805 Icf_status icf_status_
;
1806 // Whether to do a static link.
1808 // Whether to do demangling.
1810 // List of plugin libraries.
1811 Plugin_manager
* plugins_
;
1812 // The parsed output of --dynamic-list files. For convenience in
1813 // script.cc, we store this as a Script_options object, even though
1814 // we only use a single Version_tree from it.
1815 Script_options dynamic_list_
;
1816 // Whether a --dynamic-list file was provided.
1817 bool have_dynamic_list_
;
1818 // The incremental linking mode.
1819 Incremental_mode incremental_mode_
;
1820 // The disposition given by the --incremental-changed,
1821 // --incremental-unchanged or --incremental-unknown option. The
1822 // value may change as we proceed parsing the command line flags.
1823 Incremental_disposition incremental_disposition_
;
1824 // The disposition to use for startup files (those marked
1825 // INCREMENTAL_STARTUP).
1826 Incremental_disposition incremental_startup_disposition_
;
1827 // Whether we have seen one of the options that require incremental
1828 // build (--incremental-changed, --incremental-unchanged,
1829 // --incremental-unknown, or --incremental-startup-unchanged).
1830 bool implicit_incremental_
;
1831 // Libraries excluded from automatic export, via --exclude-libs.
1832 Unordered_set
<std::string
> excluded_libs_
;
1833 // List of symbol-names to keep, via -retain-symbol-info.
1834 Unordered_set
<std::string
> symbols_to_retain_
;
1835 // Map from section name to address from --section-start.
1836 std::map
<std::string
, uint64_t> section_starts_
;
1837 // Whether to process armv4 bx instruction relocation.
1840 Endianness endianness_
;
1841 // What local symbols to discard.
1842 Discard_locals discard_locals_
;
1843 // Stack of saved options for --push-state/--pop-state.
1844 std::vector
<Position_dependent_options
*> options_stack_
;
1845 // Orphan handling option, decoded to an enum value.
1846 Orphan_handling orphan_handling_enum_
;
1849 // The position-dependent options. We use this to store the state of
1850 // the commandline at a particular point in parsing for later
1851 // reference. For instance, if we see "ld --whole-archive foo.a
1852 // --no-whole-archive," we want to store the whole-archive option with
1853 // foo.a, so when the time comes to parse foo.a we know we should do
1854 // it in whole-archive mode. We could store all of General_options,
1855 // but that's big, so we just pick the subset of flags that actually
1856 // change in a position-dependent way.
1858 #define DEFINE_posdep(varname__, type__) \
1862 { return this->varname__##_; } \
1865 set_##varname__(type__ value) \
1866 { this->varname__##_ = value; } \
1870 class Position_dependent_options
1873 Position_dependent_options(const General_options
& options
1874 = Position_dependent_options::default_options_
)
1875 { copy_from_options(options
); }
1878 copy_from_options(const General_options
& options
)
1880 this->set_as_needed(options
.as_needed());
1881 this->set_Bdynamic(options
.Bdynamic());
1882 this->set_format_enum(options
.format_enum());
1883 this->set_whole_archive(options
.whole_archive());
1884 this->set_incremental_disposition(options
.incremental_disposition());
1887 DEFINE_posdep(as_needed
, bool);
1888 DEFINE_posdep(Bdynamic
, bool);
1889 DEFINE_posdep(format_enum
, General_options::Object_format
);
1890 DEFINE_posdep(whole_archive
, bool);
1891 DEFINE_posdep(incremental_disposition
, Incremental_disposition
);
1894 // This is a General_options with everything set to its default
1895 // value. A Position_dependent_options created with no argument
1896 // will take its values from here.
1897 static General_options default_options_
;
1901 // A single file or library argument from the command line.
1903 class Input_file_argument
1906 enum Input_file_type
1908 // A regular file, name used as-is, not searched.
1909 INPUT_FILE_TYPE_FILE
,
1910 // A library name. When used, "lib" will be prepended and ".so" or
1911 // ".a" appended to make a filename, and that filename will be searched
1912 // for using the -L paths.
1913 INPUT_FILE_TYPE_LIBRARY
,
1914 // A regular file, name used as-is, but searched using the -L paths.
1915 INPUT_FILE_TYPE_SEARCHED_FILE
1918 // name: file name or library name
1919 // type: the type of this input file.
1920 // extra_search_path: an extra directory to look for the file, prior
1921 // to checking the normal library search path. If this is "",
1922 // then no extra directory is added.
1923 // just_symbols: whether this file only defines symbols.
1924 // options: The position dependent options at this point in the
1925 // command line, such as --whole-archive.
1926 Input_file_argument()
1927 : name_(), type_(INPUT_FILE_TYPE_FILE
), extra_search_path_(""),
1928 just_symbols_(false), options_(), arg_serial_(0)
1931 Input_file_argument(const char* name
, Input_file_type type
,
1932 const char* extra_search_path
,
1934 const Position_dependent_options
& options
)
1935 : name_(name
), type_(type
), extra_search_path_(extra_search_path
),
1936 just_symbols_(just_symbols
), options_(options
), arg_serial_(0)
1939 // You can also pass in a General_options instance instead of a
1940 // Position_dependent_options. In that case, we extract the
1941 // position-independent vars from the General_options and only store
1943 Input_file_argument(const char* name
, Input_file_type type
,
1944 const char* extra_search_path
,
1946 const General_options
& options
)
1947 : name_(name
), type_(type
), extra_search_path_(extra_search_path
),
1948 just_symbols_(just_symbols
), options_(options
), arg_serial_(0)
1953 { return this->name_
.c_str(); }
1955 const Position_dependent_options
&
1957 { return this->options_
; }
1961 { return type_
== INPUT_FILE_TYPE_LIBRARY
; }
1964 is_searched_file() const
1965 { return type_
== INPUT_FILE_TYPE_SEARCHED_FILE
; }
1968 extra_search_path() const
1970 return (this->extra_search_path_
.empty()
1972 : this->extra_search_path_
.c_str());
1975 // Return whether we should only read symbols from this file.
1977 just_symbols() const
1978 { return this->just_symbols_
; }
1980 // Return whether this file may require a search using the -L
1983 may_need_search() const
1985 return (this->is_lib()
1986 || this->is_searched_file()
1987 || !this->extra_search_path_
.empty());
1990 // Set the serial number for this argument.
1992 set_arg_serial(unsigned int arg_serial
)
1993 { this->arg_serial_
= arg_serial
; }
1995 // Get the serial number.
1998 { return this->arg_serial_
; }
2001 // We use std::string, not const char*, here for convenience when
2002 // using script files, so that we do not have to preserve the string
2005 Input_file_type type_
;
2006 std::string extra_search_path_
;
2008 Position_dependent_options options_
;
2009 // A unique index for this file argument in the argument list.
2010 unsigned int arg_serial_
;
2013 // A file or library, or a group, from the command line.
2015 class Input_argument
2018 // Create a file or library argument.
2019 explicit Input_argument(Input_file_argument file
)
2020 : is_file_(true), file_(file
), group_(NULL
), lib_(NULL
), script_info_(NULL
)
2023 // Create a group argument.
2024 explicit Input_argument(Input_file_group
* group
)
2025 : is_file_(false), group_(group
), lib_(NULL
), script_info_(NULL
)
2028 // Create a lib argument.
2029 explicit Input_argument(Input_file_lib
* lib
)
2030 : is_file_(false), group_(NULL
), lib_(lib
), script_info_(NULL
)
2033 // Return whether this is a file.
2036 { return this->is_file_
; }
2038 // Return whether this is a group.
2041 { return !this->is_file_
&& this->lib_
== NULL
; }
2043 // Return whether this is a lib.
2046 { return this->lib_
!= NULL
; }
2048 // Return the information about the file.
2049 const Input_file_argument
&
2052 gold_assert(this->is_file_
);
2056 // Return the information about the group.
2057 const Input_file_group
*
2060 gold_assert(!this->is_file_
);
2061 return this->group_
;
2067 gold_assert(!this->is_file_
);
2068 return this->group_
;
2071 // Return the information about the lib.
2072 const Input_file_lib
*
2075 gold_assert(!this->is_file_
);
2076 gold_assert(this->lib_
);
2083 gold_assert(!this->is_file_
);
2084 gold_assert(this->lib_
);
2088 // If a script generated this argument, store a pointer to the script info.
2089 // Currently used only for recording incremental link information.
2091 set_script_info(Script_info
* info
)
2092 { this->script_info_
= info
; }
2096 { return this->script_info_
; }
2100 Input_file_argument file_
;
2101 Input_file_group
* group_
;
2102 Input_file_lib
* lib_
;
2103 Script_info
* script_info_
;
2106 typedef std::vector
<Input_argument
> Input_argument_list
;
2108 // A group from the command line. This is a set of arguments within
2109 // --start-group ... --end-group.
2111 class Input_file_group
2114 typedef Input_argument_list::const_iterator const_iterator
;
2120 // Add a file to the end of the group.
2122 add_file(const Input_file_argument
& arg
)
2124 this->files_
.push_back(Input_argument(arg
));
2125 return this->files_
.back();
2128 // Iterators to iterate over the group contents.
2132 { return this->files_
.begin(); }
2136 { return this->files_
.end(); }
2139 Input_argument_list files_
;
2142 // A lib from the command line. This is a set of arguments within
2143 // --start-lib ... --end-lib.
2145 class Input_file_lib
2148 typedef Input_argument_list::const_iterator const_iterator
;
2150 Input_file_lib(const Position_dependent_options
& options
)
2151 : files_(), options_(options
)
2154 // Add a file to the end of the lib.
2156 add_file(const Input_file_argument
& arg
)
2158 this->files_
.push_back(Input_argument(arg
));
2159 return this->files_
.back();
2162 const Position_dependent_options
&
2164 { return this->options_
; }
2166 // Iterators to iterate over the lib contents.
2170 { return this->files_
.begin(); }
2174 { return this->files_
.end(); }
2178 { return this->files_
.size(); }
2181 Input_argument_list files_
;
2182 Position_dependent_options options_
;
2185 // A list of files from the command line or a script.
2187 class Input_arguments
2190 typedef Input_argument_list::const_iterator const_iterator
;
2193 : input_argument_list_(), in_group_(false), in_lib_(false), file_count_(0)
2198 add_file(Input_file_argument
& arg
);
2200 // Start a group (the --start-group option).
2204 // End a group (the --end-group option).
2208 // Start a lib (the --start-lib option).
2210 start_lib(const Position_dependent_options
&);
2212 // End a lib (the --end-lib option).
2216 // Return whether we are currently in a group.
2219 { return this->in_group_
; }
2221 // Return whether we are currently in a lib.
2224 { return this->in_lib_
; }
2226 // The number of entries in the list.
2229 { return this->input_argument_list_
.size(); }
2231 // Iterators to iterate over the list of input files.
2235 { return this->input_argument_list_
.begin(); }
2239 { return this->input_argument_list_
.end(); }
2241 // Return whether the list is empty.
2244 { return this->input_argument_list_
.empty(); }
2246 // Return the number of input files. This may be larger than
2247 // input_argument_list_.size(), because of files that are part
2248 // of groups or libs.
2250 number_of_input_files() const
2251 { return this->file_count_
; }
2254 Input_argument_list input_argument_list_
;
2257 unsigned int file_count_
;
2261 // All the information read from the command line. These are held in
2262 // three separate structs: one to hold the options (--foo), one to
2263 // hold the filenames listed on the commandline, and one to hold
2264 // linker script information. This third is not a subset of the other
2265 // two because linker scripts can be specified either as options (via
2266 // -T) or as a file.
2271 typedef Input_arguments::const_iterator const_iterator
;
2275 // Process the command line options. This will exit with an
2276 // appropriate error message if an unrecognized option is seen.
2278 process(int argc
, const char** argv
);
2280 // Process one command-line option. This takes the index of argv to
2281 // process, and returns the index for the next option. no_more_options
2282 // is set to true if argv[i] is "--".
2284 process_one_option(int argc
, const char** argv
, int i
,
2285 bool* no_more_options
);
2287 // Get the general options.
2288 const General_options
&
2290 { return this->options_
; }
2292 // Get the position dependent options.
2293 const Position_dependent_options
&
2294 position_dependent_options() const
2295 { return this->position_options_
; }
2297 // Get the linker-script options.
2300 { return this->script_options_
; }
2302 // Finalize the version-script options and return them.
2303 const Version_script_info
&
2306 // Get the input files.
2309 { return this->inputs_
; }
2311 // The number of input files.
2313 number_of_input_files() const
2314 { return this->inputs_
.number_of_input_files(); }
2316 // Iterators to iterate over the list of input files.
2320 { return this->inputs_
.begin(); }
2324 { return this->inputs_
.end(); }
2327 Command_line(const Command_line
&);
2328 Command_line
& operator=(const Command_line
&);
2330 // This is a dummy class to provide a constructor that runs before
2331 // the constructor for the General_options. The Pre_options constructor
2332 // is used as a hook to set the flag enabling the options to register
2334 struct Pre_options
{
2338 // This must come before options_!
2339 Pre_options pre_options_
;
2340 General_options options_
;
2341 Position_dependent_options position_options_
;
2342 Script_options script_options_
;
2343 Input_arguments inputs_
;
2346 } // End namespace gold.
2348 #endif // !defined(GOLD_OPTIONS_H)