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
;
46 class Incremental_library
;
50 // Incremental input type as stored in .gnu_incremental_inputs.
52 enum Incremental_input_type
54 INCREMENTAL_INPUT_OBJECT
= 1,
55 INCREMENTAL_INPUT_ARCHIVE_MEMBER
= 2,
56 INCREMENTAL_INPUT_ARCHIVE
= 3,
57 INCREMENTAL_INPUT_SHARED_LIBRARY
= 4,
58 INCREMENTAL_INPUT_SCRIPT
= 5
61 // Incremental input file flags.
62 // The input file type is stored in the lower eight bits.
64 enum Incremental_input_flags
66 INCREMENTAL_INPUT_IN_SYSTEM_DIR
= 0x0800
69 // Create an Incremental_binary object for FILE. Returns NULL is this is not
70 // possible, e.g. FILE is not an ELF file or has an unsupported target.
73 open_incremental_binary(Output_file
* file
);
75 // Base class for recording each input file.
77 class Incremental_input_entry
80 Incremental_input_entry(Stringpool::Key filename_key
, unsigned int arg_serial
,
82 : filename_key_(filename_key
), file_index_(0), offset_(0), info_offset_(0),
83 arg_serial_(arg_serial
), mtime_(mtime
), is_in_system_directory_(false)
87 ~Incremental_input_entry()
90 // Return the type of input file.
91 Incremental_input_type
93 { return this->do_type(); }
95 // Set the index and section offset of this input file entry.
97 set_offset(unsigned int file_index
, unsigned int offset
)
99 this->file_index_
= file_index
;
100 this->offset_
= offset
;
103 // Set the section offset of the supplemental information for this entry.
105 set_info_offset(unsigned int info_offset
)
106 { this->info_offset_
= info_offset
; }
108 // Get the index of this input file entry.
110 get_file_index() const
111 { return this->file_index_
; }
113 // Get the section offset of this input file entry.
116 { return this->offset_
; }
118 // Get the section offset of the supplemental information for this entry.
120 get_info_offset() const
121 { return this->info_offset_
; }
123 // Get the stringpool key for the input filename.
125 get_filename_key() const
126 { return this->filename_key_
; }
128 // Get the serial number of the input file.
131 { return this->arg_serial_
; }
133 // Get the modification time of the input file.
136 { return this->mtime_
; }
138 // Record that the file was found in a system directory.
140 set_is_in_system_directory()
141 { this->is_in_system_directory_
= true; }
143 // Return TRUE if the file was found in a system directory.
145 is_in_system_directory() const
146 { return this->is_in_system_directory_
; }
148 // Return a pointer to the derived Incremental_script_entry object.
149 // Return NULL for input entries that are not script files.
150 Incremental_script_entry
*
152 { return this->do_script_entry(); }
154 // Return a pointer to the derived Incremental_object_entry object.
155 // Return NULL for input entries that are not object files.
156 Incremental_object_entry
*
158 { return this->do_object_entry(); }
160 // Return a pointer to the derived Incremental_archive_entry object.
161 // Return NULL for input entries that are not archive files.
162 Incremental_archive_entry
*
164 { return this->do_archive_entry(); }
167 // Return the type of input file.
168 virtual Incremental_input_type
171 // Return a pointer to the derived Incremental_script_entry object.
172 // Return NULL for input entries that are not script files.
173 virtual Incremental_script_entry
*
177 // Return a pointer to the derived Incremental_object_entry object.
178 // Return NULL for input entries that are not object files.
179 virtual Incremental_object_entry
*
183 // Return a pointer to the derived Incremental_archive_entry object.
184 // Return NULL for input entries that are not archive files.
185 virtual Incremental_archive_entry
*
190 // Key of the filename string in the section stringtable.
191 Stringpool::Key filename_key_
;
193 // Index of the entry in the output section.
194 unsigned int file_index_
;
196 // Offset of the entry in the output section.
197 unsigned int offset_
;
199 // Offset of the extra information in the output section.
200 unsigned int info_offset_
;
202 // Serial number of the file in the argument list.
203 unsigned int arg_serial_
;
205 // Last modification time of the file.
208 // TRUE if the file was found in a system directory.
209 bool is_in_system_directory_
;
212 // Information about a script input that will persist during the whole linker
213 // run. Needed only during an incremental build to retrieve the input files
214 // added by this script.
219 Script_info(const std::string
& filename
)
220 : filename_(filename
), incremental_script_entry_(NULL
)
223 // Store a pointer to the incremental information for this script.
225 set_incremental_info(Incremental_script_entry
* entry
)
226 { this->incremental_script_entry_
= entry
; }
228 // Return the filename.
231 { return this->filename_
; }
233 // Return the pointer to the incremental information for this script.
234 Incremental_script_entry
*
235 incremental_info() const
236 { return this->incremental_script_entry_
; }
239 const std::string filename_
;
240 Incremental_script_entry
* incremental_script_entry_
;
243 // Class for recording input scripts.
245 class Incremental_script_entry
: public Incremental_input_entry
248 Incremental_script_entry(Stringpool::Key filename_key
,
249 unsigned int arg_serial
, Script_info
* script
,
251 : Incremental_input_entry(filename_key
, arg_serial
, mtime
),
252 script_(script
), objects_()
255 // Add a member object to the archive.
257 add_object(Incremental_input_entry
* obj_entry
)
259 this->objects_
.push_back(obj_entry
);
262 // Return the number of objects included by this script.
265 { return this->objects_
.size(); }
267 // Return the Nth object.
268 Incremental_input_entry
*
269 get_object(unsigned int n
)
271 gold_assert(n
< this->objects_
.size());
272 return this->objects_
[n
];
276 virtual Incremental_input_type
278 { return INCREMENTAL_INPUT_SCRIPT
; }
280 // Return a pointer to the derived Incremental_script_entry object.
281 virtual Incremental_script_entry
*
286 // Information about the script file.
287 Script_info
* script_
;
288 // Objects that have been included by this script.
289 std::vector
<Incremental_input_entry
*> objects_
;
292 // Class for recording input object files.
294 class Incremental_object_entry
: public Incremental_input_entry
297 Incremental_object_entry(Stringpool::Key filename_key
, Object
* obj
,
298 unsigned int arg_serial
, Timespec mtime
)
299 : Incremental_input_entry(filename_key
, arg_serial
, mtime
), obj_(obj
),
300 is_member_(false), sections_()
302 if (!obj_
->is_dynamic())
303 this->sections_
.reserve(obj
->shnum());
309 { return this->obj_
; }
311 // Record that this object is an archive member.
314 { this->is_member_
= true; }
316 // Return true if this object is an archive member.
319 { return this->is_member_
; }
321 // Add an input section.
323 add_input_section(unsigned int shndx
, Stringpool::Key name_key
, off_t sh_size
)
324 { this->sections_
.push_back(Input_section(shndx
, name_key
, sh_size
)); }
326 // Return the number of input sections in this object.
328 get_input_section_count() const
329 { return this->sections_
.size(); }
331 // Return the input section index for the Nth input section.
333 get_input_section_index(unsigned int n
) const
334 { return this->sections_
[n
].shndx_
; }
336 // Return the stringpool key of the Nth input section.
338 get_input_section_name_key(unsigned int n
) const
339 { return this->sections_
[n
].name_key_
; }
341 // Return the size of the Nth input section.
343 get_input_section_size(unsigned int n
) const
344 { return this->sections_
[n
].sh_size_
; }
347 virtual Incremental_input_type
350 return (this->is_member_
351 ? INCREMENTAL_INPUT_ARCHIVE_MEMBER
352 : (this->obj_
->is_dynamic()
353 ? INCREMENTAL_INPUT_SHARED_LIBRARY
354 : INCREMENTAL_INPUT_OBJECT
));
357 // Return a pointer to the derived Incremental_object_entry object.
358 virtual Incremental_object_entry
*
363 // The object file itself.
366 // Whether this object is an archive member.
372 Input_section(unsigned int shndx
, Stringpool::Key name_key
, off_t sh_size
)
373 : shndx_(shndx
), name_key_(name_key
), sh_size_(sh_size
)
376 Stringpool::Key name_key_
;
379 std::vector
<Input_section
> sections_
;
382 // Class for recording archive library input files.
384 class Incremental_archive_entry
: public Incremental_input_entry
387 Incremental_archive_entry(Stringpool::Key filename_key
,
388 unsigned int arg_serial
, Timespec mtime
)
389 : Incremental_input_entry(filename_key
, arg_serial
, mtime
), members_(),
393 // Add a member object to the archive.
395 add_object(Incremental_object_entry
* obj_entry
)
397 this->members_
.push_back(obj_entry
);
398 obj_entry
->set_is_member();
401 // Add an unused global symbol to the archive.
403 add_unused_global_symbol(Stringpool::Key symbol_key
)
404 { this->unused_syms_
.push_back(symbol_key
); }
406 // Return the number of member objects included in the link.
409 { return this->members_
.size(); }
411 // Return the Nth member object.
412 Incremental_object_entry
*
413 get_member(unsigned int n
)
414 { return this->members_
[n
]; }
416 // Return the number of unused global symbols in this archive.
418 get_unused_global_symbol_count()
419 { return this->unused_syms_
.size(); }
421 // Return the Nth unused global symbol.
423 get_unused_global_symbol(unsigned int n
)
424 { return this->unused_syms_
[n
]; }
427 virtual Incremental_input_type
429 { return INCREMENTAL_INPUT_ARCHIVE
; }
431 // Return a pointer to the derived Incremental_archive_entry object.
432 virtual Incremental_archive_entry
*
437 // Members of the archive that have been included in the link.
438 std::vector
<Incremental_object_entry
*> members_
;
440 // Unused global symbols from this archive.
441 std::vector
<Stringpool::Key
> unused_syms_
;
444 // This class contains the information needed during an incremental
445 // build about the inputs necessary to build the .gnu_incremental_inputs.
447 class Incremental_inputs
450 typedef std::vector
<Incremental_input_entry
*> Input_list
;
453 : inputs_(), command_line_(), command_line_key_(0),
454 strtab_(new Stringpool()), current_object_(NULL
),
455 current_object_entry_(NULL
), inputs_section_(NULL
),
456 symtab_section_(NULL
), relocs_section_(NULL
),
460 ~Incremental_inputs() { delete this->strtab_
; }
462 // Record the command line.
464 report_command_line(int argc
, const char* const* argv
);
466 // Record the initial info for archive file ARCHIVE.
468 report_archive_begin(Library_base
* arch
, unsigned int arg_serial
,
469 Script_info
* script_info
);
471 // Record the final info for archive file ARCHIVE.
473 report_archive_end(Library_base
* arch
);
475 // Record the info for object file OBJ. If ARCH is not NULL,
476 // attach the object file to the archive.
478 report_object(Object
* obj
, unsigned int arg_serial
, Library_base
* arch
,
479 Script_info
* script_info
);
481 // Record an input section belonging to object file OBJ.
483 report_input_section(Object
* obj
, unsigned int shndx
, const char* name
,
486 // Record the info for input script SCRIPT.
488 report_script(Script_info
* script
, unsigned int arg_serial
,
491 // Return the running count of incremental relocations.
493 get_reloc_count() const
494 { return this->reloc_count_
; }
496 // Update the running count of incremental relocations.
498 set_reloc_count(unsigned int count
)
499 { this->reloc_count_
= count
; }
501 // Prepare for layout. Called from Layout::finalize.
505 // Create the .gnu_incremental_inputs and related sections.
507 create_data_sections(Symbol_table
* symtab
);
509 // Return the .gnu_incremental_inputs section.
511 inputs_section() const
512 { return this->inputs_section_
; }
514 // Return the .gnu_incremental_symtab section.
516 symtab_section() const
517 { return this->symtab_section_
; }
519 // Return the .gnu_incremental_relocs section.
521 relocs_section() const
522 { return this->relocs_section_
; }
524 // Return the .gnu_incremental_got_plt section.
526 got_plt_section() const
527 { return this->got_plt_section_
; }
529 // Return the .gnu_incremental_strtab stringpool.
531 get_stringpool() const
532 { return this->strtab_
; }
534 // Return the canonical form of the command line, as will be stored in
535 // .gnu_incremental_strtab.
538 { return this->command_line_
; }
540 // Return the stringpool key of the command line.
542 command_line_key() const
543 { return this->command_line_key_
; }
545 // Return the number of input files.
547 input_file_count() const
548 { return this->inputs_
.size(); }
550 // Return the input files.
553 { return this->inputs_
; }
555 // Return the sh_entsize value for the .gnu_incremental_relocs section.
557 relocs_entsize() const;
560 // The list of input files.
563 // Canonical form of the command line, as will be stored in
564 // .gnu_incremental_strtab.
565 std::string command_line_
;
567 // The key of the command line string in the string pool.
568 Stringpool::Key command_line_key_
;
570 // The .gnu_incremental_strtab string pool associated with the
571 // .gnu_incremental_inputs.
574 // Keep track of the object currently being processed.
575 Object
* current_object_
;
576 Incremental_object_entry
* current_object_entry_
;
578 // The .gnu_incremental_inputs section.
579 Output_section_data
* inputs_section_
;
581 // The .gnu_incremental_symtab section.
582 Output_data_space
* symtab_section_
;
584 // The .gnu_incremental_relocs section.
585 Output_data_space
* relocs_section_
;
587 // The .gnu_incremental_got_plt section.
588 Output_data_space
* got_plt_section_
;
590 // Total count of incremental relocations. Updated during Scan_relocs
591 // phase at the completion of each object file.
592 unsigned int reloc_count_
;
595 // Reader class for global symbol info from an object file entry in
596 // the .gnu_incremental_inputs section.
598 template<bool big_endian
>
599 class Incremental_global_symbol_reader
602 typedef elfcpp::Swap
<32, big_endian
> Swap32
;
605 Incremental_global_symbol_reader(const unsigned char* p
)
610 output_symndx() const
611 { return Swap32::readval(this->p_
); }
615 { return Swap32::readval(this->p_
+ 4); }
619 { return Swap32::readval(this->p_
+ 8); }
623 { return Swap32::readval(this->p_
+ 12); }
627 { return Swap32::readval(this->p_
+ 16); }
630 // Base address of the symbol entry.
631 const unsigned char* p_
;
634 // Reader class for .gnu_incremental_inputs section.
636 template<int size
, bool big_endian
>
637 class Incremental_inputs_reader
640 typedef elfcpp::Swap
<size
, big_endian
> Swap
;
641 typedef elfcpp::Swap
<16, big_endian
> Swap16
;
642 typedef elfcpp::Swap
<32, big_endian
> Swap32
;
643 typedef elfcpp::Swap
<64, big_endian
> Swap64
;
646 Incremental_inputs_reader()
647 : p_(NULL
), strtab_(NULL
, 0), input_file_count_(0)
650 Incremental_inputs_reader(const unsigned char* p
,
651 const elfcpp::Elf_strtab
& strtab
)
652 : p_(p
), strtab_(strtab
)
653 { this->input_file_count_
= Swap32::readval(this->p_
+ 4); }
655 // Return the version number.
658 { return Swap32::readval(this->p_
); }
660 // Return the count of input file entries.
662 input_file_count() const
663 { return this->input_file_count_
; }
665 // Return the command line.
669 unsigned int offset
= Swap32::readval(this->p_
+ 8);
670 return this->get_string(offset
);
673 // Reader class for an input file entry and its supplemental info.
674 class Incremental_input_entry_reader
677 Incremental_input_entry_reader(const Incremental_inputs_reader
* inputs
,
679 : inputs_(inputs
), offset_(offset
)
681 this->info_offset_
= Swap32::readval(inputs
->p_
+ offset
+ 4);
682 this->flags_
= Swap16::readval(this->inputs_
->p_
+ offset
+ 20);
685 // Return the filename.
689 unsigned int offset
= Swap32::readval(this->inputs_
->p_
+ this->offset_
);
690 return this->inputs_
->get_string(offset
);
693 // Return the argument serial number.
697 return Swap16::readval(this->inputs_
->p_
+ this->offset_
+ 22);
700 // Return the timestamp.
705 const unsigned char* p
= this->inputs_
->p_
+ this->offset_
+ 8;
706 t
.seconds
= Swap64::readval(p
);
707 t
.nanoseconds
= Swap32::readval(p
+8);
711 // Return the type of input file.
712 Incremental_input_type
714 { return static_cast<Incremental_input_type
>(this->flags_
& 0xff); }
716 // Return TRUE if the file was found in a system directory.
718 is_in_system_directory() const
719 { return (this->flags_
& INCREMENTAL_INPUT_IN_SYSTEM_DIR
) != 0; }
721 // Return the input section count -- for objects only.
723 get_input_section_count() const
725 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
726 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
727 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
730 // Return the offset of the supplemental info for symbol SYMNDX --
733 get_symbol_offset(unsigned int symndx
) const
735 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
736 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
738 unsigned int section_count
= this->get_input_section_count();
739 return (this->info_offset_
+ 16
740 + section_count
* input_section_entry_size
744 // Return the global symbol count -- for objects & shared libraries only.
746 get_global_symbol_count() const
748 switch (this->type())
750 case INCREMENTAL_INPUT_OBJECT
:
751 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
752 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 4);
753 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
754 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
760 // Return the offset of the first local symbol -- for objects only.
762 get_local_symbol_offset() const
764 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
765 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
767 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 8);
770 // Return the local symbol count -- for objects only.
772 get_local_symbol_count() const
774 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
775 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
777 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 12);
780 // Return the object count -- for scripts only.
782 get_object_count() const
784 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT
);
785 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
788 // Return the input file offset for object N -- for scripts only.
790 get_object_offset(unsigned int n
) const
792 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT
);
793 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
797 // Return the member count -- for archives only.
799 get_member_count() const
801 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
802 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
805 // Return the unused symbol count -- for archives only.
807 get_unused_symbol_count() const
809 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
810 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 4);
813 // Return the input file offset for archive member N -- for archives only.
815 get_member_offset(unsigned int n
) const
817 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
818 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
822 // Return the Nth unused global symbol -- for archives only.
824 get_unused_symbol(unsigned int n
) const
826 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
827 unsigned int member_count
= this->get_member_count();
828 unsigned int offset
= Swap32::readval(this->inputs_
->p_
829 + this->info_offset_
+ 8
832 return this->inputs_
->get_string(offset
);
835 // Information about an input section.
836 struct Input_section_info
839 unsigned int output_shndx
;
844 // Return info about the Nth input section -- for objects only.
846 get_input_section(unsigned int n
) const
848 Input_section_info info
;
849 const unsigned char* p
= (this->inputs_
->p_
850 + this->info_offset_
+ 16
851 + n
* input_section_entry_size
);
852 unsigned int name_offset
= Swap32::readval(p
);
853 info
.name
= this->inputs_
->get_string(name_offset
);
854 info
.output_shndx
= Swap32::readval(p
+ 4);
855 info
.sh_offset
= Swap::readval(p
+ 8);
856 info
.sh_size
= Swap::readval(p
+ 8 + size
/ 8);
860 // Return info about the Nth global symbol -- for objects only.
861 Incremental_global_symbol_reader
<big_endian
>
862 get_global_symbol_reader(unsigned int n
) const
864 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
865 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
866 unsigned int section_count
= this->get_input_section_count();
867 const unsigned char* p
= (this->inputs_
->p_
868 + this->info_offset_
+ 16
869 + section_count
* input_section_entry_size
871 return Incremental_global_symbol_reader
<big_endian
>(p
);
874 // Return the output symbol index for the Nth global symbol -- for shared
875 // libraries only. Sets *IS_DEF to TRUE if the symbol is defined in this
878 get_output_symbol_index(unsigned int n
, bool* is_def
)
880 gold_assert(this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY
);
881 const unsigned char* p
= (this->inputs_
->p_
882 + this->info_offset_
+ 4
884 unsigned int output_symndx
= Swap32::readval(p
);
885 *is_def
= (output_symndx
& (1U << 31)) != 0;
886 return output_symndx
& ((1U << 31) - 1);
890 // Size of an input section entry.
891 static const unsigned int input_section_entry_size
= 8 + 2 * size
/ 8;
892 // The reader instance for the containing section.
893 const Incremental_inputs_reader
* inputs_
;
894 // The flags, including the type of input file.
896 // Section offset to the input file entry.
897 unsigned int offset_
;
898 // Section offset to the supplemental info for the input file.
899 unsigned int info_offset_
;
902 // Return the offset of an input file entry given its index N.
904 input_file_offset(unsigned int n
) const
906 gold_assert(n
< this->input_file_count_
);
910 // Return the index of an input file entry given its OFFSET.
912 input_file_index(unsigned int offset
) const
914 int n
= (offset
- 16) / 24;
915 gold_assert(input_file_offset(n
) == offset
);
919 // Return a reader for the Nth input file entry.
920 Incremental_input_entry_reader
921 input_file(unsigned int n
) const
922 { return Incremental_input_entry_reader(this, this->input_file_offset(n
)); }
924 // Return a reader for the input file entry at OFFSET.
925 Incremental_input_entry_reader
926 input_file_at_offset(unsigned int offset
) const
928 gold_assert(offset
< 16 + this->input_file_count_
* 24);
929 return Incremental_input_entry_reader(this, offset
);
932 // Return a reader for the global symbol info at OFFSET.
933 Incremental_global_symbol_reader
<big_endian
>
934 global_symbol_reader_at_offset(unsigned int offset
) const
936 const unsigned char* p
= this->p_
+ offset
;
937 return Incremental_global_symbol_reader
<big_endian
>(p
);
941 // Lookup a string in the ELF string table.
942 const char* get_string(unsigned int offset
) const
945 if (this->strtab_
.get_c_string(offset
, &s
))
950 // Base address of the .gnu_incremental_inputs section.
951 const unsigned char* p_
;
952 // The associated ELF string table.
953 elfcpp::Elf_strtab strtab_
;
954 // The number of input file entries in this section.
955 unsigned int input_file_count_
;
958 // Reader class for the .gnu_incremental_symtab section.
960 template<bool big_endian
>
961 class Incremental_symtab_reader
964 Incremental_symtab_reader()
968 Incremental_symtab_reader(const unsigned char* p
, off_t len
)
972 // Return the count of symbols in this section.
975 { return static_cast<unsigned int>(this->len_
/ 4); }
977 // Return the list head for symbol table entry N.
979 get_list_head(unsigned int n
) const
980 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ 4 * n
); }
983 // Base address of the .gnu_incremental_relocs section.
984 const unsigned char* p_
;
985 // Size of the section.
989 // Reader class for the .gnu_incremental_relocs section.
991 template<int size
, bool big_endian
>
992 class Incremental_relocs_reader
995 // Size of each field.
996 static const unsigned int field_size
= size
/ 8;
999 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1000 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Addend
;
1002 // Size of each entry.
1003 static const unsigned int reloc_size
= 8 + 2 * field_size
;
1005 Incremental_relocs_reader()
1009 Incremental_relocs_reader(const unsigned char* p
, off_t len
)
1013 // Return the count of relocations in this section.
1016 { return static_cast<unsigned int>(this->len_
/ reloc_size
); }
1018 // Return the relocation type for relocation entry at offset OFF.
1020 get_r_type(unsigned int off
) const
1021 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ off
); }
1023 // Return the output section index for relocation entry at offset OFF.
1025 get_r_shndx(unsigned int off
) const
1026 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ off
+ 4); }
1028 // Return the output section offset for relocation entry at offset OFF.
1030 get_r_offset(unsigned int off
) const
1031 { return elfcpp::Swap
<size
, big_endian
>::readval(this->p_
+ off
+ 8); }
1033 // Return the addend for relocation entry at offset OFF.
1035 get_r_addend(unsigned int off
) const
1037 return elfcpp::Swap
<size
, big_endian
>::readval(this->p_
+ off
+ 8
1038 + this->field_size
);
1041 // Return a pointer to the relocation entry at offset OFF.
1042 const unsigned char*
1043 data(unsigned int off
) const
1044 { return this->p_
+ off
; }
1047 // Base address of the .gnu_incremental_relocs section.
1048 const unsigned char* p_
;
1049 // Size of the section.
1053 // Reader class for the .gnu_incremental_got_plt section.
1055 template<bool big_endian
>
1056 class Incremental_got_plt_reader
1059 Incremental_got_plt_reader()
1060 : p_(NULL
), got_count_(0), got_desc_p_(NULL
), plt_desc_p_(NULL
)
1063 Incremental_got_plt_reader(const unsigned char* p
) : p_(p
)
1065 this->got_count_
= elfcpp::Swap
<32, big_endian
>::readval(p
);
1066 this->got_desc_p_
= p
+ 8 + ((this->got_count_
+ 3) & ~3);
1067 this->plt_desc_p_
= this->got_desc_p_
+ this->got_count_
* 4;
1070 // Return the GOT entry count.
1072 get_got_entry_count() const
1074 return this->got_count_
;
1077 // Return the PLT entry count.
1079 get_plt_entry_count() const
1081 return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ 4);
1084 // Return the GOT type for GOT entry N.
1086 get_got_type(unsigned int n
)
1088 return this->p_
[8 + n
];
1091 // Return the GOT descriptor for GOT entry N.
1093 get_got_desc(unsigned int n
)
1095 return elfcpp::Swap
<32, big_endian
>::readval(this->got_desc_p_
+ n
* 4);
1098 // Return the PLT descriptor for PLT entry N.
1100 get_plt_desc(unsigned int n
)
1102 return elfcpp::Swap
<32, big_endian
>::readval(this->plt_desc_p_
+ n
* 4);
1106 // Base address of the .gnu_incremental_got_plt section.
1107 const unsigned char* p_
;
1109 unsigned int got_count_
;
1110 // Base address of the GOT descriptor array.
1111 const unsigned char* got_desc_p_
;
1112 // Base address of the PLT descriptor array.
1113 const unsigned char* plt_desc_p_
;
1116 // An object representing the ELF file we edit during an incremental build.
1117 // Similar to Object or Dynobj, but operates on Output_file and contains
1118 // methods to support incremental updating. This is the abstract parent class
1119 // implemented in Sized_incremental_binary<size, big_endian> for a specific
1120 // endianness and size.
1122 class Incremental_binary
1125 Incremental_binary(Output_file
* output
, Target
* target
)
1126 : input_args_map_(), library_map_(), script_map_(),
1127 output_(output
), target_(target
)
1131 ~Incremental_binary()
1134 // Check the .gnu_incremental_inputs section to see whether an incremental
1135 // build is possible.
1137 check_inputs(const Command_line
& cmdline
,
1138 Incremental_inputs
* incremental_inputs
)
1139 { return this->do_check_inputs(cmdline
, incremental_inputs
); }
1143 error(const char* format
, ...) const ATTRIBUTE_PRINTF_2
;
1145 // Proxy class for a sized Incremental_input_entry_reader.
1159 { return this->do_filename(); }
1163 { return this->do_get_mtime(); }
1165 Incremental_input_type
1167 { return this->do_type(); }
1171 { return this->do_arg_serial(); }
1174 get_unused_symbol_count() const
1175 { return this->do_get_unused_symbol_count(); }
1178 get_unused_symbol(unsigned int n
) const
1179 { return this->do_get_unused_symbol(n
); }
1183 do_filename() const = 0;
1186 do_get_mtime() const = 0;
1188 virtual Incremental_input_type
1189 do_type() const = 0;
1191 virtual unsigned int
1192 do_arg_serial() const = 0;
1194 virtual unsigned int
1195 do_get_unused_symbol_count() const = 0;
1198 do_get_unused_symbol(unsigned int n
) const = 0;
1201 // Return the number of input files.
1203 input_file_count() const
1204 { return this->do_input_file_count(); }
1206 // Return an Input_reader for input file N.
1208 get_input_reader(unsigned int n
) const
1209 { return this->do_get_input_reader(n
); }
1211 // Return TRUE if the input file N has changed since the last link.
1213 file_has_changed(unsigned int n
) const
1214 { return this->do_file_has_changed(n
); }
1216 // Return the Input_argument for input file N. Returns NULL if
1217 // the Input_argument is not available.
1218 const Input_argument
*
1219 get_input_argument(unsigned int n
) const
1221 const Input_reader
* input_file
= this->do_get_input_reader(n
);
1222 unsigned int arg_serial
= input_file
->arg_serial();
1223 if (arg_serial
== 0 || arg_serial
> this->input_args_map_
.size())
1225 return this->input_args_map_
[arg_serial
- 1];
1228 // Return an Incremental_library for the given input file.
1229 Incremental_library
*
1230 get_library(unsigned int n
)
1231 { return this->library_map_
[n
]; }
1233 // Return a Script_info for the given input file.
1235 get_script_info(unsigned int n
)
1236 { return this->script_map_
[n
]; }
1238 // Initialize the layout of the output file based on the existing
1241 init_layout(Layout
* layout
)
1242 { this->do_init_layout(layout
); }
1244 // Mark regions of the input file that must be kept unchanged.
1246 reserve_layout(unsigned int input_file_index
)
1247 { this->do_reserve_layout(input_file_index
); }
1249 // Process the GOT and PLT entries from the existing output file.
1251 process_got_plt(Symbol_table
* symtab
, Layout
* layout
)
1252 { this->do_process_got_plt(symtab
, layout
); }
1254 // Apply incremental relocations for symbols whose values have changed.
1256 apply_incremental_relocs(const Symbol_table
* symtab
, Layout
* layout
,
1258 { this->do_apply_incremental_relocs(symtab
, layout
, of
); }
1260 // Functions and types for the elfcpp::Elf_file interface. This
1261 // permit us to use Incremental_binary as the File template parameter for
1262 // elfcpp::Elf_file.
1264 // The View class is returned by view. It must support a single
1265 // method, data(). This is trivial, because Output_file::get_output_view
1266 // does what we need.
1270 View(const unsigned char* p
)
1274 const unsigned char*
1276 { return this->p_
; }
1279 const unsigned char* p_
;
1284 view(off_t file_offset
, section_size_type data_size
)
1285 { return View(this->output_
->get_input_view(file_offset
, data_size
)); }
1287 // A location in the file.
1293 Location(off_t fo
, section_size_type ds
)
1294 : file_offset(fo
), data_size(ds
)
1298 : file_offset(0), data_size(0)
1302 // Get a View given a Location.
1305 { return View(this->view(loc
.file_offset
, loc
.data_size
)); }
1307 // Return the Output_file.
1310 { return this->output_
; }
1313 // Check the .gnu_incremental_inputs section to see whether an incremental
1314 // build is possible.
1316 do_check_inputs(const Command_line
& cmdline
,
1317 Incremental_inputs
* incremental_inputs
) = 0;
1319 // Return TRUE if input file N has changed since the last incremental link.
1321 do_file_has_changed(unsigned int n
) const = 0;
1323 // Initialize the layout of the output file based on the existing
1326 do_init_layout(Layout
* layout
) = 0;
1328 // Mark regions of the input file that must be kept unchanged.
1330 do_reserve_layout(unsigned int input_file_index
) = 0;
1332 // Process the GOT and PLT entries from the existing output file.
1334 do_process_got_plt(Symbol_table
* symtab
, Layout
* layout
) = 0;
1336 // Apply incremental relocations for symbols whose values have changed.
1338 do_apply_incremental_relocs(const Symbol_table
*, Layout
*, Output_file
*) = 0;
1340 virtual unsigned int
1341 do_input_file_count() const = 0;
1343 virtual const Input_reader
*
1344 do_get_input_reader(unsigned int) const = 0;
1346 // Map from input file index to Input_argument.
1347 std::vector
<const Input_argument
*> input_args_map_
;
1348 // Map from an input file index to an Incremental_library.
1349 std::vector
<Incremental_library
*> library_map_
;
1350 // Map from an input file index to a Script_info.
1351 std::vector
<Script_info
*> script_map_
;
1354 // Edited output file object.
1355 Output_file
* output_
;
1356 // Target of the output file.
1360 template<int size
, bool big_endian
>
1361 class Sized_incremental_binary
: public Incremental_binary
1364 Sized_incremental_binary(Output_file
* output
,
1365 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
,
1367 : Incremental_binary(output
, target
), elf_file_(this, ehdr
),
1368 file_status_(NULL
), section_map_(), symbol_map_(), main_symtab_loc_(),
1369 main_strtab_loc_(), has_incremental_info_(false), inputs_reader_(),
1370 symtab_reader_(), relocs_reader_(), got_plt_reader_(),
1371 input_entry_readers_()
1372 { this->setup_readers(); }
1375 ~Sized_incremental_binary()
1377 if (this->file_status_
!= NULL
)
1378 delete[] this->file_status_
;
1381 // Returns TRUE if the file contains incremental info.
1383 has_incremental_info() const
1384 { return this->has_incremental_info_
; }
1386 // Set the flag for input file N to indicate that the file is unchanged.
1388 set_file_is_unchanged(unsigned int n
)
1390 gold_assert(this->file_status_
!= NULL
);
1391 this->file_status_
[n
/ 8] |= 1U << (n
% 8);
1394 // Returns TRUE if input file N is unchanged.
1396 file_is_unchanged(unsigned int n
) const
1398 gold_assert(this->file_status_
!= NULL
);
1399 return (this->file_status_
[n
/ 8] & (1U << (n
% 8))) != 0;
1402 // Return the Output_section for section index SHNDX.
1404 output_section(unsigned int shndx
)
1405 { return this->section_map_
[shndx
]; }
1407 // Map a symbol table entry from the base file to the output symbol table.
1408 // SYMNDX is relative to the first forced-local or global symbol in the
1409 // input file symbol table.
1411 add_global_symbol(unsigned int symndx
, Symbol
* gsym
)
1412 { this->symbol_map_
[symndx
] = gsym
; }
1414 // Map a symbol table entry from the base file to the output symbol table.
1415 // SYMNDX is relative to the first forced-local or global symbol in the
1416 // input file symbol table.
1418 global_symbol(unsigned int symndx
) const
1419 { return this->symbol_map_
[symndx
]; }
1421 // Readers for the incremental info sections.
1423 const Incremental_inputs_reader
<size
, big_endian
>&
1424 inputs_reader() const
1425 { return this->inputs_reader_
; }
1427 const Incremental_symtab_reader
<big_endian
>&
1428 symtab_reader() const
1429 { return this->symtab_reader_
; }
1431 const Incremental_relocs_reader
<size
, big_endian
>&
1432 relocs_reader() const
1433 { return this->relocs_reader_
; }
1435 const Incremental_got_plt_reader
<big_endian
>&
1436 got_plt_reader() const
1437 { return this->got_plt_reader_
; }
1440 get_symtab_view(View
* symtab_view
, unsigned int* sym_count
,
1441 elfcpp::Elf_strtab
* strtab
);
1444 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1445 typedef typename
Inputs_reader::Incremental_input_entry_reader
1449 do_check_inputs(const Command_line
& cmdline
,
1450 Incremental_inputs
* incremental_inputs
);
1452 // Return TRUE if input file N has changed since the last incremental link.
1454 do_file_has_changed(unsigned int n
) const;
1456 // Initialize the layout of the output file based on the existing
1459 do_init_layout(Layout
* layout
);
1461 // Mark regions of the input file that must be kept unchanged.
1463 do_reserve_layout(unsigned int input_file_index
);
1465 // Process the GOT and PLT entries from the existing output file.
1467 do_process_got_plt(Symbol_table
* symtab
, Layout
* layout
);
1469 // Apply incremental relocations for symbols whose values have changed.
1471 do_apply_incremental_relocs(const Symbol_table
* symtab
, Layout
* layout
,
1474 // Proxy class for a sized Incremental_input_entry_reader.
1476 class Sized_input_reader
: public Input_reader
1479 Sized_input_reader(Input_entry_reader r
)
1480 : Input_reader(), reader_(r
)
1484 ~Sized_input_reader()
1490 { return this->reader_
.filename(); }
1493 do_get_mtime() const
1494 { return this->reader_
.get_mtime(); }
1496 Incremental_input_type
1498 { return this->reader_
.type(); }
1501 do_arg_serial() const
1502 { return this->reader_
.arg_serial(); }
1505 do_get_unused_symbol_count() const
1506 { return this->reader_
.get_unused_symbol_count(); }
1509 do_get_unused_symbol(unsigned int n
) const
1510 { return this->reader_
.get_unused_symbol(n
); }
1512 Input_entry_reader reader_
;
1515 virtual unsigned int
1516 do_input_file_count() const
1517 { return this->inputs_reader_
.input_file_count(); }
1519 virtual const Input_reader
*
1520 do_get_input_reader(unsigned int n
) const
1522 gold_assert(n
< this->input_entry_readers_
.size());
1523 return &this->input_entry_readers_
[n
];
1528 find_incremental_inputs_sections(unsigned int* p_inputs_shndx
,
1529 unsigned int* p_symtab_shndx
,
1530 unsigned int* p_relocs_shndx
,
1531 unsigned int* p_got_plt_shndx
,
1532 unsigned int* p_strtab_shndx
);
1537 // Output as an ELF file.
1538 elfcpp::Elf_file
<size
, big_endian
, Incremental_binary
> elf_file_
;
1540 // Status flags for each input file. Each bit represents one input file;
1541 // 0 indicates that the file was replaced; 1 indicates that the file was
1543 unsigned char* file_status_
;
1545 // Map section index to an Output_section in the updated layout.
1546 std::vector
<Output_section
*> section_map_
;
1548 // Map global symbols from the input file to the symbol table.
1549 std::vector
<Symbol
*> symbol_map_
;
1551 // Locations of the main symbol table and symbol string table.
1552 Location main_symtab_loc_
;
1553 Location main_strtab_loc_
;
1555 // Readers for the incremental info sections.
1556 bool has_incremental_info_
;
1557 Incremental_inputs_reader
<size
, big_endian
> inputs_reader_
;
1558 Incremental_symtab_reader
<big_endian
> symtab_reader_
;
1559 Incremental_relocs_reader
<size
, big_endian
> relocs_reader_
;
1560 Incremental_got_plt_reader
<big_endian
> got_plt_reader_
;
1561 std::vector
<Sized_input_reader
> input_entry_readers_
;
1564 // An incremental Relobj. This class represents a relocatable object
1565 // that has not changed since the last incremental link, and whose contents
1566 // can be used directly from the base file.
1568 template<int size
, bool big_endian
>
1569 class Sized_incr_relobj
: public Sized_relobj_base
<size
, big_endian
>
1572 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1573 typedef typename Sized_relobj_base
<size
, big_endian
>::Symbols Symbols
;
1575 static const Address invalid_address
= static_cast<Address
>(0) - 1;
1577 Sized_incr_relobj(const std::string
& name
,
1578 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1579 unsigned int input_file_index
);
1581 // Checks if the offset of input section SHNDX within its output
1582 // section is invalid.
1584 is_output_section_offset_invalid(unsigned int shndx
) const
1585 { return this->section_offsets_
[shndx
] == invalid_address
; }
1587 // Get the offset of input section SHNDX within its output section.
1588 // This is -1 if the input section requires a special mapping, such
1589 // as a merge section. The output section can be found in the
1590 // output_sections_ field of the parent class Incrobj.
1592 do_output_section_offset(unsigned int shndx
) const
1594 gold_assert(shndx
< this->section_offsets_
.size());
1595 Address off
= this->section_offsets_
[shndx
];
1596 if (off
== invalid_address
)
1603 typedef Sized_incr_relobj
<size
, big_endian
> This
;
1604 static const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1606 typedef typename Sized_relobj_base
<size
, big_endian
>::Output_sections
1608 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1609 typedef typename
Inputs_reader::Incremental_input_entry_reader
1615 Local_symbol(const char* name_
, Address value_
, unsigned int size_
,
1616 unsigned int shndx_
, unsigned int type_
,
1617 bool needs_dynsym_entry_
)
1618 : st_value(value_
), name(name_
), st_size(size_
), st_shndx(shndx_
),
1619 st_type(type_
), output_dynsym_index(0),
1620 needs_dynsym_entry(needs_dynsym_entry_
)
1622 // The symbol value.
1624 // The symbol name. This points to the stringpool entry.
1627 unsigned int st_size
;
1628 // The output section index.
1629 unsigned int st_shndx
: 28;
1631 unsigned int st_type
: 4;
1632 // The index of the symbol in the output dynamic symbol table.
1633 unsigned int output_dynsym_index
: 31;
1634 // TRUE if the symbol needs to appear in the dynamic symbol table.
1635 unsigned int needs_dynsym_entry
: 1;
1638 // Return TRUE if this is an incremental (unchanged) input file.
1640 do_is_incremental() const
1643 // Return the last modified time of the file.
1646 { return this->input_reader_
.get_mtime(); }
1648 // Read the symbols.
1650 do_read_symbols(Read_symbols_data
*);
1652 // Lay out the input sections.
1654 do_layout(Symbol_table
*, Layout
*, Read_symbols_data
*);
1656 // Layout sections whose layout was deferred while waiting for
1657 // input files from a plugin.
1659 do_layout_deferred_sections(Layout
*);
1661 // Add the symbols to the symbol table.
1663 do_add_symbols(Symbol_table
*, Read_symbols_data
*, Layout
*);
1665 Archive::Should_include
1666 do_should_include_member(Symbol_table
* symtab
, Layout
*, Read_symbols_data
*,
1669 // Iterate over global symbols, calling a visitor class V for each.
1671 do_for_all_global_symbols(Read_symbols_data
* sd
,
1672 Library_base::Symbol_visitor_base
* v
);
1674 // Iterate over local symbols, calling a visitor class V for each GOT offset
1675 // associated with a local symbol.
1677 do_for_all_local_got_entries(Got_offset_list::Visitor
* v
) const;
1679 // Get the size of a section.
1681 do_section_size(unsigned int shndx
);
1683 // Get the name of a section.
1685 do_section_name(unsigned int shndx
);
1687 // Return a view of the contents of a section.
1689 do_section_contents(unsigned int shndx
);
1691 // Return section flags.
1693 do_section_flags(unsigned int shndx
);
1695 // Return section entsize.
1697 do_section_entsize(unsigned int shndx
);
1699 // Return section address.
1701 do_section_address(unsigned int shndx
);
1703 // Return section type.
1705 do_section_type(unsigned int shndx
);
1707 // Return the section link field.
1709 do_section_link(unsigned int shndx
);
1711 // Return the section link field.
1713 do_section_info(unsigned int shndx
);
1715 // Return the section alignment.
1717 do_section_addralign(unsigned int shndx
);
1719 // Return the Xindex structure to use.
1721 do_initialize_xindex();
1723 // Get symbol counts.
1725 do_get_global_symbol_counts(const Symbol_table
*, size_t*, size_t*) const;
1727 // Get global symbols.
1729 do_get_global_symbols() const
1730 { return &this->symbols_
; }
1732 // Return the number of local symbols.
1734 do_local_symbol_count() const
1735 { return this->local_symbol_count_
; }
1737 // Return the number of local symbols in the output symbol table.
1739 do_output_local_symbol_count() const
1740 { return this->local_symbol_count_
; }
1742 // Return the file offset for local symbols in the output symbol table.
1744 do_local_symbol_offset() const
1745 { return this->local_symbol_offset_
; }
1749 do_read_relocs(Read_relocs_data
*);
1751 // Process the relocs to find list of referenced sections. Used only
1752 // during garbage collection.
1754 do_gc_process_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
1756 // Scan the relocs and adjust the symbol table.
1758 do_scan_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
1760 // Count the local symbols.
1762 do_count_local_symbols(Stringpool_template
<char>*,
1763 Stringpool_template
<char>*);
1765 // Finalize the local symbols.
1767 do_finalize_local_symbols(unsigned int, off_t
, Symbol_table
*);
1769 // Set the offset where local dynamic symbol information will be stored.
1771 do_set_local_dynsym_indexes(unsigned int);
1773 // Set the offset where local dynamic symbol information will be stored.
1775 do_set_local_dynsym_offset(off_t
);
1777 // Relocate the input sections and write out the local symbols.
1779 do_relocate(const Symbol_table
* symtab
, const Layout
*, Output_file
* of
);
1781 // Set the offset of a section.
1783 do_set_section_offset(unsigned int shndx
, uint64_t off
);
1785 // The Incremental_binary base file.
1786 Sized_incremental_binary
<size
, big_endian
>* ibase_
;
1787 // The index of the object in the input file list.
1788 unsigned int input_file_index_
;
1789 // The reader for the input file.
1790 Input_entry_reader input_reader_
;
1791 // The number of local symbols.
1792 unsigned int local_symbol_count_
;
1793 // The number of local symbols which go into the output file's dynamic
1795 unsigned int output_local_dynsym_count_
;
1796 // This starting symbol index in the output symbol table.
1797 unsigned int local_symbol_index_
;
1798 // The file offset for local symbols in the output symbol table.
1799 unsigned int local_symbol_offset_
;
1800 // The file offset for local symbols in the output symbol table.
1801 unsigned int local_dynsym_offset_
;
1802 // The entries in the symbol table for the external symbols.
1804 // For each input section, the offset of the input section in its
1805 // output section. This is INVALID_ADDRESS if the input section requires a
1807 std::vector
<Address
> section_offsets_
;
1808 // The offset of the first incremental relocation for this object.
1809 unsigned int incr_reloc_offset_
;
1810 // The number of incremental relocations for this object.
1811 unsigned int incr_reloc_count_
;
1812 // The index of the first incremental relocation for this object in the
1813 // updated output file.
1814 unsigned int incr_reloc_output_index_
;
1815 // A copy of the incremental relocations from this object.
1816 unsigned char* incr_relocs_
;
1817 // The local symbols.
1818 std::vector
<Local_symbol
> local_symbols_
;
1821 // An incremental Dynobj. This class represents a shared object that has
1822 // not changed since the last incremental link, and whose contents can be
1823 // used directly from the base file.
1825 template<int size
, bool big_endian
>
1826 class Sized_incr_dynobj
: public Dynobj
1829 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1831 static const Address invalid_address
= static_cast<Address
>(0) - 1;
1833 Sized_incr_dynobj(const std::string
& name
,
1834 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1835 unsigned int input_file_index
);
1838 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1839 typedef typename
Inputs_reader::Incremental_input_entry_reader
1842 // Return TRUE if this is an incremental (unchanged) input file.
1844 do_is_incremental() const
1847 // Return the last modified time of the file.
1850 { return this->input_reader_
.get_mtime(); }
1852 // Read the symbols.
1854 do_read_symbols(Read_symbols_data
*);
1856 // Lay out the input sections.
1858 do_layout(Symbol_table
*, Layout
*, Read_symbols_data
*);
1860 // Add the symbols to the symbol table.
1862 do_add_symbols(Symbol_table
*, Read_symbols_data
*, Layout
*);
1864 Archive::Should_include
1865 do_should_include_member(Symbol_table
* symtab
, Layout
*, Read_symbols_data
*,
1868 // Iterate over global symbols, calling a visitor class V for each.
1870 do_for_all_global_symbols(Read_symbols_data
* sd
,
1871 Library_base::Symbol_visitor_base
* v
);
1873 // Iterate over local symbols, calling a visitor class V for each GOT offset
1874 // associated with a local symbol.
1876 do_for_all_local_got_entries(Got_offset_list::Visitor
* v
) const;
1878 // Get the size of a section.
1880 do_section_size(unsigned int shndx
);
1882 // Get the name of a section.
1884 do_section_name(unsigned int shndx
);
1886 // Return a view of the contents of a section.
1888 do_section_contents(unsigned int shndx
);
1890 // Return section flags.
1892 do_section_flags(unsigned int shndx
);
1894 // Return section entsize.
1896 do_section_entsize(unsigned int shndx
);
1898 // Return section address.
1900 do_section_address(unsigned int shndx
);
1902 // Return section type.
1904 do_section_type(unsigned int shndx
);
1906 // Return the section link field.
1908 do_section_link(unsigned int shndx
);
1910 // Return the section link field.
1912 do_section_info(unsigned int shndx
);
1914 // Return the section alignment.
1916 do_section_addralign(unsigned int shndx
);
1918 // Return the Xindex structure to use.
1920 do_initialize_xindex();
1922 // Get symbol counts.
1924 do_get_global_symbol_counts(const Symbol_table
*, size_t*, size_t*) const;
1926 // Get global symbols.
1928 do_get_global_symbols() const
1929 { return &this->symbols_
; }
1931 // The Incremental_binary base file.
1932 Sized_incremental_binary
<size
, big_endian
>* ibase_
;
1933 // The index of the object in the input file list.
1934 unsigned int input_file_index_
;
1935 // The reader for the input file.
1936 Input_entry_reader input_reader_
;
1937 // The entries in the symbol table for the external symbols.
1941 // Allocate an incremental object of the appropriate size and endianness.
1943 make_sized_incremental_object(
1944 Incremental_binary
* base
,
1945 unsigned int input_file_index
,
1946 Incremental_input_type input_type
,
1947 const Incremental_binary::Input_reader
* input_reader
);
1949 // This class represents an Archive library (or --start-lib/--end-lib group)
1950 // that has not changed since the last incremental link. Its contents come
1951 // from the incremental inputs entry in the base file.
1953 class Incremental_library
: public Library_base
1956 Incremental_library(const char* filename
, unsigned int input_file_index
,
1957 const Incremental_binary::Input_reader
* input_reader
)
1958 : Library_base(NULL
), filename_(filename
),
1959 input_file_index_(input_file_index
), input_reader_(input_reader
),
1960 unused_symbols_(), is_reported_(false)
1963 // Return the input file index.
1965 input_file_index() const
1966 { return this->input_file_index_
; }
1968 // Return the serial number of the input file.
1971 { return this->input_reader_
->arg_serial(); }
1973 // Copy the unused symbols from the incremental input info.
1974 // We need to do this because we may be overwriting the incremental
1975 // input info in the base file before we write the new incremental
1978 copy_unused_symbols();
1980 // Return FALSE on the first call to indicate that the library needs
1981 // to be recorded; return TRUE subsequently.
1985 bool was_reported
= this->is_reported_
;
1986 is_reported_
= true;
1987 return was_reported
;
1991 typedef std::vector
<std::string
> Symbol_list
;
1996 { return this->filename_
; }
1998 // Return the modification time of the archive file.
2001 { return this->input_reader_
->get_mtime(); }
2003 // Iterator for unused global symbols in the library.
2005 do_for_all_unused_symbols(Symbol_visitor_base
* v
) const;
2007 // The name of the library.
2008 std::string filename_
;
2009 // The input file index of this library.
2010 unsigned int input_file_index_
;
2011 // A reader for the incremental input information.
2012 const Incremental_binary::Input_reader
* input_reader_
;
2013 // List of unused symbols defined in this library.
2014 Symbol_list unused_symbols_
;
2015 // TRUE when this library has been reported to the new incremental info.
2019 } // End namespace gold.
2021 #endif // !defined(GOLD_INCREMENTAL_H)