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_dynobj_entry;
44 class Incremental_archive_entry;
45 class Incremental_inputs;
46 class Incremental_binary;
47 class Incremental_library;
51 // Incremental input type as stored in .gnu_incremental_inputs.
53 enum Incremental_input_type
55 INCREMENTAL_INPUT_OBJECT = 1,
56 INCREMENTAL_INPUT_ARCHIVE_MEMBER = 2,
57 INCREMENTAL_INPUT_ARCHIVE = 3,
58 INCREMENTAL_INPUT_SHARED_LIBRARY = 4,
59 INCREMENTAL_INPUT_SCRIPT = 5
62 // Incremental input file flags.
63 // The input file type is stored in the lower eight bits.
65 enum Incremental_input_flags
67 INCREMENTAL_INPUT_IN_SYSTEM_DIR = 0x8000,
68 INCREMENTAL_INPUT_AS_NEEDED = 0x4000
71 // Create an Incremental_binary object for FILE. Returns NULL is this is not
72 // possible, e.g. FILE is not an ELF file or has an unsupported target.
75 open_incremental_binary(Output_file* file);
77 // Base class for recording each input file.
79 class Incremental_input_entry
82 Incremental_input_entry(Stringpool::Key filename_key, unsigned int arg_serial,
84 : filename_key_(filename_key), file_index_(0), offset_(0), info_offset_(0),
85 arg_serial_(arg_serial), mtime_(mtime), is_in_system_directory_(false),
90 ~Incremental_input_entry()
93 // Return the type of input file.
94 Incremental_input_type
96 { return this->do_type(); }
98 // Set the index and section offset of this input file entry.
100 set_offset(unsigned int file_index, unsigned int offset)
102 this->file_index_ = file_index;
103 this->offset_ = offset;
106 // Set the section offset of the supplemental information for this entry.
108 set_info_offset(unsigned int info_offset)
109 { this->info_offset_ = info_offset; }
111 // Get the index of this input file entry.
113 get_file_index() const
114 { return this->file_index_; }
116 // Get the section offset of this input file entry.
119 { return this->offset_; }
121 // Get the section offset of the supplemental information for this entry.
123 get_info_offset() const
124 { return this->info_offset_; }
126 // Get the stringpool key for the input filename.
128 get_filename_key() const
129 { return this->filename_key_; }
131 // Get the serial number of the input file.
134 { return this->arg_serial_; }
136 // Get the modification time of the input file.
139 { return this->mtime_; }
141 // Record that the file was found in a system directory.
143 set_is_in_system_directory()
144 { this->is_in_system_directory_ = true; }
146 // Return TRUE if the file was found in a system directory.
148 is_in_system_directory() const
149 { return this->is_in_system_directory_; }
151 // Record that the file was linked with --as-needed.
154 { this->as_needed_ = true; }
156 // Return TRUE if the file was linked with --as-needed.
159 { return this->as_needed_; }
161 // Return a pointer to the derived Incremental_script_entry object.
162 // Return NULL for input entries that are not script files.
163 Incremental_script_entry*
165 { return this->do_script_entry(); }
167 // Return a pointer to the derived Incremental_object_entry object.
168 // Return NULL for input entries that are not object files.
169 Incremental_object_entry*
171 { return this->do_object_entry(); }
173 // Return a pointer to the derived Incremental_dynobj_entry object.
174 // Return NULL for input entries that are not shared object files.
175 Incremental_dynobj_entry*
177 { return this->do_dynobj_entry(); }
179 // Return a pointer to the derived Incremental_archive_entry object.
180 // Return NULL for input entries that are not archive files.
181 Incremental_archive_entry*
183 { return this->do_archive_entry(); }
186 // Return the type of input file.
187 virtual Incremental_input_type
190 // Return a pointer to the derived Incremental_script_entry object.
191 // Return NULL for input entries that are not script files.
192 virtual Incremental_script_entry*
196 // Return a pointer to the derived Incremental_object_entry object.
197 // Return NULL for input entries that are not object files.
198 virtual Incremental_object_entry*
202 // Return a pointer to the derived Incremental_dynobj_entry object.
203 // Return NULL for input entries that are not shared object files.
204 virtual Incremental_dynobj_entry*
208 // Return a pointer to the derived Incremental_archive_entry object.
209 // Return NULL for input entries that are not archive files.
210 virtual Incremental_archive_entry*
215 // Key of the filename string in the section stringtable.
216 Stringpool::Key filename_key_;
218 // Index of the entry in the output section.
219 unsigned int file_index_;
221 // Offset of the entry in the output section.
222 unsigned int offset_;
224 // Offset of the extra information in the output section.
225 unsigned int info_offset_;
227 // Serial number of the file in the argument list.
228 unsigned int arg_serial_;
230 // Last modification time of the file.
233 // TRUE if the file was found in a system directory.
234 bool is_in_system_directory_;
236 // TRUE if the file was linked with --as-needed.
240 // Information about a script input that will persist during the whole linker
241 // run. Needed only during an incremental build to retrieve the input files
242 // added by this script.
247 Script_info(const std::string& filename)
248 : filename_(filename), incremental_script_entry_(NULL)
251 // Store a pointer to the incremental information for this script.
253 set_incremental_info(Incremental_script_entry* entry)
254 { this->incremental_script_entry_ = entry; }
256 // Return the filename.
259 { return this->filename_; }
261 // Return the pointer to the incremental information for this script.
262 Incremental_script_entry*
263 incremental_info() const
264 { return this->incremental_script_entry_; }
267 const std::string filename_;
268 Incremental_script_entry* incremental_script_entry_;
271 // Class for recording input scripts.
273 class Incremental_script_entry : public Incremental_input_entry
276 Incremental_script_entry(Stringpool::Key filename_key,
277 unsigned int arg_serial, Script_info* script,
279 : Incremental_input_entry(filename_key, arg_serial, mtime),
280 script_(script), objects_()
283 // Add a member object to the archive.
285 add_object(Incremental_input_entry* obj_entry)
287 this->objects_.push_back(obj_entry);
290 // Return the number of objects included by this script.
293 { return this->objects_.size(); }
295 // Return the Nth object.
296 Incremental_input_entry*
297 get_object(unsigned int n)
299 gold_assert(n < this->objects_.size());
300 return this->objects_[n];
304 virtual Incremental_input_type
306 { return INCREMENTAL_INPUT_SCRIPT; }
308 // Return a pointer to the derived Incremental_script_entry object.
309 virtual Incremental_script_entry*
314 // Information about the script file.
315 Script_info* script_;
316 // Objects that have been included by this script.
317 std::vector<Incremental_input_entry*> objects_;
320 // Class for recording input object files.
322 class Incremental_object_entry : public Incremental_input_entry
325 Incremental_object_entry(Stringpool::Key filename_key, Object* obj,
326 unsigned int arg_serial, Timespec mtime)
327 : Incremental_input_entry(filename_key, arg_serial, mtime), obj_(obj),
328 is_member_(false), sections_(), groups_()
329 { this->sections_.reserve(obj->shnum()); }
334 { return this->obj_; }
336 // Record that this object is an archive member.
339 { this->is_member_ = true; }
341 // Return true if this object is an archive member.
344 { return this->is_member_; }
346 // Add an input section.
348 add_input_section(unsigned int shndx, Stringpool::Key name_key, off_t sh_size)
349 { this->sections_.push_back(Input_section(shndx, name_key, sh_size)); }
351 // Return the number of input sections in this object.
353 get_input_section_count() const
354 { return this->sections_.size(); }
356 // Return the input section index for the Nth input section.
358 get_input_section_index(unsigned int n) const
359 { return this->sections_[n].shndx_; }
361 // Return the stringpool key of the Nth input section.
363 get_input_section_name_key(unsigned int n) const
364 { return this->sections_[n].name_key_; }
366 // Return the size of the Nth input section.
368 get_input_section_size(unsigned int n) const
369 { return this->sections_[n].sh_size_; }
371 // Add a kept COMDAT group.
373 add_comdat_group(Stringpool::Key signature_key)
374 { this->groups_.push_back(signature_key); }
376 // Return the number of COMDAT groups.
378 get_comdat_group_count() const
379 { return this->groups_.size(); }
381 // Return the stringpool key for the signature of the Nth comdat group.
383 get_comdat_signature_key(unsigned int n) const
384 { return this->groups_[n]; }
387 virtual Incremental_input_type
390 return (this->is_member_
391 ? INCREMENTAL_INPUT_ARCHIVE_MEMBER
392 : INCREMENTAL_INPUT_OBJECT);
395 // Return a pointer to the derived Incremental_object_entry object.
396 virtual Incremental_object_entry*
401 // The object file itself.
404 // Whether this object is an archive member.
410 Input_section(unsigned int shndx, Stringpool::Key name_key, off_t sh_size)
411 : shndx_(shndx), name_key_(name_key), sh_size_(sh_size)
414 Stringpool::Key name_key_;
417 std::vector<Input_section> sections_;
420 std::vector<Stringpool::Key> groups_;
423 // Class for recording shared library input files.
425 class Incremental_dynobj_entry : public Incremental_input_entry
428 Incremental_dynobj_entry(Stringpool::Key filename_key,
429 Stringpool::Key soname_key, Object* obj,
430 unsigned int arg_serial, Timespec mtime)
431 : Incremental_input_entry(filename_key, arg_serial, mtime),
432 soname_key_(soname_key), obj_(obj)
438 { return this->obj_; }
440 // Get the stringpool key for the soname.
442 get_soname_key() const
443 { return this->soname_key_; }
446 virtual Incremental_input_type
448 { return INCREMENTAL_INPUT_SHARED_LIBRARY; }
450 // Return a pointer to the derived Incremental_dynobj_entry object.
451 virtual Incremental_dynobj_entry*
456 // Key of the soname string in the section stringtable.
457 Stringpool::Key soname_key_;
459 // The object file itself.
463 // Class for recording archive library input files.
465 class Incremental_archive_entry : public Incremental_input_entry
468 Incremental_archive_entry(Stringpool::Key filename_key,
469 unsigned int arg_serial, Timespec mtime)
470 : Incremental_input_entry(filename_key, arg_serial, mtime), members_(),
474 // Add a member object to the archive.
476 add_object(Incremental_object_entry* obj_entry)
478 this->members_.push_back(obj_entry);
479 obj_entry->set_is_member();
482 // Add an unused global symbol to the archive.
484 add_unused_global_symbol(Stringpool::Key symbol_key)
485 { this->unused_syms_.push_back(symbol_key); }
487 // Return the number of member objects included in the link.
490 { return this->members_.size(); }
492 // Return the Nth member object.
493 Incremental_object_entry*
494 get_member(unsigned int n)
495 { return this->members_[n]; }
497 // Return the number of unused global symbols in this archive.
499 get_unused_global_symbol_count()
500 { return this->unused_syms_.size(); }
502 // Return the Nth unused global symbol.
504 get_unused_global_symbol(unsigned int n)
505 { return this->unused_syms_[n]; }
508 virtual Incremental_input_type
510 { return INCREMENTAL_INPUT_ARCHIVE; }
512 // Return a pointer to the derived Incremental_archive_entry object.
513 virtual Incremental_archive_entry*
518 // Members of the archive that have been included in the link.
519 std::vector<Incremental_object_entry*> members_;
521 // Unused global symbols from this archive.
522 std::vector<Stringpool::Key> unused_syms_;
525 // This class contains the information needed during an incremental
526 // build about the inputs necessary to build the .gnu_incremental_inputs.
528 class Incremental_inputs
531 typedef std::vector<Incremental_input_entry*> Input_list;
534 : inputs_(), command_line_(), command_line_key_(0),
535 strtab_(new Stringpool()), current_object_(NULL),
536 current_object_entry_(NULL), inputs_section_(NULL),
537 symtab_section_(NULL), relocs_section_(NULL),
541 ~Incremental_inputs() { delete this->strtab_; }
543 // Record the command line.
545 report_command_line(int argc, const char* const* argv);
547 // Record the initial info for archive file ARCHIVE.
549 report_archive_begin(Library_base* arch, unsigned int arg_serial,
550 Script_info* script_info);
552 // Record the final info for archive file ARCHIVE.
554 report_archive_end(Library_base* arch);
556 // Record the info for object file OBJ. If ARCH is not NULL,
557 // attach the object file to the archive.
559 report_object(Object* obj, unsigned int arg_serial, Library_base* arch,
560 Script_info* script_info);
562 // Record an input section belonging to object file OBJ.
564 report_input_section(Object* obj, unsigned int shndx, const char* name,
567 // Record a kept COMDAT group belonging to object file OBJ.
569 report_comdat_group(Object* obj, const char* name);
571 // Record the info for input script SCRIPT.
573 report_script(Script_info* script, unsigned int arg_serial,
576 // Return the running count of incremental relocations.
578 get_reloc_count() const
579 { return this->reloc_count_; }
581 // Update the running count of incremental relocations.
583 set_reloc_count(unsigned int count)
584 { this->reloc_count_ = count; }
586 // Prepare for layout. Called from Layout::finalize.
590 // Create the .gnu_incremental_inputs and related sections.
592 create_data_sections(Symbol_table* symtab);
594 // Return the .gnu_incremental_inputs section.
596 inputs_section() const
597 { return this->inputs_section_; }
599 // Return the .gnu_incremental_symtab section.
601 symtab_section() const
602 { return this->symtab_section_; }
604 // Return the .gnu_incremental_relocs section.
606 relocs_section() const
607 { return this->relocs_section_; }
609 // Return the .gnu_incremental_got_plt section.
611 got_plt_section() const
612 { return this->got_plt_section_; }
614 // Return the .gnu_incremental_strtab stringpool.
616 get_stringpool() const
617 { return this->strtab_; }
619 // Return the canonical form of the command line, as will be stored in
620 // .gnu_incremental_strtab.
623 { return this->command_line_; }
625 // Return the stringpool key of the command line.
627 command_line_key() const
628 { return this->command_line_key_; }
630 // Return the number of input files.
632 input_file_count() const
633 { return this->inputs_.size(); }
635 // Return the input files.
638 { return this->inputs_; }
640 // Return the sh_entsize value for the .gnu_incremental_relocs section.
642 relocs_entsize() const;
645 // The list of input files.
648 // Canonical form of the command line, as will be stored in
649 // .gnu_incremental_strtab.
650 std::string command_line_;
652 // The key of the command line string in the string pool.
653 Stringpool::Key command_line_key_;
655 // The .gnu_incremental_strtab string pool associated with the
656 // .gnu_incremental_inputs.
659 // Keep track of the object currently being processed.
660 Object* current_object_;
661 Incremental_object_entry* current_object_entry_;
663 // The .gnu_incremental_inputs section.
664 Output_section_data* inputs_section_;
666 // The .gnu_incremental_symtab section.
667 Output_data_space* symtab_section_;
669 // The .gnu_incremental_relocs section.
670 Output_data_space* relocs_section_;
672 // The .gnu_incremental_got_plt section.
673 Output_data_space* got_plt_section_;
675 // Total count of incremental relocations. Updated during Scan_relocs
676 // phase at the completion of each object file.
677 unsigned int reloc_count_;
680 // Reader class for global symbol info from an object file entry in
681 // the .gnu_incremental_inputs section.
683 template<bool big_endian>
684 class Incremental_global_symbol_reader
687 typedef elfcpp::Swap<32, big_endian> Swap32;
690 Incremental_global_symbol_reader(const unsigned char* p)
695 output_symndx() const
696 { return Swap32::readval(this->p_); }
700 { return Swap32::readval(this->p_ + 4); }
704 { return Swap32::readval(this->p_ + 8); }
708 { return Swap32::readval(this->p_ + 12); }
712 { return Swap32::readval(this->p_ + 16); }
715 // Base address of the symbol entry.
716 const unsigned char* p_;
719 // Reader class for .gnu_incremental_inputs section.
721 template<int size, bool big_endian>
722 class Incremental_inputs_reader
725 typedef elfcpp::Swap<size, big_endian> Swap;
726 typedef elfcpp::Swap<16, big_endian> Swap16;
727 typedef elfcpp::Swap<32, big_endian> Swap32;
728 typedef elfcpp::Swap<64, big_endian> Swap64;
731 Incremental_inputs_reader()
732 : p_(NULL), strtab_(NULL, 0), input_file_count_(0)
735 Incremental_inputs_reader(const unsigned char* p,
736 const elfcpp::Elf_strtab& strtab)
737 : p_(p), strtab_(strtab)
738 { this->input_file_count_ = Swap32::readval(this->p_ + 4); }
740 // Return the version number.
743 { return Swap32::readval(this->p_); }
745 // Return the count of input file entries.
747 input_file_count() const
748 { return this->input_file_count_; }
750 // Return the command line.
754 unsigned int offset = Swap32::readval(this->p_ + 8);
755 return this->get_string(offset);
758 // Reader class for an input file entry and its supplemental info.
759 class Incremental_input_entry_reader
762 Incremental_input_entry_reader(const Incremental_inputs_reader* inputs,
764 : inputs_(inputs), offset_(offset)
766 this->info_offset_ = Swap32::readval(inputs->p_ + offset + 4);
767 this->flags_ = Swap16::readval(this->inputs_->p_ + offset + 20);
770 // Return the filename.
774 unsigned int offset = Swap32::readval(this->inputs_->p_ + this->offset_);
775 return this->inputs_->get_string(offset);
778 // Return the argument serial number.
782 return Swap16::readval(this->inputs_->p_ + this->offset_ + 22);
785 // Return the timestamp.
790 const unsigned char* p = this->inputs_->p_ + this->offset_ + 8;
791 t.seconds = Swap64::readval(p);
792 t.nanoseconds = Swap32::readval(p+8);
796 // Return the type of input file.
797 Incremental_input_type
799 { return static_cast<Incremental_input_type>(this->flags_ & 0xff); }
801 // Return TRUE if the file was found in a system directory.
803 is_in_system_directory() const
804 { return (this->flags_ & INCREMENTAL_INPUT_IN_SYSTEM_DIR) != 0; }
806 // Return TRUE if the file was linked with --as-needed.
809 { return (this->flags_ & INCREMENTAL_INPUT_AS_NEEDED) != 0; }
811 // Return the input section count -- for objects only.
813 get_input_section_count() const
815 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
816 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
817 return Swap32::readval(this->inputs_->p_ + this->info_offset_);
820 // Return the soname -- for shared libraries only.
824 gold_assert(this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY);
825 unsigned int offset = Swap32::readval(this->inputs_->p_
826 + this->info_offset_);
827 return this->inputs_->get_string(offset);
830 // Return the offset of the supplemental info for symbol SYMNDX --
833 get_symbol_offset(unsigned int symndx) const
835 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
836 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
838 unsigned int section_count = this->get_input_section_count();
839 return (this->info_offset_ + 28
840 + section_count * input_section_entry_size
844 // Return the global symbol count -- for objects & shared libraries only.
846 get_global_symbol_count() const
848 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
849 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
850 || this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY);
851 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 4);
854 // Return the offset of the first local symbol -- for objects only.
856 get_local_symbol_offset() const
858 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
859 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
861 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 8);
864 // Return the local symbol count -- for objects only.
866 get_local_symbol_count() const
868 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
869 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
871 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 12);
874 // Return the index of the first dynamic relocation -- for objects only.
876 get_first_dyn_reloc() const
878 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
879 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
881 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 16);
884 // Return the dynamic relocation count -- for objects only.
886 get_dyn_reloc_count() const
888 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
889 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
891 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 20);
894 // Return the COMDAT group count -- for objects only.
896 get_comdat_group_count() const
898 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
899 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
901 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 24);
904 // Return the object count -- for scripts only.
906 get_object_count() const
908 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT);
909 return Swap32::readval(this->inputs_->p_ + this->info_offset_);
912 // Return the input file offset for object N -- for scripts only.
914 get_object_offset(unsigned int n) const
916 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT);
917 return Swap32::readval(this->inputs_->p_ + this->info_offset_
921 // Return the member count -- for archives only.
923 get_member_count() const
925 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE);
926 return Swap32::readval(this->inputs_->p_ + this->info_offset_);
929 // Return the unused symbol count -- for archives only.
931 get_unused_symbol_count() const
933 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE);
934 return Swap32::readval(this->inputs_->p_ + this->info_offset_ + 4);
937 // Return the input file offset for archive member N -- for archives only.
939 get_member_offset(unsigned int n) const
941 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE);
942 return Swap32::readval(this->inputs_->p_ + this->info_offset_
946 // Return the Nth unused global symbol -- for archives only.
948 get_unused_symbol(unsigned int n) const
950 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE);
951 unsigned int member_count = this->get_member_count();
952 unsigned int offset = Swap32::readval(this->inputs_->p_
953 + this->info_offset_ + 8
956 return this->inputs_->get_string(offset);
959 // Information about an input section.
960 struct Input_section_info
963 unsigned int output_shndx;
968 // Return info about the Nth input section -- for objects only.
970 get_input_section(unsigned int n) const
972 Input_section_info info;
973 const unsigned char* p = (this->inputs_->p_
974 + this->info_offset_ + 28
975 + n * input_section_entry_size);
976 unsigned int name_offset = Swap32::readval(p);
977 info.name = this->inputs_->get_string(name_offset);
978 info.output_shndx = Swap32::readval(p + 4);
979 info.sh_offset = Swap::readval(p + 8);
980 info.sh_size = Swap::readval(p + 8 + size / 8);
984 // Return info about the Nth global symbol -- for objects only.
985 Incremental_global_symbol_reader<big_endian>
986 get_global_symbol_reader(unsigned int n) const
988 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
989 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER);
990 unsigned int section_count = this->get_input_section_count();
991 const unsigned char* p = (this->inputs_->p_
992 + this->info_offset_ + 28
993 + section_count * input_section_entry_size
995 return Incremental_global_symbol_reader<big_endian>(p);
998 // Return the signature of the Nth comdat group -- for objects only.
1000 get_comdat_group_signature(unsigned int n) const
1002 unsigned int section_count = this->get_input_section_count();
1003 unsigned int symbol_count = this->get_global_symbol_count();
1004 const unsigned char* p = (this->inputs_->p_
1005 + this->info_offset_ + 28
1006 + section_count * input_section_entry_size
1009 unsigned int name_offset = Swap32::readval(p);
1010 return this->inputs_->get_string(name_offset);
1013 // Return the output symbol index for the Nth global symbol -- for shared
1014 // libraries only. Sets *IS_DEF to TRUE if the symbol is defined in this
1017 get_output_symbol_index(unsigned int n, bool* is_def)
1019 gold_assert(this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY);
1020 const unsigned char* p = (this->inputs_->p_
1021 + this->info_offset_ + 8
1023 unsigned int output_symndx = Swap32::readval(p);
1024 *is_def = (output_symndx & (1U << 31)) != 0;
1025 return output_symndx & ((1U << 31) - 1);
1029 // Size of an input section entry.
1030 static const unsigned int input_section_entry_size = 8 + 2 * size / 8;
1031 // The reader instance for the containing section.
1032 const Incremental_inputs_reader* inputs_;
1033 // The flags, including the type of input file.
1034 unsigned int flags_;
1035 // Section offset to the input file entry.
1036 unsigned int offset_;
1037 // Section offset to the supplemental info for the input file.
1038 unsigned int info_offset_;
1041 // Return the offset of an input file entry given its index N.
1043 input_file_offset(unsigned int n) const
1045 gold_assert(n < this->input_file_count_);
1049 // Return the index of an input file entry given its OFFSET.
1051 input_file_index(unsigned int offset) const
1053 int n = (offset - 16) / 24;
1054 gold_assert(input_file_offset(n) == offset);
1058 // Return a reader for the Nth input file entry.
1059 Incremental_input_entry_reader
1060 input_file(unsigned int n) const
1061 { return Incremental_input_entry_reader(this, this->input_file_offset(n)); }
1063 // Return a reader for the input file entry at OFFSET.
1064 Incremental_input_entry_reader
1065 input_file_at_offset(unsigned int offset) const
1067 gold_assert(offset < 16 + this->input_file_count_ * 24);
1068 return Incremental_input_entry_reader(this, offset);
1071 // Return a reader for the global symbol info at OFFSET.
1072 Incremental_global_symbol_reader<big_endian>
1073 global_symbol_reader_at_offset(unsigned int offset) const
1075 const unsigned char* p = this->p_ + offset;
1076 return Incremental_global_symbol_reader<big_endian>(p);
1080 // Lookup a string in the ELF string table.
1081 const char* get_string(unsigned int offset) const
1084 if (this->strtab_.get_c_string(offset, &s))
1089 // Base address of the .gnu_incremental_inputs section.
1090 const unsigned char* p_;
1091 // The associated ELF string table.
1092 elfcpp::Elf_strtab strtab_;
1093 // The number of input file entries in this section.
1094 unsigned int input_file_count_;
1097 // Reader class for the .gnu_incremental_symtab section.
1099 template<bool big_endian>
1100 class Incremental_symtab_reader
1103 Incremental_symtab_reader()
1107 Incremental_symtab_reader(const unsigned char* p, off_t len)
1111 // Return the count of symbols in this section.
1113 symbol_count() const
1114 { return static_cast<unsigned int>(this->len_ / 4); }
1116 // Return the list head for symbol table entry N.
1118 get_list_head(unsigned int n) const
1119 { return elfcpp::Swap<32, big_endian>::readval(this->p_ + 4 * n); }
1122 // Base address of the .gnu_incremental_relocs section.
1123 const unsigned char* p_;
1124 // Size of the section.
1128 // Reader class for the .gnu_incremental_relocs section.
1130 template<int size, bool big_endian>
1131 class Incremental_relocs_reader
1134 // Size of each field.
1135 static const unsigned int field_size = size / 8;
1138 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
1139 typedef typename elfcpp::Elf_types<size>::Elf_Swxword Addend;
1141 // Size of each entry.
1142 static const unsigned int reloc_size = 8 + 2 * field_size;
1144 Incremental_relocs_reader()
1148 Incremental_relocs_reader(const unsigned char* p, off_t len)
1152 // Return the count of relocations in this section.
1155 { return static_cast<unsigned int>(this->len_ / reloc_size); }
1157 // Return the relocation type for relocation entry at offset OFF.
1159 get_r_type(unsigned int off) const
1160 { return elfcpp::Swap<32, big_endian>::readval(this->p_ + off); }
1162 // Return the output section index for relocation entry at offset OFF.
1164 get_r_shndx(unsigned int off) const
1165 { return elfcpp::Swap<32, big_endian>::readval(this->p_ + off + 4); }
1167 // Return the output section offset for relocation entry at offset OFF.
1169 get_r_offset(unsigned int off) const
1170 { return elfcpp::Swap<size, big_endian>::readval(this->p_ + off + 8); }
1172 // Return the addend for relocation entry at offset OFF.
1174 get_r_addend(unsigned int off) const
1176 return elfcpp::Swap<size, big_endian>::readval(this->p_ + off + 8
1177 + this->field_size);
1180 // Return a pointer to the relocation entry at offset OFF.
1181 const unsigned char*
1182 data(unsigned int off) const
1183 { return this->p_ + off; }
1186 // Base address of the .gnu_incremental_relocs section.
1187 const unsigned char* p_;
1188 // Size of the section.
1192 // Reader class for the .gnu_incremental_got_plt section.
1194 template<bool big_endian>
1195 class Incremental_got_plt_reader
1198 Incremental_got_plt_reader()
1199 : p_(NULL), got_count_(0), got_desc_p_(NULL), plt_desc_p_(NULL)
1202 Incremental_got_plt_reader(const unsigned char* p) : p_(p)
1204 this->got_count_ = elfcpp::Swap<32, big_endian>::readval(p);
1205 this->got_desc_p_ = p + 8 + ((this->got_count_ + 3) & ~3);
1206 this->plt_desc_p_ = this->got_desc_p_ + this->got_count_ * 8;
1209 // Return the GOT entry count.
1211 get_got_entry_count() const
1213 return this->got_count_;
1216 // Return the PLT entry count.
1218 get_plt_entry_count() const
1220 return elfcpp::Swap<32, big_endian>::readval(this->p_ + 4);
1223 // Return the GOT type for GOT entry N.
1225 get_got_type(unsigned int n)
1227 return this->p_[8 + n];
1230 // Return the symbol index for GOT entry N.
1232 get_got_symndx(unsigned int n)
1234 return elfcpp::Swap<32, big_endian>::readval(this->got_desc_p_ + n * 8);
1237 // Return the input file index for GOT entry N.
1239 get_got_input_index(unsigned int n)
1241 return elfcpp::Swap<32, big_endian>::readval(this->got_desc_p_ + n * 8 + 4);
1244 // Return the PLT descriptor for PLT entry N.
1246 get_plt_desc(unsigned int n)
1248 return elfcpp::Swap<32, big_endian>::readval(this->plt_desc_p_ + n * 4);
1252 // Base address of the .gnu_incremental_got_plt section.
1253 const unsigned char* p_;
1255 unsigned int got_count_;
1256 // Base address of the GOT descriptor array.
1257 const unsigned char* got_desc_p_;
1258 // Base address of the PLT descriptor array.
1259 const unsigned char* plt_desc_p_;
1262 // An object representing the ELF file we edit during an incremental build.
1263 // Similar to Object or Dynobj, but operates on Output_file and contains
1264 // methods to support incremental updating. This is the abstract parent class
1265 // implemented in Sized_incremental_binary<size, big_endian> for a specific
1266 // endianness and size.
1268 class Incremental_binary
1271 Incremental_binary(Output_file* output, Target* target)
1272 : input_args_map_(), library_map_(), script_map_(),
1273 output_(output), target_(target)
1277 ~Incremental_binary()
1280 // Check the .gnu_incremental_inputs section to see whether an incremental
1281 // build is possible.
1283 check_inputs(const Command_line& cmdline,
1284 Incremental_inputs* incremental_inputs)
1285 { return this->do_check_inputs(cmdline, incremental_inputs); }
1289 error(const char* format, ...) const ATTRIBUTE_PRINTF_2;
1291 // Proxy class for a sized Incremental_input_entry_reader.
1305 { return this->do_filename(); }
1309 { return this->do_get_mtime(); }
1311 Incremental_input_type
1313 { return this->do_type(); }
1317 { return this->do_arg_serial(); }
1320 get_unused_symbol_count() const
1321 { return this->do_get_unused_symbol_count(); }
1324 get_unused_symbol(unsigned int n) const
1325 { return this->do_get_unused_symbol(n); }
1329 do_filename() const = 0;
1332 do_get_mtime() const = 0;
1334 virtual Incremental_input_type
1335 do_type() const = 0;
1337 virtual unsigned int
1338 do_arg_serial() const = 0;
1340 virtual unsigned int
1341 do_get_unused_symbol_count() const = 0;
1344 do_get_unused_symbol(unsigned int n) const = 0;
1347 // Return the number of input files.
1349 input_file_count() const
1350 { return this->do_input_file_count(); }
1352 // Return an Input_reader for input file N.
1354 get_input_reader(unsigned int n) const
1355 { return this->do_get_input_reader(n); }
1357 // Return TRUE if the input file N has changed since the last link.
1359 file_has_changed(unsigned int n) const
1360 { return this->do_file_has_changed(n); }
1362 // Return the Input_argument for input file N. Returns NULL if
1363 // the Input_argument is not available.
1364 const Input_argument*
1365 get_input_argument(unsigned int n) const
1367 const Input_reader* input_file = this->do_get_input_reader(n);
1368 unsigned int arg_serial = input_file->arg_serial();
1369 if (arg_serial == 0 || arg_serial > this->input_args_map_.size())
1371 return this->input_args_map_[arg_serial - 1];
1374 // Return an Incremental_library for the given input file.
1375 Incremental_library*
1376 get_library(unsigned int n)
1377 { return this->library_map_[n]; }
1379 // Return a Script_info for the given input file.
1381 get_script_info(unsigned int n)
1382 { return this->script_map_[n]; }
1384 // Initialize the layout of the output file based on the existing
1387 init_layout(Layout* layout)
1388 { this->do_init_layout(layout); }
1390 // Mark regions of the input file that must be kept unchanged.
1392 reserve_layout(unsigned int input_file_index)
1393 { this->do_reserve_layout(input_file_index); }
1395 // Process the GOT and PLT entries from the existing output file.
1397 process_got_plt(Symbol_table* symtab, Layout* layout)
1398 { this->do_process_got_plt(symtab, layout); }
1400 // Apply incremental relocations for symbols whose values have changed.
1402 apply_incremental_relocs(const Symbol_table* symtab, Layout* layout,
1404 { this->do_apply_incremental_relocs(symtab, layout, of); }
1406 // Functions and types for the elfcpp::Elf_file interface. This
1407 // permit us to use Incremental_binary as the File template parameter for
1408 // elfcpp::Elf_file.
1410 // The View class is returned by view. It must support a single
1411 // method, data(). This is trivial, because Output_file::get_output_view
1412 // does what we need.
1416 View(const unsigned char* p)
1420 const unsigned char*
1422 { return this->p_; }
1425 const unsigned char* p_;
1430 view(off_t file_offset, section_size_type data_size)
1431 { return View(this->output_->get_input_view(file_offset, data_size)); }
1433 // A location in the file.
1439 Location(off_t fo, section_size_type ds)
1440 : file_offset(fo), data_size(ds)
1444 : file_offset(0), data_size(0)
1448 // Get a View given a Location.
1451 { return View(this->view(loc.file_offset, loc.data_size)); }
1453 // Return the Output_file.
1456 { return this->output_; }
1459 // Check the .gnu_incremental_inputs section to see whether an incremental
1460 // build is possible.
1462 do_check_inputs(const Command_line& cmdline,
1463 Incremental_inputs* incremental_inputs) = 0;
1465 // Return TRUE if input file N has changed since the last incremental link.
1467 do_file_has_changed(unsigned int n) const = 0;
1469 // Initialize the layout of the output file based on the existing
1472 do_init_layout(Layout* layout) = 0;
1474 // Mark regions of the input file that must be kept unchanged.
1476 do_reserve_layout(unsigned int input_file_index) = 0;
1478 // Process the GOT and PLT entries from the existing output file.
1480 do_process_got_plt(Symbol_table* symtab, Layout* layout) = 0;
1482 // Apply incremental relocations for symbols whose values have changed.
1484 do_apply_incremental_relocs(const Symbol_table*, Layout*, Output_file*) = 0;
1486 virtual unsigned int
1487 do_input_file_count() const = 0;
1489 virtual const Input_reader*
1490 do_get_input_reader(unsigned int) const = 0;
1492 // Map from input file index to Input_argument.
1493 std::vector<const Input_argument*> input_args_map_;
1494 // Map from an input file index to an Incremental_library.
1495 std::vector<Incremental_library*> library_map_;
1496 // Map from an input file index to a Script_info.
1497 std::vector<Script_info*> script_map_;
1500 // Edited output file object.
1501 Output_file* output_;
1502 // Target of the output file.
1506 template<int size, bool big_endian>
1507 class Sized_relobj_incr;
1509 template<int size, bool big_endian>
1510 class Sized_incremental_binary : public Incremental_binary
1513 Sized_incremental_binary(Output_file* output,
1514 const elfcpp::Ehdr<size, big_endian>& ehdr,
1516 : Incremental_binary(output, target), elf_file_(this, ehdr),
1517 input_objects_(), section_map_(), symbol_map_(), main_symtab_loc_(),
1518 main_strtab_loc_(), has_incremental_info_(false), inputs_reader_(),
1519 symtab_reader_(), relocs_reader_(), got_plt_reader_(),
1520 input_entry_readers_()
1521 { this->setup_readers(); }
1523 // Returns TRUE if the file contains incremental info.
1525 has_incremental_info() const
1526 { return this->has_incremental_info_; }
1528 // Record a pointer to the object for input file N.
1530 set_input_object(unsigned int n,
1531 Sized_relobj_incr<size, big_endian>* obj)
1532 { this->input_objects_[n] = obj; }
1534 // Return a pointer to the object for input file N.
1535 Sized_relobj_incr<size, big_endian>*
1536 input_object(unsigned int n) const
1538 gold_assert(n < this->input_objects_.size());
1539 return this->input_objects_[n];
1542 // Return the Output_section for section index SHNDX.
1544 output_section(unsigned int shndx)
1545 { return this->section_map_[shndx]; }
1547 // Map a symbol table entry from the base file to the output symbol table.
1548 // SYMNDX is relative to the first forced-local or global symbol in the
1549 // input file symbol table.
1551 add_global_symbol(unsigned int symndx, Symbol* gsym)
1552 { this->symbol_map_[symndx] = gsym; }
1554 // Map a symbol table entry from the base file to the output symbol table.
1555 // SYMNDX is relative to the first forced-local or global symbol in the
1556 // input file symbol table.
1558 global_symbol(unsigned int symndx) const
1559 { return this->symbol_map_[symndx]; }
1561 // Readers for the incremental info sections.
1563 const Incremental_inputs_reader<size, big_endian>&
1564 inputs_reader() const
1565 { return this->inputs_reader_; }
1567 const Incremental_symtab_reader<big_endian>&
1568 symtab_reader() const
1569 { return this->symtab_reader_; }
1571 const Incremental_relocs_reader<size, big_endian>&
1572 relocs_reader() const
1573 { return this->relocs_reader_; }
1575 const Incremental_got_plt_reader<big_endian>&
1576 got_plt_reader() const
1577 { return this->got_plt_reader_; }
1580 get_symtab_view(View* symtab_view, unsigned int* sym_count,
1581 elfcpp::Elf_strtab* strtab);
1584 typedef Incremental_inputs_reader<size, big_endian> Inputs_reader;
1585 typedef typename Inputs_reader::Incremental_input_entry_reader
1589 do_check_inputs(const Command_line& cmdline,
1590 Incremental_inputs* incremental_inputs);
1592 // Return TRUE if input file N has changed since the last incremental link.
1594 do_file_has_changed(unsigned int n) const;
1596 // Initialize the layout of the output file based on the existing
1599 do_init_layout(Layout* layout);
1601 // Mark regions of the input file that must be kept unchanged.
1603 do_reserve_layout(unsigned int input_file_index);
1605 // Process the GOT and PLT entries from the existing output file.
1607 do_process_got_plt(Symbol_table* symtab, Layout* layout);
1609 // Apply incremental relocations for symbols whose values have changed.
1611 do_apply_incremental_relocs(const Symbol_table* symtab, Layout* layout,
1614 // Proxy class for a sized Incremental_input_entry_reader.
1616 class Sized_input_reader : public Input_reader
1619 Sized_input_reader(Input_entry_reader r)
1620 : Input_reader(), reader_(r)
1624 ~Sized_input_reader()
1630 { return this->reader_.filename(); }
1633 do_get_mtime() const
1634 { return this->reader_.get_mtime(); }
1636 Incremental_input_type
1638 { return this->reader_.type(); }
1641 do_arg_serial() const
1642 { return this->reader_.arg_serial(); }
1645 do_get_unused_symbol_count() const
1646 { return this->reader_.get_unused_symbol_count(); }
1649 do_get_unused_symbol(unsigned int n) const
1650 { return this->reader_.get_unused_symbol(n); }
1652 Input_entry_reader reader_;
1655 virtual unsigned int
1656 do_input_file_count() const
1657 { return this->inputs_reader_.input_file_count(); }
1659 virtual const Input_reader*
1660 do_get_input_reader(unsigned int n) const
1662 gold_assert(n < this->input_entry_readers_.size());
1663 return &this->input_entry_readers_[n];
1668 find_incremental_inputs_sections(unsigned int* p_inputs_shndx,
1669 unsigned int* p_symtab_shndx,
1670 unsigned int* p_relocs_shndx,
1671 unsigned int* p_got_plt_shndx,
1672 unsigned int* p_strtab_shndx);
1677 // Output as an ELF file.
1678 elfcpp::Elf_file<size, big_endian, Incremental_binary> elf_file_;
1680 // Vector of pointers to the input objects for the unchanged files.
1681 // For replaced files, the corresponding pointer is NULL.
1682 std::vector<Sized_relobj_incr<size, big_endian>*> input_objects_;
1684 // Map section index to an Output_section in the updated layout.
1685 std::vector<Output_section*> section_map_;
1687 // Map global symbols from the input file to the symbol table.
1688 std::vector<Symbol*> symbol_map_;
1690 // Locations of the main symbol table and symbol string table.
1691 Location main_symtab_loc_;
1692 Location main_strtab_loc_;
1694 // Readers for the incremental info sections.
1695 bool has_incremental_info_;
1696 Incremental_inputs_reader<size, big_endian> inputs_reader_;
1697 Incremental_symtab_reader<big_endian> symtab_reader_;
1698 Incremental_relocs_reader<size, big_endian> relocs_reader_;
1699 Incremental_got_plt_reader<big_endian> got_plt_reader_;
1700 std::vector<Sized_input_reader> input_entry_readers_;
1703 // An incremental Relobj. This class represents a relocatable object
1704 // that has not changed since the last incremental link, and whose contents
1705 // can be used directly from the base file.
1707 template<int size, bool big_endian>
1708 class Sized_relobj_incr : public Sized_relobj<size, big_endian>
1711 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
1712 typedef typename Sized_relobj<size, big_endian>::Symbols Symbols;
1714 Sized_relobj_incr(const std::string& name,
1715 Sized_incremental_binary<size, big_endian>* ibase,
1716 unsigned int input_file_index);
1720 typedef Sized_relobj_incr<size, big_endian> This;
1721 static const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1723 typedef typename Sized_relobj<size, big_endian>::Output_sections
1725 typedef Incremental_inputs_reader<size, big_endian> Inputs_reader;
1726 typedef typename Inputs_reader::Incremental_input_entry_reader
1732 Local_symbol(const char* name_, Address value_, unsigned int size_,
1733 unsigned int shndx_, unsigned int type_,
1734 bool needs_dynsym_entry_)
1735 : st_value(value_), name(name_), st_size(size_), st_shndx(shndx_),
1736 st_type(type_), output_dynsym_index(0),
1737 needs_dynsym_entry(needs_dynsym_entry_)
1739 // The symbol value.
1741 // The symbol name. This points to the stringpool entry.
1744 unsigned int st_size;
1745 // The output section index.
1746 unsigned int st_shndx : 28;
1748 unsigned int st_type : 4;
1749 // The index of the symbol in the output dynamic symbol table.
1750 unsigned int output_dynsym_index : 31;
1751 // TRUE if the symbol needs to appear in the dynamic symbol table.
1752 unsigned int needs_dynsym_entry : 1;
1755 // Return TRUE if this is an incremental (unchanged) input file.
1757 do_is_incremental() const
1760 // Return the last modified time of the file.
1763 { return this->input_reader_.get_mtime(); }
1765 // Read the symbols.
1767 do_read_symbols(Read_symbols_data*);
1769 // Lay out the input sections.
1771 do_layout(Symbol_table*, Layout*, Read_symbols_data*);
1773 // Layout sections whose layout was deferred while waiting for
1774 // input files from a plugin.
1776 do_layout_deferred_sections(Layout*);
1778 // Add the symbols to the symbol table.
1780 do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
1782 Archive::Should_include
1783 do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
1786 // Iterate over global symbols, calling a visitor class V for each.
1788 do_for_all_global_symbols(Read_symbols_data* sd,
1789 Library_base::Symbol_visitor_base* v);
1791 // Get the size of a section.
1793 do_section_size(unsigned int shndx);
1795 // Get the name of a section.
1797 do_section_name(unsigned int shndx);
1799 // Return a view of the contents of a section.
1801 do_section_contents(unsigned int shndx);
1803 // Return section flags.
1805 do_section_flags(unsigned int shndx);
1807 // Return section entsize.
1809 do_section_entsize(unsigned int shndx);
1811 // Return section address.
1813 do_section_address(unsigned int shndx);
1815 // Return section type.
1817 do_section_type(unsigned int shndx);
1819 // Return the section link field.
1821 do_section_link(unsigned int shndx);
1823 // Return the section link field.
1825 do_section_info(unsigned int shndx);
1827 // Return the section alignment.
1829 do_section_addralign(unsigned int shndx);
1831 // Return the Xindex structure to use.
1833 do_initialize_xindex();
1835 // Get symbol counts.
1837 do_get_global_symbol_counts(const Symbol_table*, size_t*, size_t*) const;
1839 // Get global symbols.
1841 do_get_global_symbols() const
1842 { return &this->symbols_; }
1844 // Return the number of local symbols.
1846 do_local_symbol_count() const
1847 { return this->local_symbol_count_; }
1849 // Return the number of local symbols in the output symbol table.
1851 do_output_local_symbol_count() const
1852 { return this->local_symbol_count_; }
1854 // Return the file offset for local symbols in the output symbol table.
1856 do_local_symbol_offset() const
1857 { return this->local_symbol_offset_; }
1861 do_read_relocs(Read_relocs_data*);
1863 // Process the relocs to find list of referenced sections. Used only
1864 // during garbage collection.
1866 do_gc_process_relocs(Symbol_table*, Layout*, Read_relocs_data*);
1868 // Scan the relocs and adjust the symbol table.
1870 do_scan_relocs(Symbol_table*, Layout*, Read_relocs_data*);
1872 // Count the local symbols.
1874 do_count_local_symbols(Stringpool_template<char>*,
1875 Stringpool_template<char>*);
1877 // Finalize the local symbols.
1879 do_finalize_local_symbols(unsigned int, off_t, Symbol_table*);
1881 // Set the offset where local dynamic symbol information will be stored.
1883 do_set_local_dynsym_indexes(unsigned int);
1885 // Set the offset where local dynamic symbol information will be stored.
1887 do_set_local_dynsym_offset(off_t);
1889 // Relocate the input sections and write out the local symbols.
1891 do_relocate(const Symbol_table* symtab, const Layout*, Output_file* of);
1893 // Set the offset of a section.
1895 do_set_section_offset(unsigned int shndx, uint64_t off);
1897 // The Incremental_binary base file.
1898 Sized_incremental_binary<size, big_endian>* ibase_;
1899 // The index of the object in the input file list.
1900 unsigned int input_file_index_;
1901 // The reader for the input file.
1902 Input_entry_reader input_reader_;
1903 // The number of local symbols.
1904 unsigned int local_symbol_count_;
1905 // The number of local symbols which go into the output file's dynamic
1907 unsigned int output_local_dynsym_count_;
1908 // This starting symbol index in the output symbol table.
1909 unsigned int local_symbol_index_;
1910 // The file offset for local symbols in the output symbol table.
1911 unsigned int local_symbol_offset_;
1912 // The file offset for local symbols in the output symbol table.
1913 unsigned int local_dynsym_offset_;
1914 // The entries in the symbol table for the external symbols.
1916 // The offset of the first incremental relocation for this object.
1917 unsigned int incr_reloc_offset_;
1918 // The number of incremental relocations for this object.
1919 unsigned int incr_reloc_count_;
1920 // The index of the first incremental relocation for this object in the
1921 // updated output file.
1922 unsigned int incr_reloc_output_index_;
1923 // A copy of the incremental relocations from this object.
1924 unsigned char* incr_relocs_;
1925 // The local symbols.
1926 std::vector<Local_symbol> local_symbols_;
1929 // An incremental Dynobj. This class represents a shared object that has
1930 // not changed since the last incremental link, and whose contents can be
1931 // used directly from the base file.
1933 template<int size, bool big_endian>
1934 class Sized_incr_dynobj : public Dynobj
1937 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
1939 static const Address invalid_address = static_cast<Address>(0) - 1;
1941 Sized_incr_dynobj(const std::string& name,
1942 Sized_incremental_binary<size, big_endian>* ibase,
1943 unsigned int input_file_index);
1946 typedef Incremental_inputs_reader<size, big_endian> Inputs_reader;
1947 typedef typename Inputs_reader::Incremental_input_entry_reader
1950 // Return TRUE if this is an incremental (unchanged) input file.
1952 do_is_incremental() const
1955 // Return the last modified time of the file.
1958 { return this->input_reader_.get_mtime(); }
1960 // Read the symbols.
1962 do_read_symbols(Read_symbols_data*);
1964 // Lay out the input sections.
1966 do_layout(Symbol_table*, Layout*, Read_symbols_data*);
1968 // Add the symbols to the symbol table.
1970 do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
1972 Archive::Should_include
1973 do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
1976 // Iterate over global symbols, calling a visitor class V for each.
1978 do_for_all_global_symbols(Read_symbols_data* sd,
1979 Library_base::Symbol_visitor_base* v);
1981 // Iterate over local symbols, calling a visitor class V for each GOT offset
1982 // associated with a local symbol.
1984 do_for_all_local_got_entries(Got_offset_list::Visitor* v) const;
1986 // Get the size of a section.
1988 do_section_size(unsigned int shndx);
1990 // Get the name of a section.
1992 do_section_name(unsigned int shndx);
1994 // Return a view of the contents of a section.
1996 do_section_contents(unsigned int shndx);
1998 // Return section flags.
2000 do_section_flags(unsigned int shndx);
2002 // Return section entsize.
2004 do_section_entsize(unsigned int shndx);
2006 // Return section address.
2008 do_section_address(unsigned int shndx);
2010 // Return section type.
2012 do_section_type(unsigned int shndx);
2014 // Return the section link field.
2016 do_section_link(unsigned int shndx);
2018 // Return the section link field.
2020 do_section_info(unsigned int shndx);
2022 // Return the section alignment.
2024 do_section_addralign(unsigned int shndx);
2026 // Return the Xindex structure to use.
2028 do_initialize_xindex();
2030 // Get symbol counts.
2032 do_get_global_symbol_counts(const Symbol_table*, size_t*, size_t*) const;
2034 // Get global symbols.
2036 do_get_global_symbols() const
2037 { return &this->symbols_; }
2039 // The Incremental_binary base file.
2040 Sized_incremental_binary<size, big_endian>* ibase_;
2041 // The index of the object in the input file list.
2042 unsigned int input_file_index_;
2043 // The reader for the input file.
2044 Input_entry_reader input_reader_;
2045 // The entries in the symbol table for the external symbols.
2049 // Allocate an incremental object of the appropriate size and endianness.
2051 make_sized_incremental_object(
2052 Incremental_binary* base,
2053 unsigned int input_file_index,
2054 Incremental_input_type input_type,
2055 const Incremental_binary::Input_reader* input_reader);
2057 // This class represents an Archive library (or --start-lib/--end-lib group)
2058 // that has not changed since the last incremental link. Its contents come
2059 // from the incremental inputs entry in the base file.
2061 class Incremental_library : public Library_base
2064 Incremental_library(const char* filename, unsigned int input_file_index,
2065 const Incremental_binary::Input_reader* input_reader)
2066 : Library_base(NULL), filename_(filename),
2067 input_file_index_(input_file_index), input_reader_(input_reader),
2068 unused_symbols_(), is_reported_(false)
2071 // Return the input file index.
2073 input_file_index() const
2074 { return this->input_file_index_; }
2076 // Return the serial number of the input file.
2079 { return this->input_reader_->arg_serial(); }
2081 // Copy the unused symbols from the incremental input info.
2082 // We need to do this because we may be overwriting the incremental
2083 // input info in the base file before we write the new incremental
2086 copy_unused_symbols();
2088 // Return FALSE on the first call to indicate that the library needs
2089 // to be recorded; return TRUE subsequently.
2093 bool was_reported = this->is_reported_;
2094 is_reported_ = true;
2095 return was_reported;
2099 typedef std::vector<std::string> Symbol_list;
2104 { return this->filename_; }
2106 // Return the modification time of the archive file.
2109 { return this->input_reader_->get_mtime(); }
2111 // Iterator for unused global symbols in the library.
2113 do_for_all_unused_symbols(Symbol_visitor_base* v) const;
2115 // The name of the library.
2116 std::string filename_;
2117 // The input file index of this library.
2118 unsigned int input_file_index_;
2119 // A reader for the incremental input information.
2120 const Incremental_binary::Input_reader* input_reader_;
2121 // List of unused symbols defined in this library.
2122 Symbol_list unused_symbols_;
2123 // TRUE when this library has been reported to the new incremental info.
2127 } // End namespace gold.
2129 #endif // !defined(GOLD_INCREMENTAL_H)