This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[GOLD] plt_address_for_global/local


plt_address_for_global/_local currently returns the plt base address
to which a symbol's plt_offset applies.  This patch makes the
functions instead return the actual plt entry address.  ie. We add
plt_offset in the function instead of at each call point.  I'd like it
that way for powerpc, where the value we need to use doesn't include
plt_offset.  eg.

// Return the PLT address to use for a global symbol.
template<int size, bool big_endian>
uint64_t
Target_powerpc<size, big_endian>::do_plt_address_for_global(
    const Symbol* gsym) const
{
  if (size == 32)
    {
      const Output_data_glink<size, big_endian>* glink = this->glink_section();
      unsigned int glink_index = glink->find_entry(gsym);
      return glink->address() + glink_index * glink->glink_entry_size();
    }
  else
    gold_unreachable();
}

I could keep the same interface but then I'd need to subtract
gsym->plt_offset().  OK to apply?

	* 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.

Index: gold/i386.cc
===================================================================
RCS file: /cvs/src/src/gold/i386.cc,v
retrieving revision 1.148
diff -u -p -r1.148 i386.cc
--- gold/i386.cc	12 Sep 2012 22:43:53 -0000	1.148
+++ gold/i386.cc	28 Sep 2012 09:51:26 -0000
@@ -1151,16 +1151,19 @@ Output_data_plt_i386::address_for_global
   if (gsym->type() == elfcpp::STT_GNU_IFUNC
       && gsym->can_use_relative_reloc(false))
     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
 // IRELATIVE relocs.
 
 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.
@@ -2677,8 +2680,7 @@ Target_i386::Relocate::relocate(const Re
   else if (gsym != NULL
 	   && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
     {
-      symval.set_output_value(target->plt_address_for_global(gsym)
-			      + gsym->plt_offset());
+      symval.set_output_value(target->plt_address_for_global(gsym));
       psymval = &symval;
     }
   else if (gsym == NULL && psymval->is_ifunc_symbol())
@@ -2686,8 +2688,7 @@ Target_i386::Relocate::relocate(const Re
       unsigned int r_sym = elfcpp::elf_r_sym<32>(rel.get_r_info());
       if (object->local_has_plt_offset(r_sym))
 	{
-	  symval.set_output_value(target->plt_address_for_local(object, r_sym)
-				  + object->local_plt_offset(r_sym));
+	  symval.set_output_value(target->plt_address_for_local(object, r_sym));
 	  psymval = &symval;
 	}
     }
@@ -3649,7 +3650,7 @@ uint64_t
 Target_i386::do_dynsym_value(const Symbol* gsym) const
 {
   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
Index: gold/sparc.cc
===================================================================
RCS file: /cvs/src/src/gold/sparc.cc,v
retrieving revision 1.61
diff -u -p -r1.61 sparc.cc
--- gold/sparc.cc	12 Sep 2012 22:43:54 -0000	1.61
+++ gold/sparc.cc	28 Sep 2012 09:51:27 -0000
@@ -1619,7 +1619,7 @@ Output_data_plt_sparc<size, big_endian>:
   if (gsym->type() == elfcpp::STT_GNU_IFUNC
       && gsym->can_use_relative_reloc(false))
     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
@@ -1628,10 +1628,12 @@ Output_data_plt_sparc<size, big_endian>:
 template<int size, bool big_endian>
 uint64_t
 Output_data_plt_sparc<size, big_endian>::address_for_local(
-	const Relobj*,
-	unsigned int)
+	const Relobj* object,
+	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;
@@ -3199,7 +3201,7 @@ Target_sparc<size, big_endian>::Relocate
     {
       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);
 
@@ -3210,8 +3212,7 @@ Target_sparc<size, big_endian>::Relocate
       unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
       if (object->local_has_plt_offset(r_sym))
 	{
-	  symval.set_output_value(target->plt_address_for_local(object, r_sym)
-				  + object->local_plt_offset(r_sym));
+	  symval.set_output_value(target->plt_address_for_local(object, r_sym));
 	  psymval = &symval;
 	}
     }
Index: gold/tilegx.cc
===================================================================
RCS file: /cvs/src/src/gold/tilegx.cc,v
retrieving revision 1.1
diff -u -p -r1.1 tilegx.cc
--- gold/tilegx.cc	15 Sep 2012 17:11:28 -0000	1.1
+++ gold/tilegx.cc	28 Sep 2012 09:51:28 -0000
@@ -2194,7 +2194,7 @@ Output_data_plt_tilegx<size, big_endian>
   if (gsym->type() == elfcpp::STT_GNU_IFUNC
       && gsym->can_use_relative_reloc(false))
     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
@@ -2202,10 +2202,13 @@ Output_data_plt_tilegx<size, big_endian>
 
 template<int size, bool big_endian>
 uint64_t
-Output_data_plt_tilegx<size, big_endian>::address_for_local(const Relobj*,
-                                                            unsigned int)
-{
-  return this->address() + (this->count_ + 1) * this->get_plt_entry_size();
+Output_data_plt_tilegx<size, big_endian>::address_for_local(
+    const Relobj* object,
+    unsigned int r_sym)
+{
+  return (this->address()
+	  + (this->count_ + 1) * this->get_plt_entry_size()
+	  + object->local_plt_offset(r_sym));
 }
 
 // Set the final size.
@@ -4327,8 +4330,7 @@ Target_tilegx<size, big_endian>::Relocat
   if (gsym != NULL
       && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
     {
-      symval.set_output_value(target->plt_address_for_global(gsym)
-                              + gsym->plt_offset());
+      symval.set_output_value(target->plt_address_for_global(gsym));
       psymval = &symval;
     }
   else if (gsym == NULL && psymval->is_ifunc_symbol())
@@ -4336,8 +4338,7 @@ Target_tilegx<size, big_endian>::Relocat
       unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
       if (object->local_has_plt_offset(r_sym))
         {
-          symval.set_output_value(target->plt_address_for_local(object, r_sym)
-                                  + object->local_plt_offset(r_sym));
+          symval.set_output_value(target->plt_address_for_local(object, r_sym));
           psymval = &symval;
         }
     }
@@ -4546,8 +4547,7 @@ Target_tilegx<size, big_endian>::Relocat
                 if (opt_t == tls::TLSOPT_NONE) {
                   Symbol *tls_sym = relinfo->symtab->lookup("__tls_get_addr");
                   symval.set_output_value(
-                    target->plt_address_for_global(tls_sym)
-                     + tls_sym->plt_offset());
+                    target->plt_address_for_global(tls_sym));
                   psymval = &symval;
                   TilegxReloc::imm_x_pcrel_general(view, object, psymval,
                                                    addend, address, r_howto);
@@ -4858,7 +4858,7 @@ uint64_t
 Target_tilegx<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
 {
   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
Index: gold/x86_64.cc
===================================================================
RCS file: /cvs/src/src/gold/x86_64.cc,v
retrieving revision 1.157
diff -u -p -r1.157 x86_64.cc
--- gold/x86_64.cc	12 Sep 2012 22:43:54 -0000	1.157
+++ gold/x86_64.cc	28 Sep 2012 09:51:28 -0000
@@ -1385,7 +1385,7 @@ Output_data_plt_x86_64<size>::address_fo
   if (gsym->type() == elfcpp::STT_GNU_IFUNC
       && gsym->can_use_relative_reloc(false))
     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
@@ -1393,9 +1393,12 @@ Output_data_plt_x86_64<size>::address_fo
 
 template<int size>
 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.
@@ -3234,8 +3237,7 @@ Target_x86_64<size>::Relocate::relocate(
   if (gsym != NULL
       && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
     {
-      symval.set_output_value(target->plt_address_for_global(gsym)
-			      + gsym->plt_offset());
+      symval.set_output_value(target->plt_address_for_global(gsym));
       psymval = &symval;
     }
   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());
       if (object->local_has_plt_offset(r_sym))
 	{
-	  symval.set_output_value(target->plt_address_for_local(object, r_sym)
-				  + object->local_plt_offset(r_sym));
+	  symval.set_output_value(target->plt_address_for_local(object, r_sym));
 	  psymval = &symval;
 	}
     }
@@ -4253,7 +4254,7 @@ uint64_t
 Target_x86_64<size>::do_dynsym_value(const Symbol* gsym) const
 {
   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
Index: gold/target.h
===================================================================
RCS file: /cvs/src/src/gold/target.h,v
retrieving revision 1.70
diff -u -p -r1.70 target.h
--- gold/target.h	10 Sep 2012 23:05:54 -0000	1.70
+++ gold/target.h	28 Sep 2012 09:51:27 -0000
@@ -256,16 +256,12 @@ class Target
   reloc_addend(void* arg, unsigned int type, uint64_t addend) const
   { return this->do_reloc_addend(arg, type, addend); }
 
-  // Return the PLT address to use for a global symbol.  This is used
-  // for STT_GNU_IFUNC symbols.  The symbol's plt_offset is relative
-  // to this PLT address.
+  // Return the PLT address to use for a global symbol.
   uint64_t
   plt_address_for_global(const Symbol* sym) const
   { return this->do_plt_address_for_global(sym); }
 
-  // Return the PLT address to use for a local symbol.  This is used
-  // for STT_GNU_IFUNC symbols.  The symbol's plt_offset is relative
-  // to this PLT address.
+  // Return the PLT address to use for a local symbol.
   uint64_t
   plt_address_for_local(const Relobj* object, unsigned int symndx) const
   { return this->do_plt_address_for_local(object, symndx); }
Index: gold/output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.174
diff -u -p -r1.174 output.cc
--- gold/output.cc	12 Sep 2012 18:29:18 -0000	1.174
+++ gold/output.cc	28 Sep 2012 09:51:26 -0000
@@ -1129,11 +1129,7 @@ Output_reloc<elfcpp::SHT_REL, dynamic, s
       const Sized_symbol<size>* sym;
       sym = static_cast<const Sized_symbol<size>*>(this->u1_.gsym);
       if (this->use_plt_offset_ && sym->has_plt_offset())
-	{
-	  uint64_t plt_address =
-	    parameters->target().plt_address_for_global(sym);
-	  return plt_address + sym->plt_offset();
-	}
+	return parameters->target().plt_address_for_global(sym);
       else
 	return sym->value() + addend;
     }
@@ -1151,11 +1147,7 @@ Output_reloc<elfcpp::SHT_REL, dynamic, s
       this->u1_.relobj->sized_relobj();
   gold_assert(relobj != NULL);
   if (this->use_plt_offset_)
-    {
-      uint64_t plt_address =
-	  parameters->target().plt_address_for_local(relobj, lsi);
-      return plt_address + relobj->local_plt_offset(lsi);
-    }
+    return parameters->target().plt_address_for_local(relobj, lsi);
   const Symbol_value<size>* symval = relobj->local_symbol(lsi);
   return symval->value(relobj, addend);
 }
@@ -1385,8 +1377,7 @@ Output_data_got<got_size, big_endian>::G
 	// RELATIVE relocation.
 	Symbol* gsym = this->u_.gsym;
 	if (this->use_plt_or_tls_offset_ && gsym->has_plt_offset())
-	  val = (parameters->target().plt_address_for_global(gsym)
-		 + gsym->plt_offset());
+	  val = parameters->target().plt_address_for_global(gsym);
 	else
 	  {
 	    switch (parameters->size_and_endianness())
@@ -1442,11 +1433,7 @@ Output_data_got<got_size, big_endian>::G
         const unsigned int lsi = this->local_sym_index_;
 	bool is_tls = object->local_is_tls(lsi);
 	if (this->use_plt_or_tls_offset_ && !is_tls)
-	  {
-	    uint64_t plt_address =
-	      parameters->target().plt_address_for_local(object, lsi);
-	    val = plt_address + object->local_plt_offset(lsi);
-	  }
+	  val = parameters->target().plt_address_for_local(object, lsi);
 	else
 	  {
 	    uint64_t lval = object->local_symbol_value(lsi, 0);
@@ -2609,9 +2596,9 @@ Output_section::add_relaxed_input_sectio
 
   // For a relaxed section, we use the current data size.  Linker scripts
   // 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
-  // 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 aligned_offset_in_section = align_address(offset_in_section,
 						  poris->addralign());
Index: gold/output.h
===================================================================
RCS file: /cvs/src/src/gold/output.h,v
retrieving revision 1.140
diff -u -p -r1.140 output.h
--- gold/output.h	10 Sep 2012 23:05:54 -0000	1.140
+++ gold/output.h	28 Sep 2012 09:51:26 -0000
@@ -2247,7 +2247,7 @@ class Output_data_got : public Output_da
   add_global_plt(Symbol* gsym, unsigned int got_type);
 
   // 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
   add_global_tls(Symbol* gsym, unsigned int got_type)
   { return add_global_plt(gsym, got_type); }
@@ -2277,7 +2277,7 @@ class Output_data_got : public Output_da
   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
-  // offset using Target::tls_offset_for_local
+  // offset using Target::tls_offset_for_local.
   bool
   add_local_tls(Relobj* object, unsigned int sym_index, unsigned int got_type)
   { return add_local_plt(object, sym_index, got_type); }

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]