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 ILT |
23 | // Command_line |
24 | // Holds everything we get from the command line. | |
25 | // General_options (from Command_line::options()) | |
26 | // Options which are not position dependent. | |
27 | // Input_argument (from Command_line::inputs()) | |
28 | // The list of input files, including -l options. | |
29 | // Position_dependent_options (from Input_argument::options()) | |
30 | // Position dependent options which apply to this argument. | |
31 | ||
32 | #ifndef GOLD_OPTIONS_H | |
33 | #define GOLD_OPTIONS_H | |
34 | ||
ca3a67a5 | 35 | #include <cstdlib> |
bae7f79e | 36 | #include <list> |
61ba1cf9 | 37 | #include <string> |
92e059d8 | 38 | #include <vector> |
bae7f79e | 39 | |
0daa6f62 | 40 | #include "elfcpp.h" |
3c2fafa5 ILT |
41 | #include "script.h" |
42 | ||
bae7f79e ILT |
43 | namespace gold |
44 | { | |
45 | ||
46 | class Command_line; | |
ead1e424 | 47 | class Input_file_group; |
3c2fafa5 | 48 | class Position_dependent_options; |
0daa6f62 | 49 | class Target; |
bae7f79e | 50 | |
c7912668 ILT |
51 | namespace options |
52 | { | |
bae7f79e ILT |
53 | |
54 | class Command_line_options; | |
55 | struct One_option; | |
35cdfc9a | 56 | struct One_z_option; |
c7912668 | 57 | struct One_debug_option; |
bae7f79e ILT |
58 | |
59 | } // End namespace gold::options. | |
60 | ||
ad2d6943 ILT |
61 | // A directory to search. For each directory we record whether it is |
62 | // in the sysroot. We need to know this so that, if a linker script | |
63 | // is found within the sysroot, we will apply the sysroot to any files | |
64 | // named by that script. | |
65 | ||
66 | class Search_directory | |
67 | { | |
68 | public: | |
69 | // We need a default constructor because we put this in a | |
70 | // std::vector. | |
71 | Search_directory() | |
72 | : name_(NULL), put_in_sysroot_(false), is_in_sysroot_(false) | |
73 | { } | |
74 | ||
75 | // This is the usual constructor. | |
76 | Search_directory(const char* name, bool put_in_sysroot) | |
77 | : name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false) | |
15893b88 ILT |
78 | { |
79 | if (this->name_.empty()) | |
80 | this->name_ = "."; | |
81 | } | |
ad2d6943 ILT |
82 | |
83 | // This is called if we have a sysroot. The sysroot is prefixed to | |
84 | // any entries for which put_in_sysroot_ is true. is_in_sysroot_ is | |
85 | // set to true for any enries which are in the sysroot (this will | |
86 | // naturally include any entries for which put_in_sysroot_ is true). | |
87 | // SYSROOT is the sysroot, CANONICAL_SYSROOT is the result of | |
88 | // passing SYSROOT to lrealpath. | |
89 | void | |
90 | add_sysroot(const char* sysroot, const char* canonical_sysroot); | |
91 | ||
92 | // Get the directory name. | |
93 | const std::string& | |
94 | name() const | |
95 | { return this->name_; } | |
96 | ||
97 | // Return whether this directory is in the sysroot. | |
98 | bool | |
99 | is_in_sysroot() const | |
100 | { return this->is_in_sysroot_; } | |
101 | ||
102 | private: | |
103 | std::string name_; | |
104 | bool put_in_sysroot_; | |
105 | bool is_in_sysroot_; | |
106 | }; | |
107 | ||
bae7f79e ILT |
108 | // The position independent options which apply to the whole link. |
109 | // There are a lot of them. | |
110 | ||
111 | class General_options | |
112 | { | |
113 | public: | |
bc644c6c ILT |
114 | enum Object_format |
115 | { | |
116 | // Ordinary ELF. | |
117 | OBJECT_FORMAT_ELF, | |
118 | // Straight binary format. | |
119 | OBJECT_FORMAT_BINARY | |
120 | }; | |
121 | ||
a5dc0706 | 122 | General_options(); |
bae7f79e | 123 | |
0dfbdef4 ILT |
124 | // -d: define common symbols. |
125 | bool | |
126 | define_common() const | |
127 | { return this->define_common_; } | |
128 | ||
d391083d ILT |
129 | // -e: set entry address. |
130 | const char* | |
131 | entry() const | |
a5dc0706 | 132 | { return this->entry_; } |
d391083d | 133 | |
a6badf5a ILT |
134 | // -E: export dynamic symbols. |
135 | bool | |
136 | export_dynamic() const | |
137 | { return this->export_dynamic_; } | |
138 | ||
fced7afd ILT |
139 | // -h: shared library name. |
140 | const char* | |
141 | soname() const | |
142 | { return this->soname_; } | |
143 | ||
dbe717ef ILT |
144 | // -I: dynamic linker name. |
145 | const char* | |
146 | dynamic_linker() const | |
147 | { return this->dynamic_linker_; } | |
148 | ||
bae7f79e | 149 | // -L: Library search path. |
ad2d6943 | 150 | typedef std::vector<Search_directory> Dir_list; |
bae7f79e ILT |
151 | |
152 | const Dir_list& | |
7cc619c3 | 153 | library_path() const |
bae7f79e ILT |
154 | { return this->search_path_; } |
155 | ||
ca3a67a5 ILT |
156 | // -O: optimization level (0: don't try to optimize output size). |
157 | int | |
45aa233b | 158 | optimize() const |
ca3a67a5 ILT |
159 | { return this->optimization_level_; } |
160 | ||
61ba1cf9 ILT |
161 | // -o: Output file name. |
162 | const char* | |
163 | output_file_name() const | |
164 | { return this->output_file_name_; } | |
165 | ||
516cb3d0 | 166 | // --oformat: Output format. |
bc644c6c | 167 | Object_format |
7cc619c3 | 168 | oformat_enum() const |
45aa233b | 169 | { return this->oformat_; } |
516cb3d0 | 170 | |
8851ecca | 171 | const char* |
7cc619c3 | 172 | oformat() const |
8851ecca ILT |
173 | { return this->oformat_string_; } |
174 | ||
0daa6f62 ILT |
175 | // Return the default target. |
176 | Target* | |
177 | default_target() const; | |
178 | ||
7019cd25 ILT |
179 | // -q: Whether to emit relocations. |
180 | bool | |
181 | emit_relocs() const | |
182 | { return this->emit_relocs_; } | |
183 | ||
bae7f79e ILT |
184 | // -r: Whether we are doing a relocatable link. |
185 | bool | |
45aa233b | 186 | relocatable() const |
bae7f79e ILT |
187 | { return this->is_relocatable_; } |
188 | ||
9e2dcb77 ILT |
189 | // -s: Strip all symbols. |
190 | bool | |
191 | strip_all() const | |
192 | { return this->strip_ == STRIP_ALL; } | |
193 | ||
194 | // -S: Strip debugging information. | |
195 | bool | |
196 | strip_debug() const | |
197 | { return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG; } | |
198 | ||
9a0910c3 ILT |
199 | // --strip-debug-gdb: strip only debugging information that's not |
200 | // used by gdb (at least, for gdb versions <= 6.7). | |
02d2ba74 ILT |
201 | bool |
202 | strip_debug_gdb() const | |
203 | { return this->strip_debug() || this->strip_ == STRIP_DEBUG_UNUSED_BY_GDB; } | |
204 | ||
e2827e5f ILT |
205 | // --allow-shlib-undefined: do not warn about unresolved symbols in |
206 | // --shared libraries. | |
207 | bool | |
208 | allow_shlib_undefined() const | |
209 | { return this->allow_shlib_undefined_; } | |
210 | ||
51b08ebe ILT |
211 | // -Bsymbolic: bind defined symbols locally. |
212 | bool | |
45aa233b | 213 | Bsymbolic() const |
51b08ebe ILT |
214 | { return this->symbolic_; } |
215 | ||
9a0910c3 ILT |
216 | // --compress-debug-sections: compress .debug_* sections in the |
217 | // output file using the given compression method. This is useful | |
218 | // when the tools (such as gdb) support compressed sections. | |
219 | bool | |
220 | compress_debug_sections() const | |
221 | { return this->compress_debug_sections_ != NO_COMPRESSION; } | |
222 | ||
223 | bool | |
224 | zlib_compress_debug_sections() const | |
225 | { return this->compress_debug_sections_ == ZLIB_COMPRESSION; } | |
226 | ||
a2b1aa12 ILT |
227 | // --demangle: demangle C++ symbols in our log messages. |
228 | bool | |
229 | demangle() const | |
230 | { return this->demangle_; } | |
231 | ||
a55ce7fe ILT |
232 | // --detect-odr-violations: Whether to search for One Defn Rule violations. |
233 | bool | |
234 | detect_odr_violations() const | |
235 | { return this->detect_odr_violations_; } | |
236 | ||
7da52175 ILT |
237 | // --eh-frame-hdr: Whether to generate an exception frame header. |
238 | bool | |
45aa233b | 239 | eh_frame_hdr() const |
7da52175 ILT |
240 | { return this->create_eh_frame_hdr_; } |
241 | ||
41f542e7 ILT |
242 | // --rpath: The runtime search path. |
243 | const Dir_list& | |
244 | rpath() const | |
245 | { return this->rpath_; } | |
246 | ||
15b3cfae ILT |
247 | // --rpath-link: The link time search patch for shared libraries. |
248 | const Dir_list& | |
249 | rpath_link() const | |
250 | { return this->rpath_link_; } | |
251 | ||
92e059d8 ILT |
252 | // --shared: Whether generating a shared object. |
253 | bool | |
45aa233b | 254 | shared() const |
92e059d8 ILT |
255 | { return this->is_shared_; } |
256 | ||
8851ecca ILT |
257 | // This is not defined via a flag, but combines flags to say whether |
258 | // the output is position-independent or not. | |
259 | bool | |
260 | output_is_position_independent() const | |
261 | { return this->shared(); } | |
262 | ||
bae7f79e ILT |
263 | // --static: Whether doing a static link. |
264 | bool | |
265 | is_static() const | |
266 | { return this->is_static_; } | |
267 | ||
0c5e9c22 | 268 | // --stats: Print resource usage statistics. |
e44fcf3b | 269 | bool |
7cc619c3 | 270 | stats() const |
e44fcf3b ILT |
271 | { return this->print_stats_; } |
272 | ||
ad2d6943 ILT |
273 | // --sysroot: The system root of a cross-linker. |
274 | const std::string& | |
275 | sysroot() const | |
276 | { return this->sysroot_; } | |
277 | ||
756ac4a8 ILT |
278 | // -Tbss: The address of the BSS segment |
279 | uint64_t | |
45aa233b | 280 | Tbss() const |
756ac4a8 ILT |
281 | { return this->bss_segment_address_; } |
282 | ||
283 | // Whether -Tbss was used. | |
284 | bool | |
45aa233b | 285 | user_set_Tbss() const |
756ac4a8 ILT |
286 | { return this->bss_segment_address_ != -1U; } |
287 | ||
288 | // -Tdata: The address of the data segment | |
289 | uint64_t | |
45aa233b | 290 | Tdata() const |
756ac4a8 ILT |
291 | { return this->data_segment_address_; } |
292 | ||
293 | // Whether -Tdata was used. | |
294 | bool | |
45aa233b | 295 | user_set_Tdata() const |
756ac4a8 ILT |
296 | { return this->data_segment_address_ != -1U; } |
297 | ||
0c5e9c22 ILT |
298 | // -Ttext: The address of the .text section |
299 | uint64_t | |
45aa233b | 300 | Ttext() const |
0c5e9c22 ILT |
301 | { return this->text_segment_address_; } |
302 | ||
303 | // Whether -Ttext was used. | |
304 | bool | |
45aa233b | 305 | user_set_Ttext() const |
0c5e9c22 ILT |
306 | { return this->text_segment_address_ != -1U; } |
307 | ||
fe9a4c12 ILT |
308 | // --threads: Whether to use threads. |
309 | bool | |
310 | threads() const | |
311 | { return this->threads_; } | |
312 | ||
313 | // --thread-count-initial: Threads to use in initial pass. | |
314 | int | |
315 | thread_count_initial() const | |
316 | { return this->thread_count_initial_; } | |
317 | ||
318 | // --thread-count-middle: Threads to use in middle pass. | |
319 | int | |
320 | thread_count_middle() const | |
321 | { return this->thread_count_middle_; } | |
322 | ||
323 | // --thread-count-final: Threads to use in final pass. | |
324 | int | |
325 | thread_count_final() const | |
326 | { return this->thread_count_final_; } | |
327 | ||
35cdfc9a ILT |
328 | // -z execstack, -z noexecstack |
329 | bool | |
330 | is_execstack_set() const | |
331 | { return this->execstack_ != EXECSTACK_FROM_INPUT; } | |
332 | ||
333 | bool | |
334 | is_stack_executable() const | |
335 | { return this->execstack_ == EXECSTACK_YES; } | |
336 | ||
cd72c291 ILT |
337 | // -z max-page-size |
338 | uint64_t | |
339 | max_page_size() const | |
340 | { return this->max_page_size_; } | |
341 | ||
342 | // -z common-page-size | |
343 | uint64_t | |
344 | common_page_size() const | |
345 | { return this->common_page_size_; } | |
346 | ||
c7912668 ILT |
347 | // --debug |
348 | unsigned int | |
349 | debug() const | |
350 | { return this->debug_; } | |
351 | ||
bae7f79e | 352 | private: |
dbe717ef ILT |
353 | // Don't copy this structure. |
354 | General_options(const General_options&); | |
355 | General_options& operator=(const General_options&); | |
356 | ||
bae7f79e ILT |
357 | friend class Command_line; |
358 | friend class options::Command_line_options; | |
359 | ||
9e2dcb77 ILT |
360 | // Which symbols to strip. |
361 | enum Strip | |
362 | { | |
363 | // Don't strip any symbols. | |
364 | STRIP_NONE, | |
365 | // Strip all symbols. | |
366 | STRIP_ALL, | |
367 | // Strip debugging information. | |
02d2ba74 ILT |
368 | STRIP_DEBUG, |
369 | // Strip debugging information that's not used by gdb (at least <= 6.7) | |
370 | STRIP_DEBUG_UNUSED_BY_GDB | |
9e2dcb77 ILT |
371 | }; |
372 | ||
35cdfc9a ILT |
373 | // Whether to mark the stack as executable. |
374 | enum Execstack | |
375 | { | |
376 | // Not set on command line. | |
377 | EXECSTACK_FROM_INPUT, | |
378 | // Mark the stack as executable. | |
379 | EXECSTACK_YES, | |
380 | // Mark the stack as not executable. | |
381 | EXECSTACK_NO | |
382 | }; | |
383 | ||
9a0910c3 ILT |
384 | // What compression method to use |
385 | enum CompressionMethod | |
386 | { | |
387 | NO_COMPRESSION, | |
388 | ZLIB_COMPRESSION, | |
389 | }; | |
390 | ||
0dfbdef4 ILT |
391 | void |
392 | set_define_common(bool value) | |
393 | { | |
394 | this->define_common_ = value; | |
395 | this->user_set_define_common_ = true; | |
396 | } | |
397 | ||
398 | void | |
399 | set_no_define_common(bool value) | |
400 | { this->set_define_common(!value); } | |
401 | ||
402 | bool | |
403 | user_set_define_common() const | |
404 | { return this->user_set_define_common_; } | |
405 | ||
d391083d ILT |
406 | void |
407 | set_entry(const char* arg) | |
a5dc0706 | 408 | { this->entry_ = arg; } |
d391083d | 409 | |
a6badf5a | 410 | void |
45aa233b ILT |
411 | set_export_dynamic(bool value) |
412 | { this->export_dynamic_ = value; } | |
a6badf5a | 413 | |
fced7afd ILT |
414 | void |
415 | set_soname(const char* arg) | |
416 | { this->soname_ = arg; } | |
417 | ||
dbe717ef ILT |
418 | void |
419 | set_dynamic_linker(const char* arg) | |
420 | { this->dynamic_linker_ = arg; } | |
421 | ||
bae7f79e ILT |
422 | void |
423 | add_to_search_path(const char* arg) | |
ad2d6943 ILT |
424 | { this->search_path_.push_back(Search_directory(arg, false)); } |
425 | ||
426 | void | |
427 | add_to_search_path_with_sysroot(const char* arg) | |
428 | { this->search_path_.push_back(Search_directory(arg, true)); } | |
bae7f79e | 429 | |
ca3a67a5 | 430 | void |
45aa233b | 431 | set_optimize(const char* arg) |
3ae7da37 ILT |
432 | { |
433 | char* endptr; | |
434 | this->optimization_level_ = strtol(arg, &endptr, 0); | |
435 | if (*endptr != '\0' || this->optimization_level_ < 0) | |
436 | gold_fatal(_("invalid optimization level: %s"), arg); | |
437 | } | |
ca3a67a5 | 438 | |
61ba1cf9 | 439 | void |
45aa233b | 440 | set_output(const char* arg) |
61ba1cf9 ILT |
441 | { this->output_file_name_ = arg; } |
442 | ||
516cb3d0 | 443 | void |
45aa233b | 444 | set_oformat(const char*); |
516cb3d0 | 445 | |
7019cd25 ILT |
446 | void |
447 | set_emit_relocs(bool value) | |
448 | { this->emit_relocs_ = value; } | |
449 | ||
bae7f79e | 450 | void |
45aa233b ILT |
451 | set_relocatable(bool value) |
452 | { this->is_relocatable_ = value; } | |
bae7f79e | 453 | |
9e2dcb77 | 454 | void |
45aa233b | 455 | set_strip_all(bool) |
9e2dcb77 ILT |
456 | { this->strip_ = STRIP_ALL; } |
457 | ||
46738c9a ILT |
458 | // Note: normalize_options() depends on the fact that this turns off |
459 | // STRIP_ALL if it were already set. | |
9e2dcb77 | 460 | void |
45aa233b | 461 | set_strip_debug(bool) |
9e2dcb77 ILT |
462 | { this->strip_ = STRIP_DEBUG; } |
463 | ||
02d2ba74 | 464 | void |
45aa233b | 465 | set_strip_debug_gdb(bool) |
02d2ba74 ILT |
466 | { this->strip_ = STRIP_DEBUG_UNUSED_BY_GDB; } |
467 | ||
e2827e5f | 468 | void |
45aa233b ILT |
469 | set_allow_shlib_undefined(bool value) |
470 | { this->allow_shlib_undefined_ = value; } | |
e2827e5f ILT |
471 | |
472 | void | |
45aa233b ILT |
473 | set_no_allow_shlib_undefined(bool value) |
474 | { this->set_allow_shlib_undefined(!value); } | |
e2827e5f | 475 | |
51b08ebe | 476 | void |
45aa233b ILT |
477 | set_Bsymbolic(bool value) |
478 | { this->symbolic_ = value; } | |
51b08ebe | 479 | |
bc2c67ff | 480 | void set_compress_debug_sections(const char* arg) |
9a0910c3 ILT |
481 | { |
482 | if (strcmp(arg, "none") == 0) | |
483 | this->compress_debug_sections_ = NO_COMPRESSION; | |
484 | #ifdef HAVE_ZLIB_H | |
485 | else if (strcmp(arg, "zlib") == 0) | |
486 | this->compress_debug_sections_ = ZLIB_COMPRESSION; | |
487 | #endif | |
488 | else | |
bc2c67ff | 489 | gold_fatal(_("unsupported argument to --compress-debug-sections: %s"), |
9a0910c3 ILT |
490 | arg); |
491 | } | |
492 | ||
e5756efb | 493 | void |
45aa233b | 494 | add_to_defsym(const char* arg); |
e5756efb | 495 | |
a2b1aa12 | 496 | void |
45aa233b ILT |
497 | set_demangle(bool value) |
498 | { this->demangle_ = value; } | |
a2b1aa12 ILT |
499 | |
500 | void | |
45aa233b ILT |
501 | set_no_demangle(bool value) |
502 | { this->set_demangle(!value); } | |
a2b1aa12 | 503 | |
a55ce7fe | 504 | void |
45aa233b ILT |
505 | set_detect_odr_violations(bool value) |
506 | { this->detect_odr_violations_ = value; } | |
a55ce7fe | 507 | |
7da52175 | 508 | void |
45aa233b ILT |
509 | set_eh_frame_hdr(bool value) |
510 | { this->create_eh_frame_hdr_ = value; } | |
7da52175 | 511 | |
41f542e7 ILT |
512 | void |
513 | add_to_rpath(const char* arg) | |
ad2d6943 | 514 | { this->rpath_.push_back(Search_directory(arg, false)); } |
41f542e7 | 515 | |
15b3cfae ILT |
516 | void |
517 | add_to_rpath_link(const char* arg) | |
ad2d6943 | 518 | { this->rpath_link_.push_back(Search_directory(arg, false)); } |
15b3cfae | 519 | |
92e059d8 | 520 | void |
45aa233b ILT |
521 | set_shared(bool value) |
522 | { this->is_shared_ = value; } | |
92e059d8 | 523 | |
bae7f79e | 524 | void |
45aa233b ILT |
525 | set_static(bool value) |
526 | { this->is_static_ = value; } | |
bae7f79e | 527 | |
e44fcf3b | 528 | void |
45aa233b ILT |
529 | set_stats(bool value) |
530 | { this->print_stats_ = value; } | |
e44fcf3b | 531 | |
ad2d6943 ILT |
532 | void |
533 | set_sysroot(const char* arg) | |
534 | { this->sysroot_ = arg; } | |
535 | ||
0c5e9c22 | 536 | void |
756ac4a8 | 537 | set_segment_address(const char* name, const char* arg, uint64_t* val) |
0c5e9c22 ILT |
538 | { |
539 | char* endptr; | |
756ac4a8 ILT |
540 | *val = strtoull(arg, &endptr, 0); |
541 | if (*endptr != '\0' || *val == -1U) | |
542 | gold_fatal(_("invalid argument to %s: %s"), name, arg); | |
0c5e9c22 ILT |
543 | } |
544 | ||
756ac4a8 | 545 | void |
45aa233b | 546 | set_Tbss(const char* arg) |
756ac4a8 ILT |
547 | { this->set_segment_address("-Tbss", arg, &this->bss_segment_address_); } |
548 | ||
549 | void | |
45aa233b | 550 | set_Tdata(const char* arg) |
756ac4a8 ILT |
551 | { this->set_segment_address("-Tdata", arg, &this->data_segment_address_); } |
552 | ||
553 | void | |
45aa233b | 554 | set_Ttext(const char* arg) |
756ac4a8 ILT |
555 | { this->set_segment_address("-Ttext", arg, &this->text_segment_address_); } |
556 | ||
fe9a4c12 ILT |
557 | int |
558 | parse_thread_count(const char* arg) | |
559 | { | |
560 | char* endptr; | |
3ae7da37 | 561 | const int count = strtol(arg, &endptr, 0); |
fe9a4c12 | 562 | if (*endptr != '\0' || count < 0) |
3ae7da37 | 563 | gold_fatal(_("invalid thread count: %s"), arg); |
fe9a4c12 ILT |
564 | return count; |
565 | } | |
566 | ||
567 | void | |
45aa233b | 568 | set_threads(bool value) |
3ae7da37 ILT |
569 | { |
570 | #ifndef ENABLE_THREADS | |
45aa233b ILT |
571 | if (value) |
572 | gold_fatal(_("--threads not supported")); | |
3ae7da37 | 573 | #endif |
45aa233b | 574 | this->threads_ = value; |
3ae7da37 | 575 | } |
fe9a4c12 ILT |
576 | |
577 | void | |
45aa233b ILT |
578 | set_no_threads(bool value) |
579 | { this->set_threads(!value); } | |
fe9a4c12 ILT |
580 | |
581 | void | |
582 | set_thread_count(const char* arg) | |
583 | { | |
584 | int count = this->parse_thread_count(arg); | |
585 | this->thread_count_initial_ = count; | |
586 | this->thread_count_middle_ = count; | |
587 | this->thread_count_final_ = count; | |
588 | } | |
589 | ||
590 | void | |
591 | set_thread_count_initial(const char* arg) | |
592 | { this->thread_count_initial_ = this->parse_thread_count(arg); } | |
593 | ||
594 | void | |
595 | set_thread_count_middle(const char* arg) | |
460c00b5 | 596 | { this->thread_count_middle_ = this->parse_thread_count(arg); } |
fe9a4c12 ILT |
597 | |
598 | void | |
599 | set_thread_count_final(const char* arg) | |
460c00b5 | 600 | { this->thread_count_final_ = this->parse_thread_count(arg); } |
fe9a4c12 | 601 | |
652ec9bd ILT |
602 | void |
603 | ignore(const char*) | |
604 | { } | |
605 | ||
35cdfc9a | 606 | void |
45aa233b | 607 | set_execstack(bool) |
35cdfc9a ILT |
608 | { this->execstack_ = EXECSTACK_YES; } |
609 | ||
610 | void | |
45aa233b | 611 | set_noexecstack(bool) |
35cdfc9a ILT |
612 | { this->execstack_ = EXECSTACK_NO; } |
613 | ||
cd72c291 ILT |
614 | void |
615 | set_max_page_size(const char* arg) | |
616 | { | |
617 | char* endptr; | |
618 | this->max_page_size_ = strtoull(arg, &endptr, 0); | |
619 | if (*endptr != '\0' || this->max_page_size_ == 0) | |
620 | gold_fatal(_("invalid max-page-size: %s"), arg); | |
621 | } | |
622 | ||
623 | void | |
624 | set_common_page_size(const char* arg) | |
625 | { | |
626 | char* endptr; | |
627 | this->common_page_size_ = strtoull(arg, &endptr, 0); | |
628 | if (*endptr != '\0' || this->common_page_size_ == 0) | |
629 | gold_fatal(_("invalid common-page-size: %s"), arg); | |
630 | } | |
631 | ||
c7912668 ILT |
632 | void |
633 | set_debug(unsigned int flags) | |
634 | { this->debug_ = flags; } | |
635 | ||
35cdfc9a ILT |
636 | // Handle the -z option. |
637 | void | |
638 | handle_z_option(const char*); | |
639 | ||
c7912668 ILT |
640 | // Handle the --debug option. |
641 | void | |
642 | handle_debug_option(const char*); | |
643 | ||
ad2d6943 ILT |
644 | // Apply any sysroot to the directory lists. |
645 | void | |
646 | add_sysroot(); | |
647 | ||
0dfbdef4 ILT |
648 | bool define_common_; |
649 | bool user_set_define_common_; | |
a5dc0706 | 650 | const char* entry_; |
a6badf5a | 651 | bool export_dynamic_; |
fced7afd | 652 | const char* soname_; |
dbe717ef | 653 | const char* dynamic_linker_; |
bae7f79e | 654 | Dir_list search_path_; |
ca3a67a5 | 655 | int optimization_level_; |
61ba1cf9 | 656 | const char* output_file_name_; |
45aa233b ILT |
657 | Object_format oformat_; |
658 | const char* oformat_string_; | |
7019cd25 | 659 | bool emit_relocs_; |
bae7f79e | 660 | bool is_relocatable_; |
9e2dcb77 | 661 | Strip strip_; |
e2827e5f | 662 | bool allow_shlib_undefined_; |
51b08ebe | 663 | bool symbolic_; |
9a0910c3 | 664 | CompressionMethod compress_debug_sections_; |
a2b1aa12 | 665 | bool demangle_; |
a55ce7fe | 666 | bool detect_odr_violations_; |
7da52175 | 667 | bool create_eh_frame_hdr_; |
41f542e7 | 668 | Dir_list rpath_; |
15b3cfae | 669 | Dir_list rpath_link_; |
92e059d8 | 670 | bool is_shared_; |
bae7f79e | 671 | bool is_static_; |
e44fcf3b | 672 | bool print_stats_; |
ad2d6943 | 673 | std::string sysroot_; |
756ac4a8 ILT |
674 | uint64_t bss_segment_address_; |
675 | uint64_t data_segment_address_; | |
0c5e9c22 | 676 | uint64_t text_segment_address_; |
fe9a4c12 ILT |
677 | bool threads_; |
678 | int thread_count_initial_; | |
679 | int thread_count_middle_; | |
680 | int thread_count_final_; | |
35cdfc9a | 681 | Execstack execstack_; |
cd72c291 ILT |
682 | uint64_t max_page_size_; |
683 | uint64_t common_page_size_; | |
c7912668 | 684 | unsigned int debug_; |
bae7f79e ILT |
685 | }; |
686 | ||
687 | // The current state of the position dependent options. | |
688 | ||
689 | class Position_dependent_options | |
690 | { | |
691 | public: | |
bc644c6c ILT |
692 | typedef General_options::Object_format Object_format; |
693 | ||
bae7f79e ILT |
694 | Position_dependent_options(); |
695 | ||
61611222 ILT |
696 | // -Bdynamic/-Bstatic: Whether we are searching for a static archive |
697 | // -rather than a shared object. | |
bae7f79e | 698 | bool |
7cc619c3 ILT |
699 | Bdynamic() const |
700 | { return !this->do_static_search_; } | |
bae7f79e | 701 | |
dbe717ef ILT |
702 | // --as-needed: Whether to add a DT_NEEDED argument only if the |
703 | // dynamic object is used. | |
704 | bool | |
705 | as_needed() const | |
706 | { return this->as_needed_; } | |
bae7f79e | 707 | |
4973341a ILT |
708 | // --whole-archive: Whether to include the entire contents of an |
709 | // --archive. | |
710 | bool | |
45aa233b | 711 | whole_archive() const |
4973341a ILT |
712 | { return this->include_whole_archive_; } |
713 | ||
bc644c6c ILT |
714 | // --format: The format of the input file. |
715 | Object_format | |
7cc619c3 | 716 | format_enum() const |
bc644c6c ILT |
717 | { return this->input_format_; } |
718 | ||
bae7f79e | 719 | void |
45aa233b ILT |
720 | set_Bstatic(bool value) |
721 | { this->do_static_search_ = value; } | |
bae7f79e ILT |
722 | |
723 | void | |
45aa233b ILT |
724 | set_Bdynamic(bool value) |
725 | { this->set_Bstatic(!value); } | |
bae7f79e | 726 | |
dbe717ef | 727 | void |
45aa233b ILT |
728 | set_as_needed(bool value) |
729 | { this->as_needed_ = value; } | |
dbe717ef ILT |
730 | |
731 | void | |
45aa233b ILT |
732 | set_no_as_needed(bool value) |
733 | { this->set_as_needed(!value); } | |
dbe717ef | 734 | |
4973341a | 735 | void |
45aa233b ILT |
736 | set_whole_archive(bool value) |
737 | { this->include_whole_archive_ = value; } | |
4973341a ILT |
738 | |
739 | void | |
45aa233b ILT |
740 | set_no_whole_archive(bool value) |
741 | { this->set_whole_archive(!value); } | |
4973341a | 742 | |
bc644c6c | 743 | void |
45aa233b | 744 | set_format(const char*); |
bc644c6c | 745 | |
7cc619c3 ILT |
746 | void |
747 | set_format_enum(Object_format value) | |
748 | { this->input_format_ = value; } | |
749 | ||
dbe717ef | 750 | private: |
bae7f79e | 751 | bool do_static_search_; |
dbe717ef | 752 | bool as_needed_; |
4973341a | 753 | bool include_whole_archive_; |
bc644c6c | 754 | Object_format input_format_; |
bae7f79e ILT |
755 | }; |
756 | ||
757 | // A single file or library argument from the command line. | |
758 | ||
ead1e424 | 759 | class Input_file_argument |
bae7f79e ILT |
760 | { |
761 | public: | |
51dee2fe ILT |
762 | // name: file name or library name |
763 | // is_lib: true if name is a library name: that is, emits the leading | |
764 | // "lib" and trailing ".so"/".a" from the name | |
765 | // extra_search_path: an extra directory to look for the file, prior | |
766 | // to checking the normal library search path. If this is "", | |
767 | // then no extra directory is added. | |
88dd47ac | 768 | // just_symbols: whether this file only defines symbols. |
51dee2fe | 769 | // options: The position dependent options at this point in the |
ad2d6943 | 770 | // command line, such as --whole-archive. |
ead1e424 | 771 | Input_file_argument() |
88dd47ac ILT |
772 | : name_(), is_lib_(false), extra_search_path_(""), just_symbols_(false), |
773 | options_() | |
ead1e424 ILT |
774 | { } |
775 | ||
776 | Input_file_argument(const char* name, bool is_lib, | |
51dee2fe | 777 | const char* extra_search_path, |
88dd47ac | 778 | bool just_symbols, |
ead1e424 | 779 | const Position_dependent_options& options) |
51dee2fe | 780 | : name_(name), is_lib_(is_lib), extra_search_path_(extra_search_path), |
88dd47ac | 781 | just_symbols_(just_symbols), options_(options) |
bae7f79e ILT |
782 | { } |
783 | ||
784 | const char* | |
785 | name() const | |
dbe717ef | 786 | { return this->name_.c_str(); } |
bae7f79e ILT |
787 | |
788 | const Position_dependent_options& | |
789 | options() const | |
790 | { return this->options_; } | |
791 | ||
792 | bool | |
793 | is_lib() const | |
61ba1cf9 | 794 | { return this->is_lib_; } |
bae7f79e | 795 | |
51dee2fe ILT |
796 | const char* |
797 | extra_search_path() const | |
798 | { | |
799 | return (this->extra_search_path_.empty() | |
800 | ? NULL | |
801 | : this->extra_search_path_.c_str()); | |
802 | } | |
803 | ||
88dd47ac ILT |
804 | // Return whether we should only read symbols from this file. |
805 | bool | |
806 | just_symbols() const | |
807 | { return this->just_symbols_; } | |
808 | ||
51dee2fe ILT |
809 | // Return whether this file may require a search using the -L |
810 | // options. | |
811 | bool | |
812 | may_need_search() const | |
813 | { return this->is_lib_ || !this->extra_search_path_.empty(); } | |
814 | ||
bae7f79e | 815 | private: |
dbe717ef ILT |
816 | // We use std::string, not const char*, here for convenience when |
817 | // using script files, so that we do not have to preserve the string | |
818 | // in that case. | |
819 | std::string name_; | |
61ba1cf9 | 820 | bool is_lib_; |
51dee2fe | 821 | std::string extra_search_path_; |
88dd47ac | 822 | bool just_symbols_; |
bae7f79e ILT |
823 | Position_dependent_options options_; |
824 | }; | |
825 | ||
ead1e424 ILT |
826 | // A file or library, or a group, from the command line. |
827 | ||
828 | class Input_argument | |
829 | { | |
830 | public: | |
831 | // Create a file or library argument. | |
832 | explicit Input_argument(Input_file_argument file) | |
833 | : is_file_(true), file_(file), group_(NULL) | |
834 | { } | |
835 | ||
836 | // Create a group argument. | |
837 | explicit Input_argument(Input_file_group* group) | |
838 | : is_file_(false), group_(group) | |
839 | { } | |
840 | ||
841 | // Return whether this is a file. | |
842 | bool | |
843 | is_file() const | |
844 | { return this->is_file_; } | |
845 | ||
846 | // Return whether this is a group. | |
847 | bool | |
848 | is_group() const | |
849 | { return !this->is_file_; } | |
850 | ||
851 | // Return the information about the file. | |
852 | const Input_file_argument& | |
853 | file() const | |
854 | { | |
a3ad94ed | 855 | gold_assert(this->is_file_); |
ead1e424 ILT |
856 | return this->file_; |
857 | } | |
858 | ||
859 | // Return the information about the group. | |
860 | const Input_file_group* | |
861 | group() const | |
862 | { | |
a3ad94ed | 863 | gold_assert(!this->is_file_); |
ead1e424 ILT |
864 | return this->group_; |
865 | } | |
866 | ||
867 | Input_file_group* | |
868 | group() | |
869 | { | |
a3ad94ed | 870 | gold_assert(!this->is_file_); |
ead1e424 ILT |
871 | return this->group_; |
872 | } | |
873 | ||
874 | private: | |
875 | bool is_file_; | |
876 | Input_file_argument file_; | |
877 | Input_file_group* group_; | |
878 | }; | |
879 | ||
880 | // A group from the command line. This is a set of arguments within | |
881 | // --start-group ... --end-group. | |
882 | ||
883 | class Input_file_group | |
92e059d8 | 884 | { |
ead1e424 ILT |
885 | public: |
886 | typedef std::vector<Input_argument> Files; | |
887 | typedef Files::const_iterator const_iterator; | |
888 | ||
889 | Input_file_group() | |
890 | : files_() | |
891 | { } | |
892 | ||
893 | // Add a file to the end of the group. | |
894 | void | |
895 | add_file(const Input_file_argument& arg) | |
896 | { this->files_.push_back(Input_argument(arg)); } | |
897 | ||
898 | // Iterators to iterate over the group contents. | |
899 | ||
900 | const_iterator | |
901 | begin() const | |
902 | { return this->files_.begin(); } | |
903 | ||
904 | const_iterator | |
905 | end() const | |
906 | { return this->files_.end(); } | |
907 | ||
908 | private: | |
909 | Files files_; | |
92e059d8 ILT |
910 | }; |
911 | ||
dbe717ef ILT |
912 | // A list of files from the command line or a script. |
913 | ||
914 | class Input_arguments | |
915 | { | |
916 | public: | |
917 | typedef std::vector<Input_argument> Input_argument_list; | |
918 | typedef Input_argument_list::const_iterator const_iterator; | |
919 | ||
920 | Input_arguments() | |
921 | : input_argument_list_(), in_group_(false) | |
922 | { } | |
923 | ||
924 | // Add a file. | |
925 | void | |
926 | add_file(const Input_file_argument& arg); | |
927 | ||
928 | // Start a group (the --start-group option). | |
929 | void | |
930 | start_group(); | |
931 | ||
932 | // End a group (the --end-group option). | |
933 | void | |
934 | end_group(); | |
935 | ||
936 | // Return whether we are currently in a group. | |
937 | bool | |
938 | in_group() const | |
939 | { return this->in_group_; } | |
940 | ||
fe9a4c12 ILT |
941 | // The number of entries in the list. |
942 | int | |
943 | size() const | |
944 | { return this->input_argument_list_.size(); } | |
945 | ||
dbe717ef ILT |
946 | // Iterators to iterate over the list of input files. |
947 | ||
948 | const_iterator | |
949 | begin() const | |
950 | { return this->input_argument_list_.begin(); } | |
951 | ||
952 | const_iterator | |
953 | end() const | |
954 | { return this->input_argument_list_.end(); } | |
955 | ||
956 | // Return whether the list is empty. | |
957 | bool | |
958 | empty() const | |
959 | { return this->input_argument_list_.empty(); } | |
960 | ||
961 | private: | |
962 | Input_argument_list input_argument_list_; | |
963 | bool in_group_; | |
964 | }; | |
965 | ||
bae7f79e ILT |
966 | // All the information read from the command line. |
967 | ||
968 | class Command_line | |
969 | { | |
970 | public: | |
ead1e424 ILT |
971 | typedef Input_arguments::const_iterator const_iterator; |
972 | ||
a5dc0706 | 973 | Command_line(); |
bae7f79e ILT |
974 | |
975 | // Process the command line options. This will exit with an | |
976 | // appropriate error message if an unrecognized option is seen. | |
977 | void | |
978 | process(int argc, char** argv); | |
979 | ||
a0451b38 ILT |
980 | // Process one command-line option. This takes the index of argv to |
981 | // process, and returns the index for the next option. | |
982 | int | |
983 | process_one_option(int argc, char** argv, int i, bool* no_more_options); | |
984 | ||
61ba1cf9 ILT |
985 | // Handle a -l option. |
986 | int | |
3c2fafa5 | 987 | process_l_option(int, char**, char*, bool); |
61ba1cf9 | 988 | |
88dd47ac ILT |
989 | // Handle a -R option when it means --rpath. |
990 | void | |
991 | add_to_rpath(const char* arg) | |
992 | { this->options_.add_to_rpath(arg); } | |
993 | ||
994 | // Add a file for which we just read the symbols. | |
995 | void | |
996 | add_just_symbols_file(const char* arg) | |
997 | { | |
998 | this->inputs_.add_file(Input_file_argument(arg, false, "", true, | |
999 | this->position_options_)); | |
1000 | } | |
1001 | ||
ead1e424 ILT |
1002 | // Handle a --start-group option. |
1003 | void | |
1004 | start_group(const char* arg); | |
1005 | ||
1006 | // Handle a --end-group option. | |
1007 | void | |
1008 | end_group(const char* arg); | |
1009 | ||
3c2fafa5 ILT |
1010 | // Get an option argument--a helper function for special processing. |
1011 | const char* | |
1012 | get_special_argument(const char* longname, int argc, char** argv, | |
1013 | const char* arg, bool long_option, | |
1014 | int *pret); | |
1015 | ||
61ba1cf9 | 1016 | // Get the general options. |
bae7f79e ILT |
1017 | const General_options& |
1018 | options() const | |
1019 | { return this->options_; } | |
1020 | ||
3c2fafa5 ILT |
1021 | // Get the position dependent options. |
1022 | const Position_dependent_options& | |
1023 | position_dependent_options() const | |
1024 | { return this->position_options_; } | |
1025 | ||
a5dc0706 ILT |
1026 | // Get the linker-script options. |
1027 | Script_options& | |
e5756efb | 1028 | script_options() |
a5dc0706 | 1029 | { return this->script_options_; } |
e5756efb | 1030 | |
a5dc0706 ILT |
1031 | // Get the version-script options: a convenience routine. |
1032 | const Version_script_info& | |
1033 | version_script() const | |
1034 | { return *this->script_options_.version_script_info(); } | |
e5756efb | 1035 | |
fe9a4c12 ILT |
1036 | // The number of input files. |
1037 | int | |
1038 | number_of_input_files() const | |
1039 | { return this->inputs_.size(); } | |
1040 | ||
ead1e424 ILT |
1041 | // Iterators to iterate over the list of input files. |
1042 | ||
1043 | const_iterator | |
1044 | begin() const | |
1045 | { return this->inputs_.begin(); } | |
1046 | ||
1047 | const_iterator | |
1048 | end() const | |
1049 | { return this->inputs_.end(); } | |
bae7f79e ILT |
1050 | |
1051 | private: | |
ead1e424 ILT |
1052 | Command_line(const Command_line&); |
1053 | Command_line& operator=(const Command_line&); | |
1054 | ||
1055 | // Report usage error. | |
1056 | void | |
1057 | usage() ATTRIBUTE_NORETURN; | |
1058 | void | |
1059 | usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN; | |
1060 | void | |
1061 | usage(const char* msg, char opt) ATTRIBUTE_NORETURN; | |
1062 | ||
1063 | // Apply a command line option. | |
1064 | void | |
1065 | apply_option(const gold::options::One_option&, const char*); | |
1066 | ||
1067 | // Add a file. | |
1068 | void | |
1069 | add_file(const char* name, bool is_lib); | |
bae7f79e | 1070 | |
46738c9a ILT |
1071 | // Examine the result of processing the command-line, and verify |
1072 | // the flags do not contradict each other or are otherwise illegal. | |
1073 | void | |
1074 | normalize_options(); | |
1075 | ||
bae7f79e ILT |
1076 | General_options options_; |
1077 | Position_dependent_options position_options_; | |
a5dc0706 | 1078 | Script_options script_options_; |
ead1e424 | 1079 | Input_arguments inputs_; |
bae7f79e ILT |
1080 | }; |
1081 | ||
1082 | } // End namespace gold. | |
1083 | ||
1084 | #endif // !defined(GOLD_OPTIONS_H) |