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