* cref.cc: New file.
[deliverable/binutils-gdb.git] / gold / options.h
CommitLineData
bae7f79e
ILT
1// options.h -- handle command line options for gold -*- C++ -*-
2
e5756efb 3// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
6cb15b7f
ILT
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
bae7f79e 23// General_options (from Command_line::options())
ee1fe73e 24// All the options (a.k.a. command-line flags)
bae7f79e
ILT
25// Input_argument (from Command_line::inputs())
26// The list of input files, including -l options.
ee1fe73e
ILT
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).
bae7f79e
ILT
35
36#ifndef GOLD_OPTIONS_H
37#define GOLD_OPTIONS_H
38
ca3a67a5 39#include <cstdlib>
cbb93e63 40#include <cstring>
bae7f79e 41#include <list>
61ba1cf9 42#include <string>
92e059d8 43#include <vector>
bae7f79e 44
0daa6f62 45#include "elfcpp.h"
3c2fafa5
ILT
46#include "script.h"
47
bae7f79e
ILT
48namespace gold
49{
50
51class Command_line;
ee1fe73e
ILT
52class General_options;
53class Search_directory;
ead1e424 54class Input_file_group;
3c2fafa5 55class Position_dependent_options;
0daa6f62 56class Target;
bae7f79e 57
ee1fe73e
ILT
58// The nested namespace is to contain all the global variables and
59// structs that need to be defined in the .h file, but do not need to
60// be used outside this class.
c7912668
ILT
61namespace options
62{
ee1fe73e 63typedef std::vector<Search_directory> Dir_list;
c5818ff1 64typedef Unordered_set<std::string> String_set;
ee1fe73e
ILT
65
66// These routines convert from a string option to various types.
67// Each gives a fatal error if it cannot parse the argument.
68
69extern void
70parse_bool(const char* option_name, const char* arg, bool* retval);
71
72extern void
73parse_uint(const char* option_name, const char* arg, int* retval);
74
75extern void
c18476e7
ILT
76parse_uint64(const char* option_name, const char* arg, uint64_t* retval);
77
78extern void
79parse_double(const char* option_name, const char* arg, double* retval);
ee1fe73e
ILT
80
81extern void
82parse_string(const char* option_name, const char* arg, const char** retval);
83
086a1841
ILT
84extern void
85parse_optional_string(const char* option_name, const char* arg,
86 const char** retval);
87
ee1fe73e
ILT
88extern void
89parse_dirlist(const char* option_name, const char* arg, Dir_list* retval);
90
c5818ff1
CC
91extern void
92parse_set(const char* option_name, const char* arg, String_set* retval);
93
ee1fe73e
ILT
94extern void
95parse_choices(const char* option_name, const char* arg, const char** retval,
96 const char* choices[], int num_choices);
97
98struct Struct_var;
99
100// Most options have both a shortname (one letter) and a longname.
101// This enum controls how many dashes are expected for longname access
102// -- shortnames always use one dash. Most longnames will accept
103// either one dash or two; the only difference between ONE_DASH and
104// TWO_DASHES is how we print the option in --help. However, some
105// longnames require two dashes, and some require only one. The
106// special value DASH_Z means that the option is preceded by "-z".
107enum Dashes
108{
109 ONE_DASH, TWO_DASHES, EXACTLY_ONE_DASH, EXACTLY_TWO_DASHES, DASH_Z
110};
111
112// LONGNAME is the long-name of the option with dashes converted to
113// underscores, or else the short-name if the option has no long-name.
114// It is never the empty string.
115// DASHES is an instance of the Dashes enum: ONE_DASH, TWO_DASHES, etc.
116// SHORTNAME is the short-name of the option, as a char, or '\0' if the
117// option has no short-name. If the option has no long-name, you
118// should specify the short-name in *both* VARNAME and here.
119// DEFAULT_VALUE is the value of the option if not specified on the
120// commandline, as a string.
121// HELPSTRING is the descriptive text used with the option via --help
122// HELPARG is how you define the argument to the option.
123// --help output is "-shortname HELPARG, --longname HELPARG: HELPSTRING"
124// HELPARG should be NULL iff the option is a bool and takes no arg.
086a1841
ILT
125// OPTIONAL_ARG is true if this option takes an optional argument. An
126// optional argument must be specifid as --OPTION=VALUE, not
127// --OPTION VALUE.
ee1fe73e
ILT
128// READER provides parse_to_value, which is a function that will convert
129// a char* argument into the proper type and store it in some variable.
130// A One_option struct initializes itself with the global list of options
131// at constructor time, so be careful making one of these.
132struct One_option
133{
134 std::string longname;
135 Dashes dashes;
136 char shortname;
137 const char* default_value;
138 const char* helpstring;
139 const char* helparg;
086a1841 140 bool optional_arg;
ee1fe73e
ILT
141 Struct_var* reader;
142
143 One_option(const char* ln, Dashes d, char sn, const char* dv,
086a1841 144 const char* hs, const char* ha, bool oa, Struct_var* r)
ee1fe73e 145 : longname(ln), dashes(d), shortname(sn), default_value(dv ? dv : ""),
086a1841 146 helpstring(hs), helparg(ha), optional_arg(oa), reader(r)
ee1fe73e
ILT
147 {
148 // In longname, we convert all underscores to dashes, since GNU
149 // style uses dashes in option names. longname is likely to have
150 // underscores in it because it's also used to declare a C++
151 // function.
152 const char* pos = strchr(this->longname.c_str(), '_');
153 for (; pos; pos = strchr(pos, '_'))
154 this->longname[pos - this->longname.c_str()] = '-';
155
156 // We only register ourselves if our helpstring is not NULL. This
157 // is to support the "no-VAR" boolean variables, which we
158 // conditionally turn on by defining "no-VAR" help text.
159 if (this->helpstring)
160 this->register_option();
161 }
162
163 // This option takes an argument iff helparg is not NULL.
164 bool
165 takes_argument() const
166 { return this->helparg != NULL; }
167
086a1841
ILT
168 // Whether the argument is optional.
169 bool
170 takes_optional_argument() const
171 { return this->optional_arg; }
172
ee1fe73e
ILT
173 // Register this option with the global list of options.
174 void
175 register_option();
176
177 // Print this option to stdout (used with --help).
178 void
179 print() const;
180};
181
182// All options have a Struct_##varname that inherits from this and
183// actually implements parse_to_value for that option.
184struct Struct_var
185{
186 // OPTION: the name of the option as specified on the commandline,
187 // including leading dashes, and any text following the option:
188 // "-O", "--defsym=mysym=0x1000", etc.
189 // ARG: the arg associated with this option, or NULL if the option
190 // takes no argument: "2", "mysym=0x1000", etc.
191 // CMDLINE: the global Command_line object. Used by DEFINE_special.
192 // OPTIONS: the global General_options object. Used by DEFINE_special.
193 virtual void
194 parse_to_value(const char* option, const char* arg,
195 Command_line* cmdline, General_options* options) = 0;
196 virtual
197 ~Struct_var() // To make gcc happy.
198 { }
199};
bae7f79e 200
ee1fe73e
ILT
201// This is for "special" options that aren't of any predefined type.
202struct Struct_special : public Struct_var
203{
204 // If you change this, change the parse-fn in DEFINE_special as well.
205 typedef void (General_options::*Parse_function)(const char*, const char*,
206 Command_line*);
207 Struct_special(const char* varname, Dashes dashes, char shortname,
208 Parse_function parse_function,
209 const char* helpstring, const char* helparg)
086a1841 210 : option(varname, dashes, shortname, "", helpstring, helparg, false, this),
ee1fe73e
ILT
211 parse(parse_function)
212 { }
213
214 void parse_to_value(const char* option, const char* arg,
215 Command_line* cmdline, General_options* options)
216 { (options->*(this->parse))(option, arg, cmdline); }
217
218 One_option option;
219 Parse_function parse;
220};
221
222} // End namespace options.
223
224
225// These are helper macros use by DEFINE_uint64/etc below.
226// This macro is used inside the General_options_ class, so defines
227// var() and set_var() as General_options methods. Arguments as are
228// for the constructor for One_option. param_type__ is the same as
229// type__ for built-in types, and "const type__ &" otherwise.
230#define DEFINE_var(varname__, dashes__, shortname__, default_value__, \
231 default_value_as_string__, helpstring__, helparg__, \
086a1841 232 optional_arg__, type__, param_type__, parse_fn__) \
ee1fe73e
ILT
233 public: \
234 param_type__ \
235 varname__() const \
236 { return this->varname__##_.value; } \
237 \
238 bool \
239 user_set_##varname__() const \
240 { return this->varname__##_.user_set_via_option; } \
241 \
2b706932
ILT
242 void \
243 set_user_set_##varname__() \
244 { this->varname__##_.user_set_via_option = true; } \
245 \
ee1fe73e
ILT
246 private: \
247 struct Struct_##varname__ : public options::Struct_var \
248 { \
249 Struct_##varname__() \
250 : option(#varname__, dashes__, shortname__, default_value_as_string__, \
086a1841 251 helpstring__, helparg__, optional_arg__, this), \
ee1fe73e
ILT
252 user_set_via_option(false), value(default_value__) \
253 { } \
254 \
255 void \
256 parse_to_value(const char* option_name, const char* arg, \
257 Command_line*, General_options*) \
258 { \
259 parse_fn__(option_name, arg, &this->value); \
260 this->user_set_via_option = true; \
261 } \
262 \
263 options::One_option option; \
264 bool user_set_via_option; \
265 type__ value; \
266 }; \
267 Struct_##varname__ varname__##_; \
268 void \
269 set_##varname__(param_type__ value) \
270 { this->varname__##_.value = value; }
271
272// These macros allow for easy addition of a new commandline option.
273
274// If no_helpstring__ is not NULL, then in addition to creating
d98bc257
ILT
275// VARNAME, we also create an option called no-VARNAME (or, for a -z
276// option, noVARNAME).
ee1fe73e
ILT
277#define DEFINE_bool(varname__, dashes__, shortname__, default_value__, \
278 helpstring__, no_helpstring__) \
279 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
280 default_value__ ? "true" : "false", helpstring__, NULL, \
086a1841 281 false, bool, bool, options::parse_bool) \
ee1fe73e
ILT
282 struct Struct_no_##varname__ : public options::Struct_var \
283 { \
d98bc257
ILT
284 Struct_no_##varname__() : option((dashes__ == options::DASH_Z \
285 ? "no" #varname__ \
286 : "no-" #varname__), \
287 dashes__, '\0', \
ee1fe73e 288 default_value__ ? "false" : "true", \
086a1841 289 no_helpstring__, NULL, false, this) \
ee1fe73e
ILT
290 { } \
291 \
292 void \
293 parse_to_value(const char*, const char*, \
294 Command_line*, General_options* options) \
295 { options->set_##varname__(false); } \
296 \
297 options::One_option option; \
298 }; \
299 Struct_no_##varname__ no_##varname__##_initializer_
300
7c414435
DM
301#define DEFINE_enable(varname__, dashes__, shortname__, default_value__, \
302 helpstring__, no_helpstring__) \
303 DEFINE_var(enable_##varname__, dashes__, shortname__, default_value__, \
304 default_value__ ? "true" : "false", helpstring__, NULL, \
305 false, bool, bool, options::parse_bool) \
306 struct Struct_disable_##varname__ : public options::Struct_var \
307 { \
308 Struct_disable_##varname__() : option("disable-" #varname__, \
309 dashes__, '\0', \
310 default_value__ ? "false" : "true", \
311 no_helpstring__, NULL, false, this) \
312 { } \
313 \
314 void \
315 parse_to_value(const char*, const char*, \
316 Command_line*, General_options* options) \
317 { options->set_enable_##varname__(false); } \
318 \
319 options::One_option option; \
320 }; \
321 Struct_disable_##varname__ disable_##varname__##_initializer_
322
ee1fe73e
ILT
323#define DEFINE_uint(varname__, dashes__, shortname__, default_value__, \
324 helpstring__, helparg__) \
325 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
086a1841 326 #default_value__, helpstring__, helparg__, false, \
ee1fe73e
ILT
327 int, int, options::parse_uint)
328
329#define DEFINE_uint64(varname__, dashes__, shortname__, default_value__, \
330 helpstring__, helparg__) \
331 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
086a1841 332 #default_value__, helpstring__, helparg__, false, \
ee1fe73e
ILT
333 uint64_t, uint64_t, options::parse_uint64)
334
c18476e7
ILT
335#define DEFINE_double(varname__, dashes__, shortname__, default_value__, \
336 helpstring__, helparg__) \
337 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
086a1841 338 #default_value__, helpstring__, helparg__, false, \
c18476e7
ILT
339 double, double, options::parse_double)
340
ee1fe73e
ILT
341#define DEFINE_string(varname__, dashes__, shortname__, default_value__, \
342 helpstring__, helparg__) \
343 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
086a1841 344 default_value__, helpstring__, helparg__, false, \
ee1fe73e
ILT
345 const char*, const char*, options::parse_string)
346
347// This is like DEFINE_string, but we convert each occurrence to a
348// Search_directory and store it in a vector. Thus we also have the
349// add_to_VARNAME() method, to append to the vector.
350#define DEFINE_dirlist(varname__, dashes__, shortname__, \
351 helpstring__, helparg__) \
352 DEFINE_var(varname__, dashes__, shortname__, , \
086a1841 353 "", helpstring__, helparg__, false, options::Dir_list, \
ee1fe73e
ILT
354 const options::Dir_list&, options::parse_dirlist) \
355 void \
356 add_to_##varname__(const char* new_value) \
357 { options::parse_dirlist(NULL, new_value, &this->varname__##_.value); } \
358 void \
359 add_search_directory_to_##varname__(const Search_directory& dir) \
360 { this->varname__##_.value.push_back(dir); }
361
c5818ff1
CC
362// This is like DEFINE_string, but we store a set of strings.
363#define DEFINE_set(varname__, dashes__, shortname__, \
364 helpstring__, helparg__) \
365 DEFINE_var(varname__, dashes__, shortname__, , \
366 "", helpstring__, helparg__, false, options::String_set, \
367 const options::String_set&, options::parse_set) \
368 public: \
369 bool \
370 any_##varname__() const \
371 { return !this->varname__##_.value.empty(); } \
f3e9c5c5 372 \
c5818ff1
CC
373 bool \
374 is_##varname__(const char* symbol) const \
375 { \
376 return (!this->varname__##_.value.empty() \
377 && (this->varname__##_.value.find(std::string(symbol)) \
378 != this->varname__##_.value.end())); \
f3e9c5c5
ILT
379 } \
380 \
381 options::String_set::const_iterator \
382 varname__##_begin() const \
383 { return this->varname__##_.value.begin(); } \
384 \
385 options::String_set::const_iterator \
386 varname__##_end() const \
387 { return this->varname__##_.value.end(); }
c5818ff1 388
ee1fe73e
ILT
389// When you have a list of possible values (expressed as string)
390// After helparg__ should come an initializer list, like
391// {"foo", "bar", "baz"}
392#define DEFINE_enum(varname__, dashes__, shortname__, default_value__, \
393 helpstring__, helparg__, ...) \
394 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
086a1841 395 default_value__, helpstring__, helparg__, false, \
ee1fe73e
ILT
396 const char*, const char*, parse_choices_##varname__) \
397 private: \
398 static void parse_choices_##varname__(const char* option_name, \
399 const char* arg, \
400 const char** retval) { \
401 const char* choices[] = __VA_ARGS__; \
402 options::parse_choices(option_name, arg, retval, \
403 choices, sizeof(choices) / sizeof(*choices)); \
404 }
405
2b706932
ILT
406// This is like DEFINE_bool, but VARNAME is the name of a different
407// option. This option becomes an alias for that one. INVERT is true
408// if this option is an inversion of the other one.
409#define DEFINE_bool_alias(option__, varname__, dashes__, shortname__, \
410 helpstring__, no_helpstring__, invert__) \
411 private: \
412 struct Struct_##option__ : public options::Struct_var \
413 { \
414 Struct_##option__() \
415 : option(#option__, dashes__, shortname__, "", helpstring__, \
416 NULL, false, this) \
417 { } \
418 \
419 void \
420 parse_to_value(const char*, const char*, \
421 Command_line*, General_options* options) \
422 { \
423 options->set_##varname__(!invert__); \
424 options->set_user_set_##varname__(); \
425 } \
426 \
427 options::One_option option; \
428 }; \
429 Struct_##option__ option__##_; \
430 \
431 struct Struct_no_##option__ : public options::Struct_var \
432 { \
433 Struct_no_##option__() \
434 : option((dashes__ == options::DASH_Z \
435 ? "no" #option__ \
436 : "no-" #option__), \
437 dashes__, '\0', "", no_helpstring__, \
438 NULL, false, this) \
439 { } \
440 \
441 void \
442 parse_to_value(const char*, const char*, \
443 Command_line*, General_options* options) \
444 { \
445 options->set_##varname__(invert__); \
446 options->set_user_set_##varname__(); \
447 } \
448 \
449 options::One_option option; \
450 }; \
451 Struct_no_##option__ no_##option__##_initializer_
452
ee1fe73e
ILT
453// This is used for non-standard flags. It defines no functions; it
454// just calls General_options::parse_VARNAME whenever the flag is
455// seen. We declare parse_VARNAME as a static member of
456// General_options; you are responsible for defining it there.
457// helparg__ should be NULL iff this special-option is a boolean.
458#define DEFINE_special(varname__, dashes__, shortname__, \
459 helpstring__, helparg__) \
460 private: \
461 void parse_##varname__(const char* option, const char* arg, \
462 Command_line* inputs); \
463 struct Struct_##varname__ : public options::Struct_special \
464 { \
465 Struct_##varname__() \
466 : options::Struct_special(#varname__, dashes__, shortname__, \
467 &General_options::parse_##varname__, \
468 helpstring__, helparg__) \
469 { } \
470 }; \
471 Struct_##varname__ varname__##_initializer_
bae7f79e 472
086a1841
ILT
473// An option that takes an optional string argument. If the option is
474// used with no argument, the value will be the default, and
475// user_set_via_option will be true.
476#define DEFINE_optional_string(varname__, dashes__, shortname__, \
477 default_value__, \
478 helpstring__, helparg__) \
479 DEFINE_var(varname__, dashes__, shortname__, default_value__, \
480 default_value__, helpstring__, helparg__, true, \
481 const char*, const char*, options::parse_optional_string)
bae7f79e 482
ad2d6943
ILT
483// A directory to search. For each directory we record whether it is
484// in the sysroot. We need to know this so that, if a linker script
485// is found within the sysroot, we will apply the sysroot to any files
486// named by that script.
487
488class Search_directory
489{
490 public:
491 // We need a default constructor because we put this in a
492 // std::vector.
493 Search_directory()
494 : name_(NULL), put_in_sysroot_(false), is_in_sysroot_(false)
495 { }
496
497 // This is the usual constructor.
498 Search_directory(const char* name, bool put_in_sysroot)
499 : name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false)
15893b88
ILT
500 {
501 if (this->name_.empty())
502 this->name_ = ".";
503 }
ad2d6943
ILT
504
505 // This is called if we have a sysroot. The sysroot is prefixed to
506 // any entries for which put_in_sysroot_ is true. is_in_sysroot_ is
507 // set to true for any enries which are in the sysroot (this will
508 // naturally include any entries for which put_in_sysroot_ is true).
509 // SYSROOT is the sysroot, CANONICAL_SYSROOT is the result of
510 // passing SYSROOT to lrealpath.
511 void
512 add_sysroot(const char* sysroot, const char* canonical_sysroot);
513
514 // Get the directory name.
515 const std::string&
516 name() const
517 { return this->name_; }
518
519 // Return whether this directory is in the sysroot.
520 bool
521 is_in_sysroot() const
522 { return this->is_in_sysroot_; }
523
524 private:
525 std::string name_;
526 bool put_in_sysroot_;
527 bool is_in_sysroot_;
528};
529
bae7f79e
ILT
530class General_options
531{
ee1fe73e
ILT
532 private:
533 // NOTE: For every option that you add here, also consider if you
534 // should add it to Position_dependent_options.
535 DEFINE_special(help, options::TWO_DASHES, '\0',
a4d4b13f 536 N_("Report usage information"), NULL);
ee1fe73e 537 DEFINE_special(version, options::TWO_DASHES, 'v',
a4d4b13f 538 N_("Report version information"), NULL);
b5be4a7c
DM
539 DEFINE_special(V, options::EXACTLY_ONE_DASH, '\0',
540 N_("Report version and target information"), NULL);
ee1fe73e 541
fee2edb1
ILT
542 // These options are sorted approximately so that for each letter in
543 // the alphabet, we show the option whose shortname is that letter
544 // (if any) and then every longname that starts with that letter (in
545 // alphabetical order). For both, lowercase sorts before uppercase.
546 // The -z options come last.
547
ee1fe73e 548 DEFINE_bool(allow_shlib_undefined, options::TWO_DASHES, '\0', false,
a4d4b13f
ILT
549 N_("Allow unresolved references in shared libraries"),
550 N_("Do not allow unresolved references in shared libraries"));
ee1fe73e
ILT
551
552 DEFINE_bool(as_needed, options::TWO_DASHES, '\0', false,
a4d4b13f
ILT
553 N_("Only set DT_NEEDED for dynamic libs if used"),
554 N_("Always DT_NEEDED for dynamic libs"));
ee1fe73e 555
fee2edb1
ILT
556 // This should really be an "enum", but it's too easy for folks to
557 // forget to update the list as they add new targets. So we just
558 // accept any string. We'll fail later (when the string is parsed),
559 // if the target isn't actually supported.
560 DEFINE_string(format, options::TWO_DASHES, 'b', "elf",
561 N_("Set input format"), ("[elf,binary]"));
562
ee1fe73e 563 DEFINE_bool(Bdynamic, options::ONE_DASH, '\0', true,
a4d4b13f 564 N_("-l searches for shared libraries"), NULL);
2b706932
ILT
565 DEFINE_bool_alias(Bstatic, Bdynamic, options::ONE_DASH, '\0',
566 N_("-l does not search for shared libraries"), NULL,
567 true);
ee1fe73e
ILT
568
569 DEFINE_bool(Bsymbolic, options::ONE_DASH, '\0', false,
a4d4b13f 570 N_("Bind defined symbols locally"), NULL);
ee1fe73e 571
f1f70eae
ILT
572 DEFINE_bool(Bsymbolic_functions, options::ONE_DASH, '\0', false,
573 N_("Bind defined function symbols locally"), NULL);
574
8ed814a9
ILT
575 DEFINE_optional_string(build_id, options::TWO_DASHES, '\0', "sha1",
576 N_("Generate build ID note"),
577 N_("[=STYLE]"));
578
ee1fe73e
ILT
579#ifdef HAVE_ZLIB_H
580 DEFINE_enum(compress_debug_sections, options::TWO_DASHES, '\0', "none",
a4d4b13f
ILT
581 N_("Compress .debug_* sections in the output file"),
582 ("[none,zlib]"),
ee1fe73e
ILT
583 {"none", "zlib"});
584#else
585 DEFINE_enum(compress_debug_sections, options::TWO_DASHES, '\0', "none",
a4d4b13f
ILT
586 N_("Compress .debug_* sections in the output file"),
587 N_("[none]"),
ee1fe73e
ILT
588 {"none"});
589#endif
0dfbdef4 590
ee1fe73e 591 DEFINE_bool(define_common, options::TWO_DASHES, 'd', false,
a4d4b13f
ILT
592 N_("Define common symbols"),
593 N_("Do not define common symbols"));
ee1fe73e 594 DEFINE_bool(dc, options::ONE_DASH, '\0', false,
a4d4b13f 595 N_("Alias for -d"), NULL);
ee1fe73e 596 DEFINE_bool(dp, options::ONE_DASH, '\0', false,
a4d4b13f 597 N_("Alias for -d"), NULL);
d391083d 598
fee2edb1 599 DEFINE_string(debug, options::TWO_DASHES, '\0', "",
2285a610
ILT
600 N_("Turn on debugging"),
601 N_("[all,files,script,task][,...]"));
fee2edb1 602
ee1fe73e 603 DEFINE_special(defsym, options::TWO_DASHES, '\0',
a4d4b13f 604 N_("Define a symbol"), N_("SYMBOL=EXPRESSION"));
a6badf5a 605
086a1841
ILT
606 DEFINE_optional_string(demangle, options::TWO_DASHES, '\0', NULL,
607 N_("Demangle C++ symbols in log messages"),
608 N_("[=STYLE]"));
609
610 DEFINE_bool(no_demangle, options::TWO_DASHES, '\0', false,
611 N_("Do not demangle C++ symbols in log messages"),
612 NULL);
fced7afd 613
ee1fe73e 614 DEFINE_bool(detect_odr_violations, options::TWO_DASHES, '\0', false,
a4d4b13f 615 N_("Try to detect violations of the One Definition Rule"),
ee1fe73e
ILT
616 NULL);
617
618 DEFINE_string(entry, options::TWO_DASHES, 'e', NULL,
a4d4b13f 619 N_("Set program start address"), N_("ADDRESS"));
ee1fe73e
ILT
620
621 DEFINE_bool(export_dynamic, options::TWO_DASHES, 'E', false,
a4d4b13f 622 N_("Export all dynamic symbols"), NULL);
dbe717ef 623
ee1fe73e 624 DEFINE_bool(eh_frame_hdr, options::TWO_DASHES, '\0', false,
a4d4b13f 625 N_("Create exception frame header"), NULL);
ee1fe73e 626
d82a5bcc
ILT
627 DEFINE_bool(fatal_warnings, options::TWO_DASHES, '\0', false,
628 N_("Treat warnings as errors"),
629 N_("Do not treat warnings as errors"));
630
ee1fe73e 631 DEFINE_string(soname, options::ONE_DASH, 'h', NULL,
a4d4b13f 632 N_("Set shared library name"), N_("FILENAME"));
ee1fe73e 633
c18476e7
ILT
634 DEFINE_double(hash_bucket_empty_fraction, options::TWO_DASHES, '\0', 0.0,
635 N_("Min fraction of empty buckets in dynamic hash"),
636 N_("FRACTION"));
637
13670ee6 638 DEFINE_enum(hash_style, options::TWO_DASHES, '\0', "sysv",
a4d4b13f 639 N_("Dynamic hash style"), N_("[sysv,gnu,both]"),
13670ee6
ILT
640 {"sysv", "gnu", "both"});
641
ee1fe73e 642 DEFINE_string(dynamic_linker, options::TWO_DASHES, 'I', NULL,
a4d4b13f 643 N_("Set dynamic linker path"), N_("PROGRAM"));
ee1fe73e 644
fee2edb1
ILT
645 DEFINE_special(just_symbols, options::TWO_DASHES, '\0',
646 N_("Read only symbol values from FILE"), N_("FILE"));
647
ee1fe73e 648 DEFINE_special(library, options::TWO_DASHES, 'l',
a4d4b13f 649 N_("Search for library LIBNAME"), N_("LIBNAME"));
bae7f79e 650
ee1fe73e 651 DEFINE_dirlist(library_path, options::TWO_DASHES, 'L',
a4d4b13f 652 N_("Add directory to search path"), N_("DIR"));
ee1fe73e
ILT
653
654 DEFINE_string(m, options::EXACTLY_ONE_DASH, 'm', "",
a4d4b13f 655 N_("Ignored for compatibility"), N_("EMULATION"));
ee1fe73e 656
7d9e3d98
ILT
657 DEFINE_bool(print_map, options::TWO_DASHES, 'M', false,
658 N_("Write map file on standard output"), NULL);
659 DEFINE_string(Map, options::ONE_DASH, '\0', NULL, N_("Write map file"),
660 N_("MAPFILENAME"));
661
7c414435
DM
662 DEFINE_enable(new_dtags, options::EXACTLY_TWO_DASHES, '\0', false,
663 N_("Enable use of DT_RUNPATH and DT_FLAGS"),
664 N_("Disable use of DT_RUNPATH and DT_FLAGS"));
665
cdb0b8f5
ILT
666 DEFINE_bool(noinhibit_exec, options::TWO_DASHES, '\0', false,
667 N_("Create an output file even if errors occur"), NULL);
668
f3e9c5c5
ILT
669 DEFINE_bool_alias(no_undefined, defs, options::TWO_DASHES, '\0',
670 N_("Report undefined symbols (even with --shared)"),
671 NULL, false);
672
ee1fe73e 673 DEFINE_string(output, options::TWO_DASHES, 'o', "a.out",
a4d4b13f 674 N_("Set output file name"), N_("FILE"));
ee1fe73e
ILT
675
676 DEFINE_uint(optimize, options::EXACTLY_ONE_DASH, 'O', 0,
a4d4b13f 677 N_("Optimize output file size"), N_("LEVEL"));
ee1fe73e 678
a4d4b13f
ILT
679 DEFINE_string(oformat, options::EXACTLY_TWO_DASHES, '\0', "elf",
680 N_("Set output format"), N_("[binary]"));
ee1fe73e 681
92de84a6
ILT
682 DEFINE_string(print_symbol_counts, options::TWO_DASHES, '\0', NULL,
683 N_("Print symbols defined and used for each input"),
684 N_("FILENAME"));
685
b5be4a7c
DM
686 DEFINE_bool(Qy, options::EXACTLY_ONE_DASH, '\0', false,
687 N_("Ignored for SVR4 compatibility"), NULL);
688
ee1fe73e 689 DEFINE_bool(emit_relocs, options::TWO_DASHES, 'q', false,
a4d4b13f 690 N_("Generate relocations in output"), NULL);
ee1fe73e
ILT
691
692 DEFINE_bool(relocatable, options::EXACTLY_ONE_DASH, 'r', false,
a4d4b13f 693 N_("Generate relocatable output"), NULL);
ee1fe73e 694
706e1f5e
ILT
695 DEFINE_bool(relax, options::TWO_DASHES, '\0', false,
696 N_("Relax branches on certain targets"), NULL);
697
ee1fe73e
ILT
698 // -R really means -rpath, but can mean --just-symbols for
699 // compatibility with GNU ld. -rpath is always -rpath, so we list
700 // it separately.
701 DEFINE_special(R, options::EXACTLY_ONE_DASH, 'R',
a4d4b13f 702 N_("Add DIR to runtime search path"), N_("DIR"));
ee1fe73e
ILT
703
704 DEFINE_dirlist(rpath, options::ONE_DASH, '\0',
a4d4b13f 705 N_("Add DIR to runtime search path"), N_("DIR"));
ee1fe73e 706
ee1fe73e 707 DEFINE_dirlist(rpath_link, options::TWO_DASHES, '\0',
a4d4b13f
ILT
708 N_("Add DIR to link time shared library search path"),
709 N_("DIR"));
ee1fe73e
ILT
710
711 DEFINE_bool(strip_all, options::TWO_DASHES, 's', false,
a4d4b13f 712 N_("Strip all symbols"), NULL);
fee2edb1
ILT
713 DEFINE_bool(strip_debug, options::TWO_DASHES, 'S', false,
714 N_("Strip debugging information"), NULL);
62b01cb5
ILT
715 DEFINE_bool(strip_debug_non_line, options::TWO_DASHES, '\0', false,
716 N_("Emit only debug line number information"), NULL);
ee1fe73e 717 DEFINE_bool(strip_debug_gdb, options::TWO_DASHES, '\0', false,
a4d4b13f 718 N_("Strip debug symbols that are unused by gdb "
ee1fe73e 719 "(at least versions <= 6.7)"), NULL);
ee1fe73e
ILT
720
721 DEFINE_bool(shared, options::ONE_DASH, '\0', false,
a4d4b13f 722 N_("Generate shared library"), NULL);
ee1fe73e
ILT
723
724 // This is not actually special in any way, but I need to give it
725 // a non-standard accessor-function name because 'static' is a keyword.
726 DEFINE_special(static, options::ONE_DASH, '\0',
a4d4b13f 727 N_("Do not link against shared libraries"), NULL);
ee1fe73e
ILT
728
729 DEFINE_bool(stats, options::TWO_DASHES, '\0', false,
a4d4b13f 730 N_("Print resource usage statistics"), NULL);
ee1fe73e
ILT
731
732 DEFINE_string(sysroot, options::TWO_DASHES, '\0', "",
a4d4b13f 733 N_("Set target system root directory"), N_("DIR"));
ee1fe73e 734
c5818ff1
CC
735 DEFINE_bool(trace, options::TWO_DASHES, 't', false,
736 N_("Print the name of each input file"), NULL);
737
ee1fe73e 738 DEFINE_special(script, options::TWO_DASHES, 'T',
a4d4b13f 739 N_("Read linker script"), N_("FILE"));
ee1fe73e
ILT
740
741 DEFINE_bool(threads, options::TWO_DASHES, '\0', false,
a4d4b13f
ILT
742 N_("Run the linker multi-threaded"),
743 N_("Do not run the linker multi-threaded"));
ee1fe73e 744 DEFINE_uint(thread_count, options::TWO_DASHES, '\0', 0,
a4d4b13f 745 N_("Number of threads to use"), N_("COUNT"));
ee1fe73e 746 DEFINE_uint(thread_count_initial, options::TWO_DASHES, '\0', 0,
a4d4b13f 747 N_("Number of threads to use in initial pass"), N_("COUNT"));
ee1fe73e 748 DEFINE_uint(thread_count_middle, options::TWO_DASHES, '\0', 0,
a4d4b13f 749 N_("Number of threads to use in middle pass"), N_("COUNT"));
ee1fe73e 750 DEFINE_uint(thread_count_final, options::TWO_DASHES, '\0', 0,
a4d4b13f 751 N_("Number of threads to use in final pass"), N_("COUNT"));
ee1fe73e 752
fee2edb1
ILT
753 DEFINE_uint64(Tbss, options::ONE_DASH, '\0', -1U,
754 N_("Set the address of the bss segment"), N_("ADDRESS"));
755 DEFINE_uint64(Tdata, options::ONE_DASH, '\0', -1U,
756 N_("Set the address of the data segment"), N_("ADDRESS"));
757 DEFINE_uint64(Ttext, options::ONE_DASH, '\0', -1U,
758 N_("Set the address of the text segment"), N_("ADDRESS"));
759
f3e9c5c5
ILT
760 DEFINE_set(undefined, options::TWO_DASHES, 'u',
761 N_("Create undefined reference to SYMBOL"), N_("SYMBOL"));
2b706932 762
2285a610
ILT
763 DEFINE_bool(verbose, options::TWO_DASHES, '\0', false,
764 N_("Synonym for --debug=files"), NULL);
765
fee2edb1
ILT
766 DEFINE_special(version_script, options::TWO_DASHES, '\0',
767 N_("Read version script"), N_("FILE"));
768
ee1fe73e 769 DEFINE_bool(whole_archive, options::TWO_DASHES, '\0', false,
a4d4b13f
ILT
770 N_("Include all archive contents"),
771 N_("Include only needed archive contents"));
ee1fe73e 772
c5818ff1
CC
773 DEFINE_set(wrap, options::TWO_DASHES, '\0',
774 N_("Use wrapper functions for SYMBOL"), N_("SYMBOL"));
775
776 DEFINE_set(trace_symbol, options::TWO_DASHES, 'y',
777 N_("Trace references to symbol"), N_("SYMBOL"));
0864d551 778
706e1f5e
ILT
779 DEFINE_string(Y, options::EXACTLY_ONE_DASH, 'Y', "",
780 N_("Default search path for Solaris compatibility"),
781 N_("PATH"));
782
ee1fe73e 783 DEFINE_special(start_group, options::TWO_DASHES, '(',
a4d4b13f 784 N_("Start a library search group"), NULL);
ee1fe73e 785 DEFINE_special(end_group, options::TWO_DASHES, ')',
a4d4b13f 786 N_("End a library search group"), NULL);
ee1fe73e 787
fee2edb1 788 // The -z options.
ee1fe73e 789
d98bc257
ILT
790 DEFINE_bool(combreloc, options::DASH_Z, '\0', true,
791 N_("Sort dynamic relocs"),
792 N_("Do not sort dynamic relocs"));
fee2edb1
ILT
793 DEFINE_uint64(common_page_size, options::DASH_Z, '\0', 0,
794 N_("Set common page size to SIZE"), N_("SIZE"));
eb42429a
ILT
795 DEFINE_bool(defs, options::DASH_Z, '\0', false,
796 N_("Report undefined symbols (even with --shared)"),
797 NULL);
ee1fe73e 798 DEFINE_bool(execstack, options::DASH_Z, '\0', false,
a4d4b13f 799 N_("Mark output as requiring executable stack"), NULL);
ee1fe73e 800 DEFINE_uint64(max_page_size, options::DASH_Z, '\0', 0,
a4d4b13f 801 N_("Set maximum page size to SIZE"), N_("SIZE"));
fee2edb1
ILT
802 DEFINE_bool(noexecstack, options::DASH_Z, '\0', false,
803 N_("Mark output as not requiring executable stack"), NULL);
7c414435
DM
804 DEFINE_bool(initfirst, options::DASH_Z, '\0', false,
805 N_("Mark DSO to be initialized first at runtime"),
806 NULL);
807 DEFINE_bool(interpose, options::DASH_Z, '\0', false,
808 N_("Mark object to interpose all DSOs but executable"),
809 NULL);
810 DEFINE_bool(loadfltr, options::DASH_Z, '\0', false,
811 N_("Mark object requiring immediate process"),
812 NULL);
813 DEFINE_bool(nodefaultlib, options::DASH_Z, '\0', false,
814 N_("Mark object not to use default search paths"),
815 NULL);
816 DEFINE_bool(nodelete, options::DASH_Z, '\0', false,
817 N_("Mark DSO non-deletable at runtime"),
818 NULL);
819 DEFINE_bool(nodlopen, options::DASH_Z, '\0', false,
820 N_("Mark DSO not available to dlopen"),
821 NULL);
822 DEFINE_bool(nodump, options::DASH_Z, '\0', false,
823 N_("Mark DSO not available to dldump"),
824 NULL);
9f1d377b
ILT
825 DEFINE_bool(relro, options::DASH_Z, '\0', false,
826 N_("Where possible mark variables read-only after relocation"),
827 N_("Don't mark variables read-only after relocation"));
bae7f79e 828
ee1fe73e
ILT
829 public:
830 typedef options::Dir_list Dir_list;
ca3a67a5 831
ee1fe73e 832 General_options();
61ba1cf9 833
ee1fe73e
ILT
834 // Does post-processing on flags, making sure they all have
835 // non-conflicting values. Also converts some flags from their
836 // "standard" types (string, etc), to another type (enum, DirList),
837 // which can be accessed via a separate method. Dies if it notices
838 // any problems.
839 void finalize();
516cb3d0 840
ee1fe73e
ILT
841 // The macro defines output() (based on --output), but that's a
842 // generic name. Provide this alternative name, which is clearer.
8851ecca 843 const char*
ee1fe73e
ILT
844 output_file_name() const
845 { return this->output(); }
92e059d8 846
8851ecca
ILT
847 // This is not defined via a flag, but combines flags to say whether
848 // the output is position-independent or not.
849 bool
850 output_is_position_independent() const
851 { return this->shared(); }
852
ee1fe73e
ILT
853 // This would normally be static(), and defined automatically, but
854 // since static is a keyword, we need to come up with our own name.
bae7f79e
ILT
855 bool
856 is_static() const
ee1fe73e 857 { return static_; }
756ac4a8 858
ee1fe73e
ILT
859 // In addition to getting the input and output formats as a string
860 // (via format() and oformat()), we also give access as an enum.
861 enum Object_format
862 {
863 // Ordinary ELF.
864 OBJECT_FORMAT_ELF,
865 // Straight binary format.
866 OBJECT_FORMAT_BINARY
867 };
fe9a4c12 868
ee1fe73e
ILT
869 // Note: these functions are not very fast.
870 Object_format format_enum() const;
871 Object_format oformat_enum() const;
fe9a4c12 872
ee1fe73e
ILT
873 // These are the best way to get access to the execstack state,
874 // not execstack() and noexecstack() which are hard to use properly.
35cdfc9a
ILT
875 bool
876 is_execstack_set() const
ee1fe73e 877 { return this->execstack_status_ != EXECSTACK_FROM_INPUT; }
35cdfc9a
ILT
878
879 bool
880 is_stack_executable() const
ee1fe73e 881 { return this->execstack_status_ == EXECSTACK_YES; }
c7912668 882
086a1841
ILT
883 // The --demangle option takes an optional string, and there is also
884 // a --no-demangle option. This is the best way to decide whether
885 // to demangle or not.
886 bool
887 do_demangle() const
888 { return this->do_demangle_; }
889
bae7f79e 890 private:
dbe717ef
ILT
891 // Don't copy this structure.
892 General_options(const General_options&);
893 General_options& operator=(const General_options&);
894
35cdfc9a
ILT
895 // Whether to mark the stack as executable.
896 enum Execstack
897 {
898 // Not set on command line.
899 EXECSTACK_FROM_INPUT,
ee1fe73e 900 // Mark the stack as executable (-z execstack).
35cdfc9a 901 EXECSTACK_YES,
ee1fe73e 902 // Mark the stack as not executable (-z noexecstack).
35cdfc9a
ILT
903 EXECSTACK_NO
904 };
905
92e059d8 906 void
ee1fe73e 907 set_execstack_status(Execstack value)
086a1841
ILT
908 { this->execstack_status_ = value; }
909
910 void
911 set_do_demangle(bool value)
912 { this->do_demangle_ = value; }
92e059d8 913
bae7f79e 914 void
45aa233b 915 set_static(bool value)
ee1fe73e 916 { static_ = value; }
652ec9bd 917
ee1fe73e 918 // These are called by finalize() to set up the search-path correctly.
35cdfc9a 919 void
ee1fe73e
ILT
920 add_to_library_path_with_sysroot(const char* arg)
921 { this->add_search_directory_to_library_path(Search_directory(arg, true)); }
c7912668 922
ad2d6943
ILT
923 // Apply any sysroot to the directory lists.
924 void
925 add_sysroot();
086a1841
ILT
926
927 // Whether to mark the stack as executable.
928 Execstack execstack_status_;
929 // Whether to do a static link.
930 bool static_;
931 // Whether to do demangling.
932 bool do_demangle_;
bae7f79e
ILT
933};
934
ee1fe73e
ILT
935// The position-dependent options. We use this to store the state of
936// the commandline at a particular point in parsing for later
937// reference. For instance, if we see "ld --whole-archive foo.a
938// --no-whole-archive," we want to store the whole-archive option with
939// foo.a, so when the time comes to parse foo.a we know we should do
940// it in whole-archive mode. We could store all of General_options,
941// but that's big, so we just pick the subset of flags that actually
942// change in a position-dependent way.
943
944#define DEFINE_posdep(varname__, type__) \
945 public: \
946 type__ \
947 varname__() const \
948 { return this->varname__##_; } \
949 \
950 void \
951 set_##varname__(type__ value) \
952 { this->varname__##_ = value; } \
953 private: \
954 type__ varname__##_
bae7f79e
ILT
955
956class Position_dependent_options
957{
958 public:
ee1fe73e
ILT
959 Position_dependent_options(const General_options& options
960 = Position_dependent_options::default_options_)
961 { copy_from_options(options); }
bae7f79e 962
ee1fe73e
ILT
963 void copy_from_options(const General_options& options)
964 {
965 this->set_as_needed(options.as_needed());
966 this->set_Bdynamic(options.Bdynamic());
967 this->set_format_enum(options.format_enum());
968 this->set_whole_archive(options.whole_archive());
969 }
bc644c6c 970
ee1fe73e
ILT
971 DEFINE_posdep(as_needed, bool);
972 DEFINE_posdep(Bdynamic, bool);
973 DEFINE_posdep(format_enum, General_options::Object_format);
974 DEFINE_posdep(whole_archive, bool);
7cc619c3 975
dbe717ef 976 private:
ee1fe73e
ILT
977 // This is a General_options with everything set to its default
978 // value. A Position_dependent_options created with no argument
979 // will take its values from here.
980 static General_options default_options_;
bae7f79e
ILT
981};
982
ee1fe73e 983
bae7f79e
ILT
984// A single file or library argument from the command line.
985
ead1e424 986class Input_file_argument
bae7f79e
ILT
987{
988 public:
51dee2fe
ILT
989 // name: file name or library name
990 // is_lib: true if name is a library name: that is, emits the leading
991 // "lib" and trailing ".so"/".a" from the name
992 // extra_search_path: an extra directory to look for the file, prior
993 // to checking the normal library search path. If this is "",
994 // then no extra directory is added.
88dd47ac 995 // just_symbols: whether this file only defines symbols.
51dee2fe 996 // options: The position dependent options at this point in the
ad2d6943 997 // command line, such as --whole-archive.
ead1e424 998 Input_file_argument()
88dd47ac
ILT
999 : name_(), is_lib_(false), extra_search_path_(""), just_symbols_(false),
1000 options_()
ead1e424
ILT
1001 { }
1002
1003 Input_file_argument(const char* name, bool is_lib,
51dee2fe 1004 const char* extra_search_path,
ee1fe73e
ILT
1005 bool just_symbols,
1006 const Position_dependent_options& options)
1007 : name_(name), is_lib_(is_lib), extra_search_path_(extra_search_path),
1008 just_symbols_(just_symbols), options_(options)
1009 { }
1010
1011 // You can also pass in a General_options instance instead of a
1012 // Position_dependent_options. In that case, we extract the
1013 // position-independent vars from the General_options and only store
1014 // those.
1015 Input_file_argument(const char* name, bool is_lib,
1016 const char* extra_search_path,
1017 bool just_symbols,
1018 const General_options& options)
51dee2fe 1019 : name_(name), is_lib_(is_lib), extra_search_path_(extra_search_path),
88dd47ac 1020 just_symbols_(just_symbols), options_(options)
bae7f79e
ILT
1021 { }
1022
1023 const char*
1024 name() const
dbe717ef 1025 { return this->name_.c_str(); }
bae7f79e
ILT
1026
1027 const Position_dependent_options&
1028 options() const
1029 { return this->options_; }
1030
1031 bool
1032 is_lib() const
61ba1cf9 1033 { return this->is_lib_; }
bae7f79e 1034
51dee2fe
ILT
1035 const char*
1036 extra_search_path() const
1037 {
1038 return (this->extra_search_path_.empty()
1039 ? NULL
ee1fe73e 1040 : this->extra_search_path_.c_str());
51dee2fe
ILT
1041 }
1042
88dd47ac
ILT
1043 // Return whether we should only read symbols from this file.
1044 bool
1045 just_symbols() const
1046 { return this->just_symbols_; }
1047
51dee2fe
ILT
1048 // Return whether this file may require a search using the -L
1049 // options.
1050 bool
1051 may_need_search() const
1052 { return this->is_lib_ || !this->extra_search_path_.empty(); }
1053
bae7f79e 1054 private:
dbe717ef
ILT
1055 // We use std::string, not const char*, here for convenience when
1056 // using script files, so that we do not have to preserve the string
1057 // in that case.
1058 std::string name_;
61ba1cf9 1059 bool is_lib_;
51dee2fe 1060 std::string extra_search_path_;
88dd47ac 1061 bool just_symbols_;
bae7f79e
ILT
1062 Position_dependent_options options_;
1063};
1064
ead1e424
ILT
1065// A file or library, or a group, from the command line.
1066
1067class Input_argument
1068{
1069 public:
1070 // Create a file or library argument.
1071 explicit Input_argument(Input_file_argument file)
1072 : is_file_(true), file_(file), group_(NULL)
1073 { }
1074
1075 // Create a group argument.
1076 explicit Input_argument(Input_file_group* group)
1077 : is_file_(false), group_(group)
1078 { }
1079
1080 // Return whether this is a file.
1081 bool
1082 is_file() const
1083 { return this->is_file_; }
1084
1085 // Return whether this is a group.
1086 bool
1087 is_group() const
1088 { return !this->is_file_; }
1089
1090 // Return the information about the file.
1091 const Input_file_argument&
1092 file() const
1093 {
a3ad94ed 1094 gold_assert(this->is_file_);
ead1e424
ILT
1095 return this->file_;
1096 }
1097
1098 // Return the information about the group.
1099 const Input_file_group*
1100 group() const
1101 {
a3ad94ed 1102 gold_assert(!this->is_file_);
ead1e424
ILT
1103 return this->group_;
1104 }
1105
1106 Input_file_group*
1107 group()
1108 {
a3ad94ed 1109 gold_assert(!this->is_file_);
ead1e424
ILT
1110 return this->group_;
1111 }
1112
1113 private:
1114 bool is_file_;
1115 Input_file_argument file_;
1116 Input_file_group* group_;
1117};
1118
1119// A group from the command line. This is a set of arguments within
1120// --start-group ... --end-group.
1121
1122class Input_file_group
92e059d8 1123{
ead1e424
ILT
1124 public:
1125 typedef std::vector<Input_argument> Files;
1126 typedef Files::const_iterator const_iterator;
1127
1128 Input_file_group()
1129 : files_()
1130 { }
1131
1132 // Add a file to the end of the group.
1133 void
1134 add_file(const Input_file_argument& arg)
1135 { this->files_.push_back(Input_argument(arg)); }
1136
1137 // Iterators to iterate over the group contents.
1138
1139 const_iterator
1140 begin() const
1141 { return this->files_.begin(); }
1142
1143 const_iterator
1144 end() const
1145 { return this->files_.end(); }
1146
1147 private:
1148 Files files_;
92e059d8
ILT
1149};
1150
dbe717ef
ILT
1151// A list of files from the command line or a script.
1152
1153class Input_arguments
1154{
1155 public:
1156 typedef std::vector<Input_argument> Input_argument_list;
1157 typedef Input_argument_list::const_iterator const_iterator;
1158
1159 Input_arguments()
1160 : input_argument_list_(), in_group_(false)
1161 { }
1162
1163 // Add a file.
1164 void
1165 add_file(const Input_file_argument& arg);
1166
1167 // Start a group (the --start-group option).
1168 void
1169 start_group();
1170
1171 // End a group (the --end-group option).
1172 void
1173 end_group();
1174
1175 // Return whether we are currently in a group.
1176 bool
1177 in_group() const
1178 { return this->in_group_; }
1179
fe9a4c12
ILT
1180 // The number of entries in the list.
1181 int
1182 size() const
1183 { return this->input_argument_list_.size(); }
1184
dbe717ef
ILT
1185 // Iterators to iterate over the list of input files.
1186
1187 const_iterator
1188 begin() const
1189 { return this->input_argument_list_.begin(); }
1190
1191 const_iterator
1192 end() const
1193 { return this->input_argument_list_.end(); }
1194
1195 // Return whether the list is empty.
1196 bool
1197 empty() const
1198 { return this->input_argument_list_.empty(); }
1199
1200 private:
1201 Input_argument_list input_argument_list_;
1202 bool in_group_;
1203};
1204
ee1fe73e
ILT
1205
1206// All the information read from the command line. These are held in
1207// three separate structs: one to hold the options (--foo), one to
1208// hold the filenames listed on the commandline, and one to hold
1209// linker script information. This third is not a subset of the other
1210// two because linker scripts can be specified either as options (via
1211// -T) or as a file.
bae7f79e
ILT
1212
1213class Command_line
1214{
1215 public:
ead1e424
ILT
1216 typedef Input_arguments::const_iterator const_iterator;
1217
a5dc0706 1218 Command_line();
bae7f79e
ILT
1219
1220 // Process the command line options. This will exit with an
1221 // appropriate error message if an unrecognized option is seen.
1222 void
ee1fe73e 1223 process(int argc, const char** argv);
bae7f79e 1224
a0451b38 1225 // Process one command-line option. This takes the index of argv to
ee1fe73e
ILT
1226 // process, and returns the index for the next option. no_more_options
1227 // is set to true if argv[i] is "--".
61ba1cf9 1228 int
ee1fe73e
ILT
1229 process_one_option(int argc, const char** argv, int i,
1230 bool* no_more_options);
3c2fafa5 1231
61ba1cf9 1232 // Get the general options.
bae7f79e
ILT
1233 const General_options&
1234 options() const
1235 { return this->options_; }
1236
3c2fafa5
ILT
1237 // Get the position dependent options.
1238 const Position_dependent_options&
1239 position_dependent_options() const
1240 { return this->position_options_; }
1241
a5dc0706
ILT
1242 // Get the linker-script options.
1243 Script_options&
e5756efb 1244 script_options()
a5dc0706 1245 { return this->script_options_; }
e5756efb 1246
a5dc0706
ILT
1247 // Get the version-script options: a convenience routine.
1248 const Version_script_info&
1249 version_script() const
1250 { return *this->script_options_.version_script_info(); }
e5756efb 1251
ee1fe73e
ILT
1252 // Get the input files.
1253 Input_arguments&
1254 inputs()
1255 { return this->inputs_; }
1256
fe9a4c12
ILT
1257 // The number of input files.
1258 int
1259 number_of_input_files() const
1260 { return this->inputs_.size(); }
1261
ead1e424
ILT
1262 // Iterators to iterate over the list of input files.
1263
1264 const_iterator
1265 begin() const
1266 { return this->inputs_.begin(); }
1267
1268 const_iterator
1269 end() const
1270 { return this->inputs_.end(); }
bae7f79e
ILT
1271
1272 private:
ead1e424
ILT
1273 Command_line(const Command_line&);
1274 Command_line& operator=(const Command_line&);
1275
bae7f79e
ILT
1276 General_options options_;
1277 Position_dependent_options position_options_;
a5dc0706 1278 Script_options script_options_;
ead1e424 1279 Input_arguments inputs_;
bae7f79e
ILT
1280};
1281
1282} // End namespace gold.
1283
1284#endif // !defined(GOLD_OPTIONS_H)
This page took 0.211508 seconds and 4 git commands to generate.