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