1 // inremental.h -- incremental linking support for gold -*- C++ -*-
3 // Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 // Written by Mikolaj Zalewski <mikolajz@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
23 #ifndef GOLD_INCREMENTAL_H
24 #define GOLD_INCREMENTAL_H
29 #include "elfcpp_file.h"
30 #include "stringpool.h"
31 #include "workqueue.h"
40 class Incremental_inputs_checker
;
41 class Incremental_script_entry
;
42 class Incremental_object_entry
;
43 class Incremental_dynobj_entry
;
44 class Incremental_archive_entry
;
45 class Incremental_inputs
;
46 class Incremental_binary
;
47 class Incremental_library
;
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
= 0x8000,
67 INCREMENTAL_INPUT_AS_NEEDED
= 0x4000
70 // Symbol flags for the incremental symbol table.
71 // These flags are stored in the top two bits of
72 // the symbol index field.
74 enum Incremental_shlib_symbol_flags
76 // Symbol is defined in this library.
77 INCREMENTAL_SHLIB_SYM_DEF
= 2,
78 // Symbol is defined in this library, with a COPY relocation.
79 INCREMENTAL_SHLIB_SYM_COPY
= 3
82 static const int INCREMENTAL_SHLIB_SYM_FLAGS_SHIFT
= 30;
84 // Return TRUE if a section of type SH_TYPE can be updated in place
85 // during an incremental update.
87 can_incremental_update(unsigned int sh_type
);
89 // Create an Incremental_binary object for FILE. Returns NULL is this is not
90 // possible, e.g. FILE is not an ELF file or has an unsupported target.
93 open_incremental_binary(Output_file
* file
);
95 // Base class for recording each input file.
97 class Incremental_input_entry
100 Incremental_input_entry(Stringpool::Key filename_key
, unsigned int arg_serial
,
102 : filename_key_(filename_key
), file_index_(0), offset_(0), info_offset_(0),
103 arg_serial_(arg_serial
), mtime_(mtime
), is_in_system_directory_(false),
108 ~Incremental_input_entry()
111 // Return the type of input file.
112 Incremental_input_type
114 { return this->do_type(); }
116 // Set the index and section offset of this input file entry.
118 set_offset(unsigned int file_index
, unsigned int offset
)
120 this->file_index_
= file_index
;
121 this->offset_
= offset
;
124 // Set the section offset of the supplemental information for this entry.
126 set_info_offset(unsigned int info_offset
)
127 { this->info_offset_
= info_offset
; }
129 // Get the index of this input file entry.
131 get_file_index() const
132 { return this->file_index_
; }
134 // Get the section offset of this input file entry.
137 { return this->offset_
; }
139 // Get the section offset of the supplemental information for this entry.
141 get_info_offset() const
142 { return this->info_offset_
; }
144 // Get the stringpool key for the input filename.
146 get_filename_key() const
147 { return this->filename_key_
; }
149 // Get the serial number of the input file.
152 { return this->arg_serial_
; }
154 // Get the modification time of the input file.
157 { return this->mtime_
; }
159 // Record that the file was found in a system directory.
161 set_is_in_system_directory()
162 { this->is_in_system_directory_
= true; }
164 // Return TRUE if the file was found in a system directory.
166 is_in_system_directory() const
167 { return this->is_in_system_directory_
; }
169 // Record that the file was linked with --as-needed.
172 { this->as_needed_
= true; }
174 // Return TRUE if the file was linked with --as-needed.
177 { return this->as_needed_
; }
179 // Return a pointer to the derived Incremental_script_entry object.
180 // Return NULL for input entries that are not script files.
181 Incremental_script_entry
*
183 { return this->do_script_entry(); }
185 // Return a pointer to the derived Incremental_object_entry object.
186 // Return NULL for input entries that are not object files.
187 Incremental_object_entry
*
189 { return this->do_object_entry(); }
191 // Return a pointer to the derived Incremental_dynobj_entry object.
192 // Return NULL for input entries that are not shared object files.
193 Incremental_dynobj_entry
*
195 { return this->do_dynobj_entry(); }
197 // Return a pointer to the derived Incremental_archive_entry object.
198 // Return NULL for input entries that are not archive files.
199 Incremental_archive_entry
*
201 { return this->do_archive_entry(); }
204 // Return the type of input file.
205 virtual Incremental_input_type
208 // Return a pointer to the derived Incremental_script_entry object.
209 // Return NULL for input entries that are not script files.
210 virtual Incremental_script_entry
*
214 // Return a pointer to the derived Incremental_object_entry object.
215 // Return NULL for input entries that are not object files.
216 virtual Incremental_object_entry
*
220 // Return a pointer to the derived Incremental_dynobj_entry object.
221 // Return NULL for input entries that are not shared object files.
222 virtual Incremental_dynobj_entry
*
226 // Return a pointer to the derived Incremental_archive_entry object.
227 // Return NULL for input entries that are not archive files.
228 virtual Incremental_archive_entry
*
233 // Key of the filename string in the section stringtable.
234 Stringpool::Key filename_key_
;
236 // Index of the entry in the output section.
237 unsigned int file_index_
;
239 // Offset of the entry in the output section.
240 unsigned int offset_
;
242 // Offset of the extra information in the output section.
243 unsigned int info_offset_
;
245 // Serial number of the file in the argument list.
246 unsigned int arg_serial_
;
248 // Last modification time of the file.
251 // TRUE if the file was found in a system directory.
252 bool is_in_system_directory_
;
254 // TRUE if the file was linked with --as-needed.
258 // Information about a script input that will persist during the whole linker
259 // run. Needed only during an incremental build to retrieve the input files
260 // added by this script.
265 Script_info(const std::string
& filename
)
266 : filename_(filename
), input_file_index_(0),
267 incremental_script_entry_(NULL
)
270 Script_info(const std::string
& filename
, unsigned int input_file_index
)
271 : filename_(filename
), input_file_index_(input_file_index
),
272 incremental_script_entry_(NULL
)
275 // Store a pointer to the incremental information for this script.
277 set_incremental_info(Incremental_script_entry
* entry
)
278 { this->incremental_script_entry_
= entry
; }
280 // Return the filename.
283 { return this->filename_
; }
285 // Return the input file index.
287 input_file_index() const
288 { return this->input_file_index_
; }
290 // Return the pointer to the incremental information for this script.
291 Incremental_script_entry
*
292 incremental_info() const
293 { return this->incremental_script_entry_
; }
296 const std::string filename_
;
297 unsigned int input_file_index_
;
298 Incremental_script_entry
* incremental_script_entry_
;
301 // Class for recording input scripts.
303 class Incremental_script_entry
: public Incremental_input_entry
306 Incremental_script_entry(Stringpool::Key filename_key
,
307 unsigned int arg_serial
, Script_info
* /*script*/,
309 : Incremental_input_entry(filename_key
, arg_serial
, mtime
),
313 // Add a member object to the archive.
315 add_object(Incremental_input_entry
* obj_entry
)
317 this->objects_
.push_back(obj_entry
);
320 // Return the number of objects included by this script.
323 { return this->objects_
.size(); }
325 // Return the Nth object.
326 Incremental_input_entry
*
327 get_object(unsigned int n
)
329 gold_assert(n
< this->objects_
.size());
330 return this->objects_
[n
];
334 virtual Incremental_input_type
336 { return INCREMENTAL_INPUT_SCRIPT
; }
338 // Return a pointer to the derived Incremental_script_entry object.
339 virtual Incremental_script_entry
*
344 // Objects that have been included by this script.
345 std::vector
<Incremental_input_entry
*> objects_
;
348 // Class for recording input object files.
350 class Incremental_object_entry
: public Incremental_input_entry
353 Incremental_object_entry(Stringpool::Key filename_key
, Object
* obj
,
354 unsigned int arg_serial
, Timespec mtime
)
355 : Incremental_input_entry(filename_key
, arg_serial
, mtime
), obj_(obj
),
356 is_member_(false), sections_(), groups_()
357 { this->sections_
.reserve(obj
->shnum()); }
362 { return this->obj_
; }
364 // Record that this object is an archive member.
367 { this->is_member_
= true; }
369 // Return true if this object is an archive member.
372 { return this->is_member_
; }
374 // Add an input section.
376 add_input_section(unsigned int shndx
, Stringpool::Key name_key
, off_t sh_size
)
377 { this->sections_
.push_back(Input_section(shndx
, name_key
, sh_size
)); }
379 // Return the number of input sections in this object.
381 get_input_section_count() const
382 { return this->sections_
.size(); }
384 // Return the input section index for the Nth input section.
386 get_input_section_index(unsigned int n
) const
387 { return this->sections_
[n
].shndx_
; }
389 // Return the stringpool key of the Nth input section.
391 get_input_section_name_key(unsigned int n
) const
392 { return this->sections_
[n
].name_key_
; }
394 // Return the size of the Nth input section.
396 get_input_section_size(unsigned int n
) const
397 { return this->sections_
[n
].sh_size_
; }
399 // Add a kept COMDAT group.
401 add_comdat_group(Stringpool::Key signature_key
)
402 { this->groups_
.push_back(signature_key
); }
404 // Return the number of COMDAT groups.
406 get_comdat_group_count() const
407 { return this->groups_
.size(); }
409 // Return the stringpool key for the signature of the Nth comdat group.
411 get_comdat_signature_key(unsigned int n
) const
412 { return this->groups_
[n
]; }
415 virtual Incremental_input_type
418 return (this->is_member_
419 ? INCREMENTAL_INPUT_ARCHIVE_MEMBER
420 : INCREMENTAL_INPUT_OBJECT
);
423 // Return a pointer to the derived Incremental_object_entry object.
424 virtual Incremental_object_entry
*
429 // The object file itself.
432 // Whether this object is an archive member.
438 Input_section(unsigned int shndx
, Stringpool::Key name_key
, off_t sh_size
)
439 : shndx_(shndx
), name_key_(name_key
), sh_size_(sh_size
)
442 Stringpool::Key name_key_
;
445 std::vector
<Input_section
> sections_
;
448 std::vector
<Stringpool::Key
> groups_
;
451 // Class for recording shared library input files.
453 class Incremental_dynobj_entry
: public Incremental_input_entry
456 Incremental_dynobj_entry(Stringpool::Key filename_key
,
457 Stringpool::Key soname_key
, Object
* obj
,
458 unsigned int arg_serial
, Timespec mtime
)
459 : Incremental_input_entry(filename_key
, arg_serial
, mtime
),
460 soname_key_(soname_key
), obj_(obj
)
466 { return this->obj_
; }
468 // Get the stringpool key for the soname.
470 get_soname_key() const
471 { return this->soname_key_
; }
474 virtual Incremental_input_type
476 { return INCREMENTAL_INPUT_SHARED_LIBRARY
; }
478 // Return a pointer to the derived Incremental_dynobj_entry object.
479 virtual Incremental_dynobj_entry
*
484 // Key of the soname string in the section stringtable.
485 Stringpool::Key soname_key_
;
487 // The object file itself.
491 // Class for recording archive library input files.
493 class Incremental_archive_entry
: public Incremental_input_entry
496 Incremental_archive_entry(Stringpool::Key filename_key
,
497 unsigned int arg_serial
, Timespec mtime
)
498 : Incremental_input_entry(filename_key
, arg_serial
, mtime
), members_(),
502 // Add a member object to the archive.
504 add_object(Incremental_object_entry
* obj_entry
)
506 this->members_
.push_back(obj_entry
);
507 obj_entry
->set_is_member();
510 // Add an unused global symbol to the archive.
512 add_unused_global_symbol(Stringpool::Key symbol_key
)
513 { this->unused_syms_
.push_back(symbol_key
); }
515 // Return the number of member objects included in the link.
518 { return this->members_
.size(); }
520 // Return the Nth member object.
521 Incremental_object_entry
*
522 get_member(unsigned int n
)
523 { return this->members_
[n
]; }
525 // Return the number of unused global symbols in this archive.
527 get_unused_global_symbol_count()
528 { return this->unused_syms_
.size(); }
530 // Return the Nth unused global symbol.
532 get_unused_global_symbol(unsigned int n
)
533 { return this->unused_syms_
[n
]; }
536 virtual Incremental_input_type
538 { return INCREMENTAL_INPUT_ARCHIVE
; }
540 // Return a pointer to the derived Incremental_archive_entry object.
541 virtual Incremental_archive_entry
*
546 // Members of the archive that have been included in the link.
547 std::vector
<Incremental_object_entry
*> members_
;
549 // Unused global symbols from this archive.
550 std::vector
<Stringpool::Key
> unused_syms_
;
553 // This class contains the information needed during an incremental
554 // build about the inputs necessary to build the .gnu_incremental_inputs.
556 class Incremental_inputs
559 typedef std::vector
<Incremental_input_entry
*> Input_list
;
562 : inputs_(), command_line_(), command_line_key_(0),
563 strtab_(new Stringpool()), current_object_(NULL
),
564 current_object_entry_(NULL
), inputs_section_(NULL
),
565 symtab_section_(NULL
), relocs_section_(NULL
),
569 ~Incremental_inputs() { delete this->strtab_
; }
571 // Record the command line.
573 report_command_line(int argc
, const char* const* argv
);
575 // Record the initial info for archive file ARCHIVE.
577 report_archive_begin(Library_base
* arch
, unsigned int arg_serial
,
578 Script_info
* script_info
);
580 // Record the final info for archive file ARCHIVE.
582 report_archive_end(Library_base
* arch
);
584 // Record the info for object file OBJ. If ARCH is not NULL,
585 // attach the object file to the archive.
587 report_object(Object
* obj
, unsigned int arg_serial
, Library_base
* arch
,
588 Script_info
* script_info
);
590 // Record an input section belonging to object file OBJ.
592 report_input_section(Object
* obj
, unsigned int shndx
, const char* name
,
595 // Record a kept COMDAT group belonging to object file OBJ.
597 report_comdat_group(Object
* obj
, const char* name
);
599 // Record the info for input script SCRIPT.
601 report_script(Script_info
* script
, unsigned int arg_serial
,
604 // Return the running count of incremental relocations.
606 get_reloc_count() const
607 { return this->reloc_count_
; }
609 // Update the running count of incremental relocations.
611 set_reloc_count(unsigned int count
)
612 { this->reloc_count_
= count
; }
614 // Prepare for layout. Called from Layout::finalize.
618 // Create the .gnu_incremental_inputs and related sections.
620 create_data_sections(Symbol_table
* symtab
);
622 // Return the .gnu_incremental_inputs section.
624 inputs_section() const
625 { return this->inputs_section_
; }
627 // Return the .gnu_incremental_symtab section.
629 symtab_section() const
630 { return this->symtab_section_
; }
632 // Return the .gnu_incremental_relocs section.
634 relocs_section() const
635 { return this->relocs_section_
; }
637 // Return the .gnu_incremental_got_plt section.
639 got_plt_section() const
640 { return this->got_plt_section_
; }
642 // Return the .gnu_incremental_strtab stringpool.
644 get_stringpool() const
645 { return this->strtab_
; }
647 // Return the canonical form of the command line, as will be stored in
648 // .gnu_incremental_strtab.
651 { return this->command_line_
; }
653 // Return the stringpool key of the command line.
655 command_line_key() const
656 { return this->command_line_key_
; }
658 // Return the number of input files.
660 input_file_count() const
661 { return this->inputs_
.size(); }
663 // Return the input files.
666 { return this->inputs_
; }
668 // Return the sh_entsize value for the .gnu_incremental_relocs section.
670 relocs_entsize() const;
673 // The list of input files.
676 // Canonical form of the command line, as will be stored in
677 // .gnu_incremental_strtab.
678 std::string command_line_
;
680 // The key of the command line string in the string pool.
681 Stringpool::Key command_line_key_
;
683 // The .gnu_incremental_strtab string pool associated with the
684 // .gnu_incremental_inputs.
687 // Keep track of the object currently being processed.
688 Object
* current_object_
;
689 Incremental_object_entry
* current_object_entry_
;
691 // The .gnu_incremental_inputs section.
692 Output_section_data
* inputs_section_
;
694 // The .gnu_incremental_symtab section.
695 Output_data_space
* symtab_section_
;
697 // The .gnu_incremental_relocs section.
698 Output_data_space
* relocs_section_
;
700 // The .gnu_incremental_got_plt section.
701 Output_data_space
* got_plt_section_
;
703 // Total count of incremental relocations. Updated during Scan_relocs
704 // phase at the completion of each object file.
705 unsigned int reloc_count_
;
708 // Reader class for global symbol info from an object file entry in
709 // the .gnu_incremental_inputs section.
711 template<bool big_endian
>
712 class Incremental_global_symbol_reader
715 typedef elfcpp::Swap
<32, big_endian
> Swap32
;
718 Incremental_global_symbol_reader(const unsigned char* p
)
723 output_symndx() const
724 { return Swap32::readval(this->p_
); }
728 { return Swap32::readval(this->p_
+ 4); }
732 { return Swap32::readval(this->p_
+ 8); }
736 { return Swap32::readval(this->p_
+ 12); }
740 { return Swap32::readval(this->p_
+ 16); }
743 // Base address of the symbol entry.
744 const unsigned char* p_
;
747 // Reader class for .gnu_incremental_inputs section.
749 template<int size
, bool big_endian
>
750 class Incremental_inputs_reader
753 typedef elfcpp::Swap
<size
, big_endian
> Swap
;
754 typedef elfcpp::Swap
<16, big_endian
> Swap16
;
755 typedef elfcpp::Swap
<32, big_endian
> Swap32
;
756 typedef elfcpp::Swap
<64, big_endian
> Swap64
;
759 // Size of the .gnu_incremental_inputs header.
760 // (3 x 4-byte fields, plus 4 bytes padding.)
761 static const unsigned int header_size
= 16;
762 // Size of an input file entry.
763 // (2 x 4-byte fields, 1 x 12-byte field, 2 x 2-byte fields.)
764 static const unsigned int input_entry_size
= 24;
765 // Size of the first part of the supplemental info block for
766 // relocatable objects and archive members.
767 // (7 x 4-byte fields, plus 4 bytes padding.)
768 static const unsigned int object_info_size
= 32;
769 // Size of an input section entry.
770 // (2 x 4-byte fields, 2 x address-sized fields.)
771 static const unsigned int input_section_entry_size
= 8 + 2 * size
/ 8;
772 // Size of a global symbol entry in the supplemental info block.
773 // (5 x 4-byte fields.)
774 static const unsigned int global_sym_entry_size
= 20;
776 Incremental_inputs_reader()
777 : p_(NULL
), strtab_(NULL
, 0), input_file_count_(0)
780 Incremental_inputs_reader(const unsigned char* p
,
781 const elfcpp::Elf_strtab
& strtab
)
782 : p_(p
), strtab_(strtab
)
783 { this->input_file_count_
= Swap32::readval(this->p_
+ 4); }
785 // Return the version number.
788 { return Swap32::readval(this->p_
); }
790 // Return the count of input file entries.
792 input_file_count() const
793 { return this->input_file_count_
; }
795 // Return the command line.
799 unsigned int offset
= Swap32::readval(this->p_
+ 8);
800 return this->get_string(offset
);
803 // Reader class for an input file entry and its supplemental info.
804 class Incremental_input_entry_reader
807 static const unsigned int object_info_size
=
808 Incremental_inputs_reader
<size
, big_endian
>::object_info_size
;
809 static const unsigned int input_section_entry_size
=
810 Incremental_inputs_reader
<size
, big_endian
>::input_section_entry_size
;
811 static const unsigned int global_sym_entry_size
=
812 Incremental_inputs_reader
<size
, big_endian
>::global_sym_entry_size
;
815 Incremental_input_entry_reader(const Incremental_inputs_reader
* inputs
,
817 : inputs_(inputs
), offset_(offset
)
819 this->info_offset_
= Swap32::readval(inputs
->p_
+ offset
+ 4);
820 this->flags_
= Swap16::readval(this->inputs_
->p_
+ offset
+ 20);
823 // Return the filename.
827 unsigned int offset
= Swap32::readval(this->inputs_
->p_
+ this->offset_
);
828 return this->inputs_
->get_string(offset
);
831 // Return the argument serial number.
835 return Swap16::readval(this->inputs_
->p_
+ this->offset_
+ 22);
838 // Return the timestamp.
843 const unsigned char* p
= this->inputs_
->p_
+ this->offset_
+ 8;
844 t
.seconds
= Swap64::readval(p
);
845 t
.nanoseconds
= Swap32::readval(p
+8);
849 // Return the type of input file.
850 Incremental_input_type
852 { return static_cast<Incremental_input_type
>(this->flags_
& 0xff); }
854 // Return TRUE if the file was found in a system directory.
856 is_in_system_directory() const
857 { return (this->flags_
& INCREMENTAL_INPUT_IN_SYSTEM_DIR
) != 0; }
859 // Return TRUE if the file was linked with --as-needed.
862 { return (this->flags_
& INCREMENTAL_INPUT_AS_NEEDED
) != 0; }
864 // Return the input section count -- for objects only.
866 get_input_section_count() const
868 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
869 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
870 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
873 // Return the soname -- for shared libraries only.
877 gold_assert(this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY
);
878 unsigned int offset
= Swap32::readval(this->inputs_
->p_
879 + this->info_offset_
);
880 return this->inputs_
->get_string(offset
);
883 // Return the offset of the supplemental info for symbol SYMNDX --
886 get_symbol_offset(unsigned int symndx
) const
888 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
889 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
891 unsigned int section_count
= this->get_input_section_count();
892 return (this->info_offset_
893 + this->object_info_size
894 + section_count
* this->input_section_entry_size
895 + symndx
* this->global_sym_entry_size
);
898 // Return the global symbol count -- for objects & shared libraries only.
900 get_global_symbol_count() const
902 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
903 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
904 || this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY
);
905 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 4);
908 // Return the offset of the first local symbol -- for objects only.
910 get_local_symbol_offset() const
912 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
913 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
915 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 8);
918 // Return the local symbol count -- for objects only.
920 get_local_symbol_count() const
922 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
923 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
925 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 12);
928 // Return the index of the first dynamic relocation -- for objects only.
930 get_first_dyn_reloc() const
932 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
933 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
935 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 16);
938 // Return the dynamic relocation count -- for objects only.
940 get_dyn_reloc_count() const
942 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
943 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
945 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 20);
948 // Return the COMDAT group count -- for objects only.
950 get_comdat_group_count() const
952 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
953 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
955 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 24);
958 // Return the object count -- for scripts only.
960 get_object_count() const
962 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT
);
963 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
966 // Return the input file offset for object N -- for scripts only.
968 get_object_offset(unsigned int n
) const
970 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT
);
971 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
975 // Return the member count -- for archives only.
977 get_member_count() const
979 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
980 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
983 // Return the unused symbol count -- for archives only.
985 get_unused_symbol_count() const
987 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
988 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 4);
991 // Return the input file offset for archive member N -- for archives only.
993 get_member_offset(unsigned int n
) const
995 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
996 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
1000 // Return the Nth unused global symbol -- for archives only.
1002 get_unused_symbol(unsigned int n
) const
1004 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
1005 unsigned int member_count
= this->get_member_count();
1006 unsigned int offset
= Swap32::readval(this->inputs_
->p_
1007 + this->info_offset_
+ 8
1010 return this->inputs_
->get_string(offset
);
1013 // Information about an input section.
1014 struct Input_section_info
1017 unsigned int output_shndx
;
1022 // Return info about the Nth input section -- for objects only.
1024 get_input_section(unsigned int n
) const
1026 Input_section_info info
;
1027 const unsigned char* p
= (this->inputs_
->p_
1028 + this->info_offset_
1029 + this->object_info_size
1030 + n
* this->input_section_entry_size
);
1031 unsigned int name_offset
= Swap32::readval(p
);
1032 info
.name
= this->inputs_
->get_string(name_offset
);
1033 info
.output_shndx
= Swap32::readval(p
+ 4);
1034 info
.sh_offset
= Swap::readval(p
+ 8);
1035 info
.sh_size
= Swap::readval(p
+ 8 + size
/ 8);
1039 // Return info about the Nth global symbol -- for objects only.
1040 Incremental_global_symbol_reader
<big_endian
>
1041 get_global_symbol_reader(unsigned int n
) const
1043 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
1044 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
1045 unsigned int section_count
= this->get_input_section_count();
1046 const unsigned char* p
= (this->inputs_
->p_
1047 + this->info_offset_
1048 + this->object_info_size
1049 + section_count
* this->input_section_entry_size
1050 + n
* this->global_sym_entry_size
);
1051 return Incremental_global_symbol_reader
<big_endian
>(p
);
1054 // Return the signature of the Nth comdat group -- for objects only.
1056 get_comdat_group_signature(unsigned int n
) const
1058 unsigned int section_count
= this->get_input_section_count();
1059 unsigned int symbol_count
= this->get_global_symbol_count();
1060 const unsigned char* p
= (this->inputs_
->p_
1061 + this->info_offset_
1062 + this->object_info_size
1063 + section_count
* this->input_section_entry_size
1064 + symbol_count
* this->global_sym_entry_size
1066 unsigned int name_offset
= Swap32::readval(p
);
1067 return this->inputs_
->get_string(name_offset
);
1070 // Return the output symbol index for the Nth global symbol -- for shared
1071 // libraries only. Sets *IS_DEF to TRUE if the symbol is defined in this
1072 // input file. Sets *IS_COPY to TRUE if the symbol was copied from this
1073 // input file with a COPY relocation.
1075 get_output_symbol_index(unsigned int n
, bool* is_def
, bool* is_copy
)
1077 gold_assert(this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY
);
1078 const unsigned char* p
= (this->inputs_
->p_
1079 + this->info_offset_
+ 8
1081 unsigned int output_symndx
= Swap32::readval(p
);
1082 unsigned int flags
= output_symndx
>> INCREMENTAL_SHLIB_SYM_FLAGS_SHIFT
;
1083 output_symndx
&= ((1U << INCREMENTAL_SHLIB_SYM_FLAGS_SHIFT
) - 1);
1086 case INCREMENTAL_SHLIB_SYM_DEF
:
1090 case INCREMENTAL_SHLIB_SYM_COPY
:
1098 return output_symndx
;
1102 // The reader instance for the containing section.
1103 const Incremental_inputs_reader
* inputs_
;
1104 // The flags, including the type of input file.
1105 unsigned int flags_
;
1106 // Section offset to the input file entry.
1107 unsigned int offset_
;
1108 // Section offset to the supplemental info for the input file.
1109 unsigned int info_offset_
;
1112 // Return the offset of an input file entry given its index N.
1114 input_file_offset(unsigned int n
) const
1116 gold_assert(n
< this->input_file_count_
);
1117 return this->header_size
+ n
* this->input_entry_size
;
1120 // Return the index of an input file entry given its OFFSET.
1122 input_file_index(unsigned int offset
) const
1124 int n
= ((offset
- this->header_size
) / this->input_entry_size
);
1125 gold_assert(input_file_offset(n
) == offset
);
1129 // Return a reader for the Nth input file entry.
1130 Incremental_input_entry_reader
1131 input_file(unsigned int n
) const
1132 { return Incremental_input_entry_reader(this, this->input_file_offset(n
)); }
1134 // Return a reader for the input file entry at OFFSET.
1135 Incremental_input_entry_reader
1136 input_file_at_offset(unsigned int offset
) const
1138 gold_assert(offset
< (this->header_size
1139 + this->input_file_count_
* this->input_entry_size
));
1140 return Incremental_input_entry_reader(this, offset
);
1143 // Return a reader for the global symbol info at OFFSET.
1144 Incremental_global_symbol_reader
<big_endian
>
1145 global_symbol_reader_at_offset(unsigned int offset
) const
1147 const unsigned char* p
= this->p_
+ offset
;
1148 return Incremental_global_symbol_reader
<big_endian
>(p
);
1152 // Lookup a string in the ELF string table.
1153 const char* get_string(unsigned int offset
) const
1156 if (this->strtab_
.get_c_string(offset
, &s
))
1161 // Base address of the .gnu_incremental_inputs section.
1162 const unsigned char* p_
;
1163 // The associated ELF string table.
1164 elfcpp::Elf_strtab strtab_
;
1165 // The number of input file entries in this section.
1166 unsigned int input_file_count_
;
1169 // Reader class for the .gnu_incremental_symtab section.
1171 template<bool big_endian
>
1172 class Incremental_symtab_reader
1175 Incremental_symtab_reader()
1179 Incremental_symtab_reader(const unsigned char* p
, off_t len
)
1183 // Return the count of symbols in this section.
1185 symbol_count() const
1186 { return static_cast<unsigned int>(this->len_
/ 4); }
1188 // Return the list head for symbol table entry N.
1190 get_list_head(unsigned int n
) const
1191 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ 4 * n
); }
1194 // Base address of the .gnu_incremental_relocs section.
1195 const unsigned char* p_
;
1196 // Size of the section.
1200 // Reader class for the .gnu_incremental_relocs section.
1202 template<int size
, bool big_endian
>
1203 class Incremental_relocs_reader
1206 // Size of each field.
1207 static const unsigned int field_size
= size
/ 8;
1210 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1211 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Addend
;
1213 // Size of each entry.
1214 static const unsigned int reloc_size
= 8 + 2 * field_size
;
1216 Incremental_relocs_reader()
1220 Incremental_relocs_reader(const unsigned char* p
, off_t len
)
1224 // Return the count of relocations in this section.
1227 { return static_cast<unsigned int>(this->len_
/ reloc_size
); }
1229 // Return the relocation type for relocation entry at offset OFF.
1231 get_r_type(unsigned int off
) const
1232 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ off
); }
1234 // Return the output section index for relocation entry at offset OFF.
1236 get_r_shndx(unsigned int off
) const
1237 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ off
+ 4); }
1239 // Return the output section offset for relocation entry at offset OFF.
1241 get_r_offset(unsigned int off
) const
1242 { return elfcpp::Swap
<size
, big_endian
>::readval(this->p_
+ off
+ 8); }
1244 // Return the addend for relocation entry at offset OFF.
1246 get_r_addend(unsigned int off
) const
1248 return elfcpp::Swap
<size
, big_endian
>::readval(this->p_
+ off
+ 8
1249 + this->field_size
);
1252 // Return a pointer to the relocation entry at offset OFF.
1253 const unsigned char*
1254 data(unsigned int off
) const
1255 { return this->p_
+ off
; }
1258 // Base address of the .gnu_incremental_relocs section.
1259 const unsigned char* p_
;
1260 // Size of the section.
1264 // Reader class for the .gnu_incremental_got_plt section.
1266 template<bool big_endian
>
1267 class Incremental_got_plt_reader
1270 Incremental_got_plt_reader()
1271 : p_(NULL
), got_count_(0), got_desc_p_(NULL
), plt_desc_p_(NULL
)
1274 Incremental_got_plt_reader(const unsigned char* p
) : p_(p
)
1276 this->got_count_
= elfcpp::Swap
<32, big_endian
>::readval(p
);
1277 this->got_desc_p_
= p
+ 8 + ((this->got_count_
+ 3) & ~3);
1278 this->plt_desc_p_
= this->got_desc_p_
+ this->got_count_
* 8;
1281 // Return the GOT entry count.
1283 get_got_entry_count() const
1285 return this->got_count_
;
1288 // Return the PLT entry count.
1290 get_plt_entry_count() const
1292 return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ 4);
1295 // Return the GOT type for GOT entry N.
1297 get_got_type(unsigned int n
)
1299 return this->p_
[8 + n
];
1302 // Return the symbol index for GOT entry N.
1304 get_got_symndx(unsigned int n
)
1306 return elfcpp::Swap
<32, big_endian
>::readval(this->got_desc_p_
+ n
* 8);
1309 // Return the input file index for GOT entry N.
1311 get_got_input_index(unsigned int n
)
1313 return elfcpp::Swap
<32, big_endian
>::readval(this->got_desc_p_
+ n
* 8 + 4);
1316 // Return the PLT descriptor for PLT entry N.
1318 get_plt_desc(unsigned int n
)
1320 return elfcpp::Swap
<32, big_endian
>::readval(this->plt_desc_p_
+ n
* 4);
1324 // Base address of the .gnu_incremental_got_plt section.
1325 const unsigned char* p_
;
1327 unsigned int got_count_
;
1328 // Base address of the GOT descriptor array.
1329 const unsigned char* got_desc_p_
;
1330 // Base address of the PLT descriptor array.
1331 const unsigned char* plt_desc_p_
;
1334 // An object representing the ELF file we edit during an incremental build.
1335 // Similar to Object or Dynobj, but operates on Output_file and contains
1336 // methods to support incremental updating. This is the abstract parent class
1337 // implemented in Sized_incremental_binary<size, big_endian> for a specific
1338 // endianness and size.
1340 class Incremental_binary
1343 Incremental_binary(Output_file
* output
, Target
* /*target*/)
1344 : input_args_map_(), library_map_(), script_map_(),
1349 ~Incremental_binary()
1352 // Check the .gnu_incremental_inputs section to see whether an incremental
1353 // build is possible.
1355 check_inputs(const Command_line
& cmdline
,
1356 Incremental_inputs
* incremental_inputs
)
1357 { return this->do_check_inputs(cmdline
, incremental_inputs
); }
1361 error(const char* format
, ...) const ATTRIBUTE_PRINTF_2
;
1363 // Proxy class for a sized Incremental_input_entry_reader.
1371 Input_reader(const Input_reader
&)
1380 { return this->do_filename(); }
1384 { return this->do_get_mtime(); }
1386 Incremental_input_type
1388 { return this->do_type(); }
1392 { return this->do_arg_serial(); }
1395 get_unused_symbol_count() const
1396 { return this->do_get_unused_symbol_count(); }
1399 get_unused_symbol(unsigned int n
) const
1400 { return this->do_get_unused_symbol(n
); }
1404 do_filename() const = 0;
1407 do_get_mtime() const = 0;
1409 virtual Incremental_input_type
1410 do_type() const = 0;
1412 virtual unsigned int
1413 do_arg_serial() const = 0;
1415 virtual unsigned int
1416 do_get_unused_symbol_count() const = 0;
1419 do_get_unused_symbol(unsigned int n
) const = 0;
1422 // Return the number of input files.
1424 input_file_count() const
1425 { return this->do_input_file_count(); }
1427 // Return an Input_reader for input file N.
1429 get_input_reader(unsigned int n
) const
1430 { return this->do_get_input_reader(n
); }
1432 // Return TRUE if the input file N has changed since the last link.
1434 file_has_changed(unsigned int n
) const
1435 { return this->do_file_has_changed(n
); }
1437 // Return the Input_argument for input file N. Returns NULL if
1438 // the Input_argument is not available.
1439 const Input_argument
*
1440 get_input_argument(unsigned int n
) const
1442 const Input_reader
* input_file
= this->do_get_input_reader(n
);
1443 unsigned int arg_serial
= input_file
->arg_serial();
1444 if (arg_serial
== 0 || arg_serial
> this->input_args_map_
.size())
1446 return this->input_args_map_
[arg_serial
- 1];
1449 // Return an Incremental_library for the given input file.
1450 Incremental_library
*
1451 get_library(unsigned int n
) const
1452 { return this->library_map_
[n
]; }
1454 // Return a Script_info for the given input file.
1456 get_script_info(unsigned int n
) const
1457 { return this->script_map_
[n
]; }
1459 // Initialize the layout of the output file based on the existing
1462 init_layout(Layout
* layout
)
1463 { this->do_init_layout(layout
); }
1465 // Mark regions of the input file that must be kept unchanged.
1467 reserve_layout(unsigned int input_file_index
)
1468 { this->do_reserve_layout(input_file_index
); }
1470 // Process the GOT and PLT entries from the existing output file.
1472 process_got_plt(Symbol_table
* symtab
, Layout
* layout
)
1473 { this->do_process_got_plt(symtab
, layout
); }
1475 // Emit COPY relocations from the existing output file.
1477 emit_copy_relocs(Symbol_table
* symtab
)
1478 { this->do_emit_copy_relocs(symtab
); }
1480 // Apply incremental relocations for symbols whose values have changed.
1482 apply_incremental_relocs(const Symbol_table
* symtab
, Layout
* layout
,
1484 { this->do_apply_incremental_relocs(symtab
, layout
, of
); }
1486 // Functions and types for the elfcpp::Elf_file interface. This
1487 // permit us to use Incremental_binary as the File template parameter for
1488 // elfcpp::Elf_file.
1490 // The View class is returned by view. It must support a single
1491 // method, data(). This is trivial, because Output_file::get_output_view
1492 // does what we need.
1496 View(const unsigned char* p
)
1500 const unsigned char*
1502 { return this->p_
; }
1505 const unsigned char* p_
;
1510 view(off_t file_offset
, section_size_type data_size
)
1511 { return View(this->output_
->get_input_view(file_offset
, data_size
)); }
1513 // A location in the file.
1519 Location(off_t fo
, section_size_type ds
)
1520 : file_offset(fo
), data_size(ds
)
1524 : file_offset(0), data_size(0)
1528 // Get a View given a Location.
1531 { return View(this->view(loc
.file_offset
, loc
.data_size
)); }
1533 // Return the Output_file.
1536 { return this->output_
; }
1539 // Check the .gnu_incremental_inputs section to see whether an incremental
1540 // build is possible.
1542 do_check_inputs(const Command_line
& cmdline
,
1543 Incremental_inputs
* incremental_inputs
) = 0;
1545 // Return TRUE if input file N has changed since the last incremental link.
1547 do_file_has_changed(unsigned int n
) const = 0;
1549 // Initialize the layout of the output file based on the existing
1552 do_init_layout(Layout
* layout
) = 0;
1554 // Mark regions of the input file that must be kept unchanged.
1556 do_reserve_layout(unsigned int input_file_index
) = 0;
1558 // Process the GOT and PLT entries from the existing output file.
1560 do_process_got_plt(Symbol_table
* symtab
, Layout
* layout
) = 0;
1562 // Emit COPY relocations from the existing output file.
1564 do_emit_copy_relocs(Symbol_table
* symtab
) = 0;
1566 // Apply incremental relocations for symbols whose values have changed.
1568 do_apply_incremental_relocs(const Symbol_table
*, Layout
*, Output_file
*) = 0;
1570 virtual unsigned int
1571 do_input_file_count() const = 0;
1573 virtual const Input_reader
*
1574 do_get_input_reader(unsigned int) const = 0;
1576 // Map from input file index to Input_argument.
1577 std::vector
<const Input_argument
*> input_args_map_
;
1578 // Map from an input file index to an Incremental_library.
1579 std::vector
<Incremental_library
*> library_map_
;
1580 // Map from an input file index to a Script_info.
1581 std::vector
<Script_info
*> script_map_
;
1584 // Edited output file object.
1585 Output_file
* output_
;
1588 template<int size
, bool big_endian
>
1589 class Sized_relobj_incr
;
1591 template<int size
, bool big_endian
>
1592 class Sized_incremental_binary
: public Incremental_binary
1595 Sized_incremental_binary(Output_file
* output
,
1596 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
,
1598 : Incremental_binary(output
, target
), elf_file_(this, ehdr
),
1599 input_objects_(), section_map_(), symbol_map_(), copy_relocs_(),
1600 main_symtab_loc_(), main_strtab_loc_(), has_incremental_info_(false),
1601 inputs_reader_(), symtab_reader_(), relocs_reader_(), got_plt_reader_(),
1602 input_entry_readers_()
1603 { this->setup_readers(); }
1605 // Returns TRUE if the file contains incremental info.
1607 has_incremental_info() const
1608 { return this->has_incremental_info_
; }
1610 // Record a pointer to the object for input file N.
1612 set_input_object(unsigned int n
,
1613 Sized_relobj_incr
<size
, big_endian
>* obj
)
1614 { this->input_objects_
[n
] = obj
; }
1616 // Return a pointer to the object for input file N.
1617 Sized_relobj_incr
<size
, big_endian
>*
1618 input_object(unsigned int n
) const
1620 gold_assert(n
< this->input_objects_
.size());
1621 return this->input_objects_
[n
];
1624 // Return the Output_section for section index SHNDX.
1626 output_section(unsigned int shndx
)
1627 { return this->section_map_
[shndx
]; }
1629 // Map a symbol table entry from the base file to the output symbol table.
1630 // SYMNDX is relative to the first forced-local or global symbol in the
1631 // input file symbol table.
1633 add_global_symbol(unsigned int symndx
, Symbol
* gsym
)
1634 { this->symbol_map_
[symndx
] = gsym
; }
1636 // Map a symbol table entry from the base file to the output symbol table.
1637 // SYMNDX is relative to the first forced-local or global symbol in the
1638 // input file symbol table.
1640 global_symbol(unsigned int symndx
) const
1641 { return this->symbol_map_
[symndx
]; }
1643 // Add a COPY relocation for a global symbol.
1645 add_copy_reloc(Symbol
* gsym
, Output_section
* os
, off_t offset
)
1646 { this->copy_relocs_
.push_back(Copy_reloc(gsym
, os
, offset
)); }
1648 // Readers for the incremental info sections.
1650 const Incremental_inputs_reader
<size
, big_endian
>&
1651 inputs_reader() const
1652 { return this->inputs_reader_
; }
1654 const Incremental_symtab_reader
<big_endian
>&
1655 symtab_reader() const
1656 { return this->symtab_reader_
; }
1658 const Incremental_relocs_reader
<size
, big_endian
>&
1659 relocs_reader() const
1660 { return this->relocs_reader_
; }
1662 const Incremental_got_plt_reader
<big_endian
>&
1663 got_plt_reader() const
1664 { return this->got_plt_reader_
; }
1667 get_symtab_view(View
* symtab_view
, unsigned int* sym_count
,
1668 elfcpp::Elf_strtab
* strtab
);
1671 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1672 typedef typename
Inputs_reader::Incremental_input_entry_reader
1676 do_check_inputs(const Command_line
& cmdline
,
1677 Incremental_inputs
* incremental_inputs
);
1679 // Return TRUE if input file N has changed since the last incremental link.
1681 do_file_has_changed(unsigned int n
) const;
1683 // Initialize the layout of the output file based on the existing
1686 do_init_layout(Layout
* layout
);
1688 // Mark regions of the input file that must be kept unchanged.
1690 do_reserve_layout(unsigned int input_file_index
);
1692 // Process the GOT and PLT entries from the existing output file.
1694 do_process_got_plt(Symbol_table
* symtab
, Layout
* layout
);
1696 // Emit COPY relocations from the existing output file.
1698 do_emit_copy_relocs(Symbol_table
* symtab
);
1700 // Apply incremental relocations for symbols whose values have changed.
1702 do_apply_incremental_relocs(const Symbol_table
* symtab
, Layout
* layout
,
1705 // Proxy class for a sized Incremental_input_entry_reader.
1707 class Sized_input_reader
: public Input_reader
1710 Sized_input_reader(Input_entry_reader r
)
1711 : Input_reader(), reader_(r
)
1714 Sized_input_reader(const Sized_input_reader
& r
)
1715 : Input_reader(), reader_(r
.reader_
)
1719 ~Sized_input_reader()
1725 { return this->reader_
.filename(); }
1728 do_get_mtime() const
1729 { return this->reader_
.get_mtime(); }
1731 Incremental_input_type
1733 { return this->reader_
.type(); }
1736 do_arg_serial() const
1737 { return this->reader_
.arg_serial(); }
1740 do_get_unused_symbol_count() const
1741 { return this->reader_
.get_unused_symbol_count(); }
1744 do_get_unused_symbol(unsigned int n
) const
1745 { return this->reader_
.get_unused_symbol(n
); }
1747 Input_entry_reader reader_
;
1750 virtual unsigned int
1751 do_input_file_count() const
1752 { return this->inputs_reader_
.input_file_count(); }
1754 virtual const Input_reader
*
1755 do_get_input_reader(unsigned int n
) const
1757 gold_assert(n
< this->input_entry_readers_
.size());
1758 return &this->input_entry_readers_
[n
];
1762 // List of symbols that need COPY relocations.
1765 Copy_reloc(Symbol
* sym
, Output_section
* os
, off_t off
)
1766 : symbol(sym
), output_section(os
), offset(off
)
1769 // The global symbol to copy.
1771 // The output section into which the symbol was copied.
1772 Output_section
* output_section
;
1773 // The offset within that output section.
1776 typedef std::vector
<Copy_reloc
> Copy_relocs
;
1779 find_incremental_inputs_sections(unsigned int* p_inputs_shndx
,
1780 unsigned int* p_symtab_shndx
,
1781 unsigned int* p_relocs_shndx
,
1782 unsigned int* p_got_plt_shndx
,
1783 unsigned int* p_strtab_shndx
);
1788 // Output as an ELF file.
1789 elfcpp::Elf_file
<size
, big_endian
, Incremental_binary
> elf_file_
;
1791 // Vector of pointers to the input objects for the unchanged files.
1792 // For replaced files, the corresponding pointer is NULL.
1793 std::vector
<Sized_relobj_incr
<size
, big_endian
>*> input_objects_
;
1795 // Map section index to an Output_section in the updated layout.
1796 std::vector
<Output_section
*> section_map_
;
1798 // Map global symbols from the input file to the symbol table.
1799 std::vector
<Symbol
*> symbol_map_
;
1801 // List of symbols that need COPY relocations.
1802 Copy_relocs copy_relocs_
;
1804 // Locations of the main symbol table and symbol string table.
1805 Location main_symtab_loc_
;
1806 Location main_strtab_loc_
;
1808 // Readers for the incremental info sections.
1809 bool has_incremental_info_
;
1810 Incremental_inputs_reader
<size
, big_endian
> inputs_reader_
;
1811 Incremental_symtab_reader
<big_endian
> symtab_reader_
;
1812 Incremental_relocs_reader
<size
, big_endian
> relocs_reader_
;
1813 Incremental_got_plt_reader
<big_endian
> got_plt_reader_
;
1814 std::vector
<Sized_input_reader
> input_entry_readers_
;
1817 // An incremental Relobj. This class represents a relocatable object
1818 // that has not changed since the last incremental link, and whose contents
1819 // can be used directly from the base file.
1821 template<int size
, bool big_endian
>
1822 class Sized_relobj_incr
: public Sized_relobj
<size
, big_endian
>
1825 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1826 typedef typename Sized_relobj
<size
, big_endian
>::Symbols Symbols
;
1828 Sized_relobj_incr(const std::string
& name
,
1829 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1830 unsigned int input_file_index
);
1834 typedef Sized_relobj_incr
<size
, big_endian
> This
;
1835 static const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1837 typedef typename Sized_relobj
<size
, big_endian
>::Output_sections
1839 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1840 typedef typename
Inputs_reader::Incremental_input_entry_reader
1846 Local_symbol(const char* name_
, Address value_
, unsigned int size_
,
1847 unsigned int shndx_
, unsigned int type_
,
1848 bool needs_dynsym_entry_
)
1849 : st_value(value_
), name(name_
), st_size(size_
), st_shndx(shndx_
),
1850 st_type(type_
), output_dynsym_index(0),
1851 needs_dynsym_entry(needs_dynsym_entry_
)
1853 // The symbol value.
1855 // The symbol name. This points to the stringpool entry.
1858 unsigned int st_size
;
1859 // The output section index.
1860 unsigned int st_shndx
: 28;
1862 unsigned int st_type
: 4;
1863 // The index of the symbol in the output dynamic symbol table.
1864 unsigned int output_dynsym_index
: 31;
1865 // TRUE if the symbol needs to appear in the dynamic symbol table.
1866 unsigned int needs_dynsym_entry
: 1;
1869 // Return TRUE if this is an incremental (unchanged) input file.
1871 do_is_incremental() const
1874 // Return the last modified time of the file.
1877 { return this->input_reader_
.get_mtime(); }
1879 // Read the symbols.
1881 do_read_symbols(Read_symbols_data
*);
1883 // Lay out the input sections.
1885 do_layout(Symbol_table
*, Layout
*, Read_symbols_data
*);
1887 // Layout sections whose layout was deferred while waiting for
1888 // input files from a plugin.
1890 do_layout_deferred_sections(Layout
*);
1892 // Add the symbols to the symbol table.
1894 do_add_symbols(Symbol_table
*, Read_symbols_data
*, Layout
*);
1896 Archive::Should_include
1897 do_should_include_member(Symbol_table
* symtab
, Layout
*, Read_symbols_data
*,
1900 // Iterate over global symbols, calling a visitor class V for each.
1902 do_for_all_global_symbols(Read_symbols_data
* sd
,
1903 Library_base::Symbol_visitor_base
* v
);
1905 // Get the size of a section.
1907 do_section_size(unsigned int shndx
);
1909 // Get the name of a section.
1911 do_section_name(unsigned int shndx
) const;
1913 // Return a view of the contents of a section.
1914 const unsigned char*
1915 do_section_contents(unsigned int shndx
, section_size_type
* plen
,
1918 // Return section flags.
1920 do_section_flags(unsigned int shndx
);
1922 // Return section entsize.
1924 do_section_entsize(unsigned int shndx
);
1926 // Return section address.
1928 do_section_address(unsigned int shndx
);
1930 // Return section type.
1932 do_section_type(unsigned int shndx
);
1934 // Return the section link field.
1936 do_section_link(unsigned int shndx
);
1938 // Return the section link field.
1940 do_section_info(unsigned int shndx
);
1942 // Return the section alignment.
1944 do_section_addralign(unsigned int shndx
);
1946 // Return the Xindex structure to use.
1948 do_initialize_xindex();
1950 // Get symbol counts.
1952 do_get_global_symbol_counts(const Symbol_table
*, size_t*, size_t*) const;
1954 // Get global symbols.
1956 do_get_global_symbols() const
1957 { return &this->symbols_
; }
1959 // Return the value of a local symbol.
1961 do_local_symbol_value(unsigned int, uint64_t) const
1962 { gold_unreachable(); }
1965 do_local_plt_offset(unsigned int) const
1966 { gold_unreachable(); }
1969 do_local_is_tls(unsigned int) const
1970 { gold_unreachable(); }
1972 // Return the number of local symbols.
1974 do_local_symbol_count() const
1975 { return this->local_symbol_count_
; }
1977 // Return the number of local symbols in the output symbol table.
1979 do_output_local_symbol_count() const
1980 { return this->local_symbol_count_
; }
1982 // Return the file offset for local symbols in the output symbol table.
1984 do_local_symbol_offset() const
1985 { return this->local_symbol_offset_
; }
1989 do_read_relocs(Read_relocs_data
*);
1991 // Process the relocs to find list of referenced sections. Used only
1992 // during garbage collection.
1994 do_gc_process_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
1996 // Scan the relocs and adjust the symbol table.
1998 do_scan_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
2000 // Count the local symbols.
2002 do_count_local_symbols(Stringpool_template
<char>*,
2003 Stringpool_template
<char>*);
2005 // Finalize the local symbols.
2007 do_finalize_local_symbols(unsigned int, off_t
, Symbol_table
*);
2009 // Set the offset where local dynamic symbol information will be stored.
2011 do_set_local_dynsym_indexes(unsigned int);
2013 // Set the offset where local dynamic symbol information will be stored.
2015 do_set_local_dynsym_offset(off_t
);
2017 // Relocate the input sections and write out the local symbols.
2019 do_relocate(const Symbol_table
* symtab
, const Layout
*, Output_file
* of
);
2021 // Set the offset of a section.
2023 do_set_section_offset(unsigned int shndx
, uint64_t off
);
2025 // The Incremental_binary base file.
2026 Sized_incremental_binary
<size
, big_endian
>* ibase_
;
2027 // The index of the object in the input file list.
2028 unsigned int input_file_index_
;
2029 // The reader for the input file.
2030 Input_entry_reader input_reader_
;
2031 // The number of local symbols.
2032 unsigned int local_symbol_count_
;
2033 // The number of local symbols which go into the output file's dynamic
2035 unsigned int output_local_dynsym_count_
;
2036 // This starting symbol index in the output symbol table.
2037 unsigned int local_symbol_index_
;
2038 // The file offset for local symbols in the output symbol table.
2039 unsigned int local_symbol_offset_
;
2040 // The file offset for local symbols in the output symbol table.
2041 unsigned int local_dynsym_offset_
;
2042 // The entries in the symbol table for the external symbols.
2044 // Number of symbols defined in object file itself.
2045 size_t defined_count_
;
2046 // The offset of the first incremental relocation for this object.
2047 unsigned int incr_reloc_offset_
;
2048 // The number of incremental relocations for this object.
2049 unsigned int incr_reloc_count_
;
2050 // The index of the first incremental relocation for this object in the
2051 // updated output file.
2052 unsigned int incr_reloc_output_index_
;
2053 // A copy of the incremental relocations from this object.
2054 unsigned char* incr_relocs_
;
2055 // The local symbols.
2056 std::vector
<Local_symbol
> local_symbols_
;
2059 // An incremental Dynobj. This class represents a shared object that has
2060 // not changed since the last incremental link, and whose contents can be
2061 // used directly from the base file.
2063 template<int size
, bool big_endian
>
2064 class Sized_incr_dynobj
: public Dynobj
2067 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
2069 static const Address invalid_address
= static_cast<Address
>(0) - 1;
2071 Sized_incr_dynobj(const std::string
& name
,
2072 Sized_incremental_binary
<size
, big_endian
>* ibase
,
2073 unsigned int input_file_index
);
2076 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
2077 typedef typename
Inputs_reader::Incremental_input_entry_reader
2080 // Return TRUE if this is an incremental (unchanged) input file.
2082 do_is_incremental() const
2085 // Return the last modified time of the file.
2088 { return this->input_reader_
.get_mtime(); }
2090 // Read the symbols.
2092 do_read_symbols(Read_symbols_data
*);
2094 // Lay out the input sections.
2096 do_layout(Symbol_table
*, Layout
*, Read_symbols_data
*);
2098 // Add the symbols to the symbol table.
2100 do_add_symbols(Symbol_table
*, Read_symbols_data
*, Layout
*);
2102 Archive::Should_include
2103 do_should_include_member(Symbol_table
* symtab
, Layout
*, Read_symbols_data
*,
2106 // Iterate over global symbols, calling a visitor class V for each.
2108 do_for_all_global_symbols(Read_symbols_data
* sd
,
2109 Library_base::Symbol_visitor_base
* v
);
2111 // Iterate over local symbols, calling a visitor class V for each GOT offset
2112 // associated with a local symbol.
2114 do_for_all_local_got_entries(Got_offset_list::Visitor
* v
) const;
2116 // Get the size of a section.
2118 do_section_size(unsigned int shndx
);
2120 // Get the name of a section.
2122 do_section_name(unsigned int shndx
) const;
2124 // Return a view of the contents of a section.
2125 const unsigned char*
2126 do_section_contents(unsigned int shndx
, section_size_type
* plen
,
2129 // Return section flags.
2131 do_section_flags(unsigned int shndx
);
2133 // Return section entsize.
2135 do_section_entsize(unsigned int shndx
);
2137 // Return section address.
2139 do_section_address(unsigned int shndx
);
2141 // Return section type.
2143 do_section_type(unsigned int shndx
);
2145 // Return the section link field.
2147 do_section_link(unsigned int shndx
);
2149 // Return the section link field.
2151 do_section_info(unsigned int shndx
);
2153 // Return the section alignment.
2155 do_section_addralign(unsigned int shndx
);
2157 // Return the Xindex structure to use.
2159 do_initialize_xindex();
2161 // Get symbol counts.
2163 do_get_global_symbol_counts(const Symbol_table
*, size_t*, size_t*) const;
2165 // Get global symbols.
2167 do_get_global_symbols() const
2168 { return &this->symbols_
; }
2170 // The Incremental_binary base file.
2171 Sized_incremental_binary
<size
, big_endian
>* ibase_
;
2172 // The index of the object in the input file list.
2173 unsigned int input_file_index_
;
2174 // The reader for the input file.
2175 Input_entry_reader input_reader_
;
2176 // The entries in the symbol table for the external symbols.
2178 // Number of symbols defined in object file itself.
2179 size_t defined_count_
;
2182 // Allocate an incremental object of the appropriate size and endianness.
2184 make_sized_incremental_object(
2185 Incremental_binary
* base
,
2186 unsigned int input_file_index
,
2187 Incremental_input_type input_type
,
2188 const Incremental_binary::Input_reader
* input_reader
);
2190 // This class represents an Archive library (or --start-lib/--end-lib group)
2191 // that has not changed since the last incremental link. Its contents come
2192 // from the incremental inputs entry in the base file.
2194 class Incremental_library
: public Library_base
2197 Incremental_library(const char* filename
, unsigned int input_file_index
,
2198 const Incremental_binary::Input_reader
* input_reader
)
2199 : Library_base(NULL
), filename_(filename
),
2200 input_file_index_(input_file_index
), input_reader_(input_reader
),
2201 unused_symbols_(), is_reported_(false)
2204 // Return the input file index.
2206 input_file_index() const
2207 { return this->input_file_index_
; }
2209 // Return the serial number of the input file.
2212 { return this->input_reader_
->arg_serial(); }
2214 // Copy the unused symbols from the incremental input info.
2215 // We need to do this because we may be overwriting the incremental
2216 // input info in the base file before we write the new incremental
2219 copy_unused_symbols();
2221 // Return FALSE on the first call to indicate that the library needs
2222 // to be recorded; return TRUE subsequently.
2226 bool was_reported
= this->is_reported_
;
2227 is_reported_
= true;
2228 return was_reported
;
2232 typedef std::vector
<std::string
> Symbol_list
;
2237 { return this->filename_
; }
2239 // Return the modification time of the archive file.
2242 { return this->input_reader_
->get_mtime(); }
2244 // Iterator for unused global symbols in the library.
2246 do_for_all_unused_symbols(Symbol_visitor_base
* v
) const;
2248 // The name of the library.
2249 std::string filename_
;
2250 // The input file index of this library.
2251 unsigned int input_file_index_
;
2252 // A reader for the incremental input information.
2253 const Incremental_binary::Input_reader
* input_reader_
;
2254 // List of unused symbols defined in this library.
2255 Symbol_list unused_symbols_
;
2256 // TRUE when this library has been reported to the new incremental info.
2260 } // End namespace gold.
2262 #endif // !defined(GOLD_INCREMENTAL_H)