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