1 // options.h -- handle command line options for gold -*- C++ -*-
3 // Copyright (C) 2006-2024 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 options::String_set::size_type \
477 varname__##_size() const \
478 { return this->varname__##_.value.size(); } \
480 // When you have a list of possible values (expressed as string)
481 // After helparg__ should come an initializer list, like
482 // {"foo", "bar", "baz"}
483 #define DEFINE_enum(varname__, dashes__, shortname__, default_value__, \
484 helpstring__, helparg__, optional_arg__, ...) \
485 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
486 default_value__, helpstring__, helparg__, optional_arg__, \
487 const char*, const char*, parse_choices_##varname__, false) \
489 static void parse_choices_##varname__(const char* option_name, \
491 const char** retval) { \
492 const char* choices[] = __VA_ARGS__; \
493 options::parse_choices(option_name, arg, retval, \
494 choices, sizeof(choices) / sizeof(*choices)); \
497 // This is like DEFINE_bool, but VARNAME is the name of a different
498 // option. This option becomes an alias for that one. INVERT is true
499 // if this option is an inversion of the other one.
500 #define DEFINE_bool_alias(option__, varname__, dashes__, shortname__, \
501 helpstring__, no_helpstring__, invert__) \
503 struct Struct_##option__ : public options::Struct_var \
505 Struct_##option__() \
506 : option(#option__, dashes__, shortname__, "", helpstring__, \
508 General_options::varname__##is_default ^ invert__) \
512 parse_to_value(const char*, const char*, \
513 Command_line*, General_options* options) \
515 options->set_##varname__(!invert__); \
516 options->set_user_set_##varname__(); \
519 options::One_option option; \
521 Struct_##option__ option__##_; \
523 struct Struct_no_##option__ : public options::Struct_var \
525 Struct_no_##option__() \
526 : option((dashes__ == options::DASH_Z \
528 : "no-" #option__), \
529 dashes__, '\0', "", no_helpstring__, \
531 !General_options::varname__##is_default ^ invert__) \
535 parse_to_value(const char*, const char*, \
536 Command_line*, General_options* options) \
538 options->set_##varname__(invert__); \
539 options->set_user_set_##varname__(); \
542 options::One_option option; \
544 Struct_no_##option__ no_##option__##_initializer_
546 // This is like DEFINE_uint64, but VARNAME is the name of a different
547 // option. This option becomes an alias for that one.
548 #define DEFINE_uint64_alias(option__, varname__, dashes__, shortname__, \
549 helpstring__, helparg__) \
551 struct Struct_##option__ : public options::Struct_var \
553 Struct_##option__() \
554 : option(#option__, dashes__, shortname__, "", helpstring__, \
555 helparg__, false, this, false) \
559 parse_to_value(const char* option_name, const char* arg, \
560 Command_line*, General_options* options) \
563 options::parse_uint64(option_name, arg, &value); \
564 options->set_##varname__(value); \
565 options->set_user_set_##varname__(); \
568 options::One_option option; \
570 Struct_##option__ option__##_;
572 // This is used for non-standard flags. It defines no functions; it
573 // just calls General_options::parse_VARNAME whenever the flag is
574 // seen. We declare parse_VARNAME as a static member of
575 // General_options; you are responsible for defining it there.
576 // helparg__ should be NULL iff this special-option is a boolean.
577 #define DEFINE_special(varname__, dashes__, shortname__, \
578 helpstring__, helparg__) \
580 void parse_##varname__(const char* option, const char* arg, \
581 Command_line* inputs); \
582 struct Struct_##varname__ : public options::Struct_special \
584 Struct_##varname__() \
585 : options::Struct_special(#varname__, dashes__, shortname__, \
586 &General_options::parse_##varname__, \
587 helpstring__, helparg__) \
590 Struct_##varname__ varname__##_initializer_
592 // An option that takes an optional string argument. If the option is
593 // used with no argument, the value will be the default, and
594 // user_set_via_option will be true.
595 #define DEFINE_optional_string(varname__, dashes__, shortname__, \
597 helpstring__, helparg__) \
598 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
599 default_value__, helpstring__, helparg__, true, \
600 const char*, const char*, options::parse_optional_string, \
603 // A directory to search. For each directory we record whether it is
604 // in the sysroot. We need to know this so that, if a linker script
605 // is found within the sysroot, we will apply the sysroot to any files
606 // named by that script.
608 class Search_directory
611 // We need a default constructor because we put this in a
614 : name_(), put_in_sysroot_(false), is_in_sysroot_(false)
617 // This is the usual constructor.
618 Search_directory(const std::string
& name
, bool put_in_sysroot
)
619 : name_(name
), put_in_sysroot_(put_in_sysroot
), is_in_sysroot_(false)
621 if (this->name_
.empty())
625 // This is called if we have a sysroot. The sysroot is prefixed to
626 // any entries for which put_in_sysroot_ is true. is_in_sysroot_ is
627 // set to true for any enries which are in the sysroot (this will
628 // naturally include any entries for which put_in_sysroot_ is true).
629 // SYSROOT is the sysroot, CANONICAL_SYSROOT is the result of
630 // passing SYSROOT to lrealpath.
632 add_sysroot(const char* sysroot
, const char* canonical_sysroot
);
634 // Get the directory name.
637 { return this->name_
; }
639 // Return whether this directory is in the sysroot.
641 is_in_sysroot() const
642 { return this->is_in_sysroot_
; }
644 // Return whether this is considered a system directory.
646 is_system_directory() const
647 { return this->put_in_sysroot_
|| this->is_in_sysroot_
; }
650 // The directory name.
652 // True if the sysroot should be added as a prefix for this
653 // directory (if there is a sysroot). This is true for system
654 // directories that we search by default.
655 bool put_in_sysroot_
;
656 // True if this directory is in the sysroot (if there is a sysroot).
657 // This is true if there is a sysroot and either 1) put_in_sysroot_
658 // is true, or 2) the directory happens to be in the sysroot based
659 // on a pathname comparison.
663 class General_options
666 // NOTE: For every option that you add here, also consider if you
667 // should add it to Position_dependent_options.
668 DEFINE_special(help
, options::TWO_DASHES
, '\0',
669 N_("Report usage information"), NULL
);
670 DEFINE_special(version
, options::TWO_DASHES
, 'v',
671 N_("Report version information"), NULL
);
672 DEFINE_special(V
, options::EXACTLY_ONE_DASH
, '\0',
673 N_("Report version and target information"), NULL
);
675 // These options are sorted approximately so that for each letter in
676 // the alphabet, we show the option whose shortname is that letter
677 // (if any) and then every longname that starts with that letter (in
678 // alphabetical order). For both, lowercase sorts before uppercase.
679 // The -z options come last.
683 DEFINE_bool(add_needed
, options::TWO_DASHES
, '\0', false,
685 N_("Do not copy DT_NEEDED tags from shared libraries"));
687 DEFINE_bool_alias(allow_multiple_definition
, muldefs
, options::TWO_DASHES
,
689 N_("Allow multiple definitions of symbols"),
690 N_("Do not allow multiple definitions"), false);
692 DEFINE_bool(allow_shlib_undefined
, options::TWO_DASHES
, '\0', false,
693 N_("Allow unresolved references in shared libraries"),
694 N_("Do not allow unresolved references in shared libraries"));
696 DEFINE_bool(apply_dynamic_relocs
, options::TWO_DASHES
, '\0', true,
697 N_("Apply link-time values for dynamic relocations"),
698 N_("(aarch64 only) Do not apply link-time values "
699 "for dynamic relocations"));
701 DEFINE_bool(as_needed
, options::TWO_DASHES
, '\0', false,
702 N_("Use DT_NEEDED only for shared libraries that are used"),
703 N_("Use DT_NEEDED for all shared libraries"));
705 DEFINE_enum(assert, options::ONE_DASH
, '\0', NULL
,
706 N_("Ignored"), N_("[ignored]"), false,
707 {"definitions", "nodefinitions", "nosymbolic", "pure-text"});
711 // This should really be an "enum", but it's too easy for folks to
712 // forget to update the list as they add new targets. So we just
713 // accept any string. We'll fail later (when the string is parsed),
714 // if the target isn't actually supported.
715 DEFINE_string(format
, options::TWO_DASHES
, 'b', "elf",
716 N_("Set input format"), ("[elf,binary]"));
718 DEFINE_bool(be8
, options::TWO_DASHES
, '\0', false,
719 N_("Output BE8 format image"), NULL
);
721 DEFINE_optional_string(build_id
, options::TWO_DASHES
, '\0', "tree",
722 N_("Generate build ID note"),
725 DEFINE_uint64(build_id_chunk_size_for_treehash
,
726 options::TWO_DASHES
, '\0', 2 << 20,
727 N_("Chunk size for '--build-id=tree'"), N_("SIZE"));
729 DEFINE_uint64(build_id_min_file_size_for_treehash
, options::TWO_DASHES
,
731 N_("Minimum output file size for '--build-id=tree' to work"
732 " differently than '--build-id=sha1'"), N_("SIZE"));
734 DEFINE_bool(Bdynamic
, options::ONE_DASH
, '\0', true,
735 N_("-l searches for shared libraries"), NULL
);
736 DEFINE_bool_alias(Bstatic
, Bdynamic
, options::ONE_DASH
, '\0',
737 N_("-l does not search for shared libraries"), NULL
,
739 DEFINE_bool_alias(dy
, Bdynamic
, options::ONE_DASH
, '\0',
740 N_("alias for -Bdynamic"), NULL
, false);
741 DEFINE_bool_alias(dn
, Bdynamic
, options::ONE_DASH
, '\0',
742 N_("alias for -Bstatic"), NULL
, true);
744 DEFINE_bool(Bgroup
, options::ONE_DASH
, '\0', false,
745 N_("Use group name lookup rules for shared library"), NULL
);
747 DEFINE_bool(Bshareable
, options::ONE_DASH
, '\0', false,
748 N_("Generate shared library (alias for -G/-shared)"), NULL
);
750 DEFINE_special (Bno_symbolic
, options::ONE_DASH
, '\0',
751 N_ ("Don't bind default visibility defined symbols locally "
752 "for -shared (default)"),
755 DEFINE_special (Bsymbolic_functions
, options::ONE_DASH
, '\0',
756 N_ ("Bind default visibility defined function symbols "
757 "locally for -shared"),
761 Bsymbolic
, options::ONE_DASH
, '\0',
762 N_ ("Bind default visibility defined symbols locally for -shared"),
767 DEFINE_bool(check_sections
, options::TWO_DASHES
, '\0', true,
768 N_("Check segment addresses for overlaps"),
769 N_("Do not check segment addresses for overlaps"));
771 DEFINE_enum(compress_debug_sections
, options::TWO_DASHES
, '\0', "none",
772 N_("Compress .debug_* sections in the output file"),
773 ("[none,zlib,zlib-gnu,zlib-gabi,zstd]"), false,
774 {"none", "zlib", "zlib-gnu", "zlib-gabi", "zstd"});
776 DEFINE_bool(copy_dt_needed_entries
, options::TWO_DASHES
, '\0', false,
778 N_("Do not copy DT_NEEDED tags from shared libraries"));
780 DEFINE_bool(cref
, options::TWO_DASHES
, '\0', false,
781 N_("Output cross reference table"),
782 N_("Do not output cross reference table"));
784 DEFINE_bool(ctors_in_init_array
, options::TWO_DASHES
, '\0', true,
785 N_("Use DT_INIT_ARRAY for all constructors"),
786 N_("Handle constructors as directed by compiler"));
790 DEFINE_bool(define_common
, options::TWO_DASHES
, 'd', false,
791 N_("Define common symbols"),
792 N_("Do not define common symbols in relocatable output"));
793 DEFINE_bool(dc
, options::ONE_DASH
, '\0', false,
794 N_("Alias for -d"), NULL
);
795 DEFINE_bool(dp
, options::ONE_DASH
, '\0', false,
796 N_("Alias for -d"), NULL
);
798 DEFINE_string(debug
, options::TWO_DASHES
, '\0', "",
799 N_("Turn on debugging"),
800 N_("[all,files,script,task][,...]"));
802 DEFINE_special(defsym
, options::TWO_DASHES
, '\0',
803 N_("Define a symbol"), N_("SYMBOL=EXPRESSION"));
805 DEFINE_optional_string(demangle
, options::TWO_DASHES
, '\0', NULL
,
806 N_("Demangle C++ symbols in log messages"),
808 DEFINE_bool(no_demangle
, options::TWO_DASHES
, '\0', false,
809 N_("Do not demangle C++ symbols in log messages"),
812 DEFINE_string(dependency_file
, options::TWO_DASHES
, '\0', NULL
,
813 N_("Write a dependency file listing all files read"),
816 DEFINE_bool(detect_odr_violations
, options::TWO_DASHES
, '\0', false,
817 N_("Look for violations of the C++ One Definition Rule"),
818 N_("Do not look for violations of the C++ One Definition Rule"));
820 DEFINE_bool(dynamic_list_data
, options::TWO_DASHES
, '\0', false,
821 N_("Add data symbols to dynamic symbols"), NULL
);
823 DEFINE_bool(dynamic_list_cpp_new
, options::TWO_DASHES
, '\0', false,
824 N_("Add C++ operator new/delete to dynamic symbols"), NULL
);
826 DEFINE_bool(dynamic_list_cpp_typeinfo
, options::TWO_DASHES
, '\0', false,
827 N_("Add C++ typeinfo to dynamic symbols"), NULL
);
829 DEFINE_special(dynamic_list
, options::TWO_DASHES
, '\0',
830 N_("Read a list of dynamic symbols"), N_("FILE"));
834 DEFINE_bool(emit_stub_syms
, options::TWO_DASHES
, '\0', true,
835 N_("(PowerPC only) Label linker stubs with a symbol"),
836 N_("(PowerPC only) Do not label linker stubs with a symbol"));
838 DEFINE_string(entry
, options::TWO_DASHES
, 'e', NULL
,
839 N_("Set program start address"), N_("ADDRESS"));
841 DEFINE_bool(eh_frame_hdr
, options::TWO_DASHES
, '\0', false,
842 N_("Create exception frame header"),
843 N_("Do not create exception frame header"));
845 // Alphabetized under 'e' because the option is spelled --enable-new-dtags.
846 DEFINE_enable(new_dtags
, options::EXACTLY_TWO_DASHES
, '\0', true,
847 N_("Enable use of DT_RUNPATH"),
848 N_("Disable use of DT_RUNPATH"));
850 DEFINE_enable(linker_version
, options::EXACTLY_TWO_DASHES
, '\0', false,
851 N_("Put the linker version string into the .comment section"),
852 N_("Put the linker version string into the .note.gnu.gold-version section"));
854 DEFINE_bool(enum_size_warning
, options::TWO_DASHES
, '\0', true, NULL
,
855 N_("(ARM only) Do not warn about objects with incompatible "
858 DEFINE_special(exclude_libs
, options::TWO_DASHES
, '\0',
859 N_("Exclude libraries from automatic export"),
860 N_(("lib,lib ...")));
862 DEFINE_bool(export_dynamic
, options::TWO_DASHES
, 'E', false,
863 N_("Export all dynamic symbols"),
864 N_("Do not export all dynamic symbols"));
866 DEFINE_set(export_dynamic_symbol
, options::TWO_DASHES
, '\0',
867 N_("Export SYMBOL to dynamic symbol table"), N_("SYMBOL"));
869 DEFINE_special(EB
, options::ONE_DASH
, '\0',
870 N_("Link big-endian objects."), NULL
);
871 DEFINE_special(EL
, options::ONE_DASH
, '\0',
872 N_("Link little-endian objects."), NULL
);
876 DEFINE_set(auxiliary
, options::TWO_DASHES
, 'f',
877 N_("Auxiliary filter for shared object symbol table"),
880 DEFINE_string(filter
, options::TWO_DASHES
, 'F', NULL
,
881 N_("Filter for shared object symbol table"),
884 DEFINE_bool(fatal_warnings
, options::TWO_DASHES
, '\0', false,
885 N_("Treat warnings as errors"),
886 N_("Do not treat warnings as errors"));
888 DEFINE_string(fini
, options::ONE_DASH
, '\0', "_fini",
889 N_("Call SYMBOL at unload-time"), N_("SYMBOL"));
891 DEFINE_bool(fix_arm1176
, options::TWO_DASHES
, '\0', true,
892 N_("(ARM only) Fix binaries for ARM1176 erratum"),
893 N_("(ARM only) Do not fix binaries for ARM1176 erratum"));
895 DEFINE_bool(fix_cortex_a8
, options::TWO_DASHES
, '\0', false,
896 N_("(ARM only) Fix binaries for Cortex-A8 erratum"),
897 N_("(ARM only) Do not fix binaries for Cortex-A8 erratum"));
899 DEFINE_bool(fix_cortex_a53_843419
, options::TWO_DASHES
, '\0', false,
900 N_("(AArch64 only) Fix Cortex-A53 erratum 843419"),
901 N_("(AArch64 only) Do not fix Cortex-A53 erratum 843419"));
903 DEFINE_bool(fix_cortex_a53_835769
, options::TWO_DASHES
, '\0', false,
904 N_("(AArch64 only) Fix Cortex-A53 erratum 835769"),
905 N_("(AArch64 only) Do not fix Cortex-A53 erratum 835769"));
907 DEFINE_special(fix_v4bx
, options::TWO_DASHES
, '\0',
908 N_("(ARM only) Rewrite BX rn as MOV pc, rn for ARMv4"),
911 DEFINE_special(fix_v4bx_interworking
, options::TWO_DASHES
, '\0',
912 N_("(ARM only) Rewrite BX rn branch to ARMv4 interworking "
916 DEFINE_string(fuse_ld
, options::ONE_DASH
, '\0', "",
917 N_("Ignored for GCC linker option compatibility"),
922 DEFINE_bool(g
, options::EXACTLY_ONE_DASH
, '\0', false,
923 N_("Ignored"), NULL
);
925 DEFINE_bool(gc_sections
, options::TWO_DASHES
, '\0', false,
926 N_("Remove unused sections"),
927 N_("Don't remove unused sections"));
929 DEFINE_bool(gdb_index
, options::TWO_DASHES
, '\0', false,
930 N_("Generate .gdb_index section"),
931 N_("Do not generate .gdb_index section"));
933 DEFINE_bool(gnu_unique
, options::TWO_DASHES
, '\0', true,
934 N_("Enable STB_GNU_UNIQUE symbol binding"),
935 N_("Disable STB_GNU_UNIQUE symbol binding"));
937 DEFINE_bool(shared
, options::ONE_DASH
, 'G', false,
938 N_("Generate shared library"), NULL
);
942 DEFINE_string(soname
, options::ONE_DASH
, 'h', NULL
,
943 N_("Set shared library name"), N_("FILENAME"));
945 DEFINE_double(hash_bucket_empty_fraction
, options::TWO_DASHES
, '\0', 0.0,
946 N_("Min fraction of empty buckets in dynamic hash"),
949 DEFINE_enum(hash_style
, options::TWO_DASHES
, '\0', DEFAULT_HASH_STYLE
,
950 N_("Dynamic hash style"), N_("[sysv,gnu,both]"), false,
951 {"sysv", "gnu", "both"});
955 DEFINE_bool_alias(i
, relocatable
, options::EXACTLY_ONE_DASH
, '\0',
956 N_("Alias for -r"), NULL
, false);
958 DEFINE_enum(icf
, options::TWO_DASHES
, '\0', "none",
959 N_("Identical Code Folding. "
960 "\'--icf=safe\' Folds ctors, dtors and functions whose"
961 " pointers are definitely not taken"),
962 ("[none,all,safe]"), false,
963 {"none", "all", "safe"});
965 DEFINE_uint(icf_iterations
, options::TWO_DASHES
, '\0', 0,
966 N_("Number of iterations of ICF (default 3)"), N_("COUNT"));
968 DEFINE_special(incremental
, options::TWO_DASHES
, '\0',
969 N_("Do an incremental link if possible; "
970 "otherwise, do a full link and prepare output "
971 "for incremental linking"), NULL
);
973 DEFINE_special(no_incremental
, options::TWO_DASHES
, '\0',
974 N_("Do a full link (default)"), NULL
);
976 DEFINE_special(incremental_full
, options::TWO_DASHES
, '\0',
977 N_("Do a full link and "
978 "prepare output for incremental linking"), NULL
);
980 DEFINE_special(incremental_update
, options::TWO_DASHES
, '\0',
981 N_("Do an incremental link; exit if not possible"), NULL
);
983 DEFINE_string(incremental_base
, options::TWO_DASHES
, '\0', NULL
,
984 N_("Set base file for incremental linking"
985 " (default is output file)"),
988 DEFINE_special(incremental_changed
, options::TWO_DASHES
, '\0',
989 N_("Assume files changed"), NULL
);
991 DEFINE_special(incremental_unchanged
, options::TWO_DASHES
, '\0',
992 N_("Assume files didn't change"), NULL
);
994 DEFINE_special(incremental_unknown
, options::TWO_DASHES
, '\0',
995 N_("Use timestamps to check files (default)"), NULL
);
997 DEFINE_special(incremental_startup_unchanged
, options::TWO_DASHES
, '\0',
998 N_("Assume startup files unchanged "
999 "(files preceding this option)"), NULL
);
1001 DEFINE_percent(incremental_patch
, options::TWO_DASHES
, '\0', 10,
1002 N_("Amount of extra space to allocate for patches "
1006 DEFINE_string(init
, options::ONE_DASH
, '\0', "_init",
1007 N_("Call SYMBOL at load-time"), N_("SYMBOL"));
1009 DEFINE_string(dynamic_linker
, options::TWO_DASHES
, 'I', NULL
,
1010 N_("Set dynamic linker path"), N_("PROGRAM"));
1014 DEFINE_special(just_symbols
, options::TWO_DASHES
, '\0',
1015 N_("Read only symbol values from FILE"), N_("FILE"));
1019 DEFINE_bool(keep_files_mapped
, options::TWO_DASHES
, '\0', true,
1020 N_("Keep files mapped across passes"),
1021 N_("Release mapped files after each pass"));
1023 DEFINE_set(keep_unique
, options::TWO_DASHES
, '\0',
1024 N_("Do not fold this symbol during ICF"), N_("SYMBOL"));
1028 DEFINE_special(library
, options::TWO_DASHES
, 'l',
1029 N_("Search for library LIBNAME"), N_("LIBNAME"));
1031 DEFINE_bool(ld_generated_unwind_info
, options::TWO_DASHES
, '\0', true,
1032 N_("Generate unwind information for PLT"),
1033 N_("Do not generate unwind information for PLT"));
1035 DEFINE_dirlist(library_path
, options::TWO_DASHES
, 'L',
1036 N_("Add directory to search path"), N_("DIR"));
1038 DEFINE_bool(long_plt
, options::TWO_DASHES
, '\0', false,
1039 N_("(ARM only) Generate long PLT entries"),
1040 N_("(ARM only) Do not generate long PLT entries"));
1044 DEFINE_string(m
, options::EXACTLY_ONE_DASH
, 'm', "",
1045 N_("Set GNU linker emulation; obsolete"), N_("EMULATION"));
1047 DEFINE_bool(map_whole_files
, options::TWO_DASHES
, '\0',
1049 N_("Map whole files to memory"),
1050 N_("Map relevant file parts to memory"));
1052 DEFINE_bool(merge_exidx_entries
, options::TWO_DASHES
, '\0', true,
1053 N_("(ARM only) Merge exidx entries in debuginfo"),
1054 N_("(ARM only) Do not merge exidx entries in debuginfo"));
1056 DEFINE_bool(mmap_output_file
, options::TWO_DASHES
, '\0', true,
1057 N_("Map the output file for writing"),
1058 N_("Do not map the output file for writing"));
1060 DEFINE_bool(print_map
, options::TWO_DASHES
, 'M', false,
1061 N_("Write map file on standard output"), NULL
);
1063 DEFINE_string(Map
, options::ONE_DASH
, '\0', NULL
, N_("Write map file"),
1068 DEFINE_bool(nmagic
, options::TWO_DASHES
, 'n', false,
1069 N_("Do not page align data"), NULL
);
1070 DEFINE_bool(omagic
, options::EXACTLY_TWO_DASHES
, 'N', false,
1071 N_("Do not page align data, do not make text readonly"),
1072 N_("Page align data, make text readonly"));
1074 DEFINE_bool(no_keep_memory
, options::TWO_DASHES
, '\0', false,
1075 N_("Use less memory and more disk I/O "
1076 "(included only for compatibility with GNU ld)"), NULL
);
1078 DEFINE_bool_alias(no_undefined
, defs
, options::TWO_DASHES
, '\0',
1079 N_("Report undefined symbols (even with --shared)"),
1082 DEFINE_bool(noinhibit_exec
, options::TWO_DASHES
, '\0', false,
1083 N_("Create an output file even if errors occur"), NULL
);
1085 DEFINE_bool(nostdlib
, options::ONE_DASH
, '\0', false,
1086 N_("Only search directories specified on the command line"),
1091 DEFINE_string(output
, options::TWO_DASHES
, 'o', "a.out",
1092 N_("Set output file name"), N_("FILE"));
1094 DEFINE_string(oformat
, options::EXACTLY_TWO_DASHES
, '\0', "elf",
1095 N_("Set output format"), N_("[binary]"));
1097 DEFINE_uint(optimize
, options::EXACTLY_ONE_DASH
, 'O', 0,
1098 N_("Optimize output file size"), N_("LEVEL"));
1100 DEFINE_enum(orphan_handling
, options::TWO_DASHES
, '\0', "place",
1101 N_("Orphan section handling"), N_("[place,discard,warn,error]"),
1102 false, {"place", "discard", "warn", "error"});
1106 DEFINE_bool(p
, options::ONE_DASH
, 'p', false,
1107 N_("Ignored for ARM compatibility"), NULL
);
1109 DEFINE_optional_string(package_metadata
, options::TWO_DASHES
, '\0', NULL
,
1110 N_("Generate package metadata note"),
1113 DEFINE_bool(pie
, options::ONE_DASH
, '\0', false,
1114 N_("Create a position independent executable"),
1115 N_("Do not create a position independent executable"));
1116 DEFINE_bool_alias(pic_executable
, pie
, options::TWO_DASHES
, '\0',
1117 N_("Create a position independent executable"),
1118 N_("Do not create a position independent executable"),
1121 DEFINE_bool(pic_veneer
, options::TWO_DASHES
, '\0', false,
1122 N_("Force PIC sequences for ARM/Thumb interworking veneers"),
1125 DEFINE_bool(pipeline_knowledge
, options::ONE_DASH
, '\0', false,
1126 NULL
, N_("(ARM only) Ignore for backward compatibility"));
1128 DEFINE_var(plt_align
, options::TWO_DASHES
, '\0', 0, "5",
1129 N_("(PowerPC only) Align PLT call stubs to fit cache lines"),
1130 N_("[=P2ALIGN]"), true, int, int, options::parse_uint
, false);
1132 DEFINE_bool(plt_localentry
, options::TWO_DASHES
, '\0', false,
1133 N_("(PowerPC64 only) Optimize calls to ELFv2 localentry:0 functions"),
1134 N_("(PowerPC64 only) Don't optimize ELFv2 calls"));
1136 DEFINE_bool(plt_static_chain
, options::TWO_DASHES
, '\0', false,
1137 N_("(PowerPC64 only) PLT call stubs should load r11"),
1138 N_("(PowerPC64 only) PLT call stubs should not load r11"));
1140 DEFINE_bool(plt_thread_safe
, options::TWO_DASHES
, '\0', false,
1141 N_("(PowerPC64 only) PLT call stubs with load-load barrier"),
1142 N_("(PowerPC64 only) PLT call stubs without barrier"));
1144 #ifdef ENABLE_PLUGINS
1145 DEFINE_special(plugin
, options::TWO_DASHES
, '\0',
1146 N_("Load a plugin library"), N_("PLUGIN"));
1147 DEFINE_special(plugin_opt
, options::TWO_DASHES
, '\0',
1148 N_("Pass an option to the plugin"), N_("OPTION"));
1150 DEFINE_special(plugin
, options::TWO_DASHES
, '\0',
1151 N_("Load a plugin library (not supported)"), N_("PLUGIN"));
1152 DEFINE_special(plugin_opt
, options::TWO_DASHES
, '\0',
1153 N_("Pass an option to the plugin (not supported)"),
1157 DEFINE_bool(posix_fallocate
, options::TWO_DASHES
, '\0', true,
1158 N_("Use posix_fallocate to reserve space in the output file"),
1159 N_("Use fallocate or ftruncate to reserve space"));
1161 DEFINE_enum(power10_stubs
, options::TWO_DASHES
, '\0', "yes",
1162 N_("(PowerPC64 only) stubs use power10 insns"),
1163 N_("[=auto,no,yes]"), true, {"auto", "no", "yes"});
1164 DEFINE_special(no_power10_stubs
, options::TWO_DASHES
, '\0',
1165 N_("(PowerPC64 only) stubs do not use power10 insns"), NULL
);
1167 DEFINE_bool(preread_archive_symbols
, options::TWO_DASHES
, '\0', false,
1168 N_("Preread archive symbols when multi-threaded"), NULL
);
1170 DEFINE_bool(print_gc_sections
, options::TWO_DASHES
, '\0', false,
1171 N_("List removed unused sections on stderr"),
1172 N_("Do not list removed unused sections"));
1174 DEFINE_bool(print_icf_sections
, options::TWO_DASHES
, '\0', false,
1175 N_("List folded identical sections on stderr"),
1176 N_("Do not list folded identical sections"));
1178 DEFINE_bool(print_output_format
, options::TWO_DASHES
, '\0', false,
1179 N_("Print default output format"), NULL
);
1181 DEFINE_string(print_symbol_counts
, options::TWO_DASHES
, '\0', NULL
,
1182 N_("Print symbols defined and used for each input"),
1185 DEFINE_special(push_state
, options::TWO_DASHES
, '\0',
1186 N_("Save the state of flags related to input files"), NULL
);
1187 DEFINE_special(pop_state
, options::TWO_DASHES
, '\0',
1188 N_("Restore the state of flags related to input files"), NULL
);
1192 DEFINE_bool(emit_relocs
, options::TWO_DASHES
, 'q', false,
1193 N_("Generate relocations in output"), NULL
);
1195 DEFINE_bool(Qy
, options::EXACTLY_ONE_DASH
, '\0', false,
1196 N_("Ignored for SVR4 compatibility"), NULL
);
1200 DEFINE_bool(relocatable
, options::EXACTLY_ONE_DASH
, 'r', false,
1201 N_("Generate relocatable output"), NULL
);
1203 DEFINE_bool(relax
, options::TWO_DASHES
, '\0', false,
1204 N_("Relax branches on certain targets"),
1205 N_("Do not relax branches"));
1207 DEFINE_string(retain_symbols_file
, options::TWO_DASHES
, '\0', NULL
,
1208 N_("keep only symbols listed in this file"), N_("FILE"));
1210 DEFINE_bool(rosegment
, options::TWO_DASHES
, '\0', false,
1211 N_("Put read-only non-executable sections in their own segment"),
1212 N_("Do not put read-only non-executable sections in their own segment"));
1214 DEFINE_uint64(rosegment_gap
, options::TWO_DASHES
, '\0', -1U,
1215 N_("Set offset between executable and read-only segments"),
1218 // -R really means -rpath, but can mean --just-symbols for
1219 // compatibility with GNU ld. -rpath is always -rpath, so we list
1221 DEFINE_special(R
, options::EXACTLY_ONE_DASH
, 'R',
1222 N_("Add DIR to runtime search path"), N_("DIR"));
1224 DEFINE_dirlist(rpath
, options::ONE_DASH
, '\0',
1225 N_("Add DIR to runtime search path"), N_("DIR"));
1227 DEFINE_dirlist(rpath_link
, options::TWO_DASHES
, '\0',
1228 N_("Add DIR to link time shared library search path"),
1233 DEFINE_bool(strip_all
, options::TWO_DASHES
, 's', false,
1234 N_("Strip all symbols"), NULL
);
1235 DEFINE_bool(strip_debug
, options::TWO_DASHES
, 'S', false,
1236 N_("Strip debugging information"), NULL
);
1237 DEFINE_bool(strip_debug_non_line
, options::TWO_DASHES
, '\0', false,
1238 N_("Emit only debug line number information"), NULL
);
1239 DEFINE_bool(strip_debug_gdb
, options::TWO_DASHES
, '\0', false,
1240 N_("Strip debug symbols that are unused by gdb "
1241 "(at least versions <= 7.4)"), NULL
);
1242 DEFINE_bool(strip_lto_sections
, options::TWO_DASHES
, '\0', true,
1243 N_("Strip LTO intermediate code sections"), NULL
);
1245 DEFINE_string(section_ordering_file
, options::TWO_DASHES
, '\0', NULL
,
1246 N_("Layout sections in the order specified"),
1249 DEFINE_special(section_start
, options::TWO_DASHES
, '\0',
1250 N_("Set address of section"), N_("SECTION=ADDRESS"));
1252 DEFINE_bool(secure_plt
, options::TWO_DASHES
, '\0', true,
1253 N_("(PowerPC only) Use new-style PLT"), NULL
);
1255 DEFINE_optional_string(sort_common
, options::TWO_DASHES
, '\0', NULL
,
1256 N_("Sort common symbols by alignment"),
1257 N_("[={ascending,descending}]"));
1259 DEFINE_enum(sort_section
, options::TWO_DASHES
, '\0', "none",
1260 N_("Sort sections by name. \'--no-text-reorder\'"
1261 " will override \'--sort-section=name\' for .text"),
1262 N_("[none,name]"), false,
1265 DEFINE_uint(spare_dynamic_tags
, options::TWO_DASHES
, '\0', 5,
1266 N_("Dynamic tag slots to reserve (default 5)"),
1269 DEFINE_int(stub_group_size
, options::TWO_DASHES
, '\0', 1,
1270 N_("(ARM, PowerPC only) The maximum distance from instructions "
1271 "in a group of sections to their stubs. Negative values mean "
1272 "stubs are always after the group. 1 means use default size"),
1275 DEFINE_bool(stub_group_multi
, options::TWO_DASHES
, '\0', true,
1276 N_("(PowerPC only) Allow a group of stubs to serve multiple "
1278 N_("(PowerPC only) Each output section has its own stubs"));
1280 DEFINE_uint(split_stack_adjust_size
, options::TWO_DASHES
, '\0', 0x100000,
1281 N_("Stack size when -fsplit-stack function calls non-split"),
1284 // This is not actually special in any way, but I need to give it
1285 // a non-standard accessor-function name because 'static' is a keyword.
1286 DEFINE_special(static, options::ONE_DASH
, '\0',
1287 N_("Do not link against shared libraries"), NULL
);
1289 DEFINE_special(start_lib
, options::TWO_DASHES
, '\0',
1290 N_("Start a library"), NULL
);
1291 DEFINE_special(end_lib
, options::TWO_DASHES
, '\0',
1292 N_("End a library "), NULL
);
1294 DEFINE_bool(stats
, options::TWO_DASHES
, '\0', false,
1295 N_("Print resource usage statistics"), NULL
);
1297 DEFINE_string(sysroot
, options::TWO_DASHES
, '\0', "",
1298 N_("Set target system root directory"), N_("DIR"));
1302 DEFINE_bool(trace
, options::TWO_DASHES
, 't', false,
1303 N_("Print the name of each input file"), NULL
);
1305 DEFINE_bool(target1_abs
, options::TWO_DASHES
, '\0', false,
1306 N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_ABS32"),
1308 DEFINE_bool(target1_rel
, options::TWO_DASHES
, '\0', false,
1309 N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_REL32"),
1311 DEFINE_enum(target2
, options::TWO_DASHES
, '\0', NULL
,
1312 N_("(ARM only) Set R_ARM_TARGET2 relocation type"),
1313 N_("[rel, abs, got-rel"), false,
1314 {"rel", "abs", "got-rel"});
1316 DEFINE_bool(text_reorder
, options::TWO_DASHES
, '\0', true,
1317 N_("Enable text section reordering for GCC section names"),
1318 N_("Disable text section reordering for GCC section names"));
1320 DEFINE_bool(threads
, options::TWO_DASHES
, '\0', false,
1321 N_("Run the linker multi-threaded"),
1322 N_("Do not run the linker multi-threaded"));
1323 DEFINE_uint(thread_count
, options::TWO_DASHES
, '\0', 0,
1324 N_("Number of threads to use"), N_("COUNT"));
1325 DEFINE_uint(thread_count_initial
, options::TWO_DASHES
, '\0', 0,
1326 N_("Number of threads to use in initial pass"), N_("COUNT"));
1327 DEFINE_uint(thread_count_middle
, options::TWO_DASHES
, '\0', 0,
1328 N_("Number of threads to use in middle pass"), N_("COUNT"));
1329 DEFINE_uint(thread_count_final
, options::TWO_DASHES
, '\0', 0,
1330 N_("Number of threads to use in final pass"), N_("COUNT"));
1332 DEFINE_bool(tls_optimize
, options::TWO_DASHES
, '\0', true,
1333 N_("(PowerPC/64 only) Optimize GD/LD/IE code to IE/LE"),
1334 N_("(PowerPC/64 only) Don'\''t try to optimize TLS accesses"));
1335 DEFINE_bool(tls_get_addr_optimize
, options::TWO_DASHES
, '\0', true,
1336 N_("(PowerPC/64 only) Use a special __tls_get_addr call"),
1337 N_("(PowerPC/64 only) Don't use a special __tls_get_addr call"));
1339 DEFINE_bool(toc_optimize
, options::TWO_DASHES
, '\0', true,
1340 N_("(PowerPC64 only) Optimize TOC code sequences"),
1341 N_("(PowerPC64 only) Don't optimize TOC code sequences"));
1343 DEFINE_bool(toc_sort
, options::TWO_DASHES
, '\0', true,
1344 N_("(PowerPC64 only) Sort TOC and GOT sections"),
1345 N_("(PowerPC64 only) Don't sort TOC and GOT sections"));
1347 DEFINE_special(script
, options::TWO_DASHES
, 'T',
1348 N_("Read linker script"), N_("FILE"));
1350 DEFINE_uint64(Tbss
, options::ONE_DASH
, '\0', -1U,
1351 N_("Set the address of the bss segment"), N_("ADDRESS"));
1352 DEFINE_uint64(Tdata
, options::ONE_DASH
, '\0', -1U,
1353 N_("Set the address of the data segment"), N_("ADDRESS"));
1354 DEFINE_uint64(Ttext
, options::ONE_DASH
, '\0', -1U,
1355 N_("Set the address of the text segment"), N_("ADDRESS"));
1356 DEFINE_uint64_alias(Ttext_segment
, Ttext
, options::ONE_DASH
, '\0',
1357 N_("Set the address of the text segment"),
1359 DEFINE_uint64(Trodata_segment
, options::ONE_DASH
, '\0', -1U,
1360 N_("Set the address of the rodata segment"), N_("ADDRESS"));
1364 DEFINE_set(undefined
, options::TWO_DASHES
, 'u',
1365 N_("Create undefined reference to SYMBOL"), N_("SYMBOL"));
1367 DEFINE_enum(unresolved_symbols
, options::TWO_DASHES
, '\0', NULL
,
1368 N_("How to handle unresolved symbols"),
1369 ("ignore-all,report-all,ignore-in-object-files,"
1370 "ignore-in-shared-libs"), false,
1371 {"ignore-all", "report-all", "ignore-in-object-files",
1372 "ignore-in-shared-libs"});
1376 DEFINE_bool(verbose
, options::TWO_DASHES
, '\0', false,
1377 N_("Alias for --debug=files"), NULL
);
1379 DEFINE_special(version_script
, options::TWO_DASHES
, '\0',
1380 N_("Read version script"), N_("FILE"));
1384 DEFINE_bool(warn_common
, options::TWO_DASHES
, '\0', false,
1385 N_("Warn about duplicate common symbols"),
1386 N_("Do not warn about duplicate common symbols"));
1388 DEFINE_bool_ignore(warn_constructors
, options::TWO_DASHES
, '\0',
1389 N_("Ignored"), N_("Ignored"));
1391 DEFINE_bool(warn_drop_version
, options::TWO_DASHES
, '\0', false,
1392 N_("Warn when discarding version information"),
1393 N_("Do not warn when discarding version information"));
1395 DEFINE_bool(warn_execstack
, options::TWO_DASHES
, '\0', false,
1396 N_("Warn if the stack is executable"),
1397 N_("Do not warn if the stack is executable"));
1399 DEFINE_bool(warn_mismatch
, options::TWO_DASHES
, '\0', true,
1400 NULL
, N_("Don't warn about mismatched input files"));
1402 DEFINE_bool(warn_multiple_gp
, options::TWO_DASHES
, '\0', false,
1403 N_("Ignored"), NULL
);
1405 DEFINE_bool(warn_search_mismatch
, options::TWO_DASHES
, '\0', true,
1406 N_("Warn when skipping an incompatible library"),
1407 N_("Don't warn when skipping an incompatible library"));
1409 DEFINE_bool(warn_shared_textrel
, options::TWO_DASHES
, '\0', false,
1410 N_("Warn if text segment is not shareable"),
1411 N_("Do not warn if text segment is not shareable"));
1413 DEFINE_bool(warn_unresolved_symbols
, options::TWO_DASHES
, '\0', false,
1414 N_("Report unresolved symbols as warnings"),
1416 DEFINE_bool_alias(error_unresolved_symbols
, warn_unresolved_symbols
,
1417 options::TWO_DASHES
, '\0',
1418 N_("Report unresolved symbols as errors"),
1421 DEFINE_bool(wchar_size_warning
, options::TWO_DASHES
, '\0', true, NULL
,
1422 N_("(ARM only) Do not warn about objects with incompatible "
1425 DEFINE_bool(weak_unresolved_symbols
, options::TWO_DASHES
, '\0', false,
1426 N_("Convert unresolved symbols to weak references"),
1429 DEFINE_bool(whole_archive
, options::TWO_DASHES
, '\0', false,
1430 N_("Include all archive contents"),
1431 N_("Include only needed archive contents"));
1433 DEFINE_set(wrap
, options::TWO_DASHES
, '\0',
1434 N_("Use wrapper functions for SYMBOL"), N_("SYMBOL"));
1438 DEFINE_special(discard_all
, options::TWO_DASHES
, 'x',
1439 N_("Delete all local symbols"), NULL
);
1440 DEFINE_special(discard_locals
, options::TWO_DASHES
, 'X',
1441 N_("Delete all temporary local symbols"), NULL
);
1442 DEFINE_special(discard_none
, options::TWO_DASHES
, '\0',
1443 N_("Keep all local symbols"), NULL
);
1447 DEFINE_set(trace_symbol
, options::TWO_DASHES
, 'y',
1448 N_("Trace references to symbol"), N_("SYMBOL"));
1450 DEFINE_bool(undefined_version
, options::TWO_DASHES
, '\0', true,
1451 N_("Allow unused version in script"),
1452 N_("Do not allow unused version in script"));
1454 DEFINE_string(Y
, options::EXACTLY_ONE_DASH
, 'Y', "",
1455 N_("Default search path for Solaris compatibility"),
1458 // special characters
1460 DEFINE_special(start_group
, options::TWO_DASHES
, '(',
1461 N_("Start a library search group"), NULL
);
1462 DEFINE_special(end_group
, options::TWO_DASHES
, ')',
1463 N_("End a library search group"), NULL
);
1467 DEFINE_bool(combreloc
, options::DASH_Z
, '\0', true,
1468 N_("Sort dynamic relocs"),
1469 N_("Do not sort dynamic relocs"));
1470 DEFINE_uint64(common_page_size
, options::DASH_Z
, '\0', 0,
1471 N_("Set common page size to SIZE"), N_("SIZE"));
1472 DEFINE_bool(defs
, options::DASH_Z
, '\0', false,
1473 N_("Report undefined symbols (even with --shared)"),
1475 DEFINE_bool(execstack
, options::DASH_Z
, '\0', false,
1476 N_("Mark output as requiring executable stack"), NULL
);
1477 DEFINE_bool(global
, options::DASH_Z
, '\0', false,
1478 N_("Make symbols in DSO available for subsequently loaded "
1480 DEFINE_bool(initfirst
, options::DASH_Z
, '\0', false,
1481 N_("Mark DSO to be initialized first at runtime"),
1483 DEFINE_bool(interpose
, options::DASH_Z
, '\0', false,
1484 N_("Mark object to interpose all DSOs but executable"),
1486 DEFINE_bool(unique
, options::DASH_Z
, '\0', false,
1487 N_("Mark DSO to be loaded at most once, and only in the main namespace"),
1488 N_("Do not mark the DSO as one to be loaded only in the main namespace"));
1489 DEFINE_bool_alias(lazy
, now
, options::DASH_Z
, '\0',
1490 N_("Mark object for lazy runtime binding"),
1492 DEFINE_bool(loadfltr
, options::DASH_Z
, '\0', false,
1493 N_("Mark object requiring immediate process"),
1495 DEFINE_uint64(max_page_size
, options::DASH_Z
, '\0', 0,
1496 N_("Set maximum page size to SIZE"), N_("SIZE"));
1497 DEFINE_bool(muldefs
, options::DASH_Z
, '\0', false,
1498 N_("Allow multiple definitions of symbols"),
1500 // copyreloc is here in the list because there is only -z
1501 // nocopyreloc, not -z copyreloc.
1502 DEFINE_bool(copyreloc
, options::DASH_Z
, '\0', true,
1504 N_("Do not create copy relocs"));
1505 DEFINE_bool(nodefaultlib
, options::DASH_Z
, '\0', false,
1506 N_("Mark object not to use default search paths"),
1508 DEFINE_bool(nodelete
, options::DASH_Z
, '\0', false,
1509 N_("Mark DSO non-deletable at runtime"),
1511 DEFINE_bool(nodlopen
, options::DASH_Z
, '\0', false,
1512 N_("Mark DSO not available to dlopen"),
1514 DEFINE_bool(nodump
, options::DASH_Z
, '\0', false,
1515 N_("Mark DSO not available to dldump"),
1517 DEFINE_bool(noexecstack
, options::DASH_Z
, '\0', false,
1518 N_("Mark output as not requiring executable stack"), NULL
);
1519 DEFINE_bool(now
, options::DASH_Z
, '\0', false,
1520 N_("Mark object for immediate function binding"),
1522 DEFINE_bool(origin
, options::DASH_Z
, '\0', false,
1523 N_("Mark DSO to indicate that needs immediate $ORIGIN "
1524 "processing at runtime"), NULL
);
1525 DEFINE_bool(relro
, options::DASH_Z
, '\0', DEFAULT_LD_Z_RELRO
,
1526 N_("Where possible mark variables read-only after relocation"),
1527 N_("Don't mark variables read-only after relocation"));
1528 DEFINE_uint64(stack_size
, options::DASH_Z
, '\0', 0,
1529 N_("Set PT_GNU_STACK segment p_memsz to SIZE"), N_("SIZE"));
1530 DEFINE_enum(start_stop_visibility
, options::DASH_Z
, '\0', "protected",
1531 N_("ELF symbol visibility for synthesized "
1532 "__start_* and __stop_* symbols"),
1533 ("[default,internal,hidden,protected]"), false,
1534 {"default", "internal", "hidden", "protected"});
1535 DEFINE_bool(text
, options::DASH_Z
, '\0', false,
1536 N_("Do not permit relocations in read-only segments"),
1537 N_("Permit relocations in read-only segments"));
1538 DEFINE_bool_alias(textoff
, text
, options::DASH_Z
, '\0',
1539 N_("Permit relocations in read-only segments"),
1541 DEFINE_bool(text_unlikely_segment
, options::DASH_Z
, '\0', false,
1542 N_("Move .text.unlikely sections to a separate segment."),
1543 N_("Do not move .text.unlikely sections to a separate "
1545 DEFINE_bool(keep_text_section_prefix
, options::DASH_Z
, '\0', false,
1546 N_("Keep .text.hot, .text.startup, .text.exit and .text.unlikely "
1547 "as separate sections in the final binary."),
1548 N_("Merge all .text.* prefix sections."));
1552 typedef options::Dir_list Dir_list
;
1556 // Does post-processing on flags, making sure they all have
1557 // non-conflicting values. Also converts some flags from their
1558 // "standard" types (string, etc), to another type (enum, DirList),
1559 // which can be accessed via a separate method. Dies if it notices
1563 // True if we printed the version information.
1565 printed_version() const
1566 { return this->printed_version_
; }
1568 // The macro defines output() (based on --output), but that's a
1569 // generic name. Provide this alternative name, which is clearer.
1571 output_file_name() const
1572 { return this->output(); }
1574 // This is not defined via a flag, but combines flags to say whether
1575 // the output is position-independent or not.
1577 output_is_position_independent() const
1578 { return this->shared() || this->pie(); }
1580 // Return true if the output is something that can be exec()ed, such
1581 // as a static executable, or a position-dependent or
1582 // position-independent executable, but not a dynamic library or an
1585 output_is_executable() const
1586 { return !this->shared() && !this->relocatable(); }
1588 // This would normally be static(), and defined automatically, but
1589 // since static is a keyword, we need to come up with our own name.
1594 // In addition to getting the input and output formats as a string
1595 // (via format() and oformat()), we also give access as an enum.
1600 // Straight binary format.
1601 OBJECT_FORMAT_BINARY
1604 // Convert a string to an Object_format. Gives an error if the
1605 // string is not recognized.
1606 static Object_format
1607 string_to_object_format(const char* arg
);
1609 // Convert an Object_format to string.
1611 object_format_to_string(Object_format
);
1613 // Note: these functions are not very fast.
1614 Object_format
format_enum() const;
1615 Object_format
oformat_enum() const;
1617 // Return whether FILENAME is in a system directory.
1619 is_in_system_directory(const std::string
& name
) const;
1621 // RETURN whether SYMBOL_NAME should be kept, according to symbols_to_retain_.
1623 should_retain_symbol(const char* symbol_name
) const
1625 if (symbols_to_retain_
.empty()) // means flag wasn't specified
1627 return symbols_to_retain_
.find(symbol_name
) != symbols_to_retain_
.end();
1630 // These are the best way to get access to the execstack state,
1631 // not execstack() and noexecstack() which are hard to use properly.
1633 is_execstack_set() const
1634 { return this->execstack_status_
!= EXECSTACK_FROM_INPUT
; }
1637 is_stack_executable() const
1638 { return this->execstack_status_
== EXECSTACK_YES
; }
1642 { return this->icf_status_
!= ICF_NONE
; }
1645 icf_safe_folding() const
1646 { return this->icf_status_
== ICF_SAFE
; }
1648 // The --demangle option takes an optional string, and there is also
1649 // a --no-demangle option. This is the best way to decide whether
1650 // to demangle or not.
1653 { return this->do_demangle_
; }
1655 // Returns TRUE if any plugin libraries have been loaded.
1658 { return this->plugins_
!= NULL
; }
1660 // Return a pointer to the plugin manager.
1663 { return this->plugins_
; }
1665 // True iff SYMBOL was found in the file specified by dynamic-list.
1667 in_dynamic_list(const char* symbol
) const
1668 { return this->dynamic_list_
.version_script_info()->symbol_is_local(symbol
); }
1670 // True if a --dynamic-list script was provided.
1672 have_dynamic_list() const
1673 { return this->have_dynamic_list_
; }
1675 // Finalize the dynamic list.
1677 finalize_dynamic_list()
1678 { this->dynamic_list_
.version_script_info()->finalize(); }
1680 // The mode selected by the --incremental options.
1681 enum Incremental_mode
1683 // No incremental linking (--no-incremental).
1685 // Incremental update only (--incremental-update).
1687 // Force a full link, but prepare for subsequent incremental link
1688 // (--incremental-full).
1690 // Incremental update if possible, fallback to full link (--incremental).
1694 // The incremental linking mode.
1696 incremental_mode() const
1697 { return this->incremental_mode_
; }
1699 // The disposition given by the --incremental-changed,
1700 // --incremental-unchanged or --incremental-unknown option. The
1701 // value may change as we proceed parsing the command line flags.
1702 Incremental_disposition
1703 incremental_disposition() const
1704 { return this->incremental_disposition_
; }
1707 set_incremental_disposition(Incremental_disposition disp
)
1708 { this->incremental_disposition_
= disp
; }
1710 // The disposition to use for startup files (those that precede the
1711 // first --incremental-changed, etc. option).
1712 Incremental_disposition
1713 incremental_startup_disposition() const
1714 { return this->incremental_startup_disposition_
; }
1716 // Return true if S is the name of a library excluded from automatic
1719 check_excluded_libs(const std::string
&s
) const;
1721 // If an explicit start address was given for section SECNAME with
1722 // the --section-start option, return true and set *PADDR to the
1723 // address. Otherwise return false.
1725 section_start(const char* secname
, uint64_t* paddr
) const;
1727 // Return whether any --section-start option was used.
1729 any_section_start() const
1730 { return !this->section_starts_
.empty(); }
1734 // Leave original instruction.
1736 // Replace instruction.
1738 // Generate an interworking veneer.
1739 FIX_V4BX_INTERWORKING
1744 { return (this->fix_v4bx_
); }
1755 { return this->endianness_
; }
1760 BSYMBOLIC_FUNCTIONS
,
1766 { return this->bsymbolic_
== BSYMBOLIC_ALL
; }
1769 Bsymbolic_functions() const
1770 { return this->bsymbolic_
== BSYMBOLIC_FUNCTIONS
; }
1774 { return this->discard_locals_
== DISCARD_ALL
; }
1777 discard_locals() const
1778 { return this->discard_locals_
== DISCARD_LOCALS
; }
1781 discard_sec_merge() const
1782 { return this->discard_locals_
== DISCARD_SEC_MERGE
; }
1784 enum Orphan_handling
1786 // Place orphan sections normally (default).
1788 // Discard all orphan sections.
1790 // Warn when placing orphan sections.
1792 // Issue error for orphan sections.
1797 orphan_handling_enum() const
1798 { return this->orphan_handling_enum_
; }
1801 start_stop_visibility_enum() const
1802 { return this->start_stop_visibility_enum_
; }
1806 // Use Power10 insns on @notoc calls/branches, non-Power10 elsewhere.
1808 // Don't use Power10 insns
1810 // Always use Power10 insns
1815 power10_stubs_enum() const
1816 { return this->power10_stubs_enum_
; }
1819 // Don't copy this structure.
1820 General_options(const General_options
&);
1821 General_options
& operator=(const General_options
&);
1823 // What local symbols to discard.
1826 // Locals in merge sections (default).
1828 // None (--discard-none).
1830 // Temporary locals (--discard-locals/-X).
1832 // All locals (--discard-all/-x).
1836 // Whether to mark the stack as executable.
1839 // Not set on command line.
1840 EXECSTACK_FROM_INPUT
,
1841 // Mark the stack as executable (-z execstack).
1843 // Mark the stack as not executable (-z noexecstack).
1849 // Do not fold any functions (Default or --icf=none).
1851 // All functions are candidates for folding. (--icf=all).
1853 // Only ctors and dtors are candidates for folding. (--icf=safe).
1858 set_icf_status(Icf_status value
)
1859 { this->icf_status_
= value
; }
1862 set_execstack_status(Execstack value
)
1863 { this->execstack_status_
= value
; }
1866 set_do_demangle(bool value
)
1867 { this->do_demangle_
= value
; }
1870 set_static(bool value
)
1871 { static_
= value
; }
1874 set_orphan_handling_enum(Orphan_handling value
)
1875 { this->orphan_handling_enum_
= value
; }
1878 set_start_stop_visibility_enum(elfcpp::STV value
)
1879 { this->start_stop_visibility_enum_
= value
; }
1882 set_power10_stubs_enum(Power10_stubs value
)
1883 { this->power10_stubs_enum_
= value
; }
1885 // These are called by finalize() to set up the search-path correctly.
1887 add_to_library_path_with_sysroot(const std::string
& arg
)
1888 { this->add_search_directory_to_library_path(Search_directory(arg
, true)); }
1890 // Apply any sysroot to the directory lists.
1894 // Add a plugin and its arguments to the list of plugins.
1896 add_plugin(const char* filename
);
1898 // Add a plugin option.
1900 add_plugin_option(const char* opt
);
1903 copy_from_posdep_options(const Position_dependent_options
&);
1905 // Whether we bind default visibility defined symbols locally for -shared.
1906 Bsymbolic_kind bsymbolic_
;
1907 // Whether we printed version information.
1908 bool printed_version_
;
1909 // Whether to mark the stack as executable.
1910 Execstack execstack_status_
;
1911 // Whether to do code folding.
1912 Icf_status icf_status_
;
1913 // Whether to do a static link.
1915 // Whether to do demangling.
1917 // List of plugin libraries.
1918 Plugin_manager
* plugins_
;
1919 // The parsed output of --dynamic-list files. For convenience in
1920 // script.cc, we store this as a Script_options object, even though
1921 // we only use a single Version_tree from it.
1922 Script_options dynamic_list_
;
1923 // Whether a --dynamic-list file was provided.
1924 bool have_dynamic_list_
;
1925 // The incremental linking mode.
1926 Incremental_mode incremental_mode_
;
1927 // The disposition given by the --incremental-changed,
1928 // --incremental-unchanged or --incremental-unknown option. The
1929 // value may change as we proceed parsing the command line flags.
1930 Incremental_disposition incremental_disposition_
;
1931 // The disposition to use for startup files (those marked
1932 // INCREMENTAL_STARTUP).
1933 Incremental_disposition incremental_startup_disposition_
;
1934 // Whether we have seen one of the options that require incremental
1935 // build (--incremental-changed, --incremental-unchanged,
1936 // --incremental-unknown, or --incremental-startup-unchanged).
1937 bool implicit_incremental_
;
1938 // Libraries excluded from automatic export, via --exclude-libs.
1939 Unordered_set
<std::string
> excluded_libs_
;
1940 // List of symbol-names to keep, via -retain-symbol-info.
1941 Unordered_set
<std::string
> symbols_to_retain_
;
1942 // Map from section name to address from --section-start.
1943 std::map
<std::string
, uint64_t> section_starts_
;
1944 // Whether to process armv4 bx instruction relocation.
1947 Endianness endianness_
;
1948 // What local symbols to discard.
1949 Discard_locals discard_locals_
;
1950 // Stack of saved options for --push-state/--pop-state.
1951 std::vector
<Position_dependent_options
*> options_stack_
;
1952 // Orphan handling option, decoded to an enum value.
1953 Orphan_handling orphan_handling_enum_
;
1954 // Symbol visibility for __start_* / __stop_* magic symbols.
1955 elfcpp::STV start_stop_visibility_enum_
;
1956 // Power10 stubs option
1957 Power10_stubs power10_stubs_enum_
;
1960 // The position-dependent options. We use this to store the state of
1961 // the commandline at a particular point in parsing for later
1962 // reference. For instance, if we see "ld --whole-archive foo.a
1963 // --no-whole-archive," we want to store the whole-archive option with
1964 // foo.a, so when the time comes to parse foo.a we know we should do
1965 // it in whole-archive mode. We could store all of General_options,
1966 // but that's big, so we just pick the subset of flags that actually
1967 // change in a position-dependent way.
1969 #define DEFINE_posdep(varname__, type__) \
1973 { return this->varname__##_; } \
1976 set_##varname__(type__ value) \
1977 { this->varname__##_ = value; } \
1981 class Position_dependent_options
1984 Position_dependent_options(const General_options
& options
1985 = Position_dependent_options::default_options_
)
1986 { copy_from_options(options
); }
1989 copy_from_options(const General_options
& options
)
1991 this->set_as_needed(options
.as_needed());
1992 this->set_Bdynamic(options
.Bdynamic());
1993 this->set_format_enum(options
.format_enum());
1994 this->set_whole_archive(options
.whole_archive());
1995 this->set_incremental_disposition(options
.incremental_disposition());
1998 DEFINE_posdep(as_needed
, bool);
1999 DEFINE_posdep(Bdynamic
, bool);
2000 DEFINE_posdep(format_enum
, General_options::Object_format
);
2001 DEFINE_posdep(whole_archive
, bool);
2002 DEFINE_posdep(incremental_disposition
, Incremental_disposition
);
2005 // This is a General_options with everything set to its default
2006 // value. A Position_dependent_options created with no argument
2007 // will take its values from here.
2008 static General_options default_options_
;
2012 // A single file or library argument from the command line.
2014 class Input_file_argument
2017 enum Input_file_type
2019 // A regular file, name used as-is, not searched.
2020 INPUT_FILE_TYPE_FILE
,
2021 // A library name. When used, "lib" will be prepended and ".so" or
2022 // ".a" appended to make a filename, and that filename will be searched
2023 // for using the -L paths.
2024 INPUT_FILE_TYPE_LIBRARY
,
2025 // A regular file, name used as-is, but searched using the -L paths.
2026 INPUT_FILE_TYPE_SEARCHED_FILE
2029 // name: file name or library name
2030 // type: the type of this input file.
2031 // extra_search_path: an extra directory to look for the file, prior
2032 // to checking the normal library search path. If this is "",
2033 // then no extra directory is added.
2034 // just_symbols: whether this file only defines symbols.
2035 // options: The position dependent options at this point in the
2036 // command line, such as --whole-archive.
2037 Input_file_argument()
2038 : name_(), type_(INPUT_FILE_TYPE_FILE
), extra_search_path_(""),
2039 just_symbols_(false), options_(), arg_serial_(0)
2042 Input_file_argument(const char* name
, Input_file_type type
,
2043 const char* extra_search_path
,
2045 const Position_dependent_options
& options
)
2046 : name_(name
), type_(type
), extra_search_path_(extra_search_path
),
2047 just_symbols_(just_symbols
), options_(options
), arg_serial_(0)
2050 // You can also pass in a General_options instance instead of a
2051 // Position_dependent_options. In that case, we extract the
2052 // position-independent vars from the General_options and only store
2054 Input_file_argument(const char* name
, Input_file_type type
,
2055 const char* extra_search_path
,
2057 const General_options
& options
)
2058 : name_(name
), type_(type
), extra_search_path_(extra_search_path
),
2059 just_symbols_(just_symbols
), options_(options
), arg_serial_(0)
2064 { return this->name_
.c_str(); }
2066 const Position_dependent_options
&
2068 { return this->options_
; }
2072 { return type_
== INPUT_FILE_TYPE_LIBRARY
; }
2075 is_searched_file() const
2076 { return type_
== INPUT_FILE_TYPE_SEARCHED_FILE
; }
2079 extra_search_path() const
2081 return (this->extra_search_path_
.empty()
2083 : this->extra_search_path_
.c_str());
2086 // Return whether we should only read symbols from this file.
2088 just_symbols() const
2089 { return this->just_symbols_
; }
2091 // Return whether this file may require a search using the -L
2094 may_need_search() const
2096 return (this->is_lib()
2097 || this->is_searched_file()
2098 || !this->extra_search_path_
.empty());
2101 // Set the serial number for this argument.
2103 set_arg_serial(unsigned int arg_serial
)
2104 { this->arg_serial_
= arg_serial
; }
2106 // Get the serial number.
2109 { return this->arg_serial_
; }
2112 // We use std::string, not const char*, here for convenience when
2113 // using script files, so that we do not have to preserve the string
2116 Input_file_type type_
;
2117 std::string extra_search_path_
;
2119 Position_dependent_options options_
;
2120 // A unique index for this file argument in the argument list.
2121 unsigned int arg_serial_
;
2124 // A file or library, or a group, from the command line.
2126 class Input_argument
2129 // Create a file or library argument.
2130 explicit Input_argument(Input_file_argument file
)
2131 : is_file_(true), file_(file
), group_(NULL
), lib_(NULL
), script_info_(NULL
)
2134 // Create a group argument.
2135 explicit Input_argument(Input_file_group
* group
)
2136 : is_file_(false), group_(group
), lib_(NULL
), script_info_(NULL
)
2139 // Create a lib argument.
2140 explicit Input_argument(Input_file_lib
* lib
)
2141 : is_file_(false), group_(NULL
), lib_(lib
), script_info_(NULL
)
2144 // Return whether this is a file.
2147 { return this->is_file_
; }
2149 // Return whether this is a group.
2152 { return !this->is_file_
&& this->lib_
== NULL
; }
2154 // Return whether this is a lib.
2157 { return this->lib_
!= NULL
; }
2159 // Return the information about the file.
2160 const Input_file_argument
&
2163 gold_assert(this->is_file_
);
2167 // Return the information about the group.
2168 const Input_file_group
*
2171 gold_assert(!this->is_file_
);
2172 return this->group_
;
2178 gold_assert(!this->is_file_
);
2179 return this->group_
;
2182 // Return the information about the lib.
2183 const Input_file_lib
*
2186 gold_assert(!this->is_file_
);
2187 gold_assert(this->lib_
);
2194 gold_assert(!this->is_file_
);
2195 gold_assert(this->lib_
);
2199 // If a script generated this argument, store a pointer to the script info.
2200 // Currently used only for recording incremental link information.
2202 set_script_info(Script_info
* info
)
2203 { this->script_info_
= info
; }
2207 { return this->script_info_
; }
2211 Input_file_argument file_
;
2212 Input_file_group
* group_
;
2213 Input_file_lib
* lib_
;
2214 Script_info
* script_info_
;
2217 typedef std::vector
<Input_argument
> Input_argument_list
;
2219 // A group from the command line. This is a set of arguments within
2220 // --start-group ... --end-group.
2222 class Input_file_group
2225 typedef Input_argument_list::const_iterator const_iterator
;
2231 // Add a file to the end of the group.
2233 add_file(const Input_file_argument
& arg
)
2235 this->files_
.push_back(Input_argument(arg
));
2236 return this->files_
.back();
2239 // Iterators to iterate over the group contents.
2243 { return this->files_
.begin(); }
2247 { return this->files_
.end(); }
2250 Input_argument_list files_
;
2253 // A lib from the command line. This is a set of arguments within
2254 // --start-lib ... --end-lib.
2256 class Input_file_lib
2259 typedef Input_argument_list::const_iterator const_iterator
;
2261 Input_file_lib(const Position_dependent_options
& options
)
2262 : files_(), options_(options
)
2265 // Add a file to the end of the lib.
2267 add_file(const Input_file_argument
& arg
)
2269 this->files_
.push_back(Input_argument(arg
));
2270 return this->files_
.back();
2273 const Position_dependent_options
&
2275 { return this->options_
; }
2277 // Iterators to iterate over the lib contents.
2281 { return this->files_
.begin(); }
2285 { return this->files_
.end(); }
2289 { return this->files_
.size(); }
2292 Input_argument_list files_
;
2293 Position_dependent_options options_
;
2296 // A list of files from the command line or a script.
2298 class Input_arguments
2301 typedef Input_argument_list::const_iterator const_iterator
;
2304 : input_argument_list_(), in_group_(false), in_lib_(false), file_count_(0)
2309 add_file(Input_file_argument
& arg
);
2311 // Start a group (the --start-group option).
2315 // End a group (the --end-group option).
2319 // Start a lib (the --start-lib option).
2321 start_lib(const Position_dependent_options
&);
2323 // End a lib (the --end-lib option).
2327 // Return whether we are currently in a group.
2330 { return this->in_group_
; }
2332 // Return whether we are currently in a lib.
2335 { return this->in_lib_
; }
2337 // The number of entries in the list.
2340 { return this->input_argument_list_
.size(); }
2342 // Iterators to iterate over the list of input files.
2346 { return this->input_argument_list_
.begin(); }
2350 { return this->input_argument_list_
.end(); }
2352 // Return whether the list is empty.
2355 { return this->input_argument_list_
.empty(); }
2357 // Return the number of input files. This may be larger than
2358 // input_argument_list_.size(), because of files that are part
2359 // of groups or libs.
2361 number_of_input_files() const
2362 { return this->file_count_
; }
2365 Input_argument_list input_argument_list_
;
2368 unsigned int file_count_
;
2372 // All the information read from the command line. These are held in
2373 // three separate structs: one to hold the options (--foo), one to
2374 // hold the filenames listed on the commandline, and one to hold
2375 // linker script information. This third is not a subset of the other
2376 // two because linker scripts can be specified either as options (via
2377 // -T) or as a file.
2382 typedef Input_arguments::const_iterator const_iterator
;
2386 // Process the command line options. This will exit with an
2387 // appropriate error message if an unrecognized option is seen.
2389 process(int argc
, const char** argv
);
2391 // Process one command-line option. This takes the index of argv to
2392 // process, and returns the index for the next option. no_more_options
2393 // is set to true if argv[i] is "--".
2395 process_one_option(int argc
, const char** argv
, int i
,
2396 bool* no_more_options
);
2398 // Get the general options.
2399 const General_options
&
2401 { return this->options_
; }
2403 // Get the position dependent options.
2404 const Position_dependent_options
&
2405 position_dependent_options() const
2406 { return this->position_options_
; }
2408 // Get the linker-script options.
2411 { return this->script_options_
; }
2413 // Finalize the version-script options and return them.
2414 const Version_script_info
&
2417 // Get the input files.
2420 { return this->inputs_
; }
2422 // The number of input files.
2424 number_of_input_files() const
2425 { return this->inputs_
.number_of_input_files(); }
2427 // Iterators to iterate over the list of input files.
2431 { return this->inputs_
.begin(); }
2435 { return this->inputs_
.end(); }
2438 Command_line(const Command_line
&);
2439 Command_line
& operator=(const Command_line
&);
2441 // This is a dummy class to provide a constructor that runs before
2442 // the constructor for the General_options. The Pre_options constructor
2443 // is used as a hook to set the flag enabling the options to register
2445 struct Pre_options
{
2449 // This must come before options_!
2450 Pre_options pre_options_
;
2451 General_options options_
;
2452 Position_dependent_options position_options_
;
2453 Script_options script_options_
;
2454 Input_arguments inputs_
;
2457 } // End namespace gold.
2459 #endif // !defined(GOLD_OPTIONS_H)