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