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