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