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