Ignore version scripts for relocatable links.
[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.
88dd47ac 639 // just_symbols: whether this file only defines symbols.
51dee2fe 640 // options: The position dependent options at this point in the
ad2d6943 641 // command line, such as --whole-archive.
ead1e424 642 Input_file_argument()
88dd47ac
ILT
643 : name_(), is_lib_(false), extra_search_path_(""), just_symbols_(false),
644 options_()
ead1e424
ILT
645 { }
646
647 Input_file_argument(const char* name, bool is_lib,
51dee2fe 648 const char* extra_search_path,
88dd47ac 649 bool just_symbols,
ead1e424 650 const Position_dependent_options& options)
51dee2fe 651 : name_(name), is_lib_(is_lib), extra_search_path_(extra_search_path),
88dd47ac 652 just_symbols_(just_symbols), options_(options)
bae7f79e
ILT
653 { }
654
655 const char*
656 name() const
dbe717ef 657 { return this->name_.c_str(); }
bae7f79e
ILT
658
659 const Position_dependent_options&
660 options() const
661 { return this->options_; }
662
663 bool
664 is_lib() const
61ba1cf9 665 { return this->is_lib_; }
bae7f79e 666
51dee2fe
ILT
667 const char*
668 extra_search_path() const
669 {
670 return (this->extra_search_path_.empty()
671 ? NULL
672 : this->extra_search_path_.c_str());
673 }
674
88dd47ac
ILT
675 // Return whether we should only read symbols from this file.
676 bool
677 just_symbols() const
678 { return this->just_symbols_; }
679
51dee2fe
ILT
680 // Return whether this file may require a search using the -L
681 // options.
682 bool
683 may_need_search() const
684 { return this->is_lib_ || !this->extra_search_path_.empty(); }
685
bae7f79e 686 private:
dbe717ef
ILT
687 // We use std::string, not const char*, here for convenience when
688 // using script files, so that we do not have to preserve the string
689 // in that case.
690 std::string name_;
61ba1cf9 691 bool is_lib_;
51dee2fe 692 std::string extra_search_path_;
88dd47ac 693 bool just_symbols_;
bae7f79e
ILT
694 Position_dependent_options options_;
695};
696
ead1e424
ILT
697// A file or library, or a group, from the command line.
698
699class Input_argument
700{
701 public:
702 // Create a file or library argument.
703 explicit Input_argument(Input_file_argument file)
704 : is_file_(true), file_(file), group_(NULL)
705 { }
706
707 // Create a group argument.
708 explicit Input_argument(Input_file_group* group)
709 : is_file_(false), group_(group)
710 { }
711
712 // Return whether this is a file.
713 bool
714 is_file() const
715 { return this->is_file_; }
716
717 // Return whether this is a group.
718 bool
719 is_group() const
720 { return !this->is_file_; }
721
722 // Return the information about the file.
723 const Input_file_argument&
724 file() const
725 {
a3ad94ed 726 gold_assert(this->is_file_);
ead1e424
ILT
727 return this->file_;
728 }
729
730 // Return the information about the group.
731 const Input_file_group*
732 group() const
733 {
a3ad94ed 734 gold_assert(!this->is_file_);
ead1e424
ILT
735 return this->group_;
736 }
737
738 Input_file_group*
739 group()
740 {
a3ad94ed 741 gold_assert(!this->is_file_);
ead1e424
ILT
742 return this->group_;
743 }
744
745 private:
746 bool is_file_;
747 Input_file_argument file_;
748 Input_file_group* group_;
749};
750
751// A group from the command line. This is a set of arguments within
752// --start-group ... --end-group.
753
754class Input_file_group
92e059d8 755{
ead1e424
ILT
756 public:
757 typedef std::vector<Input_argument> Files;
758 typedef Files::const_iterator const_iterator;
759
760 Input_file_group()
761 : files_()
762 { }
763
764 // Add a file to the end of the group.
765 void
766 add_file(const Input_file_argument& arg)
767 { this->files_.push_back(Input_argument(arg)); }
768
769 // Iterators to iterate over the group contents.
770
771 const_iterator
772 begin() const
773 { return this->files_.begin(); }
774
775 const_iterator
776 end() const
777 { return this->files_.end(); }
778
779 private:
780 Files files_;
92e059d8
ILT
781};
782
dbe717ef
ILT
783// A list of files from the command line or a script.
784
785class Input_arguments
786{
787 public:
788 typedef std::vector<Input_argument> Input_argument_list;
789 typedef Input_argument_list::const_iterator const_iterator;
790
791 Input_arguments()
792 : input_argument_list_(), in_group_(false)
793 { }
794
795 // Add a file.
796 void
797 add_file(const Input_file_argument& arg);
798
799 // Start a group (the --start-group option).
800 void
801 start_group();
802
803 // End a group (the --end-group option).
804 void
805 end_group();
806
807 // Return whether we are currently in a group.
808 bool
809 in_group() const
810 { return this->in_group_; }
811
fe9a4c12
ILT
812 // The number of entries in the list.
813 int
814 size() const
815 { return this->input_argument_list_.size(); }
816
dbe717ef
ILT
817 // Iterators to iterate over the list of input files.
818
819 const_iterator
820 begin() const
821 { return this->input_argument_list_.begin(); }
822
823 const_iterator
824 end() const
825 { return this->input_argument_list_.end(); }
826
827 // Return whether the list is empty.
828 bool
829 empty() const
830 { return this->input_argument_list_.empty(); }
831
832 private:
833 Input_argument_list input_argument_list_;
834 bool in_group_;
835};
836
bae7f79e
ILT
837// All the information read from the command line.
838
839class Command_line
840{
841 public:
ead1e424
ILT
842 typedef Input_arguments::const_iterator const_iterator;
843
e5756efb 844 Command_line(Script_options*);
bae7f79e
ILT
845
846 // Process the command line options. This will exit with an
847 // appropriate error message if an unrecognized option is seen.
848 void
849 process(int argc, char** argv);
850
a0451b38
ILT
851 // Process one command-line option. This takes the index of argv to
852 // process, and returns the index for the next option.
853 int
854 process_one_option(int argc, char** argv, int i, bool* no_more_options);
855
61ba1cf9
ILT
856 // Handle a -l option.
857 int
3c2fafa5 858 process_l_option(int, char**, char*, bool);
61ba1cf9 859
88dd47ac
ILT
860 // Handle a -R option when it means --rpath.
861 void
862 add_to_rpath(const char* arg)
863 { this->options_.add_to_rpath(arg); }
864
865 // Add a file for which we just read the symbols.
866 void
867 add_just_symbols_file(const char* arg)
868 {
869 this->inputs_.add_file(Input_file_argument(arg, false, "", true,
870 this->position_options_));
871 }
872
ead1e424
ILT
873 // Handle a --start-group option.
874 void
875 start_group(const char* arg);
876
877 // Handle a --end-group option.
878 void
879 end_group(const char* arg);
880
3c2fafa5
ILT
881 // Get an option argument--a helper function for special processing.
882 const char*
883 get_special_argument(const char* longname, int argc, char** argv,
884 const char* arg, bool long_option,
885 int *pret);
886
61ba1cf9 887 // Get the general options.
bae7f79e
ILT
888 const General_options&
889 options() const
890 { return this->options_; }
891
3c2fafa5
ILT
892 // Get the position dependent options.
893 const Position_dependent_options&
894 position_dependent_options() const
895 { return this->position_options_; }
896
e5756efb
ILT
897 // Get the options which may be set from a linker script.
898 Script_options*
899 script_options()
900 { return this->options_.script_options(); }
901
902 const Script_options*
903 script_options() const
904 { return this->options_.script_options(); }
905
fe9a4c12
ILT
906 // The number of input files.
907 int
908 number_of_input_files() const
909 { return this->inputs_.size(); }
910
ead1e424
ILT
911 // Iterators to iterate over the list of input files.
912
913 const_iterator
914 begin() const
915 { return this->inputs_.begin(); }
916
917 const_iterator
918 end() const
919 { return this->inputs_.end(); }
bae7f79e
ILT
920
921 private:
ead1e424
ILT
922 Command_line(const Command_line&);
923 Command_line& operator=(const Command_line&);
924
925 // Report usage error.
926 void
927 usage() ATTRIBUTE_NORETURN;
928 void
929 usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
930 void
931 usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
932
933 // Apply a command line option.
934 void
935 apply_option(const gold::options::One_option&, const char*);
936
937 // Add a file.
938 void
939 add_file(const char* name, bool is_lib);
bae7f79e 940
46738c9a
ILT
941 // Examine the result of processing the command-line, and verify
942 // the flags do not contradict each other or are otherwise illegal.
943 void
944 normalize_options();
945
bae7f79e
ILT
946 General_options options_;
947 Position_dependent_options position_options_;
ead1e424 948 Input_arguments inputs_;
bae7f79e
ILT
949};
950
951} // End namespace gold.
952
953#endif // !defined(GOLD_OPTIONS_H)
This page took 0.116937 seconds and 4 git commands to generate.