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