* i386.cc (Output_data_plt_i386::address_for_global,

address_for_local): Add plt offset to returned value.  Adjust uses.
	* sparc.cc (Output_data_plt_sparc::address_for_global,
	address_for_local): Likewise.
	* tilegx.cc (Output_data_plt_tilegx::address_for_global,
	address_for_local): Likewise.
	* x86_64.cc (Output_data_plt_x86_64::address_for_global,
	address_for_local): Likewise.
	* target.h (Target::plt_address_for_global, plt_address_for_local):
	Update comment.
	* output.cc (Output_reloc::symbol_value): Don't add plt offset here.
	(Output_data_got::Got_entry::write): Nor here.
	* output.h: Comment fix.
This commit is contained in:
Alan Modra 2012-10-05 00:45:54 +00:00
parent fda1189bbc
commit 19fec8c1d3
8 changed files with 63 additions and 61 deletions

View File

@ -1,3 +1,19 @@
2012-10-05 Alan Modra <amodra@gmail.com>
* i386.cc (Output_data_plt_i386::address_for_global,
address_for_local): Add plt offset to returned value. Adjust uses.
* sparc.cc (Output_data_plt_sparc::address_for_global,
address_for_local): Likewise.
* tilegx.cc (Output_data_plt_tilegx::address_for_global,
address_for_local): Likewise.
* x86_64.cc (Output_data_plt_x86_64::address_for_global,
address_for_local): Likewise.
* target.h (Target::plt_address_for_global, plt_address_for_local):
Update comment.
* output.cc (Output_reloc::symbol_value): Don't add plt offset here.
(Output_data_got::Got_entry::write): Nor here.
* output.h: Comment fix.
2012-10-02 Jiong Wang <jiwang@tilera.com> 2012-10-02 Jiong Wang <jiwang@tilera.com>
* tilegx.cc (Target_tilegx::do_finalize_sections): Adjust * tilegx.cc (Target_tilegx::do_finalize_sections): Adjust

View File

@ -1151,16 +1151,19 @@ Output_data_plt_i386::address_for_global(const Symbol* gsym)
if (gsym->type() == elfcpp::STT_GNU_IFUNC if (gsym->type() == elfcpp::STT_GNU_IFUNC
&& gsym->can_use_relative_reloc(false)) && gsym->can_use_relative_reloc(false))
offset = (this->count_ + 1) * this->get_plt_entry_size(); offset = (this->count_ + 1) * this->get_plt_entry_size();
return this->address() + offset; return this->address() + offset + gsym->plt_offset();
} }
// Return the PLT address to use for a local symbol. These are always // Return the PLT address to use for a local symbol. These are always
// IRELATIVE relocs. // IRELATIVE relocs.
uint64_t uint64_t
Output_data_plt_i386::address_for_local(const Relobj*, unsigned int) Output_data_plt_i386::address_for_local(const Relobj* object,
unsigned int r_sym)
{ {
return this->address() + (this->count_ + 1) * this->get_plt_entry_size(); return (this->address()
+ (this->count_ + 1) * this->get_plt_entry_size()
+ object->local_plt_offset(r_sym));
} }
// The first entry in the PLT for an executable. // The first entry in the PLT for an executable.
@ -2677,8 +2680,7 @@ Target_i386::Relocate::relocate(const Relocate_info<32, false>* relinfo,
else if (gsym != NULL else if (gsym != NULL
&& gsym->use_plt_offset(Scan::get_reference_flags(r_type))) && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
{ {
symval.set_output_value(target->plt_address_for_global(gsym) symval.set_output_value(target->plt_address_for_global(gsym));
+ gsym->plt_offset());
psymval = &symval; psymval = &symval;
} }
else if (gsym == NULL && psymval->is_ifunc_symbol()) else if (gsym == NULL && psymval->is_ifunc_symbol())
@ -2686,8 +2688,7 @@ Target_i386::Relocate::relocate(const Relocate_info<32, false>* relinfo,
unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info()); unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
if (object->local_has_plt_offset(r_sym)) if (object->local_has_plt_offset(r_sym))
{ {
symval.set_output_value(target->plt_address_for_local(object, r_sym) symval.set_output_value(target->plt_address_for_local(object, r_sym));
+ object->local_plt_offset(r_sym));
psymval = &symval; psymval = &symval;
} }
} }
@ -3649,7 +3650,7 @@ uint64_t
Target_i386::do_dynsym_value(const Symbol* gsym) const Target_i386::do_dynsym_value(const Symbol* gsym) const
{ {
gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset()); gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
return this->plt_address_for_global(gsym) + gsym->plt_offset(); return this->plt_address_for_global(gsym);
} }
// Return a string used to fill a code section with nops to take up // Return a string used to fill a code section with nops to take up

