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