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
), 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 section offset of this input file entry.
97 set_offset(unsigned int offset
)
98 { this->offset_
= offset
; }
100 // Set the section offset of the supplemental information for this entry.
102 set_info_offset(unsigned int info_offset
)
103 { this->info_offset_
= info_offset
; }
105 // Get the section offset of this input file entry.
108 { return this->offset_
; }
110 // Get the section offset of the supplemental information for this entry.
112 get_info_offset() const
113 { return this->info_offset_
; }
115 // Get the stringpool key for the input filename.
117 get_filename_key() const
118 { return this->filename_key_
; }
120 // Get the serial number of the input file.
123 { return this->arg_serial_
; }
125 // Get the modification time of the input file.
128 { return this->mtime_
; }
130 // Record that the file was found in a system directory.
132 set_is_in_system_directory()
133 { this->is_in_system_directory_
= true; }
135 // Return TRUE if the file was found in a system directory.
137 is_in_system_directory() const
138 { return this->is_in_system_directory_
; }
140 // Return a pointer to the derived Incremental_script_entry object.
141 // Return NULL for input entries that are not script files.
142 Incremental_script_entry
*
144 { return this->do_script_entry(); }
146 // Return a pointer to the derived Incremental_object_entry object.
147 // Return NULL for input entries that are not object files.
148 Incremental_object_entry
*
150 { return this->do_object_entry(); }
152 // Return a pointer to the derived Incremental_archive_entry object.
153 // Return NULL for input entries that are not archive files.
154 Incremental_archive_entry
*
156 { return this->do_archive_entry(); }
159 // Return the type of input file.
160 virtual Incremental_input_type
163 // Return a pointer to the derived Incremental_script_entry object.
164 // Return NULL for input entries that are not script files.
165 virtual Incremental_script_entry
*
169 // Return a pointer to the derived Incremental_object_entry object.
170 // Return NULL for input entries that are not object files.
171 virtual Incremental_object_entry
*
175 // Return a pointer to the derived Incremental_archive_entry object.
176 // Return NULL for input entries that are not archive files.
177 virtual Incremental_archive_entry
*
182 // Key of the filename string in the section stringtable.
183 Stringpool::Key filename_key_
;
185 // Offset of the entry in the output section.
186 unsigned int offset_
;
188 // Offset of the extra information in the output section.
189 unsigned int info_offset_
;
191 // Serial number of the file in the argument list.
192 unsigned int arg_serial_
;
194 // Last modification time of the file.
197 // TRUE if the file was found in a system directory.
198 bool is_in_system_directory_
;
201 // Information about a script input that will persist during the whole linker
202 // run. Needed only during an incremental build to retrieve the input files
203 // added by this script.
208 Script_info(const std::string
& filename
)
209 : filename_(filename
), incremental_script_entry_(NULL
)
212 // Store a pointer to the incremental information for this script.
214 set_incremental_info(Incremental_script_entry
* entry
)
215 { this->incremental_script_entry_
= entry
; }
217 // Return the filename.
220 { return this->filename_
; }
222 // Return the pointer to the incremental information for this script.
223 Incremental_script_entry
*
224 incremental_info() const
225 { return this->incremental_script_entry_
; }
228 const std::string filename_
;
229 Incremental_script_entry
* incremental_script_entry_
;
232 // Class for recording input scripts.
234 class Incremental_script_entry
: public Incremental_input_entry
237 Incremental_script_entry(Stringpool::Key filename_key
,
238 unsigned int arg_serial
, Script_info
* script
,
240 : Incremental_input_entry(filename_key
, arg_serial
, mtime
),
241 script_(script
), objects_()
244 // Add a member object to the archive.
246 add_object(Incremental_input_entry
* obj_entry
)
248 this->objects_
.push_back(obj_entry
);
251 // Return the number of objects included by this script.
254 { return this->objects_
.size(); }
256 // Return the Nth object.
257 Incremental_input_entry
*
258 get_object(unsigned int n
)
260 gold_assert(n
< this->objects_
.size());
261 return this->objects_
[n
];
265 virtual Incremental_input_type
267 { return INCREMENTAL_INPUT_SCRIPT
; }
269 // Return a pointer to the derived Incremental_script_entry object.
270 virtual Incremental_script_entry
*
275 // Information about the script file.
276 Script_info
* script_
;
277 // Objects that have been included by this script.
278 std::vector
<Incremental_input_entry
*> objects_
;
281 // Class for recording input object files.
283 class Incremental_object_entry
: public Incremental_input_entry
286 Incremental_object_entry(Stringpool::Key filename_key
, Object
* obj
,
287 unsigned int arg_serial
, Timespec mtime
)
288 : Incremental_input_entry(filename_key
, arg_serial
, mtime
), obj_(obj
),
289 is_member_(false), sections_()
291 if (!obj_
->is_dynamic())
292 this->sections_
.reserve(obj
->shnum());
298 { return this->obj_
; }
300 // Record that this object is an archive member.
303 { this->is_member_
= true; }
305 // Return true if this object is an archive member.
308 { return this->is_member_
; }
310 // Add an input section.
312 add_input_section(unsigned int shndx
, Stringpool::Key name_key
, off_t sh_size
)
313 { this->sections_
.push_back(Input_section(shndx
, name_key
, sh_size
)); }
315 // Return the number of input sections in this object.
317 get_input_section_count() const
318 { return this->sections_
.size(); }
320 // Return the input section index for the Nth input section.
322 get_input_section_index(unsigned int n
) const
323 { return this->sections_
[n
].shndx_
; }
325 // Return the stringpool key of the Nth input section.
327 get_input_section_name_key(unsigned int n
) const
328 { return this->sections_
[n
].name_key_
; }
330 // Return the size of the Nth input section.
332 get_input_section_size(unsigned int n
) const
333 { return this->sections_
[n
].sh_size_
; }
336 virtual Incremental_input_type
339 return (this->is_member_
340 ? INCREMENTAL_INPUT_ARCHIVE_MEMBER
341 : (this->obj_
->is_dynamic()
342 ? INCREMENTAL_INPUT_SHARED_LIBRARY
343 : INCREMENTAL_INPUT_OBJECT
));
346 // Return a pointer to the derived Incremental_object_entry object.
347 virtual Incremental_object_entry
*
352 // The object file itself.
355 // Whether this object is an archive member.
361 Input_section(unsigned int shndx
, Stringpool::Key name_key
, off_t sh_size
)
362 : shndx_(shndx
), name_key_(name_key
), sh_size_(sh_size
)
365 Stringpool::Key name_key_
;
368 std::vector
<Input_section
> sections_
;
371 // Class for recording archive library input files.
373 class Incremental_archive_entry
: public Incremental_input_entry
376 Incremental_archive_entry(Stringpool::Key filename_key
,
377 unsigned int arg_serial
, Timespec mtime
)
378 : Incremental_input_entry(filename_key
, arg_serial
, mtime
), members_(),
382 // Add a member object to the archive.
384 add_object(Incremental_object_entry
* obj_entry
)
386 this->members_
.push_back(obj_entry
);
387 obj_entry
->set_is_member();
390 // Add an unused global symbol to the archive.
392 add_unused_global_symbol(Stringpool::Key symbol_key
)
393 { this->unused_syms_
.push_back(symbol_key
); }
395 // Return the number of member objects included in the link.
398 { return this->members_
.size(); }
400 // Return the Nth member object.
401 Incremental_object_entry
*
402 get_member(unsigned int n
)
403 { return this->members_
[n
]; }
405 // Return the number of unused global symbols in this archive.
407 get_unused_global_symbol_count()
408 { return this->unused_syms_
.size(); }
410 // Return the Nth unused global symbol.
412 get_unused_global_symbol(unsigned int n
)
413 { return this->unused_syms_
[n
]; }
416 virtual Incremental_input_type
418 { return INCREMENTAL_INPUT_ARCHIVE
; }
420 // Return a pointer to the derived Incremental_archive_entry object.
421 virtual Incremental_archive_entry
*
426 // Members of the archive that have been included in the link.
427 std::vector
<Incremental_object_entry
*> members_
;
429 // Unused global symbols from this archive.
430 std::vector
<Stringpool::Key
> unused_syms_
;
433 // This class contains the information needed during an incremental
434 // build about the inputs necessary to build the .gnu_incremental_inputs.
436 class Incremental_inputs
439 typedef std::vector
<Incremental_input_entry
*> Input_list
;
442 : inputs_(), command_line_(), command_line_key_(0),
443 strtab_(new Stringpool()), current_object_(NULL
),
444 current_object_entry_(NULL
), inputs_section_(NULL
),
445 symtab_section_(NULL
), relocs_section_(NULL
),
449 ~Incremental_inputs() { delete this->strtab_
; }
451 // Record the command line.
453 report_command_line(int argc
, const char* const* argv
);
455 // Record the initial info for archive file ARCHIVE.
457 report_archive_begin(Library_base
* arch
, unsigned int arg_serial
,
458 Script_info
* script_info
);
460 // Record the final info for archive file ARCHIVE.
462 report_archive_end(Library_base
* arch
);
464 // Record the info for object file OBJ. If ARCH is not NULL,
465 // attach the object file to the archive.
467 report_object(Object
* obj
, unsigned int arg_serial
, Library_base
* arch
,
468 Script_info
* script_info
);
470 // Record an input section belonging to object file OBJ.
472 report_input_section(Object
* obj
, unsigned int shndx
, const char* name
,
475 // Record the info for input script SCRIPT.
477 report_script(Script_info
* script
, unsigned int arg_serial
,
480 // Return the running count of incremental relocations.
482 get_reloc_count() const
483 { return this->reloc_count_
; }
485 // Update the running count of incremental relocations.
487 set_reloc_count(unsigned int count
)
488 { this->reloc_count_
= count
; }
490 // Prepare for layout. Called from Layout::finalize.
494 // Create the .gnu_incremental_inputs and related sections.
496 create_data_sections(Symbol_table
* symtab
);
498 // Return the .gnu_incremental_inputs section.
500 inputs_section() const
501 { return this->inputs_section_
; }
503 // Return the .gnu_incremental_symtab section.
505 symtab_section() const
506 { return this->symtab_section_
; }
508 // Return the .gnu_incremental_relocs section.
510 relocs_section() const
511 { return this->relocs_section_
; }
513 // Return the .gnu_incremental_got_plt section.
515 got_plt_section() const
516 { return this->got_plt_section_
; }
518 // Return the .gnu_incremental_strtab stringpool.
520 get_stringpool() const
521 { return this->strtab_
; }
523 // Return the canonical form of the command line, as will be stored in
524 // .gnu_incremental_strtab.
527 { return this->command_line_
; }
529 // Return the stringpool key of the command line.
531 command_line_key() const
532 { return this->command_line_key_
; }
534 // Return the number of input files.
536 input_file_count() const
537 { return this->inputs_
.size(); }
539 // Return the input files.
542 { return this->inputs_
; }
544 // Return the sh_entsize value for the .gnu_incremental_relocs section.
546 relocs_entsize() const;
549 // The list of input files.
552 // Canonical form of the command line, as will be stored in
553 // .gnu_incremental_strtab.
554 std::string command_line_
;
556 // The key of the command line string in the string pool.
557 Stringpool::Key command_line_key_
;
559 // The .gnu_incremental_strtab string pool associated with the
560 // .gnu_incremental_inputs.
563 // Keep track of the object currently being processed.
564 Object
* current_object_
;
565 Incremental_object_entry
* current_object_entry_
;
567 // The .gnu_incremental_inputs section.
568 Output_section_data
* inputs_section_
;
570 // The .gnu_incremental_symtab section.
571 Output_data_space
* symtab_section_
;
573 // The .gnu_incremental_relocs section.
574 Output_data_space
* relocs_section_
;
576 // The .gnu_incremental_got_plt section.
577 Output_data_space
* got_plt_section_
;
579 // Total count of incremental relocations. Updated during Scan_relocs
580 // phase at the completion of each object file.
581 unsigned int reloc_count_
;
584 // Reader class for global symbol info from an object file entry in
585 // the .gnu_incremental_inputs section.
587 template<bool big_endian
>
588 class Incremental_global_symbol_reader
591 typedef elfcpp::Swap
<32, big_endian
> Swap32
;
594 Incremental_global_symbol_reader(const unsigned char* p
)
599 output_symndx() const
600 { return Swap32::readval(this->p_
); }
604 { return Swap32::readval(this->p_
+ 4); }
608 { return Swap32::readval(this->p_
+ 8); }
612 { return Swap32::readval(this->p_
+ 12); }
616 { return Swap32::readval(this->p_
+ 16); }
619 // Base address of the symbol entry.
620 const unsigned char* p_
;
623 // Reader class for .gnu_incremental_inputs section.
625 template<int size
, bool big_endian
>
626 class Incremental_inputs_reader
629 typedef elfcpp::Swap
<size
, big_endian
> Swap
;
630 typedef elfcpp::Swap
<16, big_endian
> Swap16
;
631 typedef elfcpp::Swap
<32, big_endian
> Swap32
;
632 typedef elfcpp::Swap
<64, big_endian
> Swap64
;
635 Incremental_inputs_reader()
636 : p_(NULL
), strtab_(NULL
, 0), input_file_count_(0)
639 Incremental_inputs_reader(const unsigned char* p
,
640 const elfcpp::Elf_strtab
& strtab
)
641 : p_(p
), strtab_(strtab
)
642 { this->input_file_count_
= Swap32::readval(this->p_
+ 4); }
644 // Return the version number.
647 { return Swap32::readval(this->p_
); }
649 // Return the count of input file entries.
651 input_file_count() const
652 { return this->input_file_count_
; }
654 // Return the command line.
658 unsigned int offset
= Swap32::readval(this->p_
+ 8);
659 return this->get_string(offset
);
662 // Reader class for an input file entry and its supplemental info.
663 class Incremental_input_entry_reader
666 Incremental_input_entry_reader(const Incremental_inputs_reader
* inputs
,
668 : inputs_(inputs
), offset_(offset
)
670 this->info_offset_
= Swap32::readval(inputs
->p_
+ offset
+ 4);
671 this->flags_
= Swap16::readval(this->inputs_
->p_
+ offset
+ 20);
674 // Return the filename.
678 unsigned int offset
= Swap32::readval(this->inputs_
->p_
+ this->offset_
);
679 return this->inputs_
->get_string(offset
);
682 // Return the argument serial number.
686 return Swap16::readval(this->inputs_
->p_
+ this->offset_
+ 22);
689 // Return the timestamp.
694 const unsigned char* p
= this->inputs_
->p_
+ this->offset_
+ 8;
695 t
.seconds
= Swap64::readval(p
);
696 t
.nanoseconds
= Swap32::readval(p
+8);
700 // Return the type of input file.
701 Incremental_input_type
703 { return static_cast<Incremental_input_type
>(this->flags_
& 0xff); }
705 // Return TRUE if the file was found in a system directory.
707 is_in_system_directory() const
708 { return (this->flags_
& INCREMENTAL_INPUT_IN_SYSTEM_DIR
) != 0; }
710 // Return the input section count -- for objects only.
712 get_input_section_count() const
714 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
715 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
716 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
719 // Return the offset of the supplemental info for symbol SYMNDX --
722 get_symbol_offset(unsigned int symndx
) const
724 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
725 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
727 unsigned int section_count
= this->get_input_section_count();
728 return (this->info_offset_
+ 16
729 + section_count
* input_section_entry_size
733 // Return the global symbol count -- for objects & shared libraries only.
735 get_global_symbol_count() const
737 switch (this->type())
739 case INCREMENTAL_INPUT_OBJECT
:
740 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
741 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 4);
742 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
743 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
749 // Return the offset of the first local symbol -- for objects only.
751 get_local_symbol_offset() const
753 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
754 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
756 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 8);
759 // Return the local symbol count -- for objects only.
761 get_local_symbol_count() const
763 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
764 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
766 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 12);
769 // Return the object count -- for scripts only.
771 get_object_count() const
773 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT
);
774 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
777 // Return the input file offset for object N -- for scripts only.
779 get_object_offset(unsigned int n
) const
781 gold_assert(this->type() == INCREMENTAL_INPUT_SCRIPT
);
782 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
786 // Return the member count -- for archives only.
788 get_member_count() const
790 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
791 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
);
794 // Return the unused symbol count -- for archives only.
796 get_unused_symbol_count() const
798 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
799 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
+ 4);
802 // Return the input file offset for archive member N -- for archives only.
804 get_member_offset(unsigned int n
) const
806 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
807 return Swap32::readval(this->inputs_
->p_
+ this->info_offset_
811 // Return the Nth unused global symbol -- for archives only.
813 get_unused_symbol(unsigned int n
) const
815 gold_assert(this->type() == INCREMENTAL_INPUT_ARCHIVE
);
816 unsigned int member_count
= this->get_member_count();
817 unsigned int offset
= Swap32::readval(this->inputs_
->p_
818 + this->info_offset_
+ 8
821 return this->inputs_
->get_string(offset
);
824 // Information about an input section.
825 struct Input_section_info
828 unsigned int output_shndx
;
833 // Return info about the Nth input section -- for objects only.
835 get_input_section(unsigned int n
) const
837 Input_section_info info
;
838 const unsigned char* p
= (this->inputs_
->p_
839 + this->info_offset_
+ 16
840 + n
* input_section_entry_size
);
841 unsigned int name_offset
= Swap32::readval(p
);
842 info
.name
= this->inputs_
->get_string(name_offset
);
843 info
.output_shndx
= Swap32::readval(p
+ 4);
844 info
.sh_offset
= Swap::readval(p
+ 8);
845 info
.sh_size
= Swap::readval(p
+ 8 + size
/ 8);
849 // Return info about the Nth global symbol -- for objects only.
850 Incremental_global_symbol_reader
<big_endian
>
851 get_global_symbol_reader(unsigned int n
) const
853 gold_assert(this->type() == INCREMENTAL_INPUT_OBJECT
854 || this->type() == INCREMENTAL_INPUT_ARCHIVE_MEMBER
);
855 unsigned int section_count
= this->get_input_section_count();
856 const unsigned char* p
= (this->inputs_
->p_
857 + this->info_offset_
+ 16
858 + section_count
* input_section_entry_size
860 return Incremental_global_symbol_reader
<big_endian
>(p
);
863 // Return the output symbol index for the Nth global symbol -- for shared
864 // libraries only. Sets *IS_DEF to TRUE if the symbol is defined in this
867 get_output_symbol_index(unsigned int n
, bool* is_def
)
869 gold_assert(this->type() == INCREMENTAL_INPUT_SHARED_LIBRARY
);
870 const unsigned char* p
= (this->inputs_
->p_
871 + this->info_offset_
+ 4
873 unsigned int output_symndx
= Swap32::readval(p
);
874 *is_def
= (output_symndx
& (1U << 31)) != 0;
875 return output_symndx
& ((1U << 31) - 1);
879 // Size of an input section entry.
880 static const unsigned int input_section_entry_size
= 8 + 2 * size
/ 8;
881 // The reader instance for the containing section.
882 const Incremental_inputs_reader
* inputs_
;
883 // The flags, including the type of input file.
885 // Section offset to the input file entry.
886 unsigned int offset_
;
887 // Section offset to the supplemental info for the input file.
888 unsigned int info_offset_
;
891 // Return the offset of an input file entry given its index N.
893 input_file_offset(unsigned int n
) const
895 gold_assert(n
< this->input_file_count_
);
899 // Return the index of an input file entry given its OFFSET.
901 input_file_index(unsigned int offset
) const
903 int n
= (offset
- 16) / 24;
904 gold_assert(input_file_offset(n
) == offset
);
908 // Return a reader for the Nth input file entry.
909 Incremental_input_entry_reader
910 input_file(unsigned int n
) const
911 { return Incremental_input_entry_reader(this, this->input_file_offset(n
)); }
913 // Return a reader for the input file entry at OFFSET.
914 Incremental_input_entry_reader
915 input_file_at_offset(unsigned int offset
) const
917 gold_assert(offset
< 16 + this->input_file_count_
* 24);
918 return Incremental_input_entry_reader(this, offset
);
921 // Return a reader for the global symbol info at OFFSET.
922 Incremental_global_symbol_reader
<big_endian
>
923 global_symbol_reader_at_offset(unsigned int offset
) const
925 const unsigned char* p
= this->p_
+ offset
;
926 return Incremental_global_symbol_reader
<big_endian
>(p
);
930 // Lookup a string in the ELF string table.
931 const char* get_string(unsigned int offset
) const
934 if (this->strtab_
.get_c_string(offset
, &s
))
939 // Base address of the .gnu_incremental_inputs section.
940 const unsigned char* p_
;
941 // The associated ELF string table.
942 elfcpp::Elf_strtab strtab_
;
943 // The number of input file entries in this section.
944 unsigned int input_file_count_
;
947 // Reader class for the .gnu_incremental_symtab section.
949 template<bool big_endian
>
950 class Incremental_symtab_reader
953 Incremental_symtab_reader()
957 Incremental_symtab_reader(const unsigned char* p
, off_t len
)
961 // Return the count of symbols in this section.
964 { return static_cast<unsigned int>(this->len_
/ 4); }
966 // Return the list head for symbol table entry N.
968 get_list_head(unsigned int n
) const
969 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ 4 * n
); }
972 // Base address of the .gnu_incremental_relocs section.
973 const unsigned char* p_
;
974 // Size of the section.
978 // Reader class for the .gnu_incremental_relocs section.
980 template<int size
, bool big_endian
>
981 class Incremental_relocs_reader
984 // Size of each field.
985 static const unsigned int field_size
= size
/ 8;
988 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
989 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Addend
;
991 // Size of each entry.
992 static const unsigned int reloc_size
= 8 + 2 * field_size
;
994 Incremental_relocs_reader()
998 Incremental_relocs_reader(const unsigned char* p
, off_t len
)
1002 // Return the count of relocations in this section.
1005 { return static_cast<unsigned int>(this->len_
/ reloc_size
); }
1007 // Return the relocation type for relocation entry at offset OFF.
1009 get_r_type(unsigned int off
) const
1010 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ off
); }
1012 // Return the output section index for relocation entry at offset OFF.
1014 get_r_shndx(unsigned int off
) const
1015 { return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ off
+ 4); }
1017 // Return the output section offset for relocation entry at offset OFF.
1019 get_r_offset(unsigned int off
) const
1020 { return elfcpp::Swap
<size
, big_endian
>::readval(this->p_
+ off
+ 8); }
1022 // Return the addend for relocation entry at offset OFF.
1024 get_r_addend(unsigned int off
) const
1026 return elfcpp::Swap
<size
, big_endian
>::readval(this->p_
+ off
+ 8
1027 + this->field_size
);
1030 // Return a pointer to the relocation entry at offset OFF.
1031 const unsigned char*
1032 data(unsigned int off
) const
1033 { return this->p_
+ off
; }
1036 // Base address of the .gnu_incremental_relocs section.
1037 const unsigned char* p_
;
1038 // Size of the section.
1042 // Reader class for the .gnu_incremental_got_plt section.
1044 template<bool big_endian
>
1045 class Incremental_got_plt_reader
1048 Incremental_got_plt_reader()
1049 : p_(NULL
), got_count_(0), got_desc_p_(NULL
), plt_desc_p_(NULL
)
1052 Incremental_got_plt_reader(const unsigned char* p
) : p_(p
)
1054 this->got_count_
= elfcpp::Swap
<32, big_endian
>::readval(p
);
1055 this->got_desc_p_
= p
+ 8 + ((this->got_count_
+ 3) & ~3);
1056 this->plt_desc_p_
= this->got_desc_p_
+ this->got_count_
* 4;
1059 // Return the GOT entry count.
1061 get_got_entry_count() const
1063 return this->got_count_
;
1066 // Return the PLT entry count.
1068 get_plt_entry_count() const
1070 return elfcpp::Swap
<32, big_endian
>::readval(this->p_
+ 4);
1073 // Return the GOT type for GOT entry N.
1075 get_got_type(unsigned int n
)
1077 return this->p_
[8 + n
];
1080 // Return the GOT descriptor for GOT entry N.
1082 get_got_desc(unsigned int n
)
1084 return elfcpp::Swap
<32, big_endian
>::readval(this->got_desc_p_
+ n
* 4);
1087 // Return the PLT descriptor for PLT entry N.
1089 get_plt_desc(unsigned int n
)
1091 return elfcpp::Swap
<32, big_endian
>::readval(this->plt_desc_p_
+ n
* 4);
1095 // Base address of the .gnu_incremental_got_plt section.
1096 const unsigned char* p_
;
1098 unsigned int got_count_
;
1099 // Base address of the GOT descriptor array.
1100 const unsigned char* got_desc_p_
;
1101 // Base address of the PLT descriptor array.
1102 const unsigned char* plt_desc_p_
;
1105 // An object representing the ELF file we edit during an incremental build.
1106 // Similar to Object or Dynobj, but operates on Output_file and contains
1107 // methods to support incremental updating. This is the abstract parent class
1108 // implemented in Sized_incremental_binary<size, big_endian> for a specific
1109 // endianness and size.
1111 class Incremental_binary
1114 Incremental_binary(Output_file
* output
, Target
* target
)
1115 : input_args_map_(), library_map_(), script_map_(),
1116 output_(output
), target_(target
)
1120 ~Incremental_binary()
1123 // Check the .gnu_incremental_inputs section to see whether an incremental
1124 // build is possible.
1126 check_inputs(const Command_line
& cmdline
,
1127 Incremental_inputs
* incremental_inputs
)
1128 { return this->do_check_inputs(cmdline
, incremental_inputs
); }
1132 error(const char* format
, ...) const ATTRIBUTE_PRINTF_2
;
1134 // Proxy class for a sized Incremental_input_entry_reader.
1148 { return this->do_filename(); }
1152 { return this->do_get_mtime(); }
1154 Incremental_input_type
1156 { return this->do_type(); }
1160 { return this->do_arg_serial(); }
1163 get_unused_symbol_count() const
1164 { return this->do_get_unused_symbol_count(); }
1167 get_unused_symbol(unsigned int n
) const
1168 { return this->do_get_unused_symbol(n
); }
1172 do_filename() const = 0;
1175 do_get_mtime() const = 0;
1177 virtual Incremental_input_type
1178 do_type() const = 0;
1180 virtual unsigned int
1181 do_arg_serial() const = 0;
1183 virtual unsigned int
1184 do_get_unused_symbol_count() const = 0;
1187 do_get_unused_symbol(unsigned int n
) const = 0;
1190 // Return the number of input files.
1192 input_file_count() const
1193 { return this->do_input_file_count(); }
1195 // Return an Input_reader for input file N.
1197 get_input_reader(unsigned int n
) const
1198 { return this->do_get_input_reader(n
); }
1200 // Return TRUE if the input file N has changed since the last link.
1202 file_has_changed(unsigned int n
) const
1203 { return this->do_file_has_changed(n
); }
1205 // Return the Input_argument for input file N. Returns NULL if
1206 // the Input_argument is not available.
1207 const Input_argument
*
1208 get_input_argument(unsigned int n
) const
1210 const Input_reader
* input_file
= this->do_get_input_reader(n
);
1211 unsigned int arg_serial
= input_file
->arg_serial();
1212 if (arg_serial
== 0 || arg_serial
> this->input_args_map_
.size())
1214 return this->input_args_map_
[arg_serial
- 1];
1217 // Return an Incremental_library for the given input file.
1218 Incremental_library
*
1219 get_library(unsigned int n
)
1220 { return this->library_map_
[n
]; }
1222 // Return a Script_info for the given input file.
1224 get_script_info(unsigned int n
)
1225 { return this->script_map_
[n
]; }
1227 // Initialize the layout of the output file based on the existing
1230 init_layout(Layout
* layout
)
1231 { this->do_init_layout(layout
); }
1233 // Mark regions of the input file that must be kept unchanged.
1235 reserve_layout(unsigned int input_file_index
)
1236 { this->do_reserve_layout(input_file_index
); }
1238 // Apply incremental relocations for symbols whose values have changed.
1240 apply_incremental_relocs(const Symbol_table
* symtab
, Layout
* layout
,
1242 { this->do_apply_incremental_relocs(symtab
, layout
, of
); }
1244 // Functions and types for the elfcpp::Elf_file interface. This
1245 // permit us to use Incremental_binary as the File template parameter for
1246 // elfcpp::Elf_file.
1248 // The View class is returned by view. It must support a single
1249 // method, data(). This is trivial, because Output_file::get_output_view
1250 // does what we need.
1254 View(const unsigned char* p
)
1258 const unsigned char*
1260 { return this->p_
; }
1263 const unsigned char* p_
;
1268 view(off_t file_offset
, section_size_type data_size
)
1269 { return View(this->output_
->get_input_view(file_offset
, data_size
)); }
1271 // A location in the file.
1277 Location(off_t fo
, section_size_type ds
)
1278 : file_offset(fo
), data_size(ds
)
1282 : file_offset(0), data_size(0)
1286 // Get a View given a Location.
1289 { return View(this->view(loc
.file_offset
, loc
.data_size
)); }
1291 // Return the Output_file.
1294 { return this->output_
; }
1297 // Check the .gnu_incremental_inputs section to see whether an incremental
1298 // build is possible.
1300 do_check_inputs(const Command_line
& cmdline
,
1301 Incremental_inputs
* incremental_inputs
) = 0;
1303 // Return TRUE if input file N has changed since the last incremental link.
1305 do_file_has_changed(unsigned int n
) const = 0;
1307 // Initialize the layout of the output file based on the existing
1310 do_init_layout(Layout
* layout
) = 0;
1312 // Mark regions of the input file that must be kept unchanged.
1314 do_reserve_layout(unsigned int input_file_index
) = 0;
1316 // Apply incremental relocations for symbols whose values have changed.
1318 do_apply_incremental_relocs(const Symbol_table
*, Layout
*, Output_file
*) = 0;
1320 virtual unsigned int
1321 do_input_file_count() const = 0;
1323 virtual const Input_reader
*
1324 do_get_input_reader(unsigned int) const = 0;
1326 // Map from input file index to Input_argument.
1327 std::vector
<const Input_argument
*> input_args_map_
;
1328 // Map from an input file index to an Incremental_library.
1329 std::vector
<Incremental_library
*> library_map_
;
1330 // Map from an input file index to a Script_info.
1331 std::vector
<Script_info
*> script_map_
;
1334 // Edited output file object.
1335 Output_file
* output_
;
1336 // Target of the output file.
1340 template<int size
, bool big_endian
>
1341 class Sized_incremental_binary
: public Incremental_binary
1344 Sized_incremental_binary(Output_file
* output
,
1345 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
,
1347 : Incremental_binary(output
, target
), elf_file_(this, ehdr
),
1348 section_map_(), symbol_map_(), has_incremental_info_(false),
1349 inputs_reader_(), symtab_reader_(), relocs_reader_(), got_plt_reader_(),
1350 input_entry_readers_()
1351 { this->setup_readers(); }
1353 // Returns TRUE if the file contains incremental info.
1355 has_incremental_info() const
1356 { return this->has_incremental_info_
; }
1358 // Return the Output_section for section index SHNDX.
1360 output_section(unsigned int shndx
)
1361 { return this->section_map_
[shndx
]; }
1363 // Map a symbol table entry from the input file to the output symbol table.
1364 // SYMNDX is relative to the first forced-local or global symbol in the
1365 // input file symbol table.
1367 add_global_symbol(unsigned int symndx
, Symbol
* gsym
)
1368 { this->symbol_map_
[symndx
] = gsym
; }
1370 // Map a symbol table entry from the input file to the output symbol table.
1371 // SYMNDX is relative to the first forced-local or global symbol in the
1372 // input file symbol table.
1374 global_symbol(unsigned int symndx
) const
1375 { return this->symbol_map_
[symndx
]; }
1377 // Readers for the incremental info sections.
1379 const Incremental_inputs_reader
<size
, big_endian
>&
1380 inputs_reader() const
1381 { return this->inputs_reader_
; }
1383 const Incremental_symtab_reader
<big_endian
>&
1384 symtab_reader() const
1385 { return this->symtab_reader_
; }
1387 const Incremental_relocs_reader
<size
, big_endian
>&
1388 relocs_reader() const
1389 { return this->relocs_reader_
; }
1391 const Incremental_got_plt_reader
<big_endian
>&
1392 got_plt_reader() const
1393 { return this->got_plt_reader_
; }
1396 get_symtab_view(View
* symtab_view
, unsigned int* sym_count
,
1397 elfcpp::Elf_strtab
* strtab
);
1400 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1401 typedef typename
Inputs_reader::Incremental_input_entry_reader
1405 do_check_inputs(const Command_line
& cmdline
,
1406 Incremental_inputs
* incremental_inputs
);
1408 // Return TRUE if input file N has changed since the last incremental link.
1410 do_file_has_changed(unsigned int n
) const;
1412 // Initialize the layout of the output file based on the existing
1415 do_init_layout(Layout
* layout
);
1417 // Mark regions of the input file that must be kept unchanged.
1419 do_reserve_layout(unsigned int input_file_index
);
1421 // Apply incremental relocations for symbols whose values have changed.
1423 do_apply_incremental_relocs(const Symbol_table
* symtab
, Layout
* layout
,
1426 // Proxy class for a sized Incremental_input_entry_reader.
1428 class Sized_input_reader
: public Input_reader
1431 Sized_input_reader(Input_entry_reader r
)
1432 : Input_reader(), reader_(r
)
1436 ~Sized_input_reader()
1442 { return this->reader_
.filename(); }
1445 do_get_mtime() const
1446 { return this->reader_
.get_mtime(); }
1448 Incremental_input_type
1450 { return this->reader_
.type(); }
1453 do_arg_serial() const
1454 { return this->reader_
.arg_serial(); }
1457 do_get_unused_symbol_count() const
1458 { return this->reader_
.get_unused_symbol_count(); }
1461 do_get_unused_symbol(unsigned int n
) const
1462 { return this->reader_
.get_unused_symbol(n
); }
1464 Input_entry_reader reader_
;
1467 virtual unsigned int
1468 do_input_file_count() const
1469 { return this->inputs_reader_
.input_file_count(); }
1471 virtual const Input_reader
*
1472 do_get_input_reader(unsigned int n
) const
1474 gold_assert(n
< this->input_entry_readers_
.size());
1475 return &this->input_entry_readers_
[n
];
1480 find_incremental_inputs_sections(unsigned int* p_inputs_shndx
,
1481 unsigned int* p_symtab_shndx
,
1482 unsigned int* p_relocs_shndx
,
1483 unsigned int* p_got_plt_shndx
,
1484 unsigned int* p_strtab_shndx
);
1489 // Output as an ELF file.
1490 elfcpp::Elf_file
<size
, big_endian
, Incremental_binary
> elf_file_
;
1492 // Map section index to an Output_section in the updated layout.
1493 std::vector
<Output_section
*> section_map_
;
1495 // Map global symbols from the input file to the symbol table.
1496 std::vector
<Symbol
*> symbol_map_
;
1498 // Readers for the incremental info sections.
1499 bool has_incremental_info_
;
1500 Incremental_inputs_reader
<size
, big_endian
> inputs_reader_
;
1501 Incremental_symtab_reader
<big_endian
> symtab_reader_
;
1502 Incremental_relocs_reader
<size
, big_endian
> relocs_reader_
;
1503 Incremental_got_plt_reader
<big_endian
> got_plt_reader_
;
1504 std::vector
<Sized_input_reader
> input_entry_readers_
;
1507 // An incremental Relobj. This class represents a relocatable object
1508 // that has not changed since the last incremental link, and whose contents
1509 // can be used directly from the base file.
1511 template<int size
, bool big_endian
>
1512 class Sized_incr_relobj
: public Sized_relobj_base
<size
, big_endian
>
1515 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1516 typedef typename Sized_relobj_base
<size
, big_endian
>::Symbols Symbols
;
1518 static const Address invalid_address
= static_cast<Address
>(0) - 1;
1520 Sized_incr_relobj(const std::string
& name
,
1521 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1522 unsigned int input_file_index
);
1524 // Checks if the offset of input section SHNDX within its output
1525 // section is invalid.
1527 is_output_section_offset_invalid(unsigned int shndx
) const
1528 { return this->section_offsets_
[shndx
] == invalid_address
; }
1530 // Get the offset of input section SHNDX within its output section.
1531 // This is -1 if the input section requires a special mapping, such
1532 // as a merge section. The output section can be found in the
1533 // output_sections_ field of the parent class Incrobj.
1535 do_output_section_offset(unsigned int shndx
) const
1537 gold_assert(shndx
< this->section_offsets_
.size());
1538 Address off
= this->section_offsets_
[shndx
];
1539 if (off
== invalid_address
)
1546 typedef Sized_incr_relobj
<size
, big_endian
> This
;
1547 static const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1549 typedef typename Sized_relobj_base
<size
, big_endian
>::Output_sections
1551 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1552 typedef typename
Inputs_reader::Incremental_input_entry_reader
1558 Local_symbol(const char* name_
, Address value_
, unsigned int size_
,
1559 unsigned int shndx_
, unsigned int type_
,
1560 bool needs_dynsym_entry_
)
1561 : st_value(value_
), name(name_
), st_size(size_
), st_shndx(shndx_
),
1562 st_type(type_
), output_dynsym_index(0),
1563 needs_dynsym_entry(needs_dynsym_entry_
)
1565 // The symbol value.
1567 // The symbol name. This points to the stringpool entry.
1570 unsigned int st_size
;
1571 // The output section index.
1572 unsigned int st_shndx
: 28;
1574 unsigned int st_type
: 4;
1575 // The index of the symbol in the output dynamic symbol table.
1576 unsigned int output_dynsym_index
: 31;
1577 // TRUE if the symbol needs to appear in the dynamic symbol table.
1578 unsigned int needs_dynsym_entry
: 1;
1581 // Return TRUE if this is an incremental (unchanged) input file.
1583 do_is_incremental() const
1586 // Return the last modified time of the file.
1589 { return this->input_reader_
.get_mtime(); }
1591 // Read the symbols.
1593 do_read_symbols(Read_symbols_data
*);
1595 // Lay out the input sections.
1597 do_layout(Symbol_table
*, Layout
*, Read_symbols_data
*);
1599 // Layout sections whose layout was deferred while waiting for
1600 // input files from a plugin.
1602 do_layout_deferred_sections(Layout
*);
1604 // Add the symbols to the symbol table.
1606 do_add_symbols(Symbol_table
*, Read_symbols_data
*, Layout
*);
1608 Archive::Should_include
1609 do_should_include_member(Symbol_table
* symtab
, Layout
*, Read_symbols_data
*,
1612 // Iterate over global symbols, calling a visitor class V for each.
1614 do_for_all_global_symbols(Read_symbols_data
* sd
,
1615 Library_base::Symbol_visitor_base
* v
);
1617 // Iterate over local symbols, calling a visitor class V for each GOT offset
1618 // associated with a local symbol.
1620 do_for_all_local_got_entries(Got_offset_list::Visitor
* v
) const;
1622 // Get the size of a section.
1624 do_section_size(unsigned int shndx
);
1626 // Get the name of a section.
1628 do_section_name(unsigned int shndx
);
1630 // Return a view of the contents of a section.
1632 do_section_contents(unsigned int shndx
);
1634 // Return section flags.
1636 do_section_flags(unsigned int shndx
);
1638 // Return section entsize.
1640 do_section_entsize(unsigned int shndx
);
1642 // Return section address.
1644 do_section_address(unsigned int shndx
);
1646 // Return section type.
1648 do_section_type(unsigned int shndx
);
1650 // Return the section link field.
1652 do_section_link(unsigned int shndx
);
1654 // Return the section link field.
1656 do_section_info(unsigned int shndx
);
1658 // Return the section alignment.
1660 do_section_addralign(unsigned int shndx
);
1662 // Return the Xindex structure to use.
1664 do_initialize_xindex();
1666 // Get symbol counts.
1668 do_get_global_symbol_counts(const Symbol_table
*, size_t*, size_t*) const;
1670 // Get global symbols.
1672 do_get_global_symbols() const
1673 { return &this->symbols_
; }
1675 // Return the number of local symbols.
1677 do_local_symbol_count() const
1678 { return this->local_symbol_count_
; }
1680 // Return the number of local symbols in the output symbol table.
1682 do_output_local_symbol_count() const
1683 { return this->local_symbol_count_
; }
1685 // Return the file offset for local symbols in the output symbol table.
1687 do_local_symbol_offset() const
1688 { return this->local_symbol_offset_
; }
1692 do_read_relocs(Read_relocs_data
*);
1694 // Process the relocs to find list of referenced sections. Used only
1695 // during garbage collection.
1697 do_gc_process_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
1699 // Scan the relocs and adjust the symbol table.
1701 do_scan_relocs(Symbol_table
*, Layout
*, Read_relocs_data
*);
1703 // Count the local symbols.
1705 do_count_local_symbols(Stringpool_template
<char>*,
1706 Stringpool_template
<char>*);
1708 // Finalize the local symbols.
1710 do_finalize_local_symbols(unsigned int, off_t
, Symbol_table
*);
1712 // Set the offset where local dynamic symbol information will be stored.
1714 do_set_local_dynsym_indexes(unsigned int);
1716 // Set the offset where local dynamic symbol information will be stored.
1718 do_set_local_dynsym_offset(off_t
);
1720 // Relocate the input sections and write out the local symbols.
1722 do_relocate(const Symbol_table
* symtab
, const Layout
*, Output_file
* of
);
1724 // Set the offset of a section.
1726 do_set_section_offset(unsigned int shndx
, uint64_t off
);
1728 // The Incremental_binary base file.
1729 Sized_incremental_binary
<size
, big_endian
>* ibase_
;
1730 // The index of the object in the input file list.
1731 unsigned int input_file_index_
;
1732 // The reader for the input file.
1733 Input_entry_reader input_reader_
;
1734 // The number of local symbols.
1735 unsigned int local_symbol_count_
;
1736 // The number of local symbols which go into the output file's dynamic
1738 unsigned int output_local_dynsym_count_
;
1739 // This starting symbol index in the output symbol table.
1740 unsigned int local_symbol_index_
;
1741 // The file offset for local symbols in the output symbol table.
1742 unsigned int local_symbol_offset_
;
1743 // The file offset for local symbols in the output symbol table.
1744 unsigned int local_dynsym_offset_
;
1745 // The entries in the symbol table for the external symbols.
1747 // For each input section, the offset of the input section in its
1748 // output section. This is INVALID_ADDRESS if the input section requires a
1750 std::vector
<Address
> section_offsets_
;
1751 // The offset of the first incremental relocation for this object.
1752 unsigned int incr_reloc_offset_
;
1753 // The number of incremental relocations for this object.
1754 unsigned int incr_reloc_count_
;
1755 // The index of the first incremental relocation for this object in the
1756 // updated output file.
1757 unsigned int incr_reloc_output_index_
;
1758 // A copy of the incremental relocations from this object.
1759 unsigned char* incr_relocs_
;
1760 // The local symbols.
1761 std::vector
<Local_symbol
> local_symbols_
;
1764 // An incremental Dynobj. This class represents a shared object that has
1765 // not changed since the last incremental link, and whose contents can be
1766 // used directly from the base file.
1768 template<int size
, bool big_endian
>
1769 class Sized_incr_dynobj
: public Dynobj
1772 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1774 static const Address invalid_address
= static_cast<Address
>(0) - 1;
1776 Sized_incr_dynobj(const std::string
& name
,
1777 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1778 unsigned int input_file_index
);
1781 typedef Incremental_inputs_reader
<size
, big_endian
> Inputs_reader
;
1782 typedef typename
Inputs_reader::Incremental_input_entry_reader
1785 // Return TRUE if this is an incremental (unchanged) input file.
1787 do_is_incremental() const
1790 // Return the last modified time of the file.
1793 { return this->input_reader_
.get_mtime(); }
1795 // Read the symbols.
1797 do_read_symbols(Read_symbols_data
*);
1799 // Lay out the input sections.
1801 do_layout(Symbol_table
*, Layout
*, Read_symbols_data
*);
1803 // Add the symbols to the symbol table.
1805 do_add_symbols(Symbol_table
*, Read_symbols_data
*, Layout
*);
1807 Archive::Should_include
1808 do_should_include_member(Symbol_table
* symtab
, Layout
*, Read_symbols_data
*,
1811 // Iterate over global symbols, calling a visitor class V for each.
1813 do_for_all_global_symbols(Read_symbols_data
* sd
,
1814 Library_base::Symbol_visitor_base
* v
);
1816 // Iterate over local symbols, calling a visitor class V for each GOT offset
1817 // associated with a local symbol.
1819 do_for_all_local_got_entries(Got_offset_list::Visitor
* v
) const;
1821 // Get the size of a section.
1823 do_section_size(unsigned int shndx
);
1825 // Get the name of a section.
1827 do_section_name(unsigned int shndx
);
1829 // Return a view of the contents of a section.
1831 do_section_contents(unsigned int shndx
);
1833 // Return section flags.
1835 do_section_flags(unsigned int shndx
);
1837 // Return section entsize.
1839 do_section_entsize(unsigned int shndx
);
1841 // Return section address.
1843 do_section_address(unsigned int shndx
);
1845 // Return section type.
1847 do_section_type(unsigned int shndx
);
1849 // Return the section link field.
1851 do_section_link(unsigned int shndx
);
1853 // Return the section link field.
1855 do_section_info(unsigned int shndx
);
1857 // Return the section alignment.
1859 do_section_addralign(unsigned int shndx
);
1861 // Return the Xindex structure to use.
1863 do_initialize_xindex();
1865 // Get symbol counts.
1867 do_get_global_symbol_counts(const Symbol_table
*, size_t*, size_t*) const;
1869 // Get global symbols.
1871 do_get_global_symbols() const
1872 { return &this->symbols_
; }
1874 // The Incremental_binary base file.
1875 Sized_incremental_binary
<size
, big_endian
>* ibase_
;
1876 // The index of the object in the input file list.
1877 unsigned int input_file_index_
;
1878 // The reader for the input file.
1879 Input_entry_reader input_reader_
;
1880 // The entries in the symbol table for the external symbols.
1884 // Allocate an incremental object of the appropriate size and endianness.
1886 make_sized_incremental_object(
1887 Incremental_binary
* base
,
1888 unsigned int input_file_index
,
1889 Incremental_input_type input_type
,
1890 const Incremental_binary::Input_reader
* input_reader
);
1892 // This class represents an Archive library (or --start-lib/--end-lib group)
1893 // that has not changed since the last incremental link. Its contents come
1894 // from the incremental inputs entry in the base file.
1896 class Incremental_library
: public Library_base
1899 Incremental_library(const char* filename
, unsigned int input_file_index
,
1900 const Incremental_binary::Input_reader
* input_reader
)
1901 : Library_base(NULL
), filename_(filename
),
1902 input_file_index_(input_file_index
), input_reader_(input_reader
),
1903 unused_symbols_(), is_reported_(false)
1906 // Return the input file index.
1908 input_file_index() const
1909 { return this->input_file_index_
; }
1911 // Return the serial number of the input file.
1914 { return this->input_reader_
->arg_serial(); }
1916 // Copy the unused symbols from the incremental input info.
1917 // We need to do this because we may be overwriting the incremental
1918 // input info in the base file before we write the new incremental
1921 copy_unused_symbols();
1923 // Return FALSE on the first call to indicate that the library needs
1924 // to be recorded; return TRUE subsequently.
1928 bool was_reported
= this->is_reported_
;
1929 is_reported_
= true;
1930 return was_reported
;
1934 typedef std::vector
<std::string
> Symbol_list
;
1939 { return this->filename_
; }
1941 // Return the modification time of the archive file.
1944 { return this->input_reader_
->get_mtime(); }
1946 // Iterator for unused global symbols in the library.
1948 do_for_all_unused_symbols(Symbol_visitor_base
* v
) const;
1950 // The name of the library.
1951 std::string filename_
;
1952 // The input file index of this library.
1953 unsigned int input_file_index_
;
1954 // A reader for the incremental input information.
1955 const Incremental_binary::Input_reader
* input_reader_
;
1956 // List of unused symbols defined in this library.
1957 Symbol_list unused_symbols_
;
1958 // TRUE when this library has been reported to the new incremental info.
1962 } // End namespace gold.
1964 #endif // !defined(GOLD_INCREMENTAL_H)