bfd/
[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
3c2fafa5
ILT
40#include "script.h"
41
bae7f79e
ILT
42namespace gold
43{
44
45class Command_line;
ead1e424 46class Input_file_group;
3c2fafa5 47class Position_dependent_options;
bae7f79e 48
c7912668
ILT
49namespace options
50{
bae7f79e
ILT
51
52class Command_line_options;
53struct One_option;
35cdfc9a 54struct One_z_option;
c7912668 55struct One_debug_option;
bae7f79e
ILT
56
57} // End namespace gold::options.
58
ad2d6943
ILT
59// A directory to search. For each directory we record whether it is
60// in the sysroot. We need to know this so that, if a linker script
61// is found within the sysroot, we will apply the sysroot to any files
62// named by that script.
63
64class Search_directory
65{
66 public:
67 // We need a default constructor because we put this in a
68 // std::vector.
69 Search_directory()
70 : name_(NULL), put_in_sysroot_(false), is_in_sysroot_(false)
71 { }
72
73 // This is the usual constructor.
74 Search_directory(const char* name, bool put_in_sysroot)
75 : name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false)
15893b88
ILT
76 {
77 if (this->name_.empty())
78 this->name_ = ".";
79 }
ad2d6943
ILT
80
81 // This is called if we have a sysroot. The sysroot is prefixed to
82 // any entries for which put_in_sysroot_ is true. is_in_sysroot_ is
83 // set to true for any enries which are in the sysroot (this will
84 // naturally include any entries for which put_in_sysroot_ is true).
85 // SYSROOT is the sysroot, CANONICAL_SYSROOT is the result of
86 // passing SYSROOT to lrealpath.
87 void
88 add_sysroot(const char* sysroot, const char* canonical_sysroot);
89
90 // Get the directory name.
91 const std::string&
92 name() const
93 { return this->name_; }
94
95 // Return whether this directory is in the sysroot.
96 bool
97 is_in_sysroot() const
98 { return this->is_in_sysroot_; }
99
100 private:
101 std::string name_;
102 bool put_in_sysroot_;
103 bool is_in_sysroot_;
104};
105
bae7f79e
ILT
106// The position independent options which apply to the whole link.
107// There are a lot of them.
108
109class General_options
110{
111 public:
e5756efb 112 General_options(Script_options*);
bae7f79e 113
d391083d
ILT
114 // -e: set entry address.
115 const char*
116 entry() const
e5756efb 117 { return this->script_options_->entry(); }
d391083d 118
a6badf5a
ILT
119 // -E: export dynamic symbols.
120 bool
121 export_dynamic() const
122 { return this->export_dynamic_; }
123
fced7afd
ILT
124 // -h: shared library name.
125 const char*
126 soname() const
127 { return this->soname_; }
128
dbe717ef
ILT
129 // -I: dynamic linker name.
130 const char*
131 dynamic_linker() const
132 { return this->dynamic_linker_; }
133
bae7f79e 134 // -L: Library search path.
ad2d6943 135 typedef std::vector<Search_directory> Dir_list;
bae7f79e
ILT
136
137 const Dir_list&
138 search_path() const
139 { return this->search_path_; }
140
ca3a67a5
ILT
141 // -O: optimization level (0: don't try to optimize output size).
142 int
143 optimization_level() const
144 { return this->optimization_level_; }
145
61ba1cf9
ILT
146 // -o: Output file name.
147 const char*
148 output_file_name() const
149 { return this->output_file_name_; }
150
bae7f79e
ILT
151 // -r: Whether we are doing a relocatable link.
152 bool
153 is_relocatable() const
154 { return this->is_relocatable_; }
155
9e2dcb77
ILT
156 // -s: Strip all symbols.
157 bool
158 strip_all() const
159 { return this->strip_ == STRIP_ALL; }
160
161 // -S: Strip debugging information.
162 bool
163 strip_debug() const
164 { return this->strip_ == STRIP_ALL || this->strip_ == STRIP_DEBUG; }
165
9a0910c3
ILT
166 // --strip-debug-gdb: strip only debugging information that's not
167 // used by gdb (at least, for gdb versions <= 6.7).
02d2ba74
ILT
168 bool
169 strip_debug_gdb() const
170 { return this->strip_debug() || this->strip_ == STRIP_DEBUG_UNUSED_BY_GDB; }
171
e2827e5f
ILT
172 // --allow-shlib-undefined: do not warn about unresolved symbols in
173 // --shared libraries.
174 bool
175 allow_shlib_undefined() const
176 { return this->allow_shlib_undefined_; }
177
51b08ebe
ILT
178 // -Bsymbolic: bind defined symbols locally.
179 bool
180 symbolic() const
181 { return this->symbolic_; }
182
9a0910c3
ILT
183 // --compress-debug-sections: compress .debug_* sections in the
184 // output file using the given compression method. This is useful
185 // when the tools (such as gdb) support compressed sections.
186 bool
187 compress_debug_sections() const
188 { return this->compress_debug_sections_ != NO_COMPRESSION; }
189
190 bool
191 zlib_compress_debug_sections() const
192 { return this->compress_debug_sections_ == ZLIB_COMPRESSION; }
193
a2b1aa12
ILT
194 // --demangle: demangle C++ symbols in our log messages.
195 bool
196 demangle() const
197 { return this->demangle_; }
198
a55ce7fe
ILT
199 // --detect-odr-violations: Whether to search for One Defn Rule violations.
200 bool
201 detect_odr_violations() const
202 { return this->detect_odr_violations_; }
203
7da52175
ILT
204 // --eh-frame-hdr: Whether to generate an exception frame header.
205 bool
206 create_eh_frame_hdr() const
207 { return this->create_eh_frame_hdr_; }
208
41f542e7
ILT
209 // --rpath: The runtime search path.
210 const Dir_list&
211 rpath() const
212 { return this->rpath_; }
213
15b3cfae
ILT
214 // --rpath-link: The link time search patch for shared libraries.
215 const Dir_list&
216 rpath_link() const
217 { return this->rpath_link_; }
218
92e059d8
ILT
219 // --shared: Whether generating a shared object.
220 bool
221 is_shared() const
222 { return this->is_shared_; }
223
bae7f79e
ILT
224 // --static: Whether doing a static link.
225 bool
226 is_static() const
227 { return this->is_static_; }
228
0c5e9c22 229 // --stats: Print resource usage statistics.
e44fcf3b
ILT
230 bool
231 print_stats() const
232 { return this->print_stats_; }
233
ad2d6943
ILT
234 // --sysroot: The system root of a cross-linker.
235 const std::string&
236 sysroot() const
237 { return this->sysroot_; }
238
09124467
ILT
239 // --version-script: The version script to apply if --shared is true.
240 const Version_script_info&
241 version_script() const
242 { return *this->script_options_->version_script_info(); }
243
0c5e9c22
ILT
244 // -Ttext: The address of the .text section
245 uint64_t
246 text_segment_address() const
247 { return this->text_segment_address_; }
248
249 // Whether -Ttext was used.
250 bool
251 user_set_text_segment_address() const
252 { return this->text_segment_address_ != -1U; }
253
fe9a4c12
ILT
254 // --threads: Whether to use threads.
255 bool
256 threads() const
257 { return this->threads_; }
258
259 // --thread-count-initial: Threads to use in initial pass.
260 int
261 thread_count_initial() const
262 { return this->thread_count_initial_; }
263
264 // --thread-count-middle: Threads to use in middle pass.
265 int
266 thread_count_middle() const
267 { return this->thread_count_middle_; }
268
269 // --thread-count-final: Threads to use in final pass.
270 int
271 thread_count_final() const
272 { return this->thread_count_final_; }
273
35cdfc9a
ILT
274 // -z execstack, -z noexecstack
275 bool
276 is_execstack_set() const
277 { return this->execstack_ != EXECSTACK_FROM_INPUT; }
278
279 bool
280 is_stack_executable() const
281 { return this->execstack_ == EXECSTACK_YES; }
282
c7912668
ILT
283 // --debug
284 unsigned int
285 debug() const
286 { return this->debug_; }
287
e5756efb
ILT
288 // Return the options which may be set from a linker script.
289 Script_options*
290 script_options()
291 { return this->script_options_; }
292
293 const Script_options*
294 script_options() const
295 { return this->script_options_; }
296
bae7f79e 297 private:
dbe717ef
ILT
298 // Don't copy this structure.
299 General_options(const General_options&);
300 General_options& operator=(const General_options&);
301
bae7f79e
ILT
302 friend class Command_line;
303 friend class options::Command_line_options;
304
9e2dcb77
ILT
305 // Which symbols to strip.
306 enum Strip
307 {
308 // Don't strip any symbols.
309 STRIP_NONE,
310 // Strip all symbols.
311 STRIP_ALL,
312 // Strip debugging information.
02d2ba74
ILT
313 STRIP_DEBUG,
314 // Strip debugging information that's not used by gdb (at least <= 6.7)
315 STRIP_DEBUG_UNUSED_BY_GDB
9e2dcb77
ILT
316 };
317
35cdfc9a
ILT
318 // Whether to mark the stack as executable.
319 enum Execstack
320 {
321 // Not set on command line.
322 EXECSTACK_FROM_INPUT,
323 // Mark the stack as executable.
324 EXECSTACK_YES,
325 // Mark the stack as not executable.
326 EXECSTACK_NO
327 };
328
9a0910c3
ILT
329 // What compression method to use
330 enum CompressionMethod
331 {
332 NO_COMPRESSION,
333 ZLIB_COMPRESSION,
334 };
335
d391083d
ILT
336 void
337 set_entry(const char* arg)
e5756efb 338 { this->script_options_->set_entry(arg, strlen(arg)); }
d391083d 339
a6badf5a
ILT
340 void
341 set_export_dynamic()
342 { this->export_dynamic_ = true; }
343
fced7afd
ILT
344 void
345 set_soname(const char* arg)
346 { this->soname_ = arg; }
347
dbe717ef
ILT
348 void
349 set_dynamic_linker(const char* arg)
350 { this->dynamic_linker_ = arg; }
351
bae7f79e
ILT
352 void
353 add_to_search_path(const char* arg)
ad2d6943
ILT
354 { this->search_path_.push_back(Search_directory(arg, false)); }
355
356 void
357 add_to_search_path_with_sysroot(const char* arg)
358 { this->search_path_.push_back(Search_directory(arg, true)); }
bae7f79e 359
ca3a67a5
ILT
360 void
361 set_optimization_level(const char* arg)
3ae7da37
ILT
362 {
363 char* endptr;
364 this->optimization_level_ = strtol(arg, &endptr, 0);
365 if (*endptr != '\0' || this->optimization_level_ < 0)
366 gold_fatal(_("invalid optimization level: %s"), arg);
367 }
ca3a67a5 368
61ba1cf9
ILT
369 void
370 set_output_file_name(const char* arg)
371 { this->output_file_name_ = arg; }
372
bae7f79e
ILT
373 void
374 set_relocatable()
375 { this->is_relocatable_ = true; }
376
9e2dcb77
ILT
377 void
378 set_strip_all()
379 { this->strip_ = STRIP_ALL; }
380
46738c9a
ILT
381 // Note: normalize_options() depends on the fact that this turns off
382 // STRIP_ALL if it were already set.
9e2dcb77
ILT
383 void
384 set_strip_debug()
385 { this->strip_ = STRIP_DEBUG; }
386
02d2ba74
ILT
387 void
388 set_strip_debug_gdb()
389 { this->strip_ = STRIP_DEBUG_UNUSED_BY_GDB; }
390
e2827e5f
ILT
391 void
392 set_allow_shlib_undefined()
393 { this->allow_shlib_undefined_ = true; }
394
395 void
396 set_no_allow_shlib_undefined()
397 { this->allow_shlib_undefined_ = false; }
398
51b08ebe
ILT
399 void
400 set_symbolic()
401 { this->symbolic_ = true; }
402
bc2c67ff 403 void set_compress_debug_sections(const char* arg)
9a0910c3
ILT
404 {
405 if (strcmp(arg, "none") == 0)
406 this->compress_debug_sections_ = NO_COMPRESSION;
407#ifdef HAVE_ZLIB_H
408 else if (strcmp(arg, "zlib") == 0)
409 this->compress_debug_sections_ = ZLIB_COMPRESSION;
410#endif
411 else
bc2c67ff 412 gold_fatal(_("unsupported argument to --compress-debug-sections: %s"),
9a0910c3
ILT
413 arg);
414 }
415
e5756efb
ILT
416 void
417 define_symbol(const char* arg);
418
a2b1aa12
ILT
419 void
420 set_demangle()
421 { this->demangle_ = true; }
422
423 void
424 clear_demangle()
425 { this->demangle_ = false; }
426
a55ce7fe
ILT
427 void
428 set_detect_odr_violations()
429 { this->detect_odr_violations_ = true; }
430
7da52175 431 void
192f9b85 432 set_create_eh_frame_hdr()
7da52175
ILT
433 { this->create_eh_frame_hdr_ = true; }
434
41f542e7
ILT
435 void
436 add_to_rpath(const char* arg)
ad2d6943 437 { this->rpath_.push_back(Search_directory(arg, false)); }
41f542e7 438
15b3cfae
ILT
439 void
440 add_to_rpath_link(const char* arg)
ad2d6943 441 { this->rpath_link_.push_back(Search_directory(arg, false)); }
15b3cfae 442
92e059d8
ILT
443 void
444 set_shared()
445 { this->is_shared_ = true; }
446
bae7f79e
ILT
447 void
448 set_static()
449 { this->is_static_ = true; }
450
e44fcf3b
ILT
451 void
452 set_stats()
453 { this->print_stats_ = true; }
454
ad2d6943
ILT
455 void
456 set_sysroot(const char* arg)
457 { this->sysroot_ = arg; }
458
0c5e9c22
ILT
459 void
460 set_text_segment_address(const char* arg)
461 {
462 char* endptr;
463 this->text_segment_address_ = strtoull(arg, &endptr, 0);
464 if (*endptr != '\0'
465 || this->text_segment_address_ == -1U)
3ae7da37 466 gold_fatal(_("invalid argument to -Ttext: %s"), arg);
0c5e9c22
ILT
467 }
468
fe9a4c12
ILT
469 int
470 parse_thread_count(const char* arg)
471 {
472 char* endptr;
3ae7da37 473 const int count = strtol(arg, &endptr, 0);
fe9a4c12 474 if (*endptr != '\0' || count < 0)
3ae7da37 475 gold_fatal(_("invalid thread count: %s"), arg);
fe9a4c12
ILT
476 return count;
477 }
478
479 void
480 set_threads()
3ae7da37
ILT
481 {
482#ifndef ENABLE_THREADS
483 gold_fatal(_("--threads not supported"));
484#endif
485 this->threads_ = true;
486 }
fe9a4c12
ILT
487
488 void
489 clear_threads()
490 { this->threads_ = false; }
491
492 void
493 set_thread_count(const char* arg)
494 {
495 int count = this->parse_thread_count(arg);
496 this->thread_count_initial_ = count;
497 this->thread_count_middle_ = count;
498 this->thread_count_final_ = count;
499 }
500
501 void
502 set_thread_count_initial(const char* arg)
503 { this->thread_count_initial_ = this->parse_thread_count(arg); }
504
505 void
506 set_thread_count_middle(const char* arg)
460c00b5 507 { this->thread_count_middle_ = this->parse_thread_count(arg); }
fe9a4c12
ILT
508
509 void
510 set_thread_count_final(const char* arg)
460c00b5 511 { this->thread_count_final_ = this->parse_thread_count(arg); }
fe9a4c12 512
652ec9bd
ILT
513 void
514 ignore(const char*)
515 { }
516
35cdfc9a
ILT
517 void
518 set_execstack()
519 { this->execstack_ = EXECSTACK_YES; }
520
521 void
522 set_noexecstack()
523 { this->execstack_ = EXECSTACK_NO; }
524
c7912668
ILT
525 void
526 set_debug(unsigned int flags)
527 { this->debug_ = flags; }
528
35cdfc9a
ILT
529 // Handle the -z option.
530 void
531 handle_z_option(const char*);
532
c7912668
ILT
533 // Handle the --debug option.
534 void
535 handle_debug_option(const char*);
536
ad2d6943
ILT
537 // Apply any sysroot to the directory lists.
538 void
539 add_sysroot();
540
a6badf5a 541 bool export_dynamic_;
fced7afd 542 const char* soname_;
dbe717ef 543 const char* dynamic_linker_;
bae7f79e 544 Dir_list search_path_;
ca3a67a5 545 int optimization_level_;
61ba1cf9 546 const char* output_file_name_;
bae7f79e 547 bool is_relocatable_;
9e2dcb77 548 Strip strip_;
e2827e5f 549 bool allow_shlib_undefined_;
51b08ebe 550 bool symbolic_;
9a0910c3 551 CompressionMethod compress_debug_sections_;
a2b1aa12 552 bool demangle_;
a55ce7fe 553 bool detect_odr_violations_;
7da52175 554 bool create_eh_frame_hdr_;
41f542e7 555 Dir_list rpath_;
15b3cfae 556 Dir_list rpath_link_;
92e059d8 557 bool is_shared_;
bae7f79e 558 bool is_static_;
e44fcf3b 559 bool print_stats_;
ad2d6943 560 std::string sysroot_;
0c5e9c22 561 uint64_t text_segment_address_;
fe9a4c12
ILT
562 bool threads_;
563 int thread_count_initial_;
564 int thread_count_middle_;
565 int thread_count_final_;
35cdfc9a 566 Execstack execstack_;
c7912668 567 unsigned int debug_;
e5756efb
ILT
568 // Some options can also be set from linker scripts. Those are
569 // stored here.
570 Script_options* script_options_;
bae7f79e
ILT
571};
572
573// The current state of the position dependent options.
574
575class Position_dependent_options
576{
577 public:
578 Position_dependent_options();
579
61611222
ILT
580 // -Bdynamic/-Bstatic: Whether we are searching for a static archive
581 // -rather than a shared object.
bae7f79e 582 bool
dbe717ef 583 do_static_search() const
bae7f79e
ILT
584 { return this->do_static_search_; }
585
dbe717ef
ILT
586 // --as-needed: Whether to add a DT_NEEDED argument only if the
587 // dynamic object is used.
588 bool
589 as_needed() const
590 { return this->as_needed_; }
bae7f79e 591
4973341a
ILT
592 // --whole-archive: Whether to include the entire contents of an
593 // --archive.
594 bool
595 include_whole_archive() const
596 { return this->include_whole_archive_; }
597
bae7f79e
ILT
598 void
599 set_static_search()
600 { this->do_static_search_ = true; }
601
602 void
603 set_dynamic_search()
604 { this->do_static_search_ = false; }
605
dbe717ef
ILT
606 void
607 set_as_needed()
608 { this->as_needed_ = true; }
609
610 void
611 clear_as_needed()
612 { this->as_needed_ = false; }
613
4973341a
ILT
614 void
615 set_whole_archive()
616 { this->include_whole_archive_ = true; }
617
618 void
619 clear_whole_archive()
620 { this->include_whole_archive_ = false; }
621
dbe717ef 622 private:
bae7f79e 623 bool do_static_search_;
dbe717ef 624 bool as_needed_;
4973341a 625 bool include_whole_archive_;
bae7f79e
ILT
626};
627
628// A single file or library argument from the command line.
629
ead1e424 630class Input_file_argument
bae7f79e
ILT
631{
632 public:
51dee2fe
ILT
633 // name: file name or library name
634 // is_lib: true if name is a library name: that is, emits the leading
635 // "lib" and trailing ".so"/".a" from the name
636 // extra_search_path: an extra directory to look for the file, prior
637 // to checking the normal library search path. If this is "",
638 // then no extra directory is added.
639 // options: The position dependent options at this point in the
ad2d6943 640 // command line, such as --whole-archive.
ead1e424 641 Input_file_argument()
51dee2fe 642 : name_(), is_lib_(false), extra_search_path_(""), options_()
ead1e424
ILT
643 { }
644
645 Input_file_argument(const char* name, bool is_lib,
51dee2fe 646 const char* extra_search_path,
ead1e424 647 const Position_dependent_options& options)
51dee2fe
ILT
648 : name_(name), is_lib_(is_lib), extra_search_path_(extra_search_path),
649 options_(options)
bae7f79e
ILT
650 { }
651
652 const char*
653 name() const
dbe717ef 654 { return this->name_.c_str(); }
bae7f79e
ILT
655
656 const Position_dependent_options&
657 options() const
658 { return this->options_; }
659
660 bool
661 is_lib() const
61ba1cf9 662 { return this->is_lib_; }
bae7f79e 663
51dee2fe
ILT
664 const char*
665 extra_search_path() const
666 {
667 return (this->extra_search_path_.empty()
668 ? NULL
669 : this->extra_search_path_.c_str());
670 }
671
672 // Return whether this file may require a search using the -L
673 // options.
674 bool
675 may_need_search() const
676 { return this->is_lib_ || !this->extra_search_path_.empty(); }
677
bae7f79e 678 private:
dbe717ef
ILT
679 // We use std::string, not const char*, here for convenience when
680 // using script files, so that we do not have to preserve the string
681 // in that case.
682 std::string name_;
61ba1cf9 683 bool is_lib_;
51dee2fe 684 std::string extra_search_path_;
bae7f79e
ILT
685 Position_dependent_options options_;
686};
687
ead1e424
ILT
688// A file or library, or a group, from the command line.
689
690class Input_argument
691{
692 public:
693 // Create a file or library argument.
694 explicit Input_argument(Input_file_argument file)
695 : is_file_(true), file_(file), group_(NULL)
696 { }
697
698 // Create a group argument.
699 explicit Input_argument(Input_file_group* group)
700 : is_file_(false), group_(group)
701 { }
702
703 // Return whether this is a file.
704 bool
705 is_file() const
706 { return this->is_file_; }
707
708 // Return whether this is a group.
709 bool
710 is_group() const
711 { return !this->is_file_; }
712
713 // Return the information about the file.
714 const Input_file_argument&
715 file() const
716 {
a3ad94ed 717 gold_assert(this->is_file_);
ead1e424
ILT
718 return this->file_;
719 }
720
721 // Return the information about the group.
722 const Input_file_group*
723 group() const
724 {
a3ad94ed 725 gold_assert(!this->is_file_);
ead1e424
ILT
726 return this->group_;
727 }
728
729 Input_file_group*
730 group()
731 {
a3ad94ed 732 gold_assert(!this->is_file_);
ead1e424
ILT
733 return this->group_;
734 }
735
736 private:
737 bool is_file_;
738 Input_file_argument file_;
739 Input_file_group* group_;
740};
741
742// A group from the command line. This is a set of arguments within
743// --start-group ... --end-group.
744
745class Input_file_group
92e059d8 746{
ead1e424
ILT
747 public:
748 typedef std::vector<Input_argument> Files;
749 typedef Files::const_iterator const_iterator;
750
751 Input_file_group()
752 : files_()
753 { }
754
755 // Add a file to the end of the group.
756 void
757 add_file(const Input_file_argument& arg)
758 { this->files_.push_back(Input_argument(arg)); }
759
760 // Iterators to iterate over the group contents.
761
762 const_iterator
763 begin() const
764 { return this->files_.begin(); }
765
766 const_iterator
767 end() const
768 { return this->files_.end(); }
769
770 private:
771 Files files_;
92e059d8
ILT
772};
773
dbe717ef
ILT
774// A list of files from the command line or a script.
775
776class Input_arguments
777{
778 public:
779 typedef std::vector<Input_argument> Input_argument_list;
780 typedef Input_argument_list::const_iterator const_iterator;
781
782 Input_arguments()
783 : input_argument_list_(), in_group_(false)
784 { }
785
786 // Add a file.
787 void
788 add_file(const Input_file_argument& arg);
789
790 // Start a group (the --start-group option).
791 void
792 start_group();
793
794 // End a group (the --end-group option).
795 void
796 end_group();
797
798 // Return whether we are currently in a group.
799 bool
800 in_group() const
801 { return this->in_group_; }
802
fe9a4c12
ILT
803 // The number of entries in the list.
804 int
805 size() const
806 { return this->input_argument_list_.size(); }
807
dbe717ef
ILT
808 // Iterators to iterate over the list of input files.
809
810 const_iterator
811 begin() const
812 { return this->input_argument_list_.begin(); }
813
814 const_iterator
815 end() const
816 { return this->input_argument_list_.end(); }
817
818 // Return whether the list is empty.
819 bool
820 empty() const
821 { return this->input_argument_list_.empty(); }
822
823 private:
824 Input_argument_list input_argument_list_;
825 bool in_group_;
826};
827
bae7f79e
ILT
828// All the information read from the command line.
829
830class Command_line
831{
832 public:
ead1e424
ILT
833 typedef Input_arguments::const_iterator const_iterator;
834
e5756efb 835 Command_line(Script_options*);
bae7f79e
ILT
836
837 // Process the command line options. This will exit with an
838 // appropriate error message if an unrecognized option is seen.
839 void
840 process(int argc, char** argv);
841
a0451b38
ILT
842 // Process one command-line option. This takes the index of argv to
843 // process, and returns the index for the next option.
844 int
845 process_one_option(int argc, char** argv, int i, bool* no_more_options);
846
61ba1cf9
ILT
847 // Handle a -l option.
848 int
3c2fafa5 849 process_l_option(int, char**, char*, bool);
61ba1cf9 850
ead1e424
ILT
851 // Handle a --start-group option.
852 void
853 start_group(const char* arg);
854
855 // Handle a --end-group option.
856 void
857 end_group(const char* arg);
858
3c2fafa5
ILT
859 // Get an option argument--a helper function for special processing.
860 const char*
861 get_special_argument(const char* longname, int argc, char** argv,
862 const char* arg, bool long_option,
863 int *pret);
864
61ba1cf9 865 // Get the general options.
bae7f79e
ILT
866 const General_options&
867 options() const
868 { return this->options_; }
869
3c2fafa5
ILT
870 // Get the position dependent options.
871 const Position_dependent_options&
872 position_dependent_options() const
873 { return this->position_options_; }
874
e5756efb
ILT
875 // Get the options which may be set from a linker script.
876 Script_options*
877 script_options()
878 { return this->options_.script_options(); }
879
880 const Script_options*
881 script_options() const
882 { return this->options_.script_options(); }
883
fe9a4c12
ILT
884 // The number of input files.
885 int
886 number_of_input_files() const
887 { return this->inputs_.size(); }
888
ead1e424
ILT
889 // Iterators to iterate over the list of input files.
890
891 const_iterator
892 begin() const
893 { return this->inputs_.begin(); }
894
895 const_iterator
896 end() const
897 { return this->inputs_.end(); }
bae7f79e
ILT
898
899 private:
ead1e424
ILT
900 Command_line(const Command_line&);
901 Command_line& operator=(const Command_line&);
902
903 // Report usage error.
904 void
905 usage() ATTRIBUTE_NORETURN;
906 void
907 usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
908 void
909 usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
910
911 // Apply a command line option.
912 void
913 apply_option(const gold::options::One_option&, const char*);
914
915 // Add a file.
916 void
917 add_file(const char* name, bool is_lib);
bae7f79e 918
46738c9a
ILT
919 // Examine the result of processing the command-line, and verify
920 // the flags do not contradict each other or are otherwise illegal.
921 void
922 normalize_options();
923
bae7f79e
ILT
924 General_options options_;
925 Position_dependent_options position_options_;
ead1e424 926 Input_arguments inputs_;
bae7f79e
ILT
927};
928
929} // End namespace gold.
930
931#endif // !defined(GOLD_OPTIONS_H)
This page took 0.11413 seconds and 4 git commands to generate.