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