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