+// Write the supplemental information blocks.
+
+template<int size, bool big_endian>
+unsigned char*
+Output_section_incremental_inputs<size, big_endian>::write_info_blocks(
+ unsigned char* oview,
+ unsigned char* pov,
+ Stringpool* strtab,
+ unsigned int* global_syms,
+ unsigned int global_sym_count)
+{
+ const Incremental_inputs* inputs = this->inputs_;
+ unsigned int first_global_index = this->symtab_->first_global_index();
+
+ for (Incremental_inputs::Input_list::const_iterator p =
+ inputs->input_files().begin();
+ p != inputs->input_files().end();
+ ++p)
+ {
+ switch ((*p)->type())
+ {
+ case INCREMENTAL_INPUT_SCRIPT:
+ {
+ gold_assert(static_cast<unsigned int>(pov - oview)
+ == (*p)->get_info_offset());
+ Incremental_script_entry* entry = (*p)->script_entry();
+ gold_assert(entry != NULL);
+
+ // Write the object count.
+ unsigned int nobjects = entry->get_object_count();
+ Swap32::writeval(pov, nobjects);
+ pov += 4;
+
+ // For each object, write the offset to its input file entry.
+ for (unsigned int i = 0; i < nobjects; ++i)
+ {
+ Incremental_input_entry* obj = entry->get_object(i);
+ Swap32::writeval(pov, obj->get_offset());
+ pov += 4;
+ }
+ }
+ break;
+
+ case INCREMENTAL_INPUT_OBJECT:
+ case INCREMENTAL_INPUT_ARCHIVE_MEMBER:
+ {
+ gold_assert(static_cast<unsigned int>(pov - oview)
+ == (*p)->get_info_offset());
+ Incremental_object_entry* entry = (*p)->object_entry();
+ gold_assert(entry != NULL);
+ const Object* obj = entry->object();
+ const Relobj* relobj = static_cast<const Relobj*>(obj);
+ const Object::Symbols* syms = obj->get_global_symbols();
+ // Write the input section count and global symbol count.
+ unsigned int nsections = entry->get_input_section_count();
+ unsigned int nsyms = syms->size();
+ off_t locals_offset = relobj->local_symbol_offset();
+ unsigned int nlocals = relobj->output_local_symbol_count();
+ unsigned int first_dynrel = relobj->first_dyn_reloc();
+ unsigned int ndynrel = relobj->dyn_reloc_count();
+ unsigned int ncomdat = entry->get_comdat_group_count();
+ Swap32::writeval(pov, nsections);
+ Swap32::writeval(pov + 4, nsyms);
+ Swap32::writeval(pov + 8, static_cast<unsigned int>(locals_offset));
+ Swap32::writeval(pov + 12, nlocals);
+ Swap32::writeval(pov + 16, first_dynrel);
+ Swap32::writeval(pov + 20, ndynrel);
+ Swap32::writeval(pov + 24, ncomdat);
+ Swap32::writeval(pov + 28, 0);
+ gold_assert(this->object_info_size == 32);
+ pov += this->object_info_size;
+
+ // Build a temporary array to map input section indexes
+ // from the original object file index to the index in the
+ // incremental info table.
+ unsigned int* index_map = new unsigned int[obj->shnum()];
+ memset(index_map, 0, obj->shnum() * sizeof(unsigned int));
+
+ // For each input section, write the name, output section index,
+ // offset within output section, and input section size.
+ for (unsigned int i = 0; i < nsections; i++)
+ {
+ unsigned int shndx = entry->get_input_section_index(i);
+ index_map[shndx] = i + 1;
+ Stringpool::Key key = entry->get_input_section_name_key(i);
+ off_t name_offset = 0;
+ if (key != 0)
+ name_offset = strtab->get_offset_from_key(key);
+ int out_shndx = 0;
+ off_t out_offset = 0;
+ off_t sh_size = 0;
+ Output_section* os = obj->output_section(shndx);
+ if (os != NULL)
+ {
+ out_shndx = os->out_shndx();
+ out_offset = obj->output_section_offset(shndx);
+ sh_size = entry->get_input_section_size(i);
+ }
+ Swap32::writeval(pov, name_offset);
+ Swap32::writeval(pov + 4, out_shndx);
+ Swap::writeval(pov + 8, out_offset);
+ Swap::writeval(pov + 8 + sizeof_addr, sh_size);
+ gold_assert(this->input_section_entry_size
+ == 8 + 2 * sizeof_addr);
+ pov += this->input_section_entry_size;
+ }
+
+ // For each global symbol, write its associated relocations,
+ // add it to the linked list of globals, then write the
+ // supplemental information: global symbol table index,
+ // input section index, linked list chain pointer, relocation
+ // count, and offset to the relocations.
+ for (unsigned int i = 0; i < nsyms; i++)
+ {
+ const Symbol* sym = (*syms)[i];
+ if (sym->is_forwarder())
+ sym = this->symtab_->resolve_forwards(sym);
+ unsigned int shndx = 0;
+ if (sym->source() != Symbol::FROM_OBJECT)
+ {
+ // The symbol was defined by the linker (e.g., common).
+ // We mark these symbols with a special SHNDX of -1,
+ // but exclude linker-predefined symbols and symbols
+ // copied from shared objects.
+ if (!sym->is_predefined()
+ && !sym->is_copied_from_dynobj())
+ shndx = -1U;
+ }
+ else if (sym->object() == obj && sym->is_defined())
+ {
+ bool is_ordinary;
+ unsigned int orig_shndx = sym->shndx(&is_ordinary);
+ if (is_ordinary)
+ shndx = index_map[orig_shndx];
+ else
+ shndx = 1;
+ }
+ unsigned int symtab_index = sym->symtab_index();
+ unsigned int chain = 0;
+ unsigned int first_reloc = 0;
+ unsigned int nrelocs = obj->get_incremental_reloc_count(i);
+ if (nrelocs > 0)
+ {
+ gold_assert(symtab_index != -1U
+ && (symtab_index - first_global_index
+ < global_sym_count));
+ first_reloc = obj->get_incremental_reloc_base(i);
+ chain = global_syms[symtab_index - first_global_index];
+ global_syms[symtab_index - first_global_index] =
+ pov - oview;
+ }
+ Swap32::writeval(pov, symtab_index);
+ Swap32::writeval(pov + 4, shndx);
+ Swap32::writeval(pov + 8, chain);
+ Swap32::writeval(pov + 12, nrelocs);
+ Swap32::writeval(pov + 16,
+ first_reloc * (8 + 2 * sizeof_addr));
+ gold_assert(this->global_sym_entry_size == 20);
+ pov += this->global_sym_entry_size;
+ }
+
+ // For each kept COMDAT group, write the group signature.
+ for (unsigned int i = 0; i < ncomdat; i++)
+ {
+ Stringpool::Key key = entry->get_comdat_signature_key(i);
+ off_t name_offset = 0;
+ if (key != 0)
+ name_offset = strtab->get_offset_from_key(key);
+ Swap32::writeval(pov, name_offset);
+ pov += 4;
+ }
+
+ delete[] index_map;
+ }
+ break;
+
+ case INCREMENTAL_INPUT_SHARED_LIBRARY:
+ {
+ gold_assert(static_cast<unsigned int>(pov - oview)
+ == (*p)->get_info_offset());
+ Incremental_dynobj_entry* entry = (*p)->dynobj_entry();
+ gold_assert(entry != NULL);
+ Object* obj = entry->object();
+ Dynobj* dynobj = obj->dynobj();
+ gold_assert(dynobj != NULL);
+ const Object::Symbols* syms = obj->get_global_symbols();
+
+ // Write the soname string table index.
+ section_offset_type soname_offset =
+ strtab->get_offset_from_key(entry->get_soname_key());
+ Swap32::writeval(pov, soname_offset);
+ pov += 4;
+
+ // Skip the global symbol count for now.
+ unsigned char* orig_pov = pov;
+ pov += 4;
+
+ // For each global symbol, write the global symbol table index.
+ unsigned int nsyms = syms->size();
+ unsigned int nsyms_out = 0;
+ for (unsigned int i = 0; i < nsyms; i++)
+ {
+ const Symbol* sym = (*syms)[i];
+ if (sym == NULL)
+ continue;
+ if (sym->is_forwarder())
+ sym = this->symtab_->resolve_forwards(sym);
+ if (sym->symtab_index() == -1U)
+ continue;
+ unsigned int flags = 0;
+ // If the symbol has hidden or internal visibility, we
+ // mark it as defined in the shared object so we don't
+ // try to resolve it during an incremental update.
+ if (sym->visibility() == elfcpp::STV_HIDDEN
+ || sym->visibility() == elfcpp::STV_INTERNAL)
+ flags = INCREMENTAL_SHLIB_SYM_DEF;
+ else if (sym->source() == Symbol::FROM_OBJECT
+ && sym->object() == obj
+ && sym->is_defined())
+ flags = INCREMENTAL_SHLIB_SYM_DEF;
+ else if (sym->is_copied_from_dynobj()
+ && this->symtab_->get_copy_source(sym) == dynobj)
+ flags = INCREMENTAL_SHLIB_SYM_COPY;
+ flags <<= INCREMENTAL_SHLIB_SYM_FLAGS_SHIFT;
+ Swap32::writeval(pov, sym->symtab_index() | flags);
+ pov += 4;
+ ++nsyms_out;
+ }
+
+ // Now write the global symbol count.
+ Swap32::writeval(orig_pov, nsyms_out);
+ }
+ break;
+
+ case INCREMENTAL_INPUT_ARCHIVE:
+ {
+ gold_assert(static_cast<unsigned int>(pov - oview)
+ == (*p)->get_info_offset());
+ Incremental_archive_entry* entry = (*p)->archive_entry();
+ gold_assert(entry != NULL);
+
+ // Write the member count and unused global symbol count.
+ unsigned int nmembers = entry->get_member_count();
+ unsigned int nsyms = entry->get_unused_global_symbol_count();
+ Swap32::writeval(pov, nmembers);
+ Swap32::writeval(pov + 4, nsyms);
+ pov += 8;
+
+ // For each member, write the offset to its input file entry.
+ for (unsigned int i = 0; i < nmembers; ++i)
+ {
+ Incremental_object_entry* member = entry->get_member(i);
+ Swap32::writeval(pov, member->get_offset());
+ pov += 4;
+ }
+
+ // For each global symbol, write the name offset.
+ for (unsigned int i = 0; i < nsyms; ++i)
+ {
+ Stringpool::Key key = entry->get_unused_global_symbol(i);
+ Swap32::writeval(pov, strtab->get_offset_from_key(key));
+ pov += 4;
+ }
+ }
+ break;
+
+ default:
+ gold_unreachable();
+ }
+
+ // Pad the info block to a multiple of 8 bytes.
+ if (static_cast<unsigned int>(pov - oview) & 4)
+ {
+ Swap32::writeval(pov, 0);
+ pov += 4;
+ }
+ }
+ return pov;
+}
+
+// Write the contents of the .gnu_incremental_symtab section.
+
+template<int size, bool big_endian>
+void
+Output_section_incremental_inputs<size, big_endian>::write_symtab(
+ unsigned char* pov,
+ unsigned int* global_syms,
+ unsigned int global_sym_count)
+{
+ for (unsigned int i = 0; i < global_sym_count; ++i)
+ {
+ Swap32::writeval(pov, global_syms[i]);
+ pov += 4;
+ }
+}
+
+// This struct holds the view information needed to write the
+// .gnu_incremental_got_plt section.
+
+struct Got_plt_view_info
+{
+ // Start of the GOT type array in the output view.
+ unsigned char* got_type_p;
+ // Start of the GOT descriptor array in the output view.
+ unsigned char* got_desc_p;
+ // Start of the PLT descriptor array in the output view.
+ unsigned char* plt_desc_p;
+ // Number of GOT entries.
+ unsigned int got_count;
+ // Number of PLT entries.
+ unsigned int plt_count;
+ // Offset of the first non-reserved PLT entry (this is a target-dependent value).
+ unsigned int first_plt_entry_offset;
+ // Size of a PLT entry (this is a target-dependent value).
+ unsigned int plt_entry_size;
+ // Size of a GOT entry (this is a target-dependent value).
+ unsigned int got_entry_size;
+ // Symbol index to write in the GOT descriptor array. For global symbols,
+ // this is the global symbol table index; for local symbols, it is the
+ // local symbol table index.
+ unsigned int sym_index;
+ // Input file index to write in the GOT descriptor array. For global
+ // symbols, this is 0; for local symbols, it is the index of the input
+ // file entry in the .gnu_incremental_inputs section.
+ unsigned int input_index;
+};
+
+// Functor class for processing a GOT offset list for local symbols.
+// Writes the GOT type and symbol index into the GOT type and descriptor
+// arrays in the output section.
+
+template<int size, bool big_endian>
+class Local_got_offset_visitor : public Got_offset_list::Visitor
+{
+ public:
+ Local_got_offset_visitor(struct Got_plt_view_info& info)
+ : info_(info)
+ { }
+
+ void
+ visit(unsigned int got_type, unsigned int got_offset)
+ {
+ unsigned int got_index = got_offset / this->info_.got_entry_size;
+ gold_assert(got_index < this->info_.got_count);
+ // We can only handle GOT entry types in the range 0..0x7e
+ // because we use a byte array to store them, and we use the
+ // high bit to flag a local symbol.
+ gold_assert(got_type < 0x7f);
+ this->info_.got_type_p[got_index] = got_type | 0x80;
+ unsigned char* pov = this->info_.got_desc_p + got_index * 8;
+ elfcpp::Swap<32, big_endian>::writeval(pov, this->info_.sym_index);
+ elfcpp::Swap<32, big_endian>::writeval(pov + 4, this->info_.input_index);
+ }
+
+ private:
+ struct Got_plt_view_info& info_;
+};
+
+// Functor class for processing a GOT offset list. Writes the GOT type
+// and symbol index into the GOT type and descriptor arrays in the output
+// section.
+
+template<int size, bool big_endian>
+class Global_got_offset_visitor : public Got_offset_list::Visitor
+{
+ public:
+ Global_got_offset_visitor(struct Got_plt_view_info& info)
+ : info_(info)
+ { }
+
+ void
+ visit(unsigned int got_type, unsigned int got_offset)
+ {
+ unsigned int got_index = got_offset / this->info_.got_entry_size;
+ gold_assert(got_index < this->info_.got_count);
+ // We can only handle GOT entry types in the range 0..0x7e
+ // because we use a byte array to store them, and we use the
+ // high bit to flag a local symbol.
+ gold_assert(got_type < 0x7f);
+ this->info_.got_type_p[got_index] = got_type;
+ unsigned char* pov = this->info_.got_desc_p + got_index * 8;
+ elfcpp::Swap<32, big_endian>::writeval(pov, this->info_.sym_index);
+ elfcpp::Swap<32, big_endian>::writeval(pov + 4, 0);
+ }
+
+ private:
+ struct Got_plt_view_info& info_;
+};
+
+// Functor class for processing the global symbol table. Processes the
+// GOT offset list for the symbol, and writes the symbol table index
+// into the PLT descriptor array in the output section.
+
+template<int size, bool big_endian>
+class Global_symbol_visitor_got_plt
+{
+ public:
+ Global_symbol_visitor_got_plt(struct Got_plt_view_info& info)
+ : info_(info)
+ { }
+
+ void
+ operator()(const Sized_symbol<size>* sym)
+ {
+ typedef Global_got_offset_visitor<size, big_endian> Got_visitor;
+ const Got_offset_list* got_offsets = sym->got_offset_list();
+ if (got_offsets != NULL)
+ {
+ this->info_.sym_index = sym->symtab_index();
+ this->info_.input_index = 0;
+ Got_visitor v(this->info_);
+ got_offsets->for_all_got_offsets(&v);
+ }
+ if (sym->has_plt_offset())
+ {
+ unsigned int plt_index =
+ ((sym->plt_offset() - this->info_.first_plt_entry_offset)
+ / this->info_.plt_entry_size);
+ gold_assert(plt_index < this->info_.plt_count);
+ unsigned char* pov = this->info_.plt_desc_p + plt_index * 4;
+ elfcpp::Swap<32, big_endian>::writeval(pov, sym->symtab_index());
+ }
+ }
+
+ private:
+ struct Got_plt_view_info& info_;
+};
+
+// Write the contents of the .gnu_incremental_got_plt section.
+
+template<int size, bool big_endian>
+void
+Output_section_incremental_inputs<size, big_endian>::write_got_plt(
+ unsigned char* pov,
+ off_t view_size)
+{
+ Sized_target<size, big_endian>* target =
+ parameters->sized_target<size, big_endian>();
+
+ // Set up the view information for the functors.
+ struct Got_plt_view_info view_info;
+ view_info.got_count = target->got_entry_count();
+ view_info.plt_count = target->plt_entry_count();
+ view_info.first_plt_entry_offset = target->first_plt_entry_offset();
+ view_info.plt_entry_size = target->plt_entry_size();
+ view_info.got_entry_size = target->got_entry_size();
+ view_info.got_type_p = pov + 8;
+ view_info.got_desc_p = (view_info.got_type_p
+ + ((view_info.got_count + 3) & ~3));
+ view_info.plt_desc_p = view_info.got_desc_p + view_info.got_count * 8;
+
+ gold_assert(pov + view_size ==
+ view_info.plt_desc_p + view_info.plt_count * 4);
+
+ // Write the section header.
+ Swap32::writeval(pov, view_info.got_count);
+ Swap32::writeval(pov + 4, view_info.plt_count);
+
+ // Initialize the GOT type array to 0xff (reserved).
+ memset(view_info.got_type_p, 0xff, view_info.got_count);
+
+ // Write the incremental GOT descriptors for local symbols.
+ typedef Local_got_offset_visitor<size, big_endian> Got_visitor;
+ for (Incremental_inputs::Input_list::const_iterator p =
+ this->inputs_->input_files().begin();
+ p != this->inputs_->input_files().end();
+ ++p)
+ {
+ if ((*p)->type() != INCREMENTAL_INPUT_OBJECT
+ && (*p)->type() != INCREMENTAL_INPUT_ARCHIVE_MEMBER)
+ continue;
+ Incremental_object_entry* entry = (*p)->object_entry();
+ gold_assert(entry != NULL);
+ const Object* obj = entry->object();
+ gold_assert(obj != NULL);
+ view_info.input_index = (*p)->get_file_index();
+ Got_visitor v(view_info);
+ obj->for_all_local_got_entries(&v);
+ }
+
+ // Write the incremental GOT and PLT descriptors for global symbols.
+ typedef Global_symbol_visitor_got_plt<size, big_endian> Symbol_visitor;
+ symtab_->for_all_symbols<size, Symbol_visitor>(Symbol_visitor(view_info));
+}
+
+// Class Sized_relobj_incr. Most of these methods are not used for
+// Incremental objects, but are required to be implemented by the
+// base class Object.
+
+template<int size, bool big_endian>
+Sized_relobj_incr<size, big_endian>::Sized_relobj_incr(
+ const std::string& name,
+ Sized_incremental_binary<size, big_endian>* ibase,
+ unsigned int input_file_index)
+ : Sized_relobj<size, big_endian>(name, NULL), ibase_(ibase),
+ input_file_index_(input_file_index),
+ input_reader_(ibase->inputs_reader().input_file(input_file_index)),
+ local_symbol_count_(0), output_local_dynsym_count_(0),
+ local_symbol_index_(0), local_symbol_offset_(0), local_dynsym_offset_(0),
+ symbols_(), defined_count_(0), incr_reloc_offset_(-1U),
+ incr_reloc_count_(0), incr_reloc_output_index_(0), incr_relocs_(NULL),
+ local_symbols_()
+{
+ if (this->input_reader_.is_in_system_directory())
+ this->set_is_in_system_directory();
+ const unsigned int shnum = this->input_reader_.get_input_section_count() + 1;
+ this->set_shnum(shnum);
+ ibase->set_input_object(input_file_index, this);
+}
+
+// Read the symbols.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_read_symbols(Read_symbols_data*)
+{
+ gold_unreachable();
+}
+
+// Lay out the input sections.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_layout(
+ Symbol_table*,
+ Layout* layout,
+ Read_symbols_data*)
+{
+ const unsigned int shnum = this->shnum();
+ Incremental_inputs* incremental_inputs = layout->incremental_inputs();
+ gold_assert(incremental_inputs != NULL);
+ Output_sections& out_sections(this->output_sections());
+ out_sections.resize(shnum);
+ this->section_offsets().resize(shnum);
+
+ // Keep track of .debug_info and .debug_types sections.
+ std::vector<unsigned int> debug_info_sections;
+ std::vector<unsigned int> debug_types_sections;
+
+ for (unsigned int i = 1; i < shnum; i++)
+ {
+ typename Input_entry_reader::Input_section_info sect =
+ this->input_reader_.get_input_section(i - 1);
+ // Add the section to the incremental inputs layout.
+ incremental_inputs->report_input_section(this, i, sect.name,
+ sect.sh_size);
+ if (sect.output_shndx == 0 || sect.sh_offset == -1)
+ continue;
+ Output_section* os = this->ibase_->output_section(sect.output_shndx);
+ gold_assert(os != NULL);
+ out_sections[i] = os;
+ this->section_offsets()[i] = static_cast<Address>(sect.sh_offset);
+
+ // When generating a .gdb_index section, we do additional
+ // processing of .debug_info and .debug_types sections after all
+ // the other sections.
+ if (parameters->options().gdb_index())
+ {
+ const char* name = os->name();
+ if (strcmp(name, ".debug_info") == 0)
+ debug_info_sections.push_back(i);
+ else if (strcmp(name, ".debug_types") == 0)
+ debug_types_sections.push_back(i);
+ }
+ }
+
+ // Process the COMDAT groups.
+ unsigned int ncomdat = this->input_reader_.get_comdat_group_count();
+ for (unsigned int i = 0; i < ncomdat; i++)
+ {
+ const char* signature = this->input_reader_.get_comdat_group_signature(i);
+ if (signature == NULL || signature[0] == '\0')
+ this->error(_("COMDAT group has no signature"));
+ bool keep = layout->find_or_add_kept_section(signature, this, i, true,
+ true, NULL);
+ if (keep)
+ incremental_inputs->report_comdat_group(this, signature);
+ else
+ this->error(_("COMDAT group %s included twice in incremental link"),
+ signature);
+ }
+
+ // When building a .gdb_index section, scan the .debug_info and
+ // .debug_types sections.
+ for (std::vector<unsigned int>::const_iterator p
+ = debug_info_sections.begin();
+ p != debug_info_sections.end();
+ ++p)
+ {
+ unsigned int i = *p;
+ layout->add_to_gdb_index(false, this, NULL, 0, i, 0, 0);
+ }
+ for (std::vector<unsigned int>::const_iterator p
+ = debug_types_sections.begin();
+ p != debug_types_sections.end();
+ ++p)
+ {
+ unsigned int i = *p;
+ layout->add_to_gdb_index(true, this, 0, 0, i, 0, 0);
+ }
+}
+
+// Layout sections whose layout was deferred while waiting for
+// input files from a plugin.
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_layout_deferred_sections(Layout*)
+{
+}
+
+// Add the symbols to the symbol table.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_add_symbols(
+ Symbol_table* symtab,
+ Read_symbols_data*,
+ Layout*)
+{
+ const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
+ unsigned char symbuf[sym_size];
+ elfcpp::Sym<size, big_endian> sym(symbuf);
+ elfcpp::Sym_write<size, big_endian> osym(symbuf);
+
+ typedef typename elfcpp::Elf_types<size>::Elf_WXword Elf_size_type;
+
+ unsigned int nsyms = this->input_reader_.get_global_symbol_count();
+ this->symbols_.resize(nsyms);
+
+ Incremental_binary::View symtab_view(NULL);
+ unsigned int symtab_count;
+ elfcpp::Elf_strtab strtab(NULL, 0);
+ this->ibase_->get_symtab_view(&symtab_view, &symtab_count, &strtab);
+
+ Incremental_symtab_reader<big_endian> isymtab(this->ibase_->symtab_reader());
+ unsigned int isym_count = isymtab.symbol_count();
+ unsigned int first_global = symtab_count - isym_count;
+
+ const unsigned char* sym_p;
+ for (unsigned int i = 0; i < nsyms; ++i)
+ {
+ Incremental_global_symbol_reader<big_endian> info =
+ this->input_reader_.get_global_symbol_reader(i);
+ unsigned int output_symndx = info.output_symndx();
+ sym_p = symtab_view.data() + output_symndx * sym_size;
+ elfcpp::Sym<size, big_endian> gsym(sym_p);
+ const char* name;
+ if (!strtab.get_c_string(gsym.get_st_name(), &name))
+ name = "";
+
+ typename elfcpp::Elf_types<size>::Elf_Addr v = gsym.get_st_value();
+ unsigned int shndx = gsym.get_st_shndx();
+ elfcpp::STB st_bind = gsym.get_st_bind();
+ elfcpp::STT st_type = gsym.get_st_type();
+
+ // Local hidden symbols start out as globals, but get converted to
+ // to local during output.
+ if (st_bind == elfcpp::STB_LOCAL)
+ st_bind = elfcpp::STB_GLOBAL;
+
+ unsigned int input_shndx = info.shndx();
+ if (input_shndx == 0 || input_shndx == -1U)
+ {
+ shndx = elfcpp::SHN_UNDEF;
+ v = 0;
+ }
+ else if (shndx != elfcpp::SHN_ABS)
+ {
+ // Find the input section and calculate the section-relative value.
+ gold_assert(shndx != elfcpp::SHN_UNDEF);
+ Output_section* os = this->ibase_->output_section(shndx);
+ gold_assert(os != NULL && os->has_fixed_layout());
+ typename Input_entry_reader::Input_section_info sect =
+ this->input_reader_.get_input_section(input_shndx - 1);
+ gold_assert(sect.output_shndx == shndx);
+ if (st_type != elfcpp::STT_TLS)
+ v -= os->address();
+ v -= sect.sh_offset;
+ shndx = input_shndx;
+ }
+
+ osym.put_st_name(0);
+ osym.put_st_value(v);
+ osym.put_st_size(gsym.get_st_size());
+ osym.put_st_info(st_bind, st_type);
+ osym.put_st_other(gsym.get_st_other());
+ osym.put_st_shndx(shndx);
+
+ Symbol* res = symtab->add_from_incrobj(this, name, NULL, &sym);
+
+ if (shndx != elfcpp::SHN_UNDEF)
+ ++this->defined_count_;
+
+ // If this is a linker-defined symbol that hasn't yet been defined,
+ // define it now.
+ if (input_shndx == -1U && !res->is_defined())
+ {
+ shndx = gsym.get_st_shndx();
+ v = gsym.get_st_value();
+ Elf_size_type symsize = gsym.get_st_size();
+ if (shndx == elfcpp::SHN_ABS)
+ {
+ symtab->define_as_constant(name, NULL,
+ Symbol_table::INCREMENTAL_BASE,
+ v, symsize, st_type, st_bind,
+ gsym.get_st_visibility(), 0,
+ false, false);
+ }
+ else
+ {
+ Output_section* os = this->ibase_->output_section(shndx);
+ gold_assert(os != NULL && os->has_fixed_layout());
+ v -= os->address();
+ if (symsize > 0)
+ os->reserve(v, symsize);
+ symtab->define_in_output_data(name, NULL,
+ Symbol_table::INCREMENTAL_BASE,
+ os, v, symsize, st_type, st_bind,
+ gsym.get_st_visibility(), 0,
+ false, false);
+ }
+ }
+
+ this->symbols_[i] = res;
+ this->ibase_->add_global_symbol(output_symndx - first_global, res);
+ }
+}
+
+// Return TRUE if we should include this object from an archive library.
+
+template<int size, bool big_endian>
+Archive::Should_include
+Sized_relobj_incr<size, big_endian>::do_should_include_member(
+ Symbol_table*,
+ Layout*,
+ Read_symbols_data*,
+ std::string*)
+{
+ gold_unreachable();
+}
+
+// Iterate over global symbols, calling a visitor class V for each.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_for_all_global_symbols(
+ Read_symbols_data*,
+ Library_base::Symbol_visitor_base*)
+{
+ // This routine is not used for incremental objects.
+}
+
+// Get the size of a section.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_relobj_incr<size, big_endian>::do_section_size(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Get the name of a section. This returns the name of the output
+// section, because we don't usually track the names of the input
+// sections.
+
+template<int size, bool big_endian>
+std::string
+Sized_relobj_incr<size, big_endian>::do_section_name(unsigned int shndx) const
+{
+ const Output_sections& out_sections(this->output_sections());
+ const Output_section* os = out_sections[shndx];
+ if (os == NULL)
+ return NULL;
+ return os->name();
+}
+
+// Return a view of the contents of a section.
+
+template<int size, bool big_endian>
+const unsigned char*
+Sized_relobj_incr<size, big_endian>::do_section_contents(
+ unsigned int shndx,
+ section_size_type* plen,
+ bool)
+{
+ Output_sections& out_sections(this->output_sections());
+ Output_section* os = out_sections[shndx];
+ gold_assert(os != NULL);
+ off_t section_offset = os->offset();
+ typename Input_entry_reader::Input_section_info sect =
+ this->input_reader_.get_input_section(shndx - 1);
+ section_offset += sect.sh_offset;
+ *plen = sect.sh_size;
+ return this->ibase_->view(section_offset, sect.sh_size).data();
+}
+
+// Return section flags.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_relobj_incr<size, big_endian>::do_section_flags(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return section entsize.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_relobj_incr<size, big_endian>::do_section_entsize(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return section address.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_relobj_incr<size, big_endian>::do_section_address(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return section type.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_relobj_incr<size, big_endian>::do_section_type(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return the section link field.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_relobj_incr<size, big_endian>::do_section_link(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return the section link field.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_relobj_incr<size, big_endian>::do_section_info(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return the section alignment.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_relobj_incr<size, big_endian>::do_section_addralign(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return the Xindex structure to use.
+
+template<int size, bool big_endian>
+Xindex*
+Sized_relobj_incr<size, big_endian>::do_initialize_xindex()
+{
+ gold_unreachable();
+}
+
+// Get symbol counts.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_get_global_symbol_counts(
+ const Symbol_table*,
+ size_t* defined,
+ size_t* used) const
+{
+ *defined = this->defined_count_;
+ size_t count = 0;
+ for (typename Symbols::const_iterator p = this->symbols_.begin();
+ p != this->symbols_.end();
+ ++p)
+ if (*p != NULL
+ && (*p)->source() == Symbol::FROM_OBJECT
+ && (*p)->object() == this
+ && (*p)->is_defined())
+ ++count;
+ *used = count;
+}
+
+// Read the relocs.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_read_relocs(Read_relocs_data*)
+{
+}
+
+// Process the relocs to find list of referenced sections. Used only
+// during garbage collection.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_gc_process_relocs(Symbol_table*,
+ Layout*,
+ Read_relocs_data*)
+{
+ gold_unreachable();
+}
+
+// Scan the relocs and adjust the symbol table.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_scan_relocs(Symbol_table*,
+ Layout* layout,
+ Read_relocs_data*)
+{
+ // Count the incremental relocations for this object.
+ unsigned int nsyms = this->input_reader_.get_global_symbol_count();
+ this->allocate_incremental_reloc_counts();
+ for (unsigned int i = 0; i < nsyms; i++)
+ {
+ Incremental_global_symbol_reader<big_endian> sym =
+ this->input_reader_.get_global_symbol_reader(i);
+ unsigned int reloc_count = sym.reloc_count();
+ if (reloc_count > 0 && this->incr_reloc_offset_ == -1U)
+ this->incr_reloc_offset_ = sym.reloc_offset();
+ this->incr_reloc_count_ += reloc_count;
+ for (unsigned int j = 0; j < reloc_count; j++)
+ this->count_incremental_reloc(i);
+ }
+ this->incr_reloc_output_index_ =
+ layout->incremental_inputs()->get_reloc_count();
+ this->finalize_incremental_relocs(layout, false);
+
+ // The incoming incremental relocations may not end up in the same
+ // location after the incremental update, because the incremental info
+ // is regenerated in each link. Because the new location may overlap
+ // with other data in the updated output file, we need to copy the
+ // relocations into a buffer so that we can still read them safely
+ // after we start writing updates to the output file.
+ if (this->incr_reloc_count_ > 0)
+ {
+ const Incremental_relocs_reader<size, big_endian>& relocs_reader =
+ this->ibase_->relocs_reader();
+ const unsigned int incr_reloc_size = relocs_reader.reloc_size;
+ unsigned int len = this->incr_reloc_count_ * incr_reloc_size;
+ this->incr_relocs_ = new unsigned char[len];
+ memcpy(this->incr_relocs_,
+ relocs_reader.data(this->incr_reloc_offset_),
+ len);
+ }
+}
+
+// Count the local symbols.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_count_local_symbols(
+ Stringpool_template<char>* pool,
+ Stringpool_template<char>*)
+{
+ const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
+
+ // Set the count of local symbols based on the incremental info.
+ unsigned int nlocals = this->input_reader_.get_local_symbol_count();
+ this->local_symbol_count_ = nlocals;
+ this->local_symbols_.reserve(nlocals);
+
+ // Get views of the base file's symbol table and string table.
+ Incremental_binary::View symtab_view(NULL);
+ unsigned int symtab_count;
+ elfcpp::Elf_strtab strtab(NULL, 0);
+ this->ibase_->get_symtab_view(&symtab_view, &symtab_count, &strtab);
+
+ // Read the local symbols from the base file's symbol table.
+ off_t off = this->input_reader_.get_local_symbol_offset();
+ const unsigned char* symp = symtab_view.data() + off;
+ for (unsigned int i = 0; i < nlocals; ++i, symp += sym_size)
+ {
+ elfcpp::Sym<size, big_endian> sym(symp);
+ const char* name;
+ if (!strtab.get_c_string(sym.get_st_name(), &name))
+ name = "";
+ gold_debug(DEBUG_INCREMENTAL, "Local symbol %d: %s", i, name);
+ name = pool->add(name, true, NULL);
+ this->local_symbols_.push_back(Local_symbol(name,
+ sym.get_st_value(),
+ sym.get_st_size(),
+ sym.get_st_shndx(),
+ sym.get_st_type(),
+ false));
+ }
+}
+
+// Finalize the local symbols.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_relobj_incr<size, big_endian>::do_finalize_local_symbols(
+ unsigned int index,
+ off_t off,
+ Symbol_table*)
+{
+ this->local_symbol_index_ = index;
+ this->local_symbol_offset_ = off;
+ return index + this->local_symbol_count_;
+}
+
+// Set the offset where local dynamic symbol information will be stored.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_relobj_incr<size, big_endian>::do_set_local_dynsym_indexes(
+ unsigned int index)
+{
+ // FIXME: set local dynsym indexes.
+ return index;
+}
+
+// Set the offset where local dynamic symbol information will be stored.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_relobj_incr<size, big_endian>::do_set_local_dynsym_offset(off_t)
+{
+ return 0;
+}
+
+// Relocate the input sections and write out the local symbols.
+// We don't actually do any relocation here. For unchanged input files,
+// we reapply relocations only for symbols that have changed; that happens
+// in Layout_task_runner::run(). We do need to rewrite the incremental
+// relocations for this object.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_relocate(const Symbol_table*,
+ const Layout* layout,
+ Output_file* of)
+{
+ if (this->incr_reloc_count_ == 0)
+ return;
+
+ const unsigned int incr_reloc_size =
+ Incremental_relocs_reader<size, big_endian>::reloc_size;
+
+ // Get a view for the .gnu_incremental_relocs section.
+ Incremental_inputs* inputs = layout->incremental_inputs();
+ gold_assert(inputs != NULL);
+ const off_t relocs_off = inputs->relocs_section()->offset();
+ const off_t relocs_size = inputs->relocs_section()->data_size();
+ unsigned char* const view = of->get_output_view(relocs_off, relocs_size);
+
+ // Copy the relocations from the buffer.
+ off_t off = this->incr_reloc_output_index_ * incr_reloc_size;
+ unsigned int len = this->incr_reloc_count_ * incr_reloc_size;
+ memcpy(view + off, this->incr_relocs_, len);
+
+ // The output section table may have changed, so we need to map
+ // the old section index to the new section index for each relocation.
+ for (unsigned int i = 0; i < this->incr_reloc_count_; ++i)
+ {
+ unsigned char* pov = view + off + i * incr_reloc_size;
+ unsigned int shndx = elfcpp::Swap<32, big_endian>::readval(pov + 4);
+ Output_section* os = this->ibase_->output_section(shndx);
+ gold_assert(os != NULL);
+ shndx = os->out_shndx();
+ elfcpp::Swap<32, big_endian>::writeval(pov + 4, shndx);
+ }
+
+ of->write_output_view(off, len, view);
+
+ // Get views into the output file for the portions of the symbol table
+ // and the dynamic symbol table that we will be writing.
+ off_t symtab_off = layout->symtab_section()->offset();
+ off_t output_size = this->local_symbol_count_ * This::sym_size;
+ unsigned char* oview = NULL;
+ if (output_size > 0)
+ oview = of->get_output_view(symtab_off + this->local_symbol_offset_,
+ output_size);
+
+ off_t dyn_output_size = this->output_local_dynsym_count_ * sym_size;
+ unsigned char* dyn_oview = NULL;
+ if (dyn_output_size > 0)
+ dyn_oview = of->get_output_view(this->local_dynsym_offset_,
+ dyn_output_size);
+
+ // Write the local symbols.
+ unsigned char* ov = oview;
+ unsigned char* dyn_ov = dyn_oview;
+ const Stringpool* sympool = layout->sympool();
+ const Stringpool* dynpool = layout->dynpool();
+ Output_symtab_xindex* symtab_xindex = layout->symtab_xindex();
+ Output_symtab_xindex* dynsym_xindex = layout->dynsym_xindex();
+ for (unsigned int i = 0; i < this->local_symbol_count_; ++i)
+ {
+ Local_symbol& lsym(this->local_symbols_[i]);
+
+ bool is_ordinary;
+ unsigned int st_shndx = this->adjust_sym_shndx(i, lsym.st_shndx,
+ &is_ordinary);
+ if (is_ordinary)
+ {
+ Output_section* os = this->ibase_->output_section(st_shndx);
+ st_shndx = os->out_shndx();
+ if (st_shndx >= elfcpp::SHN_LORESERVE)
+ {
+ symtab_xindex->add(this->local_symbol_index_ + i, st_shndx);
+ if (lsym.needs_dynsym_entry)
+ dynsym_xindex->add(lsym.output_dynsym_index, st_shndx);
+ st_shndx = elfcpp::SHN_XINDEX;
+ }
+ }
+
+ // Write the symbol to the output symbol table.
+ {
+ elfcpp::Sym_write<size, big_endian> osym(ov);
+ osym.put_st_name(sympool->get_offset(lsym.name));
+ osym.put_st_value(lsym.st_value);
+ osym.put_st_size(lsym.st_size);
+ osym.put_st_info(elfcpp::STB_LOCAL,
+ static_cast<elfcpp::STT>(lsym.st_type));
+ osym.put_st_other(0);
+ osym.put_st_shndx(st_shndx);
+ ov += sym_size;
+ }
+
+ // Write the symbol to the output dynamic symbol table.
+ if (lsym.needs_dynsym_entry)
+ {
+ gold_assert(dyn_ov < dyn_oview + dyn_output_size);
+ elfcpp::Sym_write<size, big_endian> osym(dyn_ov);
+ osym.put_st_name(dynpool->get_offset(lsym.name));
+ osym.put_st_value(lsym.st_value);
+ osym.put_st_size(lsym.st_size);
+ osym.put_st_info(elfcpp::STB_LOCAL,
+ static_cast<elfcpp::STT>(lsym.st_type));
+ osym.put_st_other(0);
+ osym.put_st_shndx(st_shndx);
+ dyn_ov += sym_size;
+ }
+ }
+
+ if (output_size > 0)
+ {
+ gold_assert(ov - oview == output_size);
+ of->write_output_view(symtab_off + this->local_symbol_offset_,
+ output_size, oview);
+ }
+
+ if (dyn_output_size > 0)
+ {
+ gold_assert(dyn_ov - dyn_oview == dyn_output_size);
+ of->write_output_view(this->local_dynsym_offset_, dyn_output_size,
+ dyn_oview);
+ }
+}
+
+// Set the offset of a section.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_incr<size, big_endian>::do_set_section_offset(unsigned int,
+ uint64_t)
+{
+}
+
+// Class Sized_incr_dynobj. Most of these methods are not used for
+// Incremental objects, but are required to be implemented by the
+// base class Object.
+
+template<int size, bool big_endian>
+Sized_incr_dynobj<size, big_endian>::Sized_incr_dynobj(
+ const std::string& name,
+ Sized_incremental_binary<size, big_endian>* ibase,
+ unsigned int input_file_index)
+ : Dynobj(name, NULL), ibase_(ibase),
+ input_file_index_(input_file_index),
+ input_reader_(ibase->inputs_reader().input_file(input_file_index)),
+ symbols_(), defined_count_(0)
+{
+ if (this->input_reader_.is_in_system_directory())
+ this->set_is_in_system_directory();
+ if (this->input_reader_.as_needed())
+ this->set_as_needed();
+ this->set_soname_string(this->input_reader_.get_soname());
+ this->set_shnum(0);
+}
+
+// Read the symbols.
+
+template<int size, bool big_endian>
+void
+Sized_incr_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data*)
+{
+ gold_unreachable();
+}
+
+// Lay out the input sections.
+
+template<int size, bool big_endian>
+void
+Sized_incr_dynobj<size, big_endian>::do_layout(
+ Symbol_table*,
+ Layout*,
+ Read_symbols_data*)
+{
+}
+
+// Add the symbols to the symbol table.
+
+template<int size, bool big_endian>
+void
+Sized_incr_dynobj<size, big_endian>::do_add_symbols(
+ Symbol_table* symtab,
+ Read_symbols_data*,
+ Layout*)
+{
+ const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
+ unsigned char symbuf[sym_size];
+ elfcpp::Sym<size, big_endian> sym(symbuf);
+ elfcpp::Sym_write<size, big_endian> osym(symbuf);
+
+ unsigned int nsyms = this->input_reader_.get_global_symbol_count();
+ this->symbols_.resize(nsyms);
+
+ Incremental_binary::View symtab_view(NULL);
+ unsigned int symtab_count;
+ elfcpp::Elf_strtab strtab(NULL, 0);
+ this->ibase_->get_symtab_view(&symtab_view, &symtab_count, &strtab);
+
+ Incremental_symtab_reader<big_endian> isymtab(this->ibase_->symtab_reader());
+ unsigned int isym_count = isymtab.symbol_count();
+ unsigned int first_global = symtab_count - isym_count;
+
+ // We keep a set of symbols that we have generated COPY relocations
+ // for, indexed by the symbol value. We do not need more than one
+ // COPY relocation per address.
+ typedef typename std::set<Address> Copied_symbols;
+ Copied_symbols copied_symbols;
+
+ const unsigned char* sym_p;
+ for (unsigned int i = 0; i < nsyms; ++i)
+ {
+ bool is_def;
+ bool is_copy;
+ unsigned int output_symndx =
+ this->input_reader_.get_output_symbol_index(i, &is_def, &is_copy);
+ sym_p = symtab_view.data() + output_symndx * sym_size;
+ elfcpp::Sym<size, big_endian> gsym(sym_p);
+ const char* name;
+ if (!strtab.get_c_string(gsym.get_st_name(), &name))
+ name = "";
+
+ Address v;
+ unsigned int shndx;
+ elfcpp::STB st_bind = gsym.get_st_bind();
+ elfcpp::STT st_type = gsym.get_st_type();
+
+ // Local hidden symbols start out as globals, but get converted to
+ // to local during output.
+ if (st_bind == elfcpp::STB_LOCAL)
+ st_bind = elfcpp::STB_GLOBAL;
+
+ if (!is_def)
+ {
+ shndx = elfcpp::SHN_UNDEF;
+ v = 0;
+ }
+ else
+ {
+ // For a symbol defined in a shared object, the section index
+ // is meaningless, as long as it's not SHN_UNDEF.
+ shndx = 1;
+ v = gsym.get_st_value();
+ ++this->defined_count_;
+ }
+
+ osym.put_st_name(0);
+ osym.put_st_value(v);
+ osym.put_st_size(gsym.get_st_size());
+ osym.put_st_info(st_bind, st_type);
+ osym.put_st_other(gsym.get_st_other());
+ osym.put_st_shndx(shndx);
+
+ Sized_symbol<size>* res =
+ symtab->add_from_incrobj<size, big_endian>(this, name, NULL, &sym);
+ this->symbols_[i] = res;
+ this->ibase_->add_global_symbol(output_symndx - first_global,
+ this->symbols_[i]);
+
+ if (is_copy)
+ {
+ std::pair<typename Copied_symbols::iterator, bool> ins =
+ copied_symbols.insert(v);
+ if (ins.second)
+ {
+ unsigned int shndx = gsym.get_st_shndx();
+ Output_section* os = this->ibase_->output_section(shndx);
+ off_t offset = v - os->address();
+ this->ibase_->add_copy_reloc(this->symbols_[i], os, offset);
+ }
+ }
+ }
+}
+
+// Return TRUE if we should include this object from an archive library.
+
+template<int size, bool big_endian>
+Archive::Should_include
+Sized_incr_dynobj<size, big_endian>::do_should_include_member(
+ Symbol_table*,
+ Layout*,
+ Read_symbols_data*,
+ std::string*)
+{
+ gold_unreachable();
+}
+
+// Iterate over global symbols, calling a visitor class V for each.
+
+template<int size, bool big_endian>
+void
+Sized_incr_dynobj<size, big_endian>::do_for_all_global_symbols(
+ Read_symbols_data*,
+ Library_base::Symbol_visitor_base*)
+{
+ // This routine is not used for dynamic libraries.
+}
+
+// Iterate over local symbols, calling a visitor class V for each GOT offset
+// associated with a local symbol.
+
+template<int size, bool big_endian>
+void
+Sized_incr_dynobj<size, big_endian>::do_for_all_local_got_entries(
+ Got_offset_list::Visitor*) const
+{
+}
+
+// Get the size of a section.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_incr_dynobj<size, big_endian>::do_section_size(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Get the name of a section.
+
+template<int size, bool big_endian>
+std::string
+Sized_incr_dynobj<size, big_endian>::do_section_name(unsigned int) const
+{
+ gold_unreachable();
+}
+
+// Return a view of the contents of a section.
+
+template<int size, bool big_endian>
+const unsigned char*
+Sized_incr_dynobj<size, big_endian>::do_section_contents(
+ unsigned int,
+ section_size_type*,
+ bool)
+{
+ gold_unreachable();
+}
+
+// Return section flags.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_incr_dynobj<size, big_endian>::do_section_flags(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return section entsize.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_incr_dynobj<size, big_endian>::do_section_entsize(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return section address.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_incr_dynobj<size, big_endian>::do_section_address(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return section type.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_incr_dynobj<size, big_endian>::do_section_type(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return the section link field.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_incr_dynobj<size, big_endian>::do_section_link(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return the section link field.
+
+template<int size, bool big_endian>
+unsigned int
+Sized_incr_dynobj<size, big_endian>::do_section_info(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return the section alignment.
+
+template<int size, bool big_endian>
+uint64_t
+Sized_incr_dynobj<size, big_endian>::do_section_addralign(unsigned int)
+{
+ gold_unreachable();
+}
+
+// Return the Xindex structure to use.
+
+template<int size, bool big_endian>
+Xindex*
+Sized_incr_dynobj<size, big_endian>::do_initialize_xindex()
+{
+ gold_unreachable();
+}
+
+// Get symbol counts.
+
+template<int size, bool big_endian>
+void
+Sized_incr_dynobj<size, big_endian>::do_get_global_symbol_counts(
+ const Symbol_table*,
+ size_t* defined,
+ size_t* used) const
+{
+ *defined = this->defined_count_;
+ size_t count = 0;
+ for (typename Symbols::const_iterator p = this->symbols_.begin();
+ p != this->symbols_.end();
+ ++p)
+ if (*p != NULL
+ && (*p)->source() == Symbol::FROM_OBJECT
+ && (*p)->object() == this
+ && (*p)->is_defined()
+ && (*p)->dynsym_index() != -1U)
+ ++count;
+ *used = count;
+}
+
+// Allocate an incremental object of the appropriate size and endianness.
+
+Object*
+make_sized_incremental_object(
+ Incremental_binary* ibase,
+ unsigned int input_file_index,
+ Incremental_input_type input_type,
+ const Incremental_binary::Input_reader* input_reader)
+{
+ Object* obj = NULL;
+ std::string name(input_reader->filename());
+
+ switch (parameters->size_and_endianness())
+ {
+#ifdef HAVE_TARGET_32_LITTLE
+ case Parameters::TARGET_32_LITTLE:
+ {
+ Sized_incremental_binary<32, false>* sized_ibase =
+ static_cast<Sized_incremental_binary<32, false>*>(ibase);
+ if (input_type == INCREMENTAL_INPUT_SHARED_LIBRARY)
+ obj = new Sized_incr_dynobj<32, false>(name, sized_ibase,
+ input_file_index);
+ else
+ obj = new Sized_relobj_incr<32, false>(name, sized_ibase,
+ input_file_index);
+ }
+ break;
+#endif
+#ifdef HAVE_TARGET_32_BIG
+ case Parameters::TARGET_32_BIG:
+ {
+ Sized_incremental_binary<32, true>* sized_ibase =
+ static_cast<Sized_incremental_binary<32, true>*>(ibase);
+ if (input_type == INCREMENTAL_INPUT_SHARED_LIBRARY)
+ obj = new Sized_incr_dynobj<32, true>(name, sized_ibase,
+ input_file_index);
+ else
+ obj = new Sized_relobj_incr<32, true>(name, sized_ibase,
+ input_file_index);
+ }
+ break;
+#endif
+#ifdef HAVE_TARGET_64_LITTLE
+ case Parameters::TARGET_64_LITTLE:
+ {
+ Sized_incremental_binary<64, false>* sized_ibase =
+ static_cast<Sized_incremental_binary<64, false>*>(ibase);
+ if (input_type == INCREMENTAL_INPUT_SHARED_LIBRARY)
+ obj = new Sized_incr_dynobj<64, false>(name, sized_ibase,
+ input_file_index);
+ else
+ obj = new Sized_relobj_incr<64, false>(name, sized_ibase,
+ input_file_index);
+ }
+ break;
+#endif
+#ifdef HAVE_TARGET_64_BIG
+ case Parameters::TARGET_64_BIG:
+ {
+ Sized_incremental_binary<64, true>* sized_ibase =
+ static_cast<Sized_incremental_binary<64, true>*>(ibase);
+ if (input_type == INCREMENTAL_INPUT_SHARED_LIBRARY)
+ obj = new Sized_incr_dynobj<64, true>(name, sized_ibase,
+ input_file_index);
+ else
+ obj = new Sized_relobj_incr<64, true>(name, sized_ibase,
+ input_file_index);
+ }
+ break;
+#endif
+ default:
+ gold_unreachable();
+ }
+
+ gold_assert(obj != NULL);
+ return obj;
+}
+
+// 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
+Incremental_library::copy_unused_symbols()
+{
+ unsigned int symcount = this->input_reader_->get_unused_symbol_count();
+ this->unused_symbols_.reserve(symcount);
+ for (unsigned int i = 0; i < symcount; ++i)
+ {
+ std::string name(this->input_reader_->get_unused_symbol(i));
+ this->unused_symbols_.push_back(name);
+ }
+}
+
+// Iterator for unused global symbols in the library.
+void
+Incremental_library::do_for_all_unused_symbols(Symbol_visitor_base* v) const
+{
+ for (Symbol_list::const_iterator p = this->unused_symbols_.begin();
+ p != this->unused_symbols_.end();
+ ++p)
+ v->visit(p->c_str());
+}
+
+// Instantiate the templates we need.
+
+#ifdef HAVE_TARGET_32_LITTLE
+template
+class Sized_incremental_binary<32, false>;
+
+template
+class Sized_relobj_incr<32, false>;
+
+template
+class Sized_incr_dynobj<32, false>;
+#endif
+
+#ifdef HAVE_TARGET_32_BIG
+template
+class Sized_incremental_binary<32, true>;
+
+template
+class Sized_relobj_incr<32, true>;
+
+template
+class Sized_incr_dynobj<32, true>;
+#endif
+
+#ifdef HAVE_TARGET_64_LITTLE
+template
+class Sized_incremental_binary<64, false>;
+
+template
+class Sized_relobj_incr<64, false>;
+
+template
+class Sized_incr_dynobj<64, false>;
+#endif
+
+#ifdef HAVE_TARGET_64_BIG
+template
+class Sized_incremental_binary<64, true>;
+
+template
+class Sized_relobj_incr<64, true>;
+
+template
+class Sized_incr_dynobj<64, true>;
+#endif
+