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_
+ 24
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 index of the first dynamic relocation -- for objects only.
782 get_first_dyn_reloc() const
784 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
785 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
787 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 16);
790 // Return the dynamic relocation count -- for objects only.
792 get_dyn_reloc_count() const
794 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
795 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
797 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 20);
800 // Return the object count -- for scripts only.
802 get_object_count() const
804 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT
);
805 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
808 // Return the input file offset for object N -- for scripts only.
810 get_object_offset(unsigned int n
) const
812 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT
);
813 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
817 // Return the member count -- for archives only.
819 get_member_count() const
821 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
822 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
825 // Return the unused symbol count -- for archives only.
827 get_unused_symbol_count() const
829 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
830 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 4);
833 // Return the input file offset for archive member N -- for archives only.
835 get_member_offset(unsigned int n
) const
837 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
838 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
842 // Return the Nth unused global symbol -- for archives only.
844 get_unused_symbol(unsigned int n
) const
846 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
847 unsigned int member_count
= this->get_member_count();
848 unsigned int offset
= Swap32::readval(this->inputs_
->p_
849 + this->info_offset_
+ 8
852 return this->inputs_
->get_string(offset
);
855 // Information about an input section.
856 struct Input_section_info
859 unsigned int output_shndx
;
864 // Return info about the Nth input section -- for objects only.
866 get_input_section(unsigned int n
) const
868 Input_section_info info
;
869 const unsigned char* p
= (this->inputs_
->p_
870 + this->info_offset_
+ 24
871 + n
* input_section_entry_size
);
872 unsigned int name_offset
= Swap32::readval(p
);
873 info
.name
= this->inputs_
->get_string(name_offset
);
874 info
.output_shndx
= Swap32::readval(p
+ 4);
875 info
.sh_offset
= Swap::readval(p
+ 8);
876 info
.sh_size
= Swap::readval(p
+ 8 + size
/ 8);
880 // Return info about the Nth global symbol -- for objects only.
881 Incremental_global_symbol_reader
<big_endian
>
882 get_global_symbol_reader(unsigned int n
) const
884 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
885 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
886 unsigned int section_count
= this->get_input_section_count();
887 const unsigned char* p
= (this->inputs_
->p_
888 + this->info_offset_
+ 24
889 + section_count
* input_section_entry_size
891 return Incremental_global_symbol_reader
<big_endian
>(p
);
894 // Return the output symbol index for the Nth global symbol -- for shared
895 // libraries only. Sets *IS_DEF to TRUE if the symbol is defined in this
898 get_output_symbol_index(unsigned int n
, bool* is_def
)
900 gold_assert(this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY
);
901 const unsigned char* p
= (this->inputs_
->p_
902 + this->info_offset_
+ 4
904 unsigned int output_symndx
= Swap32::readval(p
);
905 *is_def
= (output_symndx
& (1U << 31)) != 0;
906 return output_symndx
& ((1U << 31) - 1);
910 // Size of an input section entry.
911 static const unsigned int input_section_entry_size
= 8 + 2 * size
/ 8;
912 // The reader instance for the containing section.
913 const Incremental_inputs_reader
* inputs_
;
914 // The flags, including the type of input file.
916 // Section offset to the input file entry.
917 unsigned int offset_
;
918 // Section offset to the supplemental info for the input file.
919 unsigned int info_offset_
;
922 // Return the offset of an input file entry given its index N.
924 input_file_offset(unsigned int n
) const
926 gold_assert(n
< this->input_file_count_
);
930 // Return the index of an input file entry given its OFFSET.
932 input_file_index(unsigned int offset
) const
934 int n
= (offset
- 16) / 24;
935 gold_assert(input_file_offset(n
) == offset
);
939 // Return a reader for the Nth input file entry.
940 Incremental_input_entry_reader
941 input_file(unsigned int n
) const
942 { return Incremental_input_entry_reader(this, this->input_file_offset(n
)); }
944 // Return a reader for the input file entry at OFFSET.
945 Incremental_input_entry_reader
946 input_file_at_offset(unsigned int offset
) const
948 gold_assert(offset
< 16 + this->input_file_count_
* 24);
949 return Incremental_input_entry_reader(this, offset
);
952 // Return a reader for the global symbol info at OFFSET.
953 Incremental_global_symbol_reader
<big_endian
>
954 global_symbol_reader_at_offset(unsigned int offset
) const
956 const unsigned char* p
= this->p_
+ offset
;
957 return Incremental_global_symbol_reader
<big_endian
>(p
);
961 // Lookup a string in the ELF string table.
962 const char* get_string(unsigned int offset
) const
965 if (this->strtab_
.get_c_string(offset
, &s
))
970 // Base address of the .gnu_incremental_inputs section.
971 const unsigned char* p_
;
972 // The associated ELF string table.
973 elfcpp::Elf_strtab strtab_
;
974 // The number of input file entries in this section.
975 unsigned int input_file_count_
;
978 // Reader class for the .gnu_incremental_symtab section.
980 template<bool big_endian
>
981 class Incremental_symtab_reader
984 Incremental_symtab_reader()
988 Incremental_symtab_reader(const unsigned char* p
, off_t len
)
992 // Return the count of symbols in this section.
995 { return static_cast<unsigned int>(this->len_
/ 4); }
997 // Return the list head for symbol table entry N.
999 get_list_head(unsigned int n
) const
1000 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ 4 * n
); }
1003 // Base address of the .gnu_incremental_relocs section.
1004 const unsigned char* p_
;
1005 // Size of the section.
1009 // Reader class for the .gnu_incremental_relocs section.
1011 template<int size
, bool big_endian
>
1012 class Incremental_relocs_reader
1015 // Size of each field.
1016 static const unsigned int field_size
= size
/ 8;
1019 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1020 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Addend
;
1022 // Size of each entry.
1023 static const unsigned int reloc_size
= 8 + 2 * field_size
;
1025 Incremental_relocs_reader()
1029 Incremental_relocs_reader(const unsigned char* p
, off_t len
)
1033 // Return the count of relocations in this section.
1036 { return static_cast<unsigned int>(this->len_
/ reloc_size
); }
1038 // Return the relocation type for relocation entry at offset OFF.
1040 get_r_type(unsigned int off
) const
1041 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ off
); }
1043 // Return the output section index for relocation entry at offset OFF.
1045 get_r_shndx(unsigned int off
) const
1046 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ off
+ 4); }
1048 // Return the output section offset for relocation entry at offset OFF.
1050 get_r_offset(unsigned int off
) const
1051 { return elfcpp::Swap
<size
, big_endian
>::readval(this->p_
+ off
+ 8); }
1053 // Return the addend for relocation entry at offset OFF.
1055 get_r_addend(unsigned int off
) const
1057 return elfcpp::Swap
<size
, big_endian
>::readval(this->p_
+ off
+ 8
1058 + this->field_size
);
1061 // Return a pointer to the relocation entry at offset OFF.
1062 const unsigned char*
1063 data(unsigned int off
) const
1064 { return this->p_
+ off
; }
1067 // Base address of the .gnu_incremental_relocs section.
1068 const unsigned char* p_
;
1069 // Size of the section.
1073 // Reader class for the .gnu_incremental_got_plt section.
1075 template<bool big_endian
>
1076 class Incremental_got_plt_reader
1079 Incremental_got_plt_reader()
1080 : p_(NULL
), got_count_(0), got_desc_p_(NULL
), plt_desc_p_(NULL
)
1083 Incremental_got_plt_reader(const unsigned char* p
) : p_(p
)
1085 this->got_count_
= elfcpp::Swap
<32, big_endian
>::readval(p
);
1086 this->got_desc_p_
= p
+ 8 + ((this->got_count_
+ 3) & ~3);
1087 this->plt_desc_p_
= this->got_desc_p_
+ this->got_count_
* 8;
1090 // Return the GOT entry count.
1092 get_got_entry_count() const
1094 return this->got_count_
;
1097 // Return the PLT entry count.
1099 get_plt_entry_count() const
1101 return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ 4);
1104 // Return the GOT type for GOT entry N.
1106 get_got_type(unsigned int n
)
1108 return this->p_
[8 + n
];
1111 // Return the symbol index for GOT entry N.
1113 get_got_symndx(unsigned int n
)
1115 return elfcpp::Swap
<32, big_endian
>::readval(this->got_desc_p_
+ n
* 8);
1118 // Return the input file index for GOT entry N.
1120 get_got_input_index(unsigned int n
)
1122 return elfcpp::Swap
<32, big_endian
>::readval(this->got_desc_p_
+ n
* 8 + 4);
1125 // Return the PLT descriptor for PLT entry N.
1127 get_plt_desc(unsigned int n
)
1129 return elfcpp::Swap
<32, big_endian
>::readval(this->plt_desc_p_
+ n
* 4);
1133 // Base address of the .gnu_incremental_got_plt section.
1134 const unsigned char* p_
;
1136 unsigned int got_count_
;
1137 // Base address of the GOT descriptor array.
1138 const unsigned char* got_desc_p_
;
1139 // Base address of the PLT descriptor array.
1140 const unsigned char* plt_desc_p_
;
1143 // An object representing the ELF file we edit during an incremental build.
1144 // Similar to Object or Dynobj, but operates on Output_file and contains
1145 // methods to support incremental updating. This is the abstract parent class
1146 // implemented in Sized_incremental_binary<size, big_endian> for a specific
1147 // endianness and size.
1149 class Incremental_binary
1152 Incremental_binary(Output_file
* output
, Target
* target
)
1153 : input_args_map_(), library_map_(), script_map_(),
1154 output_(output
), target_(target
)
1158 ~Incremental_binary()
1161 // Check the .gnu_incremental_inputs section to see whether an incremental
1162 // build is possible.
1164 check_inputs(const Command_line
& cmdline
,
1165 Incremental_inputs
* incremental_inputs
)
1166 { return this->do_check_inputs(cmdline
, incremental_inputs
); }
1170 error(const char* format
, ...) const ATTRIBUTE_PRINTF_2
;
1172 // Proxy class for a sized Incremental_input_entry_reader.
1186 { return this->do_filename(); }
1190 { return this->do_get_mtime(); }
1192 Incremental_input_type
1194 { return this->do_type(); }
1198 { return this->do_arg_serial(); }
1201 get_unused_symbol_count() const
1202 { return this->do_get_unused_symbol_count(); }
1205 get_unused_symbol(unsigned int n
) const
1206 { return this->do_get_unused_symbol(n
); }
1210 do_filename() const = 0;
1213 do_get_mtime() const = 0;
1215 virtual Incremental_input_type
1216 do_type() const = 0;
1218 virtual unsigned int
1219 do_arg_serial() const = 0;
1221 virtual unsigned int
1222 do_get_unused_symbol_count() const = 0;
1225 do_get_unused_symbol(unsigned int n
) const = 0;
1228 // Return the number of input files.
1230 input_file_count() const
1231 { return this->do_input_file_count(); }
1233 // Return an Input_reader for input file N.
1235 get_input_reader(unsigned int n
) const
1236 { return this->do_get_input_reader(n
); }
1238 // Return TRUE if the input file N has changed since the last link.
1240 file_has_changed(unsigned int n
) const
1241 { return this->do_file_has_changed(n
); }
1243 // Return the Input_argument for input file N. Returns NULL if
1244 // the Input_argument is not available.
1245 const Input_argument
*
1246 get_input_argument(unsigned int n
) const
1248 const Input_reader
* input_file
= this->do_get_input_reader(n
);
1249 unsigned int arg_serial
= input_file
->arg_serial();
1250 if (arg_serial
== 0 || arg_serial
> this->input_args_map_
.size())
1252 return this->input_args_map_
[arg_serial
- 1];
1255 // Return an Incremental_library for the given input file.
1256 Incremental_library
*
1257 get_library(unsigned int n
)
1258 { return this->library_map_
[n
]; }
1260 // Return a Script_info for the given input file.
1262 get_script_info(unsigned int n
)
1263 { return this->script_map_
[n
]; }
1265 // Initialize the layout of the output file based on the existing
1268 init_layout(Layout
* layout
)
1269 { this->do_init_layout(layout
); }
1271 // Mark regions of the input file that must be kept unchanged.
1273 reserve_layout(unsigned int input_file_index
)
1274 { this->do_reserve_layout(input_file_index
); }
1276 // Process the GOT and PLT entries from the existing output file.
1278 process_got_plt(Symbol_table
* symtab
, Layout
* layout
)
1279 { this->do_process_got_plt(symtab
, layout
); }
1281 // Apply incremental relocations for symbols whose values have changed.
1283 apply_incremental_relocs(const Symbol_table
* symtab
, Layout
* layout
,
1285 { this->do_apply_incremental_relocs(symtab
, layout
, of
); }
1287 // Functions and types for the elfcpp::Elf_file interface. This
1288 // permit us to use Incremental_binary as the File template parameter for
1289 // elfcpp::Elf_file.
1291 // The View class is returned by view. It must support a single
1292 // method, data(). This is trivial, because Output_file::get_output_view
1293 // does what we need.
1297 View(const unsigned char* p
)
1301 const unsigned char*
1303 { return this->p_
; }
1306 const unsigned char* p_
;
1311 view(off_t file_offset
, section_size_type data_size
)
1312 { return View(this->output_
->get_input_view(file_offset
, data_size
)); }
1314 // A location in the file.
1320 Location(off_t fo
, section_size_type ds
)
1321 : file_offset(fo
), data_size(ds
)
1325 : file_offset(0), data_size(0)
1329 // Get a View given a Location.
1332 { return View(this->view(loc
.file_offset
, loc
.data_size
)); }
1334 // Return the Output_file.
1337 { return this->output_
; }
1340 // Check the .gnu_incremental_inputs section to see whether an incremental
1341 // build is possible.
1343 do_check_inputs(const Command_line
& cmdline
,
1344 Incremental_inputs
* incremental_inputs
) = 0;
1346 // Return TRUE if input file N has changed since the last incremental link.
1348 do_file_has_changed(unsigned int n
) const = 0;
1350 // Initialize the layout of the output file based on the existing
1353 do_init_layout(Layout
* layout
) = 0;
1355 // Mark regions of the input file that must be kept unchanged.
1357 do_reserve_layout(unsigned int input_file_index
) = 0;
1359 // Process the GOT and PLT entries from the existing output file.
1361 do_process_got_plt(Symbol_table
* symtab
, Layout
* layout
) = 0;
1363 // Apply incremental relocations for symbols whose values have changed.
1365 do_apply_incremental_relocs(const Symbol_table
*, Layout
*, Output_file
*) = 0;
1367 virtual unsigned int
1368 do_input_file_count() const = 0;
1370 virtual const Input_reader
*
1371 do_get_input_reader(unsigned int) const = 0;
1373 // Map from input file index to Input_argument.
1374 std::vector
<const Input_argument
*> input_args_map_
;
1375 // Map from an input file index to an Incremental_library.
1376 std::vector
<Incremental_library
*> library_map_
;
1377 // Map from an input file index to a Script_info.
1378 std::vector
<Script_info
*> script_map_
;
1381 // Edited output file object.
1382 Output_file
* output_
;
1383 // Target of the output file.
1387 template<int size
, bool big_endian
>
1388 class Sized_relobj_incr
;
1390 template<int size
, bool big_endian
>
1391 class Sized_incremental_binary
: public Incremental_binary
1394 Sized_incremental_binary(Output_file
* output
,
1395 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
,
1397 : Incremental_binary(output
, target
), elf_file_(this, ehdr
),
1398 input_objects_(), section_map_(), symbol_map_(), main_symtab_loc_(),
1399 main_strtab_loc_(), has_incremental_info_(false), inputs_reader_(),
1400 symtab_reader_(), relocs_reader_(), got_plt_reader_(),
1401 input_entry_readers_()
1402 { this->setup_readers(); }
1404 // Returns TRUE if the file contains incremental info.
1406 has_incremental_info() const
1407 { return this->has_incremental_info_
; }
1409 // Record a pointer to the object for input file N.
1411 set_input_object(unsigned int n
,
1412 Sized_relobj_incr
<size
, big_endian
>* obj
)
1413 { this->input_objects_
[n
] = obj
; }
1415 // Return a pointer to the object for input file N.
1416 Sized_relobj_incr
<size
, big_endian
>*
1417 input_object(unsigned int n
) const
1419 gold_assert(n
< this->input_objects_
.size());
1420 return this->input_objects_
[n
];
1423 // Return the Output_section for section index SHNDX.
1425 output_section(unsigned int shndx
)
1426 { return this->section_map_
[shndx
]; }
1428 // Map a symbol table entry from the base file to the output symbol table.
1429 // SYMNDX is relative to the first forced-local or global symbol in the
1430 // input file symbol table.
1432 add_global_symbol(unsigned int symndx
, Symbol
* gsym
)
1433 { this->symbol_map_
[symndx
] = gsym
; }
1435 // Map a symbol table entry from the base file to the output symbol table.
1436 // SYMNDX is relative to the first forced-local or global symbol in the
1437 // input file symbol table.
1439 global_symbol(unsigned int symndx
) const
1440 { return this->symbol_map_
[symndx
]; }
1442 // Readers for the incremental info sections.
1444 const Incremental_inputs_reader
<size
, big_endian
>&
1445 inputs_reader() const
1446 { return this->inputs_reader_
; }
1448 const Incremental_symtab_reader
<big_endian
>&
1449 symtab_reader() const
1450 { return this->symtab_reader_
; }
1452 const Incremental_relocs_reader
<size
, big_endian
>&
1453 relocs_reader() const
1454 { return this->relocs_reader_
; }
1456 const Incremental_got_plt_reader
<big_endian
>&
1457 got_plt_reader() const
1458 { return this->got_plt_reader_
; }
1461 get_symtab_view(View
* symtab_view
, unsigned int* sym_count
,
1462 elfcpp::Elf_strtab
* strtab
);
1465 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1466 typedef typename
Inputs_reader::Incremental_input_entry_reader
1470 do_check_inputs(const Command_line
& cmdline
,
1471 Incremental_inputs
* incremental_inputs
);
1473 // Return TRUE if input file N has changed since the last incremental link.
1475 do_file_has_changed(unsigned int n
) const;
1477 // Initialize the layout of the output file based on the existing
1480 do_init_layout(Layout
* layout
);
1482 // Mark regions of the input file that must be kept unchanged.
1484 do_reserve_layout(unsigned int input_file_index
);
1486 // Process the GOT and PLT entries from the existing output file.
1488 do_process_got_plt(Symbol_table
* symtab
, Layout
* layout
);
1490 // Apply incremental relocations for symbols whose values have changed.
1492 do_apply_incremental_relocs(const Symbol_table
* symtab
, Layout
* layout
,
1495 // Proxy class for a sized Incremental_input_entry_reader.
1497 class Sized_input_reader
: public Input_reader
1500 Sized_input_reader(Input_entry_reader r
)
1501 : Input_reader(), reader_(r
)
1505 ~Sized_input_reader()
1511 { return this->reader_
.filename(); }
1514 do_get_mtime() const
1515 { return this->reader_
.get_mtime(); }
1517 Incremental_input_type
1519 { return this->reader_
.type(); }
1522 do_arg_serial() const
1523 { return this->reader_
.arg_serial(); }
1526 do_get_unused_symbol_count() const
1527 { return this->reader_
.get_unused_symbol_count(); }
1530 do_get_unused_symbol(unsigned int n
) const
1531 { return this->reader_
.get_unused_symbol(n
); }
1533 Input_entry_reader reader_
;
1536 virtual unsigned int
1537 do_input_file_count() const
1538 { return this->inputs_reader_
.input_file_count(); }
1540 virtual const Input_reader
*
1541 do_get_input_reader(unsigned int n
) const
1543 gold_assert(n
< this->input_entry_readers_
.size());
1544 return &this->input_entry_readers_
[n
];
1549 find_incremental_inputs_sections(unsigned int* p_inputs_shndx
,
1550 unsigned int* p_symtab_shndx
,
1551 unsigned int* p_relocs_shndx
,
1552 unsigned int* p_got_plt_shndx
,
1553 unsigned int* p_strtab_shndx
);
1558 // Output as an ELF file.
1559 elfcpp::Elf_file
<size
, big_endian
, Incremental_binary
> elf_file_
;
1561 // Vector of pointers to the input objects for the unchanged files.
1562 // For replaced files, the corresponding pointer is NULL.
1563 std::vector
<Sized_relobj_incr
<size
, big_endian
>*> input_objects_
;
1565 // Map section index to an Output_section in the updated layout.
1566 std::vector
<Output_section
*> section_map_
;
1568 // Map global symbols from the input file to the symbol table.
1569 std::vector
<Symbol
*> symbol_map_
;
1571 // Locations of the main symbol table and symbol string table.
1572 Location main_symtab_loc_
;
1573 Location main_strtab_loc_
;
1575 // Readers for the incremental info sections.
1576 bool has_incremental_info_
;
1577 Incremental_inputs_reader
<size
, big_endian
> inputs_reader_
;
1578 Incremental_symtab_reader
<big_endian
> symtab_reader_
;
1579 Incremental_relocs_reader
<size
, big_endian
> relocs_reader_
;
1580 Incremental_got_plt_reader
<big_endian
> got_plt_reader_
;
1581 std::vector
<Sized_input_reader
> input_entry_readers_
;
1584 // An incremental Relobj. This class represents a relocatable object
1585 // that has not changed since the last incremental link, and whose contents
1586 // can be used directly from the base file.
1588 template<int size
, bool big_endian
>
1589 class Sized_relobj_incr
: public Sized_relobj
<size
, big_endian
>
1592 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1593 typedef typename Sized_relobj
<size
, big_endian
>::Symbols Symbols
;
1595 Sized_relobj_incr(const std::string
& name
,
1596 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1597 unsigned int input_file_index
);
1601 typedef Sized_relobj_incr
<size
, big_endian
> This
;
1602 static const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1604 typedef typename Sized_relobj
<size
, big_endian
>::Output_sections
1606 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1607 typedef typename
Inputs_reader::Incremental_input_entry_reader
1613 Local_symbol(const char* name_
, Address value_
, unsigned int size_
,
1614 unsigned int shndx_
, unsigned int type_
,
1615 bool needs_dynsym_entry_
)
1616 : st_value(value_
), name(name_
), st_size(size_
), st_shndx(shndx_
),
1617 st_type(type_
), output_dynsym_index(0),
1618 needs_dynsym_entry(needs_dynsym_entry_
)
1620 // The symbol value.
1622 // The symbol name. This points to the stringpool entry.
1625 unsigned int st_size
;
1626 // The output section index.
1627 unsigned int st_shndx
: 28;
1629 unsigned int st_type
: 4;
1630 // The index of the symbol in the output dynamic symbol table.
1631 unsigned int output_dynsym_index
: 31;
1632 // TRUE if the symbol needs to appear in the dynamic symbol table.
1633 unsigned int needs_dynsym_entry
: 1;
1636 // Return TRUE if this is an incremental (unchanged) input file.
1638 do_is_incremental() const
1641 // Return the last modified time of the file.
1644 { return this->input_reader_
.get_mtime(); }
1646 // Read the symbols.
1648 do_read_symbols(Read_symbols_data
*);
1650 // Lay out the input sections.
1652 do_layout(Symbol_table
*, Layout
*, Read_symbols_data
*);
1654 // Layout sections whose layout was deferred while waiting for
1655 // input files from a plugin.
1657 do_layout_deferred_sections(Layout
*);
1659 // Add the symbols to the symbol table.
1661 do_add_symbols(Symbol_table
*, Read_symbols_data
*, Layout
*);
1663 Archive::Should_include
1664 do_should_include_member(Symbol_table
* symtab
, Layout
*, Read_symbols_data
*,
1667 // Iterate over global symbols, calling a visitor class V for each.
1669 do_for_all_global_symbols(Read_symbols_data
* sd
,
1670 Library_base::Symbol_visitor_base
* v
);
1672 // Get the size of a section.
1674 do_section_size(unsigned int shndx
);
1676 // Get the name of a section.
1678 do_section_name(unsigned int shndx
);
1680 // Return a view of the contents of a section.
1682 do_section_contents(unsigned int shndx
);
1684 // Return section flags.
1686 do_section_flags(unsigned int shndx
);
1688 // Return section entsize.
1690 do_section_entsize(unsigned int shndx
);
1692 // Return section address.
1694 do_section_address(unsigned int shndx
);
1696 // Return section type.
1698 do_section_type(unsigned int shndx
);
1700 // Return the section link field.
1702 do_section_link(unsigned int shndx
);
1704 // Return the section link field.
1706 do_section_info(unsigned int shndx
);
1708 // Return the section alignment.
1710 do_section_addralign(unsigned int shndx
);
1712 // Return the Xindex structure to use.
1714 do_initialize_xindex();
1716 // Get symbol counts.
1718 do_get_global_symbol_counts(const Symbol_table
*, size_t*, size_t*) const;
1720 // Get global symbols.
1722 do_get_global_symbols() const
1723 { return &this->symbols_
; }
1725 // Return the number of local symbols.
1727 do_local_symbol_count() const
1728 { return this->local_symbol_count_
; }
1730 // Return the number of local symbols in the output symbol table.
1732 do_output_local_symbol_count() const
1733 { return this->local_symbol_count_
; }
1735 // Return the file offset for local symbols in the output symbol table.
1737 do_local_symbol_offset() const
1738 { return this->local_symbol_offset_
; }
1742 do_read_relocs(Read_relocs_data
*);
1744 // Process the relocs to find list of referenced sections. Used only
1745 // during garbage collection.
1747 do_gc_process_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
1749 // Scan the relocs and adjust the symbol table.
1751 do_scan_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
1753 // Count the local symbols.
1755 do_count_local_symbols(Stringpool_template
<char>*,
1756 Stringpool_template
<char>*);
1758 // Finalize the local symbols.
1760 do_finalize_local_symbols(unsigned int, off_t
, Symbol_table
*);
1762 // Set the offset where local dynamic symbol information will be stored.
1764 do_set_local_dynsym_indexes(unsigned int);
1766 // Set the offset where local dynamic symbol information will be stored.
1768 do_set_local_dynsym_offset(off_t
);
1770 // Relocate the input sections and write out the local symbols.
1772 do_relocate(const Symbol_table
* symtab
, const Layout
*, Output_file
* of
);
1774 // Set the offset of a section.
1776 do_set_section_offset(unsigned int shndx
, uint64_t off
);
1778 // The Incremental_binary base file.
1779 Sized_incremental_binary
<size
, big_endian
>* ibase_
;
1780 // The index of the object in the input file list.
1781 unsigned int input_file_index_
;
1782 // The reader for the input file.
1783 Input_entry_reader input_reader_
;
1784 // The number of local symbols.
1785 unsigned int local_symbol_count_
;
1786 // The number of local symbols which go into the output file's dynamic
1788 unsigned int output_local_dynsym_count_
;
1789 // This starting symbol index in the output symbol table.
1790 unsigned int local_symbol_index_
;
1791 // The file offset for local symbols in the output symbol table.
1792 unsigned int local_symbol_offset_
;
1793 // The file offset for local symbols in the output symbol table.
1794 unsigned int local_dynsym_offset_
;
1795 // The entries in the symbol table for the external symbols.
1797 // The offset of the first incremental relocation for this object.
1798 unsigned int incr_reloc_offset_
;
1799 // The number of incremental relocations for this object.
1800 unsigned int incr_reloc_count_
;
1801 // The index of the first incremental relocation for this object in the
1802 // updated output file.
1803 unsigned int incr_reloc_output_index_
;
1804 // A copy of the incremental relocations from this object.
1805 unsigned char* incr_relocs_
;
1806 // The local symbols.
1807 std::vector
<Local_symbol
> local_symbols_
;
1810 // An incremental Dynobj. This class represents a shared object that has
1811 // not changed since the last incremental link, and whose contents can be
1812 // used directly from the base file.
1814 template<int size
, bool big_endian
>
1815 class Sized_incr_dynobj
: public Dynobj
1818 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1820 static const Address invalid_address
= static_cast<Address
>(0) - 1;
1822 Sized_incr_dynobj(const std::string
& name
,
1823 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1824 unsigned int input_file_index
);
1827 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1828 typedef typename
Inputs_reader::Incremental_input_entry_reader
1831 // Return TRUE if this is an incremental (unchanged) input file.
1833 do_is_incremental() const
1836 // Return the last modified time of the file.
1839 { return this->input_reader_
.get_mtime(); }
1841 // Read the symbols.
1843 do_read_symbols(Read_symbols_data
*);
1845 // Lay out the input sections.
1847 do_layout(Symbol_table
*, Layout
*, Read_symbols_data
*);
1849 // Add the symbols to the symbol table.
1851 do_add_symbols(Symbol_table
*, Read_symbols_data
*, Layout
*);
1853 Archive::Should_include
1854 do_should_include_member(Symbol_table
* symtab
, Layout
*, Read_symbols_data
*,
1857 // Iterate over global symbols, calling a visitor class V for each.
1859 do_for_all_global_symbols(Read_symbols_data
* sd
,
1860 Library_base::Symbol_visitor_base
* v
);
1862 // Iterate over local symbols, calling a visitor class V for each GOT offset
1863 // associated with a local symbol.
1865 do_for_all_local_got_entries(Got_offset_list::Visitor
* v
) const;
1867 // Get the size of a section.
1869 do_section_size(unsigned int shndx
);
1871 // Get the name of a section.
1873 do_section_name(unsigned int shndx
);
1875 // Return a view of the contents of a section.
1877 do_section_contents(unsigned int shndx
);
1879 // Return section flags.
1881 do_section_flags(unsigned int shndx
);
1883 // Return section entsize.
1885 do_section_entsize(unsigned int shndx
);
1887 // Return section address.
1889 do_section_address(unsigned int shndx
);
1891 // Return section type.
1893 do_section_type(unsigned int shndx
);
1895 // Return the section link field.
1897 do_section_link(unsigned int shndx
);
1899 // Return the section link field.
1901 do_section_info(unsigned int shndx
);
1903 // Return the section alignment.
1905 do_section_addralign(unsigned int shndx
);
1907 // Return the Xindex structure to use.
1909 do_initialize_xindex();
1911 // Get symbol counts.
1913 do_get_global_symbol_counts(const Symbol_table
*, size_t*, size_t*) const;
1915 // Get global symbols.
1917 do_get_global_symbols() const
1918 { return &this->symbols_
; }
1920 // The Incremental_binary base file.
1921 Sized_incremental_binary
<size
, big_endian
>* ibase_
;
1922 // The index of the object in the input file list.
1923 unsigned int input_file_index_
;
1924 // The reader for the input file.
1925 Input_entry_reader input_reader_
;
1926 // The entries in the symbol table for the external symbols.
1930 // Allocate an incremental object of the appropriate size and endianness.
1932 make_sized_incremental_object(
1933 Incremental_binary
* base
,
1934 unsigned int input_file_index
,
1935 Incremental_input_type input_type
,
1936 const Incremental_binary::Input_reader
* input_reader
);
1938 // This class represents an Archive library (or --start-lib/--end-lib group)
1939 // that has not changed since the last incremental link. Its contents come
1940 // from the incremental inputs entry in the base file.
1942 class Incremental_library
: public Library_base
1945 Incremental_library(const char* filename
, unsigned int input_file_index
,
1946 const Incremental_binary::Input_reader
* input_reader
)
1947 : Library_base(NULL
), filename_(filename
),
1948 input_file_index_(input_file_index
), input_reader_(input_reader
),
1949 unused_symbols_(), is_reported_(false)
1952 // Return the input file index.
1954 input_file_index() const
1955 { return this->input_file_index_
; }
1957 // Return the serial number of the input file.
1960 { return this->input_reader_
->arg_serial(); }
1962 // Copy the unused symbols from the incremental input info.
1963 // We need to do this because we may be overwriting the incremental
1964 // input info in the base file before we write the new incremental
1967 copy_unused_symbols();
1969 // Return FALSE on the first call to indicate that the library needs
1970 // to be recorded; return TRUE subsequently.
1974 bool was_reported
= this->is_reported_
;
1975 is_reported_
= true;
1976 return was_reported
;
1980 typedef std::vector
<std::string
> Symbol_list
;
1985 { return this->filename_
; }
1987 // Return the modification time of the archive file.
1990 { return this->input_reader_
->get_mtime(); }
1992 // Iterator for unused global symbols in the library.
1994 do_for_all_unused_symbols(Symbol_visitor_base
* v
) const;
1996 // The name of the library.
1997 std::string filename_
;
1998 // The input file index of this library.
1999 unsigned int input_file_index_
;
2000 // A reader for the incremental input information.
2001 const Incremental_binary::Input_reader
* input_reader_
;
2002 // List of unused symbols defined in this library.
2003 Symbol_list unused_symbols_
;
2004 // TRUE when this library has been reported to the new incremental info.
2008 } // End namespace gold.
2010 #endif // !defined(GOLD_INCREMENTAL_H)