View File

@ -1129,11 +1129,7 @@ Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::symbol_value(
const Sized_symbol<size>* sym; const Sized_symbol<size>* sym;
sym = static_cast<const Sized_symbol<size>*>(this->u1_.gsym); sym = static_cast<const Sized_symbol<size>*>(this->u1_.gsym);
if (this->use_plt_offset_ && sym->has_plt_offset()) if (this->use_plt_offset_ && sym->has_plt_offset())
{ return parameters->target().plt_address_for_global(sym);
uint64_t plt_address =
parameters->target().plt_address_for_global(sym);
return plt_address + sym->plt_offset();
}
else else
return sym->value() + addend; return sym->value() + addend;
} }
@ -1151,11 +1147,7 @@ Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::symbol_value(
this->u1_.relobj->sized_relobj(); this->u1_.relobj->sized_relobj();
gold_assert(relobj != NULL); gold_assert(relobj != NULL);
if (this->use_plt_offset_) if (this->use_plt_offset_)
{ return parameters->target().plt_address_for_local(relobj, lsi);
uint64_t plt_address =
parameters->target().plt_address_for_local(relobj, lsi);
return plt_address + relobj->local_plt_offset(lsi);
}
const Symbol_value<size>* symval = relobj->local_symbol(lsi); const Symbol_value<size>* symval = relobj->local_symbol(lsi);
return symval->value(relobj, addend); return symval->value(relobj, addend);
} }
@ -1385,8 +1377,7 @@ Output_data_got<got_size, big_endian>::Got_entry::write(
// RELATIVE relocation. // RELATIVE relocation.
Symbol* gsym = this->u_.gsym; Symbol* gsym = this->u_.gsym;
if (this->use_plt_or_tls_offset_ && gsym->has_plt_offset()) if (this->use_plt_or_tls_offset_ && gsym->has_plt_offset())
val = (parameters->target().plt_address_for_global(gsym) val = parameters->target().plt_address_for_global(gsym);
+ gsym->plt_offset());
else else
{ {
switch (parameters->size_and_endianness()) switch (parameters->size_and_endianness())
@ -1442,11 +1433,7 @@ Output_data_got<got_size, big_endian>::Got_entry::write(
const unsigned int lsi = this->local_sym_index_; const unsigned int lsi = this->local_sym_index_;
bool is_tls = object->local_is_tls(lsi); bool is_tls = object->local_is_tls(lsi);
if (this->use_plt_or_tls_offset_ && !is_tls) if (this->use_plt_or_tls_offset_ && !is_tls)
{ val = parameters->target().plt_address_for_local(object, lsi);
uint64_t plt_address =
parameters->target().plt_address_for_local(object, lsi);
val = plt_address + object->local_plt_offset(lsi);
}
else else
{ {
uint64_t lval = object->local_symbol_value(lsi, 0); uint64_t lval = object->local_symbol_value(lsi, 0);
@ -2609,9 +2596,9 @@ Output_section::add_relaxed_input_section(Layout* layout,
// For a relaxed section, we use the current data size. Linker scripts // For a relaxed section, we use the current data size. Linker scripts
// get all the input sections, including relaxed one from an output // get all the input sections, including relaxed one from an output
// section and add them back to them same output section to compute the // section and add them back to the same output section to compute the
// output section size. If we do not account for sizes of relaxed input // output section size. If we do not account for sizes of relaxed input
// sections, an output section would be incorrectly sized. // sections, an output section would be incorrectly sized.
off_t offset_in_section = this->current_data_size_for_child(); off_t offset_in_section = this->current_data_size_for_child();
off_t aligned_offset_in_section = align_address(offset_in_section, off_t aligned_offset_in_section = align_address(offset_in_section,
poris->addralign()); poris->addralign());

View File

@ -2247,7 +2247,7 @@ class Output_data_got : public Output_data_got_base
add_global_plt(Symbol* gsym, unsigned int got_type); add_global_plt(Symbol* gsym, unsigned int got_type);
// Like add_global, but for a TLS symbol where the value will be // Like add_global, but for a TLS symbol where the value will be
// offset using Target::tls_offset_for_global // offset using Target::tls_offset_for_global.
bool bool
add_global_tls(Symbol* gsym, unsigned int got_type) add_global_tls(Symbol* gsym, unsigned int got_type)
{ return add_global_plt(gsym, got_type); } { return add_global_plt(gsym, got_type); }
@ -2277,7 +2277,7 @@ class Output_data_got : public Output_data_got_base
add_local_plt(Relobj* object, unsigned int sym_index, unsigned int got_type); add_local_plt(Relobj* object, unsigned int sym_index, unsigned int got_type);
// Like add_local, but for a TLS symbol where the value will be // Like add_local, but for a TLS symbol where the value will be
// offset using Target::tls_offset_for_local // offset using Target::tls_offset_for_local.
bool bool
add_local_tls(Relobj* object, unsigned int sym_index, unsigned int got_type) add_local_tls(Relobj* object, unsigned int sym_index, unsigned int got_type)
{ return add_local_plt(object, sym_index, got_type); } { return add_local_plt(object, sym_index, got_type); }

View File

@ -1619,7 +1619,7 @@ Output_data_plt_sparc<size, big_endian>::address_for_global(const Symbol* gsym)
if (gsym->type() == elfcpp::STT_GNU_IFUNC if (gsym->type() == elfcpp::STT_GNU_IFUNC
&& gsym->can_use_relative_reloc(false)) && gsym->can_use_relative_reloc(false))
offset = plt_index_to_offset(this->count_ + 4); offset = plt_index_to_offset(this->count_ + 4);
return this->address() + offset; return this->address() + offset + gsym->plt_offset();
} }
// Return the PLT address to use for a local symbol. These are always // Return the PLT address to use for a local symbol. These are always
@ -1628,10 +1628,12 @@ Output_data_plt_sparc<size, big_endian>::address_for_global(const Symbol* gsym)
template<int size, bool big_endian> template<int size, bool big_endian>
uint64_t uint64_t
Output_data_plt_sparc<size, big_endian>::address_for_local( Output_data_plt_sparc<size, big_endian>::address_for_local(
const Relobj*, const Relobj* object,
unsigned int) unsigned int r_sym)
{ {
return this->address() + plt_index_to_offset(this->count_ + 4); return (this->address()
+ plt_index_to_offset(this->count_ + 4)
+ object->local_plt_offset(r_sym));
} }
static const unsigned int sparc_nop = 0x01000000; static const unsigned int sparc_nop = 0x01000000;
@ -3199,7 +3201,7 @@ Target_sparc<size, big_endian>::Relocate::relocate(
{ {
elfcpp::Elf_Xword value; elfcpp::Elf_Xword value;
value = target->plt_address_for_global(gsym) + gsym->plt_offset(); value = target->plt_address_for_global(gsym);
symval.set_output_value(value); symval.set_output_value(value);
@ -3210,8 +3212,7 @@ Target_sparc<size, big_endian>::Relocate::relocate(
unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
if (object->local_has_plt_offset(r_sym)) if (object->local_has_plt_offset(r_sym))
{ {
symval.set_output_value(target->plt_address_for_local(object, r_sym) symval.set_output_value(target->plt_address_for_local(object, r_sym));
+ object->local_plt_offset(r_sym));
psymval = &symval; psymval = &symval;
} }
} }

View File

@ -256,16 +256,12 @@ class Target
reloc_addend(void* arg, unsigned int type, uint64_t addend) const reloc_addend(void* arg, unsigned int type, uint64_t addend) const
{ return this->do_reloc_addend(arg, type, addend); } { return this->do_reloc_addend(arg, type, addend); }
// Return the PLT address to use for a global symbol. This is used // Return the PLT address to use for a global symbol.
// for STT_GNU_IFUNC symbols. The symbol's plt_offset is relative
// to this PLT address.
uint64_t uint64_t
plt_address_for_global(const Symbol* sym) const plt_address_for_global(const Symbol* sym) const
{ return this->do_plt_address_for_global(sym); } { return this->do_plt_address_for_global(sym); }
// Return the PLT address to use for a local symbol. This is used // Return the PLT address to use for a local symbol.
// for STT_GNU_IFUNC symbols. The symbol's plt_offset is relative
// to this PLT address.
uint64_t uint64_t
plt_address_for_local(const Relobj* object, unsigned int symndx) const plt_address_for_local(const Relobj* object, unsigned int symndx) const
{ return this->do_plt_address_for_local(object, symndx); } { return this->do_plt_address_for_local(object, symndx); }

View File

@ -2194,7 +2194,7 @@ Output_data_plt_tilegx<size, big_endian>::address_for_global(
if (gsym->type() == elfcpp::STT_GNU_IFUNC if (gsym->type() == elfcpp::STT_GNU_IFUNC
&& gsym->can_use_relative_reloc(false)) && gsym->can_use_relative_reloc(false))
offset = (this->count_ + 1) * this->get_plt_entry_size(); offset = (this->count_ + 1) * this->get_plt_entry_size();
return this->address() + offset; return this->address() + offset + gsym->plt_offset();
} }
// Return the PLT address to use for a local symbol. These are always // Return the PLT address to use for a local symbol. These are always
@ -2202,10 +2202,13 @@ Output_data_plt_tilegx<size, big_endian>::address_for_global(
template<int size, bool big_endian> template<int size, bool big_endian>
uint64_t uint64_t
Output_data_plt_tilegx<size, big_endian>::address_for_local(const Relobj*, Output_data_plt_tilegx<size, big_endian>::address_for_local(
unsigned int) const Relobj* object,
unsigned int r_sym)
{ {
return this->address() + (this->count_ + 1) * this->get_plt_entry_size(); return (this->address()
+ (this->count_ + 1) * this->get_plt_entry_size()
+ object->local_plt_offset(r_sym));
} }
// Set the final size. // Set the final size.
@ -4334,8 +4337,7 @@ Target_tilegx<size, big_endian>::Relocate::relocate(
if (gsym != NULL if (gsym != NULL
&& gsym->use_plt_offset(Scan::get_reference_flags(r_type))) && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
{ {
symval.set_output_value(target->plt_address_for_global(gsym) symval.set_output_value(target->plt_address_for_global(gsym));
+ gsym->plt_offset());
psymval = &symval; psymval = &symval;
} }
else if (gsym == NULL && psymval->is_ifunc_symbol()) else if (gsym == NULL && psymval->is_ifunc_symbol())
@ -4343,8 +4345,7 @@ Target_tilegx<size, big_endian>::Relocate::relocate(
unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
if (object->local_has_plt_offset(r_sym)) if (object->local_has_plt_offset(r_sym))
{ {
symval.set_output_value(target->plt_address_for_local(object, r_sym) symval.set_output_value(target->plt_address_for_local(object, r_sym));
+ object->local_plt_offset(r_sym));
psymval = &symval; psymval = &symval;
} }
} }
@ -4557,8 +4558,7 @@ Target_tilegx<size, big_endian>::Relocate::relocate(
if (opt_t == tls::TLSOPT_NONE) { if (opt_t == tls::TLSOPT_NONE) {
Symbol *tls_sym = relinfo->symtab->lookup("__tls_get_addr"); Symbol *tls_sym = relinfo->symtab->lookup("__tls_get_addr");
symval.set_output_value( symval.set_output_value(
target->plt_address_for_global(tls_sym) target->plt_address_for_global(tls_sym));
+ tls_sym->plt_offset());
psymval = &symval; psymval = &symval;
TilegxReloc::imm_x_pcrel_general(view, object, psymval, TilegxReloc::imm_x_pcrel_general(view, object, psymval,
addend, address, r_howto); addend, address, r_howto);
@ -4870,7 +4870,7 @@ uint64_t
Target_tilegx<size, big_endian>::do_dynsym_value(const Symbol* gsym) const Target_tilegx<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
{ {
gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset()); gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
return this->plt_address_for_global(gsym) + gsym->plt_offset(); return this->plt_address_for_global(gsym);
} }
// Return the value to use for the base of a DW_EH_PE_datarel offset // Return the value to use for the base of a DW_EH_PE_datarel offset

View File

@ -1385,7 +1385,7 @@ Output_data_plt_x86_64<size>::address_for_global(const Symbol* gsym)
if (gsym->type() == elfcpp::STT_GNU_IFUNC if (gsym->type() == elfcpp::STT_GNU_IFUNC
&& gsym->can_use_relative_reloc(false)) && gsym->can_use_relative_reloc(false))
offset = (this->count_ + 1) * this->get_plt_entry_size(); offset = (this->count_ + 1) * this->get_plt_entry_size();
return this->address() + offset; return this->address() + offset + gsym->plt_offset();
} }
// Return the PLT address to use for a local symbol. These are always // Return the PLT address to use for a local symbol. These are always
@ -1393,9 +1393,12 @@ Output_data_plt_x86_64<size>::address_for_global(const Symbol* gsym)
template<int size> template<int size>
uint64_t uint64_t
Output_data_plt_x86_64<size>::address_for_local(const Relobj*, unsigned int) Output_data_plt_x86_64<size>::address_for_local(const Relobj* object,
unsigned int r_sym)
{ {
return this->address() + (this->count_ + 1) * this->get_plt_entry_size(); return (this->address()
+ (this->count_ + 1) * this->get_plt_entry_size()
+ object->local_plt_offset(r_sym));
} }
// Set the final size. // Set the final size.
@ -3234,8 +3237,7 @@ Target_x86_64<size>::Relocate::relocate(
if (gsym != NULL if (gsym != NULL
&& gsym->use_plt_offset(Scan::get_reference_flags(r_type))) && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
{ {
symval.set_output_value(target->plt_address_for_global(gsym) symval.set_output_value(target->plt_address_for_global(gsym));
+ gsym->plt_offset());
psymval = &symval; psymval = &symval;
} }
else if (gsym == NULL && psymval->is_ifunc_symbol()) else if (gsym == NULL && psymval->is_ifunc_symbol())
@ -3243,8 +3245,7 @@ Target_x86_64<size>::Relocate::relocate(
unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info()); unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
if (object->local_has_plt_offset(r_sym)) if (object->local_has_plt_offset(r_sym))
{ {
symval.set_output_value(target->plt_address_for_local(object, r_sym) symval.set_output_value(target->plt_address_for_local(object, r_sym));
+ object->local_plt_offset(r_sym));
psymval = &symval; psymval = &symval;
} }
} }
@ -4253,7 +4254,7 @@ uint64_t
Target_x86_64<size>::do_dynsym_value(const Symbol* gsym) const Target_x86_64<size>::do_dynsym_value(const Symbol* gsym) const
{ {
gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset()); gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
return this->plt_address_for_global(gsym) + gsym->plt_offset(); return this->plt_address_for_global(gsym);
} }
// Return a string used to fill a code section with nops to take up // Return a string used to fill a code section with nops to take up