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