+ gold_assert(static_cast<unsigned int>(pov - oview) == (*p)->get_offset());
+ section_offset_type filename_offset =
+ strtab->get_offset_from_key((*p)->get_filename_key());
+ const Timespec& mtime = (*p)->get_mtime();
+ Swap32::writeval(pov, filename_offset);
+ Swap32::writeval(pov + 4, (*p)->get_info_offset());
+ Swap64::writeval(pov + 8, mtime.seconds);
+ Swap32::writeval(pov + 16, mtime.nanoseconds);
+ Swap16::writeval(pov + 20, (*p)->type());
+ Swap16::writeval(pov + 22, 0);
+ pov += this->input_entry_size;
+ }
+ return pov;
+}
+
+// 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:
+ // No supplemental info for a script.
+ 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 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();
+ Swap32::writeval(pov, nsections);
+ Swap32::writeval(pov + 4, nsyms);
+ pov += 8;
+
+ // 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++)
+ {
+ 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(i);
+ if (os != NULL)
+ {
+ out_shndx = os->out_shndx();
+ out_offset = obj->output_section_offset(i);
+ 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);
+ pov += 8 + 2 * sizeof_addr;
+ }
+
+ // 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,
+ // 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 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, chain);
+ Swap32::writeval(pov + 8, nrelocs);
+ Swap32::writeval(pov + 12, first_reloc * 3 * sizeof_addr);
+ pov += 16;
+ }
+ }
+ break;
+
+ case INCREMENTAL_INPUT_SHARED_LIBRARY:
+ {
+ 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 Object::Symbols* syms = obj->get_global_symbols();
+
+ // Write the global symbol count.
+ unsigned int nsyms = syms != NULL ? syms->size() : 0;
+ Swap32::writeval(pov, nsyms);
+ pov += 4;
+
+ // For each global symbol, write the global symbol table index.
+ for (unsigned int i = 0; i < nsyms; i++)
+ {
+ const Symbol* sym = (*syms)[i];
+ Swap32::writeval(pov, sym->symtab_index());
+ pov += 4;
+ }
+ }
+ 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();
+ }
+ }
+ 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;
+ // Value to write in the GOT descriptor array. For global symbols,
+ // this is the global symbol table index; for local symbols, it is
+ // the offset of the input file entry in the .gnu_incremental_inputs
+ // section.
+ unsigned int got_descriptor;
+};
+
+// 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:
+ Local_got_offset_visitor(struct Got_plt_view_info& info)
+ : info_(info)
+ { }
+
+ void
+ operator()(unsigned int got_type, unsigned int got_offset)
+ {
+ unsigned int got_index = got_offset / this->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 * 4;
+ elfcpp::Swap<32, big_endian>::writeval(pov, this->info_.got_descriptor);
+ }
+
+ private:
+ static const unsigned int got_entry_size_ = size / 8;
+ 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:
+ Global_got_offset_visitor(struct Got_plt_view_info& info)
+ : info_(info)
+ { }
+
+ void
+ operator()(unsigned int got_type, unsigned int got_offset)
+ {
+ unsigned int got_index = got_offset / this->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 * 4;
+ elfcpp::Swap<32, big_endian>::writeval(pov, this->info_.got_descriptor);
+ }
+
+ private:
+ static const unsigned int got_entry_size_ = size / 8;
+ 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)
+ {
+ info_.got_descriptor = sym->symtab_index();
+ got_offsets->for_all_got_offsets(Got_visitor(info_));
+ }
+ 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_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 * 4;
+
+ 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.
+ 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 Sized_relobj<size, big_endian>* obj =
+ static_cast<Sized_relobj<size, big_endian>*>(entry->object());
+ gold_assert(obj != NULL);
+ unsigned int nsyms = obj->local_symbol_count();
+ for (unsigned int i = 0; i < nsyms; i++)