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