+ // Size of the section.
+ off_t len_;
+};
+
+// Reader class for the .gnu_incremental_got_plt section.
+
+template<bool big_endian>
+class Incremental_got_plt_reader
+{
+ public:
+ Incremental_got_plt_reader()
+ : p_(NULL), got_count_(0), got_desc_p_(NULL), plt_desc_p_(NULL)
+ { }
+
+ Incremental_got_plt_reader(const unsigned char* p) : p_(p)
+ {
+ this->got_count_ = elfcpp::Swap<32, big_endian>::readval(p);
+ this->got_desc_p_ = p + 8 + ((this->got_count_ + 3) & ~3);
+ this->plt_desc_p_ = this->got_desc_p_ + this->got_count_ * 8;
+ }
+
+ // Return the GOT entry count.
+ unsigned int
+ get_got_entry_count() const
+ {
+ return this->got_count_;
+ }
+
+ // Return the PLT entry count.
+ unsigned int
+ get_plt_entry_count() const
+ {
+ return elfcpp::Swap<32, big_endian>::readval(this->p_ + 4);
+ }
+
+ // Return the GOT type for GOT entry N.
+ unsigned int
+ get_got_type(unsigned int n)
+ {
+ return this->p_[8 + n];
+ }
+
+ // Return the symbol index for GOT entry N.
+ unsigned int
+ get_got_symndx(unsigned int n)
+ {
+ return elfcpp::Swap<32, big_endian>::readval(this->got_desc_p_ + n * 8);
+ }
+
+ // Return the input file index for GOT entry N.
+ unsigned int
+ get_got_input_index(unsigned int n)
+ {
+ return elfcpp::Swap<32, big_endian>::readval(this->got_desc_p_ + n * 8 + 4);
+ }
+
+ // Return the PLT descriptor for PLT entry N.
+ unsigned int
+ get_plt_desc(unsigned int n)
+ {
+ return elfcpp::Swap<32, big_endian>::readval(this->plt_desc_p_ + n * 4);
+ }
+
+ private:
+ // Base address of the .gnu_incremental_got_plt section.
+ const unsigned char* p_;
+ // GOT entry count.
+ unsigned int got_count_;
+ // Base address of the GOT descriptor array.
+ const unsigned char* got_desc_p_;
+ // Base address of the PLT descriptor array.
+ const unsigned char* plt_desc_p_;
+};
+
+// An object representing the ELF file we edit during an incremental build.
+// Similar to Object or Dynobj, but operates on Output_file and contains
+// methods to support incremental updating. This is the abstract parent class
+// implemented in Sized_incremental_binary<size, big_endian> for a specific
+// endianness and size.
+
+class Incremental_binary
+{
+ public:
+ Incremental_binary(Output_file* output, Target* /*target*/)
+ : input_args_map_(), library_map_(), script_map_(),
+ output_(output)
+ { }
+
+ virtual
+ ~Incremental_binary()
+ { }
+
+ // Check the .gnu_incremental_inputs section to see whether an incremental
+ // build is possible.
+ bool
+ check_inputs(const Command_line& cmdline,
+ Incremental_inputs* incremental_inputs)
+ { return this->do_check_inputs(cmdline, incremental_inputs); }
+
+ // Report an error.
+ void
+ error(const char* format, ...) const ATTRIBUTE_PRINTF_2;
+
+ // Proxy class for a sized Incremental_input_entry_reader.
+
+ class Input_reader
+ {
+ public:
+ Input_reader()
+ { }
+
+ Input_reader(const Input_reader&)
+ { }
+
+ virtual
+ ~Input_reader()
+ { }
+
+ const char*
+ filename() const
+ { return this->do_filename(); }
+
+ Timespec
+ get_mtime() const
+ { return this->do_get_mtime(); }
+
+ Incremental_input_type
+ type() const
+ { return this->do_type(); }
+
+ unsigned int
+ arg_serial() const
+ { return this->do_arg_serial(); }
+
+ unsigned int
+ get_unused_symbol_count() const
+ { return this->do_get_unused_symbol_count(); }
+
+ const char*
+ get_unused_symbol(unsigned int n) const
+ { return this->do_get_unused_symbol(n); }
+
+ protected:
+ virtual const char*
+ do_filename() const = 0;
+
+ virtual Timespec
+ do_get_mtime() const = 0;
+
+ virtual Incremental_input_type
+ do_type() const = 0;
+
+ virtual unsigned int
+ do_arg_serial() const = 0;
+
+ virtual unsigned int
+ do_get_unused_symbol_count() const = 0;
+
+ virtual const char*
+ do_get_unused_symbol(unsigned int n) const = 0;
+ };
+
+ // Return the number of input files.
+ unsigned int
+ input_file_count() const
+ { return this->do_input_file_count(); }
+
+ // Return an Input_reader for input file N.
+ const Input_reader*
+ get_input_reader(unsigned int n) const
+ { return this->do_get_input_reader(n); }
+
+ // Return TRUE if the input file N has changed since the last link.
+ bool
+ file_has_changed(unsigned int n) const
+ { return this->do_file_has_changed(n); }
+
+ // Return the Input_argument for input file N. Returns NULL if
+ // the Input_argument is not available.
+ const Input_argument*
+ get_input_argument(unsigned int n) const
+ {
+ const Input_reader* input_file = this->do_get_input_reader(n);
+ unsigned int arg_serial = input_file->arg_serial();
+ if (arg_serial == 0 || arg_serial > this->input_args_map_.size())
+ return NULL;
+ return this->input_args_map_[arg_serial - 1];
+ }
+
+ // Return an Incremental_library for the given input file.
+ Incremental_library*
+ get_library(unsigned int n) const
+ { return this->library_map_[n]; }
+
+ // Return a Script_info for the given input file.
+ Script_info*
+ get_script_info(unsigned int n) const
+ { return this->script_map_[n]; }
+
+ // Initialize the layout of the output file based on the existing
+ // output file.
+ void
+ init_layout(Layout* layout)
+ { this->do_init_layout(layout); }
+
+ // Mark regions of the input file that must be kept unchanged.
+ void
+ reserve_layout(unsigned int input_file_index)
+ { this->do_reserve_layout(input_file_index); }
+
+ // Process the GOT and PLT entries from the existing output file.
+ void
+ process_got_plt(Symbol_table* symtab, Layout* layout)
+ { this->do_process_got_plt(symtab, layout); }
+
+ // Emit COPY relocations from the existing output file.
+ void
+ emit_copy_relocs(Symbol_table* symtab)
+ { this->do_emit_copy_relocs(symtab); }
+
+ // Apply incremental relocations for symbols whose values have changed.
+ void
+ apply_incremental_relocs(const Symbol_table* symtab, Layout* layout,
+ Output_file* of)
+ { this->do_apply_incremental_relocs(symtab, layout, of); }
+
+ // Functions and types for the elfcpp::Elf_file interface. This
+ // permit us to use Incremental_binary as the File template parameter for
+ // elfcpp::Elf_file.
+
+ // The View class is returned by view. It must support a single
+ // method, data(). This is trivial, because Output_file::get_output_view
+ // does what we need.
+ class View
+ {
+ public:
+ View(const unsigned char* p)
+ : p_(p)
+ { }
+
+ const unsigned char*
+ data() const
+ { return this->p_; }
+
+ private:
+ const unsigned char* p_;
+ };
+
+ // Return a View.
+ View
+ view(off_t file_offset, section_size_type data_size)
+ { return View(this->output_->get_input_view(file_offset, data_size)); }
+
+ // A location in the file.
+ struct Location
+ {
+ off_t file_offset;
+ off_t data_size;
+
+ Location(off_t fo, section_size_type ds)
+ : file_offset(fo), data_size(ds)
+ { }
+
+ Location()
+ : file_offset(0), data_size(0)
+ { }
+ };
+
+ // Get a View given a Location.
+ View
+ view(Location loc)
+ { return View(this->view(loc.file_offset, loc.data_size)); }
+
+ // Return the Output_file.
+ Output_file*
+ output_file()
+ { return this->output_; }
+
+ protected:
+ // Check the .gnu_incremental_inputs section to see whether an incremental
+ // build is possible.
+ virtual bool
+ do_check_inputs(const Command_line& cmdline,
+ Incremental_inputs* incremental_inputs) = 0;
+
+ // Return TRUE if input file N has changed since the last incremental link.
+ virtual bool
+ do_file_has_changed(unsigned int n) const = 0;
+
+ // Initialize the layout of the output file based on the existing
+ // output file.
+ virtual void
+ do_init_layout(Layout* layout) = 0;
+
+ // Mark regions of the input file that must be kept unchanged.
+ virtual void
+ do_reserve_layout(unsigned int input_file_index) = 0;
+
+ // Process the GOT and PLT entries from the existing output file.
+ virtual void
+ do_process_got_plt(Symbol_table* symtab, Layout* layout) = 0;
+
+ // Emit COPY relocations from the existing output file.
+ virtual void
+ do_emit_copy_relocs(Symbol_table* symtab) = 0;
+
+ // Apply incremental relocations for symbols whose values have changed.
+ virtual void
+ do_apply_incremental_relocs(const Symbol_table*, Layout*, Output_file*) = 0;
+
+ virtual unsigned int
+ do_input_file_count() const = 0;
+
+ virtual const Input_reader*
+ do_get_input_reader(unsigned int) const = 0;
+
+ // Map from input file index to Input_argument.
+ std::vector<const Input_argument*> input_args_map_;
+ // Map from an input file index to an Incremental_library.
+ std::vector<Incremental_library*> library_map_;
+ // Map from an input file index to a Script_info.
+ std::vector<Script_info*> script_map_;
+
+ private:
+ // Edited output file object.
+ Output_file* output_;
+};
+
+template<int size, bool big_endian>
+class Sized_relobj_incr;
+
+template<int size, bool big_endian>
+class Sized_incremental_binary : public Incremental_binary
+{
+ public:
+ Sized_incremental_binary(Output_file* output,
+ const elfcpp::Ehdr<size, big_endian>& ehdr,
+ Target* target)
+ : Incremental_binary(output, target), elf_file_(this, ehdr),
+ input_objects_(), section_map_(), symbol_map_(), copy_relocs_(),
+ main_symtab_loc_(), main_strtab_loc_(), has_incremental_info_(false),
+ inputs_reader_(), symtab_reader_(), relocs_reader_(), got_plt_reader_(),
+ input_entry_readers_()
+ { this->setup_readers(); }
+
+ // Returns TRUE if the file contains incremental info.
+ bool
+ has_incremental_info() const
+ { return this->has_incremental_info_; }
+
+ // Record a pointer to the object for input file N.
+ void
+ set_input_object(unsigned int n,
+ Sized_relobj_incr<size, big_endian>* obj)
+ { this->input_objects_[n] = obj; }
+
+ // Return a pointer to the object for input file N.
+ Sized_relobj_incr<size, big_endian>*
+ input_object(unsigned int n) const
+ {
+ gold_assert(n < this->input_objects_.size());
+ return this->input_objects_[n];
+ }
+
+ // Return the Output_section for section index SHNDX.
+ Output_section*
+ output_section(unsigned int shndx)
+ { return this->section_map_[shndx]; }
+
+ // Map a symbol table entry from the base file to the output symbol table.
+ // SYMNDX is relative to the first forced-local or global symbol in the
+ // input file symbol table.
+ void
+ add_global_symbol(unsigned int symndx, Symbol* gsym)
+ { this->symbol_map_[symndx] = gsym; }
+
+ // Map a symbol table entry from the base file to the output symbol table.
+ // SYMNDX is relative to the first forced-local or global symbol in the
+ // input file symbol table.
+ Symbol*
+ global_symbol(unsigned int symndx) const
+ { return this->symbol_map_[symndx]; }
+
+ // Add a COPY relocation for a global symbol.
+ void
+ add_copy_reloc(Symbol* gsym, Output_section* os, off_t offset)
+ { this->copy_relocs_.push_back(Copy_reloc(gsym, os, offset)); }
+
+ // Readers for the incremental info sections.
+
+ const Incremental_inputs_reader<size, big_endian>&
+ inputs_reader() const
+ { return this->inputs_reader_; }
+
+ const Incremental_symtab_reader<big_endian>&
+ symtab_reader() const
+ { return this->symtab_reader_; }
+
+ const Incremental_relocs_reader<size, big_endian>&
+ relocs_reader() const
+ { return this->relocs_reader_; }
+
+ const Incremental_got_plt_reader<big_endian>&
+ got_plt_reader() const
+ { return this->got_plt_reader_; }
+
+ void
+ get_symtab_view(View* symtab_view, unsigned int* sym_count,
+ elfcpp::Elf_strtab* strtab);
+
+ protected:
+ typedef Incremental_inputs_reader<size, big_endian> Inputs_reader;
+ typedef typename Inputs_reader::Incremental_input_entry_reader
+ Input_entry_reader;
+
+ virtual bool
+ do_check_inputs(const Command_line& cmdline,
+ Incremental_inputs* incremental_inputs);
+
+ // Return TRUE if input file N has changed since the last incremental link.
+ virtual bool
+ do_file_has_changed(unsigned int n) const;
+
+ // Initialize the layout of the output file based on the existing
+ // output file.
+ virtual void
+ do_init_layout(Layout* layout);
+
+ // Mark regions of the input file that must be kept unchanged.
+ virtual void
+ do_reserve_layout(unsigned int input_file_index);
+
+ // Process the GOT and PLT entries from the existing output file.
+ virtual void
+ do_process_got_plt(Symbol_table* symtab, Layout* layout);
+
+ // Emit COPY relocations from the existing output file.
+ virtual void
+ do_emit_copy_relocs(Symbol_table* symtab);
+
+ // Apply incremental relocations for symbols whose values have changed.
+ virtual void
+ do_apply_incremental_relocs(const Symbol_table* symtab, Layout* layout,
+ Output_file* of);
+
+ // Proxy class for a sized Incremental_input_entry_reader.
+
+ class Sized_input_reader : public Input_reader
+ {
+ public:
+ Sized_input_reader(Input_entry_reader r)
+ : Input_reader(), reader_(r)
+ { }
+
+ Sized_input_reader(const Sized_input_reader& r)
+ : Input_reader(), reader_(r.reader_)
+ { }
+
+ virtual
+ ~Sized_input_reader()
+ { }
+
+ private:
+ const char*
+ do_filename() const
+ { return this->reader_.filename(); }
+
+ Timespec
+ do_get_mtime() const
+ { return this->reader_.get_mtime(); }
+
+ Incremental_input_type
+ do_type() const
+ { return this->reader_.type(); }
+
+ unsigned int
+ do_arg_serial() const
+ { return this->reader_.arg_serial(); }
+
+ unsigned int
+ do_get_unused_symbol_count() const
+ { return this->reader_.get_unused_symbol_count(); }
+
+ const char*
+ do_get_unused_symbol(unsigned int n) const
+ { return this->reader_.get_unused_symbol(n); }
+
+ Input_entry_reader reader_;
+ };
+
+ virtual unsigned int
+ do_input_file_count() const
+ { return this->inputs_reader_.input_file_count(); }
+
+ virtual const Input_reader*
+ do_get_input_reader(unsigned int n) const
+ {
+ gold_assert(n < this->input_entry_readers_.size());
+ return &this->input_entry_readers_[n];
+ }
+
+ private:
+ // List of symbols that need COPY relocations.
+ struct Copy_reloc
+ {
+ Copy_reloc(Symbol* sym, Output_section* os, off_t off)
+ : symbol(sym), output_section(os), offset(off)
+ { }
+
+ // The global symbol to copy.
+ Symbol* symbol;
+ // The output section into which the symbol was copied.
+ Output_section* output_section;
+ // The offset within that output section.
+ off_t offset;
+ };
+ typedef std::vector<Copy_reloc> Copy_relocs;
+
+ bool
+ find_incremental_inputs_sections(unsigned int* p_inputs_shndx,
+ unsigned int* p_symtab_shndx,
+ unsigned int* p_relocs_shndx,
+ unsigned int* p_got_plt_shndx,
+ unsigned int* p_strtab_shndx);
+
+ void
+ setup_readers();
+
+ // Output as an ELF file.
+ elfcpp::Elf_file<size, big_endian, Incremental_binary> elf_file_;
+
+ // Vector of pointers to the input objects for the unchanged files.
+ // For replaced files, the corresponding pointer is NULL.
+ std::vector<Sized_relobj_incr<size, big_endian>*> input_objects_;
+
+ // Map section index to an Output_section in the updated layout.
+ std::vector<Output_section*> section_map_;
+
+ // Map global symbols from the input file to the symbol table.
+ std::vector<Symbol*> symbol_map_;
+
+ // List of symbols that need COPY relocations.
+ Copy_relocs copy_relocs_;
+
+ // Locations of the main symbol table and symbol string table.
+ Location main_symtab_loc_;
+ Location main_strtab_loc_;
+
+ // Readers for the incremental info sections.
+ bool has_incremental_info_;
+ Incremental_inputs_reader<size, big_endian> inputs_reader_;
+ Incremental_symtab_reader<big_endian> symtab_reader_;
+ Incremental_relocs_reader<size, big_endian> relocs_reader_;
+ Incremental_got_plt_reader<big_endian> got_plt_reader_;
+ std::vector<Sized_input_reader> input_entry_readers_;
+};
+
+// An incremental Relobj. This class represents a relocatable object
+// that has not changed since the last incremental link, and whose contents
+// can be used directly from the base file.
+
+template<int size, bool big_endian>
+class Sized_relobj_incr : public Sized_relobj<size, big_endian>
+{
+ public:
+ typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
+ typedef typename Sized_relobj<size, big_endian>::Symbols Symbols;
+
+ Sized_relobj_incr(const std::string& name,
+ Sized_incremental_binary<size, big_endian>* ibase,
+ unsigned int input_file_index);
+
+ private:
+ // For convenience.
+ typedef Sized_relobj_incr<size, big_endian> This;
+ static const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
+
+ typedef typename Sized_relobj<size, big_endian>::Output_sections
+ Output_sections;
+ typedef Incremental_inputs_reader<size, big_endian> Inputs_reader;
+ typedef typename Inputs_reader::Incremental_input_entry_reader
+ Input_entry_reader;
+
+ // A local symbol.
+ struct Local_symbol
+ {
+ Local_symbol(const char* name_, Address value_, unsigned int size_,
+ unsigned int shndx_, unsigned int type_,
+ bool needs_dynsym_entry_)
+ : st_value(value_), name(name_), st_size(size_), st_shndx(shndx_),
+ st_type(type_), output_dynsym_index(0),
+ needs_dynsym_entry(needs_dynsym_entry_)
+ { }
+ // The symbol value.
+ Address st_value;
+ // The symbol name. This points to the stringpool entry.
+ const char* name;
+ // The symbol size.
+ unsigned int st_size;
+ // The output section index.
+ unsigned int st_shndx : 28;
+ // The symbol type.
+ unsigned int st_type : 4;
+ // The index of the symbol in the output dynamic symbol table.
+ unsigned int output_dynsym_index : 31;
+ // TRUE if the symbol needs to appear in the dynamic symbol table.
+ unsigned int needs_dynsym_entry : 1;
+ };
+
+ // Return TRUE if this is an incremental (unchanged) input file.
+ bool
+ do_is_incremental() const
+ { return true; }
+
+ // Return the last modified time of the file.
+ Timespec
+ do_get_mtime()
+ { return this->input_reader_.get_mtime(); }
+
+ // Read the symbols.
+ void
+ do_read_symbols(Read_symbols_data*);
+
+ // Lay out the input sections.
+ void
+ do_layout(Symbol_table*, Layout*, Read_symbols_data*);
+
+ // Layout sections whose layout was deferred while waiting for
+ // input files from a plugin.
+ void
+ do_layout_deferred_sections(Layout*);
+
+ // Add the symbols to the symbol table.
+ void
+ do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
+
+ Archive::Should_include
+ do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
+ std::string* why);
+
+ // Iterate over global symbols, calling a visitor class V for each.
+ void
+ do_for_all_global_symbols(Read_symbols_data* sd,
+ Library_base::Symbol_visitor_base* v);
+
+ // Get the size of a section.
+ uint64_t
+ do_section_size(unsigned int shndx);
+
+ // Get the name of a section.
+ std::string
+ do_section_name(unsigned int shndx) const;
+
+ // Return a view of the contents of a section.
+ const unsigned char*
+ do_section_contents(unsigned int shndx, section_size_type* plen,
+ bool cache);
+
+ // Return section flags.
+ uint64_t
+ do_section_flags(unsigned int shndx);
+
+ // Return section entsize.
+ uint64_t
+ do_section_entsize(unsigned int shndx);
+
+ // Return section address.
+ uint64_t
+ do_section_address(unsigned int shndx);
+
+ // Return section type.
+ unsigned int
+ do_section_type(unsigned int shndx);
+
+ // Return the section link field.
+ unsigned int
+ do_section_link(unsigned int shndx);
+
+ // Return the section link field.
+ unsigned int
+ do_section_info(unsigned int shndx);
+
+ // Return the section alignment.
+ uint64_t
+ do_section_addralign(unsigned int shndx);
+
+ // Return the Xindex structure to use.
+ Xindex*
+ do_initialize_xindex();
+
+ // Get symbol counts.
+ void
+ do_get_global_symbol_counts(const Symbol_table*, size_t*, size_t*) const;
+
+ // Get global symbols.
+ const Symbols*
+ do_get_global_symbols() const
+ { return &this->symbols_; }
+
+ // Return the value of a local symbol.
+ uint64_t
+ do_local_symbol_value(unsigned int, uint64_t) const
+ { gold_unreachable(); }
+
+ unsigned int
+ do_local_plt_offset(unsigned int) const
+ { gold_unreachable(); }
+
+ bool
+ do_local_is_tls(unsigned int) const
+ { gold_unreachable(); }
+
+ // Return the number of local symbols.
+ unsigned int
+ do_local_symbol_count() const
+ { return this->local_symbol_count_; }
+
+ // Return the number of local symbols in the output symbol table.
+ unsigned int
+ do_output_local_symbol_count() const
+ { return this->local_symbol_count_; }
+
+ // Return the file offset for local symbols in the output symbol table.
+ off_t
+ do_local_symbol_offset() const
+ { return this->local_symbol_offset_; }
+
+ // Read the relocs.
+ void
+ do_read_relocs(Read_relocs_data*);
+
+ // Process the relocs to find list of referenced sections. Used only
+ // during garbage collection.
+ void
+ do_gc_process_relocs(Symbol_table*, Layout*, Read_relocs_data*);
+
+ // Scan the relocs and adjust the symbol table.
+ void
+ do_scan_relocs(Symbol_table*, Layout*, Read_relocs_data*);
+
+ // Count the local symbols.
+ void
+ do_count_local_symbols(Stringpool_template<char>*,
+ Stringpool_template<char>*);
+
+ // Finalize the local symbols.
+ unsigned int
+ do_finalize_local_symbols(unsigned int, off_t, Symbol_table*);
+
+ // Set the offset where local dynamic symbol information will be stored.
+ unsigned int
+ do_set_local_dynsym_indexes(unsigned int);
+
+ // Set the offset where local dynamic symbol information will be stored.
+ unsigned int
+ do_set_local_dynsym_offset(off_t);
+
+ // Relocate the input sections and write out the local symbols.
+ void
+ do_relocate(const Symbol_table* symtab, const Layout*, Output_file* of);
+
+ // Set the offset of a section.
+ void
+ do_set_section_offset(unsigned int shndx, uint64_t off);
+
+ // The Incremental_binary base file.
+ Sized_incremental_binary<size, big_endian>* ibase_;
+ // The index of the object in the input file list.
+ unsigned int input_file_index_;
+ // The reader for the input file.
+ Input_entry_reader input_reader_;
+ // The number of local symbols.
+ unsigned int local_symbol_count_;
+ // The number of local symbols which go into the output file's dynamic
+ // symbol table.
+ unsigned int output_local_dynsym_count_;
+ // This starting symbol index in the output symbol table.
+ unsigned int local_symbol_index_;
+ // The file offset for local symbols in the output symbol table.
+ unsigned int local_symbol_offset_;
+ // The file offset for local symbols in the output symbol table.
+ unsigned int local_dynsym_offset_;
+ // The entries in the symbol table for the external symbols.
+ Symbols symbols_;
+ // Number of symbols defined in object file itself.
+ size_t defined_count_;
+ // The offset of the first incremental relocation for this object.
+ unsigned int incr_reloc_offset_;
+ // The number of incremental relocations for this object.
+ unsigned int incr_reloc_count_;
+ // The index of the first incremental relocation for this object in the
+ // updated output file.
+ unsigned int incr_reloc_output_index_;
+ // A copy of the incremental relocations from this object.
+ unsigned char* incr_relocs_;
+ // The local symbols.
+ std::vector<Local_symbol> local_symbols_;
+};
+
+// An incremental Dynobj. This class represents a shared object that has
+// not changed since the last incremental link, and whose contents can be
+// used directly from the base file.
+
+template<int size, bool big_endian>
+class Sized_incr_dynobj : public Dynobj
+{
+ public:
+ typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
+
+ static const Address invalid_address = static_cast<Address>(0) - 1;
+
+ Sized_incr_dynobj(const std::string& name,
+ Sized_incremental_binary<size, big_endian>* ibase,
+ unsigned int input_file_index);
+
+ private:
+ typedef Incremental_inputs_reader<size, big_endian> Inputs_reader;
+ typedef typename Inputs_reader::Incremental_input_entry_reader
+ Input_entry_reader;
+
+ // Return TRUE if this is an incremental (unchanged) input file.
+ bool
+ do_is_incremental() const
+ { return true; }
+
+ // Return the last modified time of the file.
+ Timespec
+ do_get_mtime()
+ { return this->input_reader_.get_mtime(); }
+
+ // Read the symbols.
+ void
+ do_read_symbols(Read_symbols_data*);
+
+ // Lay out the input sections.
+ void
+ do_layout(Symbol_table*, Layout*, Read_symbols_data*);
+
+ // Add the symbols to the symbol table.
+ void
+ do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*);
+
+ Archive::Should_include
+ do_should_include_member(Symbol_table* symtab, Layout*, Read_symbols_data*,
+ std::string* why);
+
+ // Iterate over global symbols, calling a visitor class V for each.
+ void
+ do_for_all_global_symbols(Read_symbols_data* sd,
+ Library_base::Symbol_visitor_base* v);
+
+ // Iterate over local symbols, calling a visitor class V for each GOT offset
+ // associated with a local symbol.
+ void
+ do_for_all_local_got_entries(Got_offset_list::Visitor* v) const;
+
+ // Get the size of a section.
+ uint64_t
+ do_section_size(unsigned int shndx);
+
+ // Get the name of a section.
+ std::string
+ do_section_name(unsigned int shndx) const;
+
+ // Return a view of the contents of a section.
+ const unsigned char*
+ do_section_contents(unsigned int shndx, section_size_type* plen,
+ bool cache);
+
+ // Return section flags.
+ uint64_t
+ do_section_flags(unsigned int shndx);
+
+ // Return section entsize.
+ uint64_t
+ do_section_entsize(unsigned int shndx);
+
+ // Return section address.
+ uint64_t
+ do_section_address(unsigned int shndx);
+
+ // Return section type.
+ unsigned int
+ do_section_type(unsigned int shndx);
+
+ // Return the section link field.
+ unsigned int
+ do_section_link(unsigned int shndx);
+
+ // Return the section link field.
+ unsigned int
+ do_section_info(unsigned int shndx);
+
+ // Return the section alignment.
+ uint64_t
+ do_section_addralign(unsigned int shndx);
+
+ // Return the Xindex structure to use.
+ Xindex*
+ do_initialize_xindex();
+
+ // Get symbol counts.
+ void
+ do_get_global_symbol_counts(const Symbol_table*, size_t*, size_t*) const;
+
+ // Get global symbols.
+ const Symbols*
+ do_get_global_symbols() const
+ { return &this->symbols_; }
+
+ // The Incremental_binary base file.
+ Sized_incremental_binary<size, big_endian>* ibase_;
+ // The index of the object in the input file list.
+ unsigned int input_file_index_;
+ // The reader for the input file.
+ Input_entry_reader input_reader_;
+ // The entries in the symbol table for the external symbols.
+ Symbols symbols_;
+ // Number of symbols defined in object file itself.
+ size_t defined_count_;
+};
+
+// Allocate an incremental object of the appropriate size and endianness.
+extern Object*
+make_sized_incremental_object(
+ Incremental_binary* base,
+ unsigned int input_file_index,
+ Incremental_input_type input_type,
+ const Incremental_binary::Input_reader* input_reader);
+
+// This class represents an Archive library (or --start-lib/--end-lib group)
+// that has not changed since the last incremental link. Its contents come
+// from the incremental inputs entry in the base file.
+
+class Incremental_library : public Library_base
+{
+ public:
+ Incremental_library(const char* filename, unsigned int input_file_index,
+ const Incremental_binary::Input_reader* input_reader)
+ : Library_base(NULL), filename_(filename),
+ input_file_index_(input_file_index), input_reader_(input_reader),
+ unused_symbols_(), is_reported_(false)
+ { }
+
+ // Return the input file index.
+ unsigned int
+ input_file_index() const
+ { return this->input_file_index_; }
+
+ // Return the serial number of the input file.
+ unsigned int
+ arg_serial() const
+ { return this->input_reader_->arg_serial(); }
+
+ // Copy the unused symbols from the incremental input info.
+ // We need to do this because we may be overwriting the incremental
+ // input info in the base file before we write the new incremental
+ // info.
+ void
+ copy_unused_symbols();
+
+ // Return FALSE on the first call to indicate that the library needs
+ // to be recorded; return TRUE subsequently.
+ bool
+ is_reported()
+ {
+ bool was_reported = this->is_reported_;
+ is_reported_ = true;
+ return was_reported;
+ }
+
+ private:
+ typedef std::vector<std::string> Symbol_list;
+
+ // The file name.
+ const std::string&
+ do_filename() const
+ { return this->filename_; }
+
+ // Return the modification time of the archive file.
+ Timespec
+ do_get_mtime()
+ { return this->input_reader_->get_mtime(); }
+
+ // Iterator for unused global symbols in the library.
+ void
+ do_for_all_unused_symbols(Symbol_visitor_base* v) const;
+
+ // The name of the library.
+ std::string filename_;
+ // The input file index of this library.
+ unsigned int input_file_index_;
+ // A reader for the incremental input information.
+ const Incremental_binary::Input_reader* input_reader_;
+ // List of unused symbols defined in this library.
+ Symbol_list unused_symbols_;
+ // TRUE when this library has been reported to the new incremental info.
+ bool is_reported_;