[gold patch] Incremental 9/18: Apply incremental relocations
Ian Lance Taylor
iant@google.com
Wed Apr 13 04:12:00 GMT 2011
Cary Coutant <ccoutant@google.com> writes:
> 2011-03-30 Cary Coutant <ccoutant@google.com>
>
> * incremental.cc (Sized_incremental_binary::setup_readers): Allocate
> global symbol map.
> (Sized_incremental_binary::do_apply_incremental_relocs): New function.
> (Sized_incr_relobj::do_add_symbols): Add symbols to global symbol map.
> (Sized_incr_relobj::do_relocate): Remap section indices in incremental
> relocations.
> (Sized_incr_dynobj::do_add_symbols): Add symbols to global symbol map.
> (Sized_incr_dynobj::do_for_all_global_symbols): Remove FIXME.
> (Sized_incr_dynobj::do_for_all_local_got_entries): Likewise.
> * incremental.h
> (Incremental_inputs_reader::global_symbol_reader_at_offset): New
> function.
> (Incremental_binary::apply_incremental_relocs): New function.
> (Incremental_binary::do_apply_incremental_relocs): New function.
> (Sized_incremental_binary::Sized_incremental_binary): Initialize new
> data member.
> (Sized_incremental_binary::add_global_symbol): New function.
> (Sized_incremental_binary::global_symbol): New function.
> (Sized_incremental_binary::do_apply_incremental_relocs): New function.
> (Sized_incremental_binary::symbol_map_): New data member.
> * layout.cc (Layout_task_runner::run): Apply incremental relocations.
> * target.h (Sized_target::apply_relocation): New function.
> * x86_64.cc (Target_x86_64::apply_relocation): New function.
> +// Apply an incremental relocation. Incremental relocations always refer
> +// to global symbols.
> +
> +void
> +Target_x86_64::apply_relocation(
> + const Relocate_info<64, false>* relinfo,
> + elfcpp::Elf_types<64>::Elf_Addr r_offset,
> + unsigned int r_type,
> + elfcpp::Elf_types<64>::Elf_Swxword r_addend,
> + const Symbol* gsym,
> + unsigned char* view,
> + elfcpp::Elf_types<64>::Elf_Addr address,
> + section_size_type view_size)
> +{
> + // Construct the ELF relocation in a temporary buffer.
> + const int reloc_size = elfcpp::Elf_sizes<64>::rela_size;
> + unsigned char relbuf[reloc_size];
> + elfcpp::Rela<64, false> rel(relbuf);
> + elfcpp::Rela_write<64, false> orel(relbuf);
> + orel.put_r_offset(r_offset);
> + orel.put_r_info(elfcpp::elf_r_info<64>(0, r_type));
> + orel.put_r_addend(r_addend);
> +
> + // Setup a Symbol_value for the global symbol.
> + const Sized_symbol<64>* sym = static_cast<const Sized_symbol<64>*>(gsym);
> + Symbol_value<64> symval;
> + gold_assert(sym->has_symtab_index() && sym->symtab_index() != -1U);
> + symval.set_output_symtab_index(sym->symtab_index());
> + symval.set_output_value(sym->value());
> + if (gsym->type() == elfcpp::STT_TLS)
> + symval.set_is_tls_symbol();
> + else if (gsym->type() == elfcpp::STT_GNU_IFUNC)
> + symval.set_is_ifunc_symbol();
> +
> + Target_x86_64::Relocate relocate;
> + relocate.relocate(relinfo, this, NULL, -1U, rel, r_type, sym, &symval,
> + view + r_offset, address + r_offset, view_size);
> +}
I don't see why this should be a target virtual function. It seems that
the above could be templatized <int sh_type, int size, bool big_endian>
and work for any target. That templatized function could go in
target-relocs.h and be called from do_apply_incremental_relocs.
The rest of the patch looks fine.
Ian
More information about the Binutils
mailing list