1 // inremental.h -- incremental linking support for gold -*- C++ -*-
3 // Copyright 2009, 2010 Free Software Foundation, Inc.
4 // Written by Mikolaj Zalewski <mikolajz@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #ifndef GOLD_INCREMENTAL_H
24 #define GOLD_INCREMENTAL_H
29 #include "elfcpp_file.h"
30 #include "stringpool.h"
31 #include "workqueue.h"
40 class Incremental_inputs_checker;
41 class Incremental_script_entry;
42 class Incremental_object_entry;
43 class Incremental_archive_entry;
44 class Incremental_inputs;
45 class Incremental_binary;
48 // Incremental input type as stored in .gnu_incremental_inputs.
50 enum Incremental_input_type
52 INCREMENTAL_INPUT_OBJECT = 1,
53 INCREMENTAL_INPUT_ARCHIVE_MEMBER = 2,
54 INCREMENTAL_INPUT_ARCHIVE = 3,
55 INCREMENTAL_INPUT_SHARED_LIBRARY = 4,
56 INCREMENTAL_INPUT_SCRIPT = 5
59 // Create an Incremental_binary object for FILE. Returns NULL is this is not
60 // possible, e.g. FILE is not an ELF file or has an unsupported target.
63 open_incremental_binary(Output_file* file);
65 // Code invoked early during an incremental link that checks what files need
68 class Incremental_checker
71 // Check if the file named OUTPUT_NAME can be linked incrementally.
72 // INCREMENTAL_INPUTS must have the canonical form of the command line
73 // and input arguments filled - at this point of linking other fields are
74 // probably not filled yet. TODO: for inputs that don't need to be
75 // rebuilt, this function should fill the incremental input information.
76 Incremental_checker(const char* output_name,
77 Incremental_inputs* incremental_inputs)
78 : output_name_(output_name), incremental_inputs_(incremental_inputs)
81 // Analyzes the output file to check if incremental linking is possible and
82 // what files needs to be relinked.
84 can_incrementally_link_output_file();
87 // Name of the output file to analyze.
88 const char* output_name_;
90 // The Incremental_inputs object. At this stage of link, only the command
91 // line and inputs are filled.
92 Incremental_inputs* incremental_inputs_;
95 // Base class for recording each input file.
97 class Incremental_input_entry
100 Incremental_input_entry(Stringpool::Key filename_key, Timespec mtime)
101 : filename_key_(filename_key), offset_(0), info_offset_(0), mtime_(mtime)
105 ~Incremental_input_entry()
108 // Return the type of input file.
109 Incremental_input_type
111 { return this->do_type(); }
113 // Set the section offset of this input file entry.
115 set_offset(unsigned int offset)
116 { this->offset_ = offset; }
118 // Set the section offset of the supplemental information for this entry.
120 set_info_offset(unsigned int info_offset)
121 { this->info_offset_ = info_offset; }
123 // Get the section offset of this input file entry.
126 { return this->offset_; }
128 // Get the section offset of the supplemental information for this entry.
130 get_info_offset() const
131 { return this->info_offset_; }
133 // Get the stringpool key for the input filename.
135 get_filename_key() const
136 { return this->filename_key_; }
138 // Get the modification time of the input file.
141 { return this->mtime_; }
143 // Return a pointer to the derived Incremental_script_entry object.
144 // Return NULL for input entries that are not script files.
145 Incremental_script_entry*
147 { return this->do_script_entry(); }
149 // Return a pointer to the derived Incremental_object_entry object.
150 // Return NULL for input entries that are not object files.
151 Incremental_object_entry*
153 { return this->do_object_entry(); }
155 // Return a pointer to the derived Incremental_archive_entry object.
156 // Return NULL for input entries that are not archive files.
157 Incremental_archive_entry*
159 { return this->do_archive_entry(); }
162 // Return the type of input file.
163 virtual Incremental_input_type
166 // Return a pointer to the derived Incremental_script_entry object.
167 // Return NULL for input entries that are not script files.
168 virtual Incremental_script_entry*
172 // Return a pointer to the derived Incremental_object_entry object.
173 // Return NULL for input entries that are not object files.
174 virtual Incremental_object_entry*
178 // Return a pointer to the derived Incremental_archive_entry object.
179 // Return NULL for input entries that are not archive files.
180 virtual Incremental_archive_entry*
185 // Key of the filename string in the section stringtable.
186 Stringpool::Key filename_key_;
188 // Offset of the entry in the output section.
189 unsigned int offset_;
191 // Offset of the extra information in the output section.
192 unsigned int info_offset_;
194 // Last modification time of the file.
198 // Class for recording input scripts.
200 class Incremental_script_entry : public Incremental_input_entry
203 Incremental_script_entry(Stringpool::Key filename_key, Script_info* script,
205 : Incremental_input_entry(filename_key, mtime), script_(script), objects_()
208 // Add a member object to the archive.
210 add_object(Incremental_input_entry* obj_entry)
212 this->objects_.push_back(obj_entry);
215 // Return the number of objects included by this script.
218 { return this->objects_.size(); }
220 // Return the Nth object.
221 Incremental_input_entry*
222 get_object(unsigned int n)
224 gold_assert(n < this->objects_.size());
225 return this->objects_[n];
229 virtual Incremental_input_type
231 { return INCREMENTAL_INPUT_SCRIPT; }
233 // Return a pointer to the derived Incremental_script_entry object.
234 virtual Incremental_script_entry*
239 // Information about the script file.
240 Script_info* script_;
241 // Objects that have been included by this script.
242 std::vector<Incremental_input_entry*> objects_;
245 // Class for recording input object files.
247 class Incremental_object_entry : public Incremental_input_entry
250 Incremental_object_entry(Stringpool::Key filename_key, Object* obj,
252 : Incremental_input_entry(filename_key, mtime), obj_(obj),
253 is_member_(false), sections_()
255 if (!obj_->is_dynamic())
256 this->sections_.reserve(obj->shnum());
262 { return this->obj_; }
264 // Record that this object is an archive member.
267 { this->is_member_ = true; }
269 // Return true if this object is an archive member.
272 { return this->is_member_; }
274 // Add an input section.
276 add_input_section(unsigned int shndx, Stringpool::Key name_key, off_t sh_size)
278 if (shndx >= this->sections_.size())
279 this->sections_.resize(shndx + 1);
280 this->sections_[shndx].name_key = name_key;
281 this->sections_[shndx].sh_size = sh_size;
284 // Return the number of input sections in this object.
286 get_input_section_count() const
287 { return this->sections_.size(); }
289 // Return the stringpool key of the Nth input section.
291 get_input_section_name_key(unsigned int n) const
292 { return this->sections_[n].name_key; }
294 // Return the size of the Nth input section.
296 get_input_section_size(unsigned int n) const
297 { return this->sections_[n].sh_size; }
300 virtual Incremental_input_type
303 return (this->is_member_
304 ? INCREMENTAL_INPUT_ARCHIVE_MEMBER
305 : (this->obj_->is_dynamic()
306 ? INCREMENTAL_INPUT_SHARED_LIBRARY
307 : INCREMENTAL_INPUT_OBJECT));
310 // Return a pointer to the derived Incremental_object_entry object.
311 virtual Incremental_object_entry*
316 // The object file itself.
319 // Whether this object is an archive member.
325 Stringpool::Key name_key;
328 std::vector<Input_section> sections_;
331 // Class for recording archive library input files.
333 class Incremental_archive_entry : public Incremental_input_entry
336 Incremental_archive_entry(Stringpool::Key filename_key, Timespec mtime)
337 : Incremental_input_entry(filename_key, mtime), members_(), unused_syms_()
340 // Add a member object to the archive.
342 add_object(Incremental_object_entry* obj_entry)
344 this->members_.push_back(obj_entry);
345 obj_entry->set_is_member();
348 // Add an unused global symbol to the archive.
350 add_unused_global_symbol(Stringpool::Key symbol_key)
351 { this->unused_syms_.push_back(symbol_key); }
353 // Return the number of member objects included in the link.
356 { return this->members_.size(); }
358 // Return the Nth member object.
359 Incremental_object_entry*
360 get_member(unsigned int n)
361 { return this->members_[n]; }
363 // Return the number of unused global symbols in this archive.
365 get_unused_global_symbol_count()
366 { return this->unused_syms_.size(); }
368 // Return the Nth unused global symbol.
370 get_unused_global_symbol(unsigned int n)
371 { return this->unused_syms_[n]; }
374 virtual Incremental_input_type
376 { return INCREMENTAL_INPUT_ARCHIVE; }
378 // Return a pointer to the derived Incremental_archive_entry object.
379 virtual Incremental_archive_entry*
384 // Members of the archive that have been included in the link.
385 std::vector<Incremental_object_entry*> members_;
387 // Unused global symbols from this archive.
388 std::vector<Stringpool::Key> unused_syms_;
391 // This class contains the information needed during an incremental
392 // build about the inputs necessary to build the .gnu_incremental_inputs.
394 class Incremental_inputs
397 typedef std::vector<Incremental_input_entry*> Input_list;
400 : inputs_(), command_line_(), command_line_key_(0),
401 strtab_(new Stringpool()), current_object_(NULL),
402 current_object_entry_(NULL), inputs_section_(NULL),
403 symtab_section_(NULL), relocs_section_(NULL),
407 ~Incremental_inputs() { delete this->strtab_; }
409 // Record the command line.
411 report_command_line(int argc, const char* const* argv);
413 // Record the initial info for archive file ARCHIVE.
415 report_archive_begin(Library_base* arch, Script_info* script_info);
417 // Record the final info for archive file ARCHIVE.
419 report_archive_end(Library_base* arch);
421 // Record the info for object file OBJ. If ARCH is not NULL,
422 // attach the object file to the archive.
424 report_object(Object* obj, Library_base* arch, Script_info* script_info);
426 // Record an input section belonging to object file OBJ.
428 report_input_section(Object* obj, unsigned int shndx, const char* name,
431 // Record the info for input script SCRIPT.
433 report_script(const std::string& filename, Script_info* script,
436 // Return the running count of incremental relocations.
438 get_reloc_count() const
439 { return this->reloc_count_; }
441 // Update the running count of incremental relocations.
443 set_reloc_count(unsigned int count)
444 { this->reloc_count_ = count; }
446 // Prepare for layout. Called from Layout::finalize.
450 // Create the .gnu_incremental_inputs and related sections.
452 create_data_sections(Symbol_table* symtab);
454 // Return the .gnu_incremental_inputs section.
456 inputs_section() const
457 { return this->inputs_section_; }
459 // Return the .gnu_incremental_symtab section.
461 symtab_section() const
462 { return this->symtab_section_; }
464 // Return the .gnu_incremental_relocs section.
466 relocs_section() const
467 { return this->relocs_section_; }
469 // Return the .gnu_incremental_got_plt section.
471 got_plt_section() const
472 { return this->got_plt_section_; }
474 // Return the .gnu_incremental_strtab stringpool.
476 get_stringpool() const
477 { return this->strtab_; }
479 // Return the canonical form of the command line, as will be stored in
480 // .gnu_incremental_strtab.
483 { return this->command_line_; }
485 // Return the stringpool key of the command line.
487 command_line_key() const
488 { return this->command_line_key_; }
490 // Return the number of input files.
492 input_file_count() const
493 { return this->inputs_.size(); }
495 // Return the input files.
498 { return this->inputs_; }
500 // Return the sh_entsize value for the .gnu_incremental_relocs section.
502 relocs_entsize() const;
505 // The list of input files.
508 // Canonical form of the command line, as will be stored in
509 // .gnu_incremental_strtab.
510 std::string command_line_;
512 // The key of the command line string in the string pool.
513 Stringpool::Key command_line_key_;
515 // The .gnu_incremental_strtab string pool associated with the
516 // .gnu_incremental_inputs.
519 // Keep track of the object currently being processed.
520 Object* current_object_;
521 Incremental_object_entry* current_object_entry_;
523 // The .gnu_incremental_inputs section.
524 Output_section_data* inputs_section_;
526 // The .gnu_incremental_symtab section.
527 Output_data_space* symtab_section_;
529 // The .gnu_incremental_relocs section.
530 Output_data_space* relocs_section_;
532 // The .gnu_incremental_got_plt section.
533 Output_data_space* got_plt_section_;
535 // Total count of incremental relocations. Updated during Scan_relocs
536 // phase at the completion of each object file.
537 unsigned int reloc_count_;
540 // Reader class for .gnu_incremental_inputs section.
542 template<int size, bool big_endian>
543 class Incremental_inputs_reader
546 typedef elfcpp::Swap<size, big_endian> Swap;
547 typedef elfcpp::Swap<16, big_endian> Swap16;
548 typedef elfcpp::Swap<32, big_endian> Swap32;
549 typedef elfcpp::Swap<64, big_endian> Swap64;
552 Incremental_inputs_reader()
553 : p_(NULL), strtab_(NULL, 0), input_file_count_(0)
556 Incremental_inputs_reader(const unsigned char* p,
557 const elfcpp::Elf_strtab& strtab)
558 : p_(p), strtab_(strtab)
559 { this->input_file_count_ = Swap32::readval(this->p_ + 4); }
561 // Return the version number.
564 { return Swap32::readval(this->p_); }
566 // Return the count of input file entries.
568 input_file_count() const
569 { return this->input_file_count_; }
571 // Return the command line.
575 unsigned int offset = Swap32::readval(this->p_ + 8);
576 return this->get_string(offset);
579 // Reader class for an input file entry and its supplemental info.
580 class Incremental_input_entry_reader
583 Incremental_input_entry_reader(const Incremental_inputs_reader* inputs,
585 : inputs_(inputs), offset_(offset)
587 this->info_offset_ = Swap32::readval(inputs->p_ + offset + 4);
588 int type = Swap16::readval(this->inputs_->p_ + offset + 20);
589 this->type_ = static_cast<Incremental_input_type>(type);
592 // Return the filename.
596 unsigned int offset = Swap32::readval(this->inputs_->p_ + this->offset_);
597 return this->inputs_->get_string(offset);
600 // Return the timestamp.
605 const unsigned char* p = this->inputs_->p_ + this->offset_ + 8;
606 t.seconds = Swap64::readval(p);
607 t.nanoseconds = Swap32::readval(p+8);
611 // Return the type of input file.
612 Incremental_input_type
614 { return this->type_; }
616 // Return the input section count -- for objects only.
618 get_input_section_count() const
620 gold_assert(this->type_ == INCREMENTAL_INPUT_OBJECT
621 || this->type_ == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
622 return Swap32::readval(this->inputs_->p_ + this->info_offset_);
625 // Return the offset of the supplemental info for symbol SYMNDX --
628 get_symbol_offset(unsigned int symndx) const
630 gold_assert(this->type_ == INCREMENTAL_INPUT_OBJECT
631 || this->type_ == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
633 unsigned int section_count = this->get_input_section_count();
634 return (this->info_offset_ + 8
635 + section_count * input_section_entry_size
639 // Return the global symbol count -- for objects & shared libraries only.
641 get_global_symbol_count() const
645 case INCREMENTAL_INPUT_OBJECT:
646 case INCREMENTAL_INPUT_ARCHIVE_MEMBER:
647 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 4);
648 case INCREMENTAL_INPUT_SHARED_LIBRARY:
649 return Swap32::readval(this->inputs_->p_ + this->info_offset_);
655 // Return the object count -- for scripts only.
657 get_object_count() const
659 gold_assert(this->type_ == INCREMENTAL_INPUT_SCRIPT);
660 return Swap32::readval(this->inputs_->p_ + this->info_offset_);
663 // Return the input file offset for object N -- for scripts only.
665 get_object_offset(unsigned int n) const
667 gold_assert(this->type_ == INCREMENTAL_INPUT_SCRIPT);
668 return Swap32::readval(this->inputs_->p_ + this->info_offset_
672 // Return the member count -- for archives only.
674 get_member_count() const
676 gold_assert(this->type_ == INCREMENTAL_INPUT_ARCHIVE);
677 return Swap32::readval(this->inputs_->p_ + this->info_offset_);
680 // Return the unused symbol count -- for archives only.
682 get_unused_symbol_count() const
684 gold_assert(this->type_ == INCREMENTAL_INPUT_ARCHIVE);
685 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 4);
688 // Return the input file offset for archive member N -- for archives only.
690 get_member_offset(unsigned int n) const
692 gold_assert(this->type_ == INCREMENTAL_INPUT_ARCHIVE);
693 return Swap32::readval(this->inputs_->p_ + this->info_offset_
697 // Return the Nth unused global symbol -- for archives only.
699 get_unused_symbol(unsigned int n) const
701 gold_assert(this->type_ == INCREMENTAL_INPUT_ARCHIVE);
702 unsigned int member_count = this->get_member_count();
703 unsigned int offset = Swap32::readval(this->inputs_->p_
704 + this->info_offset_ + 8
707 return this->inputs_->get_string(offset);
710 // Information about an input section.
711 struct Input_section_info
714 unsigned int output_shndx;
719 // Return info about the Nth input section -- for objects only.
721 get_input_section(unsigned int n) const
723 Input_section_info info;
724 const unsigned char* p = (this->inputs_->p_
725 + this->info_offset_ + 8
726 + n * input_section_entry_size);
727 unsigned int name_offset = Swap32::readval(p);
728 info.name = this->inputs_->get_string(name_offset);
729 info.output_shndx = Swap32::readval(p + 4);
730 info.sh_offset = Swap::readval(p + 8);
731 info.sh_size = Swap::readval(p + 8 + size / 8);
735 // Information about a global symbol.
736 struct Global_symbol_info
738 unsigned int output_symndx;
739 unsigned int next_offset;
740 unsigned int reloc_count;
741 unsigned int reloc_offset;
744 // Return info about the Nth global symbol -- for objects only.
746 get_global_symbol_info(unsigned int n) const
748 Global_symbol_info info;
749 unsigned int section_count = this->get_input_section_count();
750 const unsigned char* p = (this->inputs_->p_
751 + this->info_offset_ + 8
752 + section_count * input_section_entry_size
754 info.output_symndx = Swap32::readval(p);
755 info.next_offset = Swap32::readval(p + 4);
756 info.reloc_count = Swap::readval(p + 8);
757 info.reloc_offset = Swap::readval(p + 12);
762 // Size of an input section entry.
763 static const unsigned int input_section_entry_size = 8 + 2 * size / 8;
764 // The reader instance for the containing section.
765 const Incremental_inputs_reader* inputs_;
766 // The type of input file.
767 Incremental_input_type type_;
768 // Section offset to the input file entry.
769 unsigned int offset_;
770 // Section offset to the supplemental info for the input file.
771 unsigned int info_offset_;
774 // Return a reader for the Nth input file entry.
775 Incremental_input_entry_reader
776 input_file(unsigned int n) const
778 gold_assert(n < this->input_file_count_);
779 Incremental_input_entry_reader input(this, 16 + n * 24);
784 // Lookup a string in the ELF string table.
785 const char* get_string(unsigned int offset) const
788 if (this->strtab_.get_c_string(offset, &s))
793 // Base address of the .gnu_incremental_inputs section.
794 const unsigned char* p_;
795 // The associated ELF string table.
796 elfcpp::Elf_strtab strtab_;
797 // The number of input file entries in this section.
798 unsigned int input_file_count_;
801 // Reader class for the .gnu_incremental_symtab section.
803 template<bool big_endian>
804 class Incremental_symtab_reader
807 Incremental_symtab_reader()
811 Incremental_symtab_reader(const unsigned char* p, off_t len)
815 // Return the count of symbols in this section.
818 { return static_cast<unsigned int>(this->len_ / 4); }
820 // Return the list head for symbol table entry N.
822 get_list_head(unsigned int n) const
823 { return elfcpp::Swap<32, big_endian>::readval(this->p_ + 4 * n); }
826 // Base address of the .gnu_incremental_relocs section.
827 const unsigned char* p_;
828 // Size of the section.
832 // Reader class for the .gnu_incremental_relocs section.
834 template<int size, bool big_endian>
835 class Incremental_relocs_reader
838 // Size of each field.
839 static const unsigned int field_size = size / 8;
842 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
843 typedef typename elfcpp::Elf_types<size>::Elf_Swxword Addend;
845 // Size of each entry.
846 static const unsigned int reloc_size = 8 + 2 * field_size;
848 Incremental_relocs_reader()
852 Incremental_relocs_reader(const unsigned char* p, off_t len)
856 // Return the count of relocations in this section.
859 { return static_cast<unsigned int>(this->len_ / reloc_size); }
861 // Return the relocation type for relocation entry at offset OFF.
863 get_r_type(unsigned int off) const
865 return elfcpp::Swap<32, big_endian>::readval(this->p_ + off);
868 // Return the output section index for relocation entry at offset OFF.
870 get_r_shndx(unsigned int off) const
872 return elfcpp::Swap<32, big_endian>::readval(this->p_ + off + 4);
875 // Return the output section offset for relocation entry at offset OFF.
877 get_r_offset(unsigned int off) const
879 return elfcpp::Swap<size, big_endian>::readval(this->p_ + off + 8);
882 // Return the addend for relocation entry at offset OFF.
884 get_r_addend(unsigned int off) const
886 return elfcpp::Swap<size, big_endian>::readval(this->p_ + off + 8
891 // Base address of the .gnu_incremental_relocs section.
892 const unsigned char* p_;
893 // Size of the section.
897 // Reader class for the .gnu_incremental_got_plt section.
899 template<bool big_endian>
900 class Incremental_got_plt_reader
903 Incremental_got_plt_reader()
904 : p_(NULL), got_count_(0), got_desc_p_(NULL), plt_desc_p_(NULL)
907 Incremental_got_plt_reader(const unsigned char* p) : p_(p)
909 this->got_count_ = elfcpp::Swap<32, big_endian>::readval(p);
910 this->got_desc_p_ = p + 8 + ((this->got_count_ + 3) & ~3);
911 this->plt_desc_p_ = this->got_desc_p_ + this->got_count_ * 4;
914 // Return the GOT entry count.
916 get_got_entry_count() const
918 return this->got_count_;
921 // Return the PLT entry count.
923 get_plt_entry_count() const
925 return elfcpp::Swap<32, big_endian>::readval(this->p_ + 4);
928 // Return the GOT type for GOT entry N.
930 get_got_type(unsigned int n)
932 return this->p_[8 + n];
935 // Return the GOT descriptor for GOT entry N.
937 get_got_desc(unsigned int n)
939 return elfcpp::Swap<32, big_endian>::readval(this->got_desc_p_ + n * 4);
942 // Return the PLT descriptor for PLT entry N.
944 get_plt_desc(unsigned int n)
946 return elfcpp::Swap<32, big_endian>::readval(this->plt_desc_p_ + n * 4);
950 // Base address of the .gnu_incremental_got_plt section.
951 const unsigned char* p_;
953 unsigned int got_count_;
954 // Base address of the GOT descriptor array.
955 const unsigned char* got_desc_p_;
956 // Base address of the PLT descriptor array.
957 const unsigned char* plt_desc_p_;
960 // An object representing the ELF file we edit during an incremental build.
961 // Similar to Object or Dynobj, but operates on Output_file and contains
962 // methods to support incremental updating. This is the abstract parent class
963 // implemented in Sized_incremental_binary<size, big_endian> for a specific
964 // endianness and size.
966 class Incremental_binary
969 Incremental_binary(Output_file* output, Target* target)
970 : output_(output), target_(target)
974 ~Incremental_binary()
977 // Check the .gnu_incremental_inputs section to see whether an incremental
978 // build is possible.
980 check_inputs(Incremental_inputs* incremental_inputs)
981 { return this->do_check_inputs(incremental_inputs); }
983 // Return TRUE if the file specified by INPUT_ARGUMENT is unchanged
984 // with respect to the base file.
986 file_is_unchanged(const Input_argument* input_argument) const
987 { return this->do_file_is_unchanged(input_argument); }
991 error(const char* format, ...) const ATTRIBUTE_PRINTF_2;
993 // Wrapper class for a sized Incremental_input_entry_reader.
1007 { return this->do_filename(); }
1011 { return this->do_get_mtime(); }
1013 Incremental_input_type
1015 { return this->do_type(); }
1019 do_filename() const = 0;
1022 do_get_mtime() const = 0;
1024 virtual Incremental_input_type
1025 do_type() const = 0;
1029 get_input_reader(const char* filename)
1030 { return this->do_get_input_reader(filename); }
1032 // Functions and types for the elfcpp::Elf_file interface. This
1033 // permit us to use Incremental_binary as the File template parameter for
1034 // elfcpp::Elf_file.
1036 // The View class is returned by view. It must support a single
1037 // method, data(). This is trivial, because Output_file::get_output_view
1038 // does what we need.
1042 View(const unsigned char* p)
1046 const unsigned char*
1048 { return this->p_; }
1051 const unsigned char* p_;
1056 view(off_t file_offset, section_size_type data_size)
1057 { return View(this->output_->get_input_view(file_offset, data_size)); }
1059 // A location in the file.
1065 Location(off_t fo, section_size_type ds)
1066 : file_offset(fo), data_size(ds)
1070 : file_offset(0), data_size(0)
1074 // Get a View given a Location.
1077 { return View(this->view(loc.file_offset, loc.data_size)); }
1080 // Check the .gnu_incremental_inputs section to see whether an incremental
1081 // build is possible.
1083 do_check_inputs(Incremental_inputs* incremental_inputs) = 0;
1085 // Return TRUE if the file specified by INPUT_ARGUMENT is unchanged
1086 // with respect to the base file.
1088 do_file_is_unchanged(const Input_argument* input_argument) const = 0;
1090 virtual Input_reader*
1091 do_get_input_reader(const char* filename) = 0;
1094 // Edited output file object.
1095 Output_file* output_;
1096 // Target of the output file.
1100 template<int size, bool big_endian>
1101 class Sized_incremental_binary : public Incremental_binary
1104 Sized_incremental_binary(Output_file* output,
1105 const elfcpp::Ehdr<size, big_endian>& ehdr,
1107 : Incremental_binary(output, target), elf_file_(this, ehdr),
1108 has_incremental_info_(false), inputs_reader_(), symtab_reader_(),
1109 relocs_reader_(), got_plt_reader_(), current_input_file_(0)
1110 { this->setup_readers(); }
1112 // Returns TRUE if the file contains incremental info.
1114 has_incremental_info() const
1115 { return this->has_incremental_info_; }
1117 // Readers for the incremental info sections.
1119 Incremental_inputs_reader<size, big_endian>
1120 inputs_reader() const
1121 { return this->inputs_reader_; }
1123 Incremental_symtab_reader<big_endian>
1124 symtab_reader() const
1125 { return this->symtab_reader_; }
1127 Incremental_relocs_reader<size, big_endian>
1128 relocs_reader() const
1129 { return this->relocs_reader_; }
1131 Incremental_got_plt_reader<big_endian>
1132 got_plt_reader() const
1133 { return this->got_plt_reader_; }
1137 do_check_inputs(Incremental_inputs* incremental_inputs);
1139 // Return TRUE if the file specified by INPUT_ARGUMENT is unchanged
1140 // with respect to the base file.
1142 do_file_is_unchanged(const Input_argument* input_argument) const;
1144 // Wrapper class for a sized Incremental_input_entry_reader.
1146 class Sized_input_reader : public Input_reader
1149 typedef Incremental_inputs_reader<size, big_endian> Inputs_reader;
1150 typedef typename Inputs_reader::Incremental_input_entry_reader
1153 Sized_input_reader(Input_entry_reader r)
1154 : Input_reader(), reader_(r)
1158 ~Sized_input_reader()
1164 { return this->reader_.filename(); }
1167 do_get_mtime() const
1168 { return this->reader_.get_mtime(); }
1170 Incremental_input_type
1172 { return this->reader_.type(); }
1174 Input_entry_reader reader_;
1177 virtual Input_reader*
1178 do_get_input_reader(const char* filename);
1182 find_incremental_inputs_sections(unsigned int* p_inputs_shndx,
1183 unsigned int* p_symtab_shndx,
1184 unsigned int* p_relocs_shndx,
1185 unsigned int* p_got_plt_shndx,
1186 unsigned int* p_strtab_shndx);
1191 // Output as an ELF file.
1192 elfcpp::Elf_file<size, big_endian, Incremental_binary> elf_file_;
1194 // Readers for the incremental info sections.
1195 bool has_incremental_info_;
1196 Incremental_inputs_reader<size, big_endian> inputs_reader_;
1197 Incremental_symtab_reader<big_endian> symtab_reader_;
1198 Incremental_relocs_reader<size, big_endian> relocs_reader_;
1199 Incremental_got_plt_reader<big_endian> got_plt_reader_;
1201 // Index of the current input file entry.
1202 int current_input_file_;
1205 } // End namespace gold.
1207 #endif // !defined(GOLD_INCREMENTAL_H)