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