2008-02-26 H.J. Lu <hongjiu.lu@intel.com>
[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
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
153 optimization_level() const
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
516cb3d0
ILT
163 output_format() const
164 { return this->output_format_; }
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
172 is_relocatable() const
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
199 symbolic() const
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
225 create_eh_frame_hdr() const
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
240 is_shared() const
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
265 bss_segment_address() const
266 { return this->bss_segment_address_; }
267
268 // Whether -Tbss was used.
269 bool
270 user_set_bss_segment_address() const
271 { return this->bss_segment_address_ != -1U; }
272
273 // -Tdata: The address of the data segment
274 uint64_t
275 data_segment_address() const
276 { return this->data_segment_address_; }
277
278 // Whether -Tdata was used.
279 bool
280 user_set_data_segment_address() const
281 { return this->data_segment_address_ != -1U; }
282
0c5e9c22
ILT
283 // -Ttext: The address of the .text section
284 uint64_t
285 text_segment_address() const
286 { return this->text_segment_address_; }
287
288 // Whether -Ttext was used.
289 bool
290 user_set_text_segment_address() const
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
c7912668
ILT
322 // --debug
323 unsigned int
324 debug() const
325 { return this->debug_; }
326
e5756efb
ILT
327 // Return the options which may be set from a linker script.
328 Script_options*
329 script_options()
330 { return this->script_options_; }
331
332 const Script_options*
333 script_options() const
334 { return this->script_options_; }
335
bae7f79e 336 private:
dbe717ef
ILT
337 // Don't copy this structure.
338 General_options(const General_options&);
339 General_options& operator=(const General_options&);
340
bae7f79e
ILT
341 friend class Command_line;
342 friend class options::Command_line_options;
343
9e2dcb77
ILT
344 // Which symbols to strip.
345 enum Strip
346 {
347 // Don't strip any symbols.
348 STRIP_NONE,
349 // Strip all symbols.
350 STRIP_ALL,
351 // Strip debugging information.
02d2ba74
ILT
352 STRIP_DEBUG,
353 // Strip debugging information that's not used by gdb (at least <= 6.7)
354 STRIP_DEBUG_UNUSED_BY_GDB
9e2dcb77
ILT
355 };
356
35cdfc9a
ILT
357 // Whether to mark the stack as executable.
358 enum Execstack
359 {
360 // Not set on command line.
361 EXECSTACK_FROM_INPUT,
362 // Mark the stack as executable.
363 EXECSTACK_YES,
364 // Mark the stack as not executable.
365 EXECSTACK_NO
366 };
367
9a0910c3
ILT
368 // What compression method to use
369 enum CompressionMethod
370 {
371 NO_COMPRESSION,
372 ZLIB_COMPRESSION,
373 };
374
d391083d
ILT
375 void
376 set_entry(const char* arg)
e5756efb 377 { this->script_options_->set_entry(arg, strlen(arg)); }
d391083d 378
a6badf5a
ILT
379 void
380 set_export_dynamic()
381 { this->export_dynamic_ = true; }
382
fced7afd
ILT
383 void
384 set_soname(const char* arg)
385 { this->soname_ = arg; }
386
dbe717ef
ILT
387 void
388 set_dynamic_linker(const char* arg)
389 { this->dynamic_linker_ = arg; }
390
bae7f79e
ILT
391 void
392 add_to_search_path(const char* arg)
ad2d6943
ILT
393 { this->search_path_.push_back(Search_directory(arg, false)); }
394
395 void
396 add_to_search_path_with_sysroot(const char* arg)
397 { this->search_path_.push_back(Search_directory(arg, true)); }
bae7f79e 398
ca3a67a5
ILT
399 void
400 set_optimization_level(const char* arg)
3ae7da37
ILT
401 {
402 char* endptr;
403 this->optimization_level_ = strtol(arg, &endptr, 0);
404 if (*endptr != '\0' || this->optimization_level_ < 0)
405 gold_fatal(_("invalid optimization level: %s"), arg);
406 }
ca3a67a5 407
61ba1cf9
ILT
408 void
409 set_output_file_name(const char* arg)
410 { this->output_file_name_ = arg; }
411
516cb3d0
ILT
412 void
413 set_output_format(const char*);
414
bae7f79e
ILT
415 void
416 set_relocatable()
417 { this->is_relocatable_ = true; }
418
9e2dcb77
ILT
419 void
420 set_strip_all()
421 { this->strip_ = STRIP_ALL; }
422
46738c9a
ILT
423 // Note: normalize_options() depends on the fact that this turns off
424 // STRIP_ALL if it were already set.
9e2dcb77
ILT
425 void
426 set_strip_debug()
427 { this->strip_ = STRIP_DEBUG; }
428
02d2ba74
ILT
429 void
430 set_strip_debug_gdb()
431 { this->strip_ = STRIP_DEBUG_UNUSED_BY_GDB; }
432
e2827e5f
ILT
433 void
434 set_allow_shlib_undefined()
435 { this->allow_shlib_undefined_ = true; }
436
437 void
438 set_no_allow_shlib_undefined()
439 { this->allow_shlib_undefined_ = false; }
440
51b08ebe
ILT
441 void
442 set_symbolic()
443 { this->symbolic_ = true; }
444
bc2c67ff 445 void set_compress_debug_sections(const char* arg)
9a0910c3
ILT
446 {
447 if (strcmp(arg, "none") == 0)
448 this->compress_debug_sections_ = NO_COMPRESSION;
449#ifdef HAVE_ZLIB_H
450 else if (strcmp(arg, "zlib") == 0)
451 this->compress_debug_sections_ = ZLIB_COMPRESSION;
452#endif
453 else
bc2c67ff 454 gold_fatal(_("unsupported argument to --compress-debug-sections: %s"),
9a0910c3
ILT
455 arg);
456 }
457
e5756efb
ILT
458 void
459 define_symbol(const char* arg);
460
a2b1aa12
ILT
461 void
462 set_demangle()
463 { this->demangle_ = true; }
464
465 void
466 clear_demangle()
467 { this->demangle_ = false; }
468
a55ce7fe
ILT
469 void
470 set_detect_odr_violations()
471 { this->detect_odr_violations_ = true; }
472
7da52175 473 void
192f9b85 474 set_create_eh_frame_hdr()
7da52175
ILT
475 { this->create_eh_frame_hdr_ = true; }
476
41f542e7
ILT
477 void
478 add_to_rpath(const char* arg)
ad2d6943 479 { this->rpath_.push_back(Search_directory(arg, false)); }
41f542e7 480
15b3cfae
ILT
481 void
482 add_to_rpath_link(const char* arg)
ad2d6943 483 { this->rpath_link_.push_back(Search_directory(arg, false)); }
15b3cfae 484
92e059d8
ILT
485 void
486 set_shared()
487 { this->is_shared_ = true; }
488
bae7f79e
ILT
489 void
490 set_static()
491 { this->is_static_ = true; }
492
e44fcf3b
ILT
493 void
494 set_stats()
495 { this->print_stats_ = true; }
496
ad2d6943
ILT
497 void
498 set_sysroot(const char* arg)
499 { this->sysroot_ = arg; }
500
0c5e9c22 501 void
756ac4a8 502 set_segment_address(const char* name, const char* arg, uint64_t* val)
0c5e9c22
ILT
503 {
504 char* endptr;
756ac4a8
ILT
505 *val = strtoull(arg, &endptr, 0);
506 if (*endptr != '\0' || *val == -1U)
507 gold_fatal(_("invalid argument to %s: %s"), name, arg);
0c5e9c22
ILT
508 }
509
756ac4a8
ILT
510 void
511 set_bss_segment_address(const char* arg)
512 { this->set_segment_address("-Tbss", arg, &this->bss_segment_address_); }
513
514 void
515 set_data_segment_address(const char* arg)
516 { this->set_segment_address("-Tdata", arg, &this->data_segment_address_); }
517
518 void
519 set_text_segment_address(const char* arg)
520 { this->set_segment_address("-Ttext", arg, &this->text_segment_address_); }
521
fe9a4c12
ILT
522 int
523 parse_thread_count(const char* arg)
524 {
525 char* endptr;
3ae7da37 526 const int count = strtol(arg, &endptr, 0);
fe9a4c12 527 if (*endptr != '\0' || count < 0)
3ae7da37 528 gold_fatal(_("invalid thread count: %s"), arg);
fe9a4c12
ILT
529 return count;
530 }
531
532 void
533 set_threads()
3ae7da37
ILT
534 {
535#ifndef ENABLE_THREADS
536 gold_fatal(_("--threads not supported"));
537#endif
538 this->threads_ = true;
539 }
fe9a4c12
ILT
540
541 void
542 clear_threads()
543 { this->threads_ = false; }
544
545 void
546 set_thread_count(const char* arg)
547 {
548 int count = this->parse_thread_count(arg);
549 this->thread_count_initial_ = count;
550 this->thread_count_middle_ = count;
551 this->thread_count_final_ = count;
552 }
553
554 void
555 set_thread_count_initial(const char* arg)
556 { this->thread_count_initial_ = this->parse_thread_count(arg); }
557
558 void
559 set_thread_count_middle(const char* arg)
460c00b5 560 { this->thread_count_middle_ = this->parse_thread_count(arg); }
fe9a4c12
ILT
561
562 void
563 set_thread_count_final(const char* arg)
460c00b5 564 { this->thread_count_final_ = this->parse_thread_count(arg); }
fe9a4c12 565
652ec9bd
ILT
566 void
567 ignore(const char*)
568 { }
569
35cdfc9a
ILT
570 void
571 set_execstack()
572 { this->execstack_ = EXECSTACK_YES; }
573
574 void
575 set_noexecstack()
576 { this->execstack_ = EXECSTACK_NO; }
577
c7912668
ILT
578 void
579 set_debug(unsigned int flags)
580 { this->debug_ = flags; }
581
35cdfc9a
ILT
582 // Handle the -z option.
583 void
584 handle_z_option(const char*);
585
c7912668
ILT
586 // Handle the --debug option.
587 void
588 handle_debug_option(const char*);
589
ad2d6943
ILT
590 // Apply any sysroot to the directory lists.
591 void
592 add_sysroot();
593
a6badf5a 594 bool export_dynamic_;
fced7afd 595 const char* soname_;
dbe717ef 596 const char* dynamic_linker_;
bae7f79e 597 Dir_list search_path_;
ca3a67a5 598 int optimization_level_;
61ba1cf9 599 const char* output_file_name_;
bc644c6c 600 Object_format output_format_;
0daa6f62 601 const char* output_format_string_;
bae7f79e 602 bool is_relocatable_;
9e2dcb77 603 Strip strip_;
e2827e5f 604 bool allow_shlib_undefined_;
51b08ebe 605 bool symbolic_;
9a0910c3 606 CompressionMethod compress_debug_sections_;
a2b1aa12 607 bool demangle_;
a55ce7fe 608 bool detect_odr_violations_;
7da52175 609 bool create_eh_frame_hdr_;
41f542e7 610 Dir_list rpath_;
15b3cfae 611 Dir_list rpath_link_;
92e059d8 612 bool is_shared_;
bae7f79e 613 bool is_static_;
e44fcf3b 614 bool print_stats_;
ad2d6943 615 std::string sysroot_;
756ac4a8
ILT
616 uint64_t bss_segment_address_;
617 uint64_t data_segment_address_;
0c5e9c22 618 uint64_t text_segment_address_;
fe9a4c12
ILT
619 bool threads_;
620 int thread_count_initial_;
621 int thread_count_middle_;
622 int thread_count_final_;
35cdfc9a 623 Execstack execstack_;
c7912668 624 unsigned int debug_;
e5756efb
ILT
625 // Some options can also be set from linker scripts. Those are
626 // stored here.
627 Script_options* script_options_;
bae7f79e
ILT
628};
629
630// The current state of the position dependent options.
631
632class Position_dependent_options
633{
634 public:
bc644c6c
ILT
635 typedef General_options::Object_format Object_format;
636
bae7f79e
ILT
637 Position_dependent_options();
638
61611222
ILT
639 // -Bdynamic/-Bstatic: Whether we are searching for a static archive
640 // -rather than a shared object.
bae7f79e 641 bool
dbe717ef 642 do_static_search() const
bae7f79e
ILT
643 { return this->do_static_search_; }
644
dbe717ef
ILT
645 // --as-needed: Whether to add a DT_NEEDED argument only if the
646 // dynamic object is used.
647 bool
648 as_needed() const
649 { return this->as_needed_; }
bae7f79e 650
4973341a
ILT
651 // --whole-archive: Whether to include the entire contents of an
652 // --archive.
653 bool
654 include_whole_archive() const
655 { return this->include_whole_archive_; }
656
bc644c6c
ILT
657 // --format: The format of the input file.
658 Object_format
659 input_format() const
660 { return this->input_format_; }
661
bae7f79e
ILT
662 void
663 set_static_search()
664 { this->do_static_search_ = true; }
665
666 void
667 set_dynamic_search()
668 { this->do_static_search_ = false; }
669
dbe717ef
ILT
670 void
671 set_as_needed()
672 { this->as_needed_ = true; }
673
674 void
675 clear_as_needed()
676 { this->as_needed_ = false; }
677
4973341a
ILT
678 void
679 set_whole_archive()
680 { this->include_whole_archive_ = true; }
681
682 void
683 clear_whole_archive()
684 { this->include_whole_archive_ = false; }
685
bc644c6c
ILT
686 void
687 set_input_format(const char*);
688
dbe717ef 689 private:
bae7f79e 690 bool do_static_search_;
dbe717ef 691 bool as_needed_;
4973341a 692 bool include_whole_archive_;
bc644c6c 693 Object_format input_format_;
bae7f79e
ILT
694};
695
696// A single file or library argument from the command line.
697
ead1e424 698class Input_file_argument
bae7f79e
ILT
699{
700 public:
51dee2fe
ILT
701 // name: file name or library name
702 // is_lib: true if name is a library name: that is, emits the leading
703 // "lib" and trailing ".so"/".a" from the name
704 // extra_search_path: an extra directory to look for the file, prior
705 // to checking the normal library search path. If this is "",
706 // then no extra directory is added.
88dd47ac 707 // just_symbols: whether this file only defines symbols.
51dee2fe 708 // options: The position dependent options at this point in the
ad2d6943 709 // command line, such as --whole-archive.
ead1e424 710 Input_file_argument()
88dd47ac
ILT
711 : name_(), is_lib_(false), extra_search_path_(""), just_symbols_(false),
712 options_()
ead1e424
ILT
713 { }
714
715 Input_file_argument(const char* name, bool is_lib,
51dee2fe 716 const char* extra_search_path,
88dd47ac 717 bool just_symbols,
ead1e424 718 const Position_dependent_options& options)
51dee2fe 719 : name_(name), is_lib_(is_lib), extra_search_path_(extra_search_path),
88dd47ac 720 just_symbols_(just_symbols), options_(options)
bae7f79e
ILT
721 { }
722
723 const char*
724 name() const
dbe717ef 725 { return this->name_.c_str(); }
bae7f79e
ILT
726
727 const Position_dependent_options&
728 options() const
729 { return this->options_; }
730
731 bool
732 is_lib() const
61ba1cf9 733 { return this->is_lib_; }
bae7f79e 734
51dee2fe
ILT
735 const char*
736 extra_search_path() const
737 {
738 return (this->extra_search_path_.empty()
739 ? NULL
740 : this->extra_search_path_.c_str());
741 }
742
88dd47ac
ILT
743 // Return whether we should only read symbols from this file.
744 bool
745 just_symbols() const
746 { return this->just_symbols_; }
747
51dee2fe
ILT
748 // Return whether this file may require a search using the -L
749 // options.
750 bool
751 may_need_search() const
752 { return this->is_lib_ || !this->extra_search_path_.empty(); }
753
bae7f79e 754 private:
dbe717ef
ILT
755 // We use std::string, not const char*, here for convenience when
756 // using script files, so that we do not have to preserve the string
757 // in that case.
758 std::string name_;
61ba1cf9 759 bool is_lib_;
51dee2fe 760 std::string extra_search_path_;
88dd47ac 761 bool just_symbols_;
bae7f79e
ILT
762 Position_dependent_options options_;
763};
764
ead1e424
ILT
765// A file or library, or a group, from the command line.
766
767class Input_argument
768{
769 public:
770 // Create a file or library argument.
771 explicit Input_argument(Input_file_argument file)
772 : is_file_(true), file_(file), group_(NULL)
773 { }
774
775 // Create a group argument.
776 explicit Input_argument(Input_file_group* group)
777 : is_file_(false), group_(group)
778 { }
779
780 // Return whether this is a file.
781 bool
782 is_file() const
783 { return this->is_file_; }
784
785 // Return whether this is a group.
786 bool
787 is_group() const
788 { return !this->is_file_; }
789
790 // Return the information about the file.
791 const Input_file_argument&
792 file() const
793 {
a3ad94ed 794 gold_assert(this->is_file_);
ead1e424
ILT
795 return this->file_;
796 }
797
798 // Return the information about the group.
799 const Input_file_group*
800 group() const
801 {
a3ad94ed 802 gold_assert(!this->is_file_);
ead1e424
ILT
803 return this->group_;
804 }
805
806 Input_file_group*
807 group()
808 {
a3ad94ed 809 gold_assert(!this->is_file_);
ead1e424
ILT
810 return this->group_;
811 }
812
813 private:
814 bool is_file_;
815 Input_file_argument file_;
816 Input_file_group* group_;
817};
818
819// A group from the command line. This is a set of arguments within
820// --start-group ... --end-group.
821
822class Input_file_group
92e059d8 823{
ead1e424
ILT
824 public:
825 typedef std::vector<Input_argument> Files;
826 typedef Files::const_iterator const_iterator;
827
828 Input_file_group()
829 : files_()
830 { }
831
832 // Add a file to the end of the group.
833 void
834 add_file(const Input_file_argument& arg)
835 { this->files_.push_back(Input_argument(arg)); }
836
837 // Iterators to iterate over the group contents.
838
839 const_iterator
840 begin() const
841 { return this->files_.begin(); }
842
843 const_iterator
844 end() const
845 { return this->files_.end(); }
846
847 private:
848 Files files_;
92e059d8
ILT
849};
850
dbe717ef
ILT
851// A list of files from the command line or a script.
852
853class Input_arguments
854{
855 public:
856 typedef std::vector<Input_argument> Input_argument_list;
857 typedef Input_argument_list::const_iterator const_iterator;
858
859 Input_arguments()
860 : input_argument_list_(), in_group_(false)
861 { }
862
863 // Add a file.
864 void
865 add_file(const Input_file_argument& arg);
866
867 // Start a group (the --start-group option).
868 void
869 start_group();
870
871 // End a group (the --end-group option).
872 void
873 end_group();
874
875 // Return whether we are currently in a group.
876 bool
877 in_group() const
878 { return this->in_group_; }
879
fe9a4c12
ILT
880 // The number of entries in the list.
881 int
882 size() const
883 { return this->input_argument_list_.size(); }
884
dbe717ef
ILT
885 // Iterators to iterate over the list of input files.
886
887 const_iterator
888 begin() const
889 { return this->input_argument_list_.begin(); }
890
891 const_iterator
892 end() const
893 { return this->input_argument_list_.end(); }
894
895 // Return whether the list is empty.
896 bool
897 empty() const
898 { return this->input_argument_list_.empty(); }
899
900 private:
901 Input_argument_list input_argument_list_;
902 bool in_group_;
903};
904
bae7f79e
ILT
905// All the information read from the command line.
906
907class Command_line
908{
909 public:
ead1e424
ILT
910 typedef Input_arguments::const_iterator const_iterator;
911
e5756efb 912 Command_line(Script_options*);
bae7f79e
ILT
913
914 // Process the command line options. This will exit with an
915 // appropriate error message if an unrecognized option is seen.
916 void
917 process(int argc, char** argv);
918
a0451b38
ILT
919 // Process one command-line option. This takes the index of argv to
920 // process, and returns the index for the next option.
921 int
922 process_one_option(int argc, char** argv, int i, bool* no_more_options);
923
61ba1cf9
ILT
924 // Handle a -l option.
925 int
3c2fafa5 926 process_l_option(int, char**, char*, bool);
61ba1cf9 927
88dd47ac
ILT
928 // Handle a -R option when it means --rpath.
929 void
930 add_to_rpath(const char* arg)
931 { this->options_.add_to_rpath(arg); }
932
933 // Add a file for which we just read the symbols.
934 void
935 add_just_symbols_file(const char* arg)
936 {
937 this->inputs_.add_file(Input_file_argument(arg, false, "", true,
938 this->position_options_));
939 }
940
ead1e424
ILT
941 // Handle a --start-group option.
942 void
943 start_group(const char* arg);
944
945 // Handle a --end-group option.
946 void
947 end_group(const char* arg);
948
3c2fafa5
ILT
949 // Get an option argument--a helper function for special processing.
950 const char*
951 get_special_argument(const char* longname, int argc, char** argv,
952 const char* arg, bool long_option,
953 int *pret);
954
61ba1cf9 955 // Get the general options.
bae7f79e
ILT
956 const General_options&
957 options() const
958 { return this->options_; }
959
3c2fafa5
ILT
960 // Get the position dependent options.
961 const Position_dependent_options&
962 position_dependent_options() const
963 { return this->position_options_; }
964
e5756efb
ILT
965 // Get the options which may be set from a linker script.
966 Script_options*
967 script_options()
968 { return this->options_.script_options(); }
969
970 const Script_options*
971 script_options() const
972 { return this->options_.script_options(); }
973
fe9a4c12
ILT
974 // The number of input files.
975 int
976 number_of_input_files() const
977 { return this->inputs_.size(); }
978
ead1e424
ILT
979 // Iterators to iterate over the list of input files.
980
981 const_iterator
982 begin() const
983 { return this->inputs_.begin(); }
984
985 const_iterator
986 end() const
987 { return this->inputs_.end(); }
bae7f79e
ILT
988
989 private:
ead1e424
ILT
990 Command_line(const Command_line&);
991 Command_line& operator=(const Command_line&);
992
993 // Report usage error.
994 void
995 usage() ATTRIBUTE_NORETURN;
996 void
997 usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
998 void
999 usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
1000
1001 // Apply a command line option.
1002 void
1003 apply_option(const gold::options::One_option&, const char*);
1004
1005 // Add a file.
1006 void
1007 add_file(const char* name, bool is_lib);
bae7f79e 1008
46738c9a
ILT
1009 // Examine the result of processing the command-line, and verify
1010 // the flags do not contradict each other or are otherwise illegal.
1011 void
1012 normalize_options();
1013
bae7f79e
ILT
1014 General_options options_;
1015 Position_dependent_options position_options_;
ead1e424 1016 Input_arguments inputs_;
bae7f79e
ILT
1017};
1018
1019} // End namespace gold.
1020
1021#endif // !defined(GOLD_OPTIONS_H)
This page took 0.126344 seconds and 4 git commands to generate.