public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [GOLD] tidy powerpc Glink_sym_ent
@ 2012-08-13 14:24 Alan Modra
  2012-08-13 16:11 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2012-08-13 14:24 UTC (permalink / raw)
  To: binutils; +Cc: Ian Lance Taylor

This tidies ppc32 plt call stub handling.  Glink_sym_ent tracked both
the object and .got2 section index, when just the object is sufficient.
I also move code handling the special case for R_PPC_PLTREL24 relocs
into Glink_sym_ent, and remove a needless accessor function.  OK to
apply?

	* powerpc.cc (Powerpc_relobj::set_got2_shndx): Delete.
	(Powerpc_relobj::do_find_special_sections): Don't use set_got2_shndx.
	(Output_data_glink::add_entry,find_entry): Remove shndx param.
	(class Glink_sym_ent): Rename from struct Glink_sym_ent.  Remove
	all references to shndx_.  Handle special case for R_PPC_PLTREL24
	here.
	(class Glink_sym_ent_hash): Rename from struct Glink_sym_ent_hash.
	(Output_data_glink::do_write): Retrieve got2_shdnx from object.
	(Target_powerpc::make_plt_entry): Don't special case R_PPC_PLTREL24
	here.
	(Target_powerpc::Scan::global): Nor on make_plt_entry call.
	(Target_powerpc::Relocate::relocate): Nor on glink->find_entry call.

Index: gold/powerpc.cc
===================================================================
RCS file: /cvs/src/src/gold/powerpc.cc,v
retrieving revision 1.46
diff -u -p -r1.46 powerpc.cc
--- gold/powerpc.cc	12 Aug 2012 03:07:32 -0000	1.46
+++ gold/powerpc.cc	12 Aug 2012 12:08:55 -0000
@@ -75,15 +75,6 @@ public:
       return 0;
   }
 
-  void
-  set_got2_shndx(unsigned int shndx)
-  {
-    if (size == 32)
-      this->got2_section_ = shndx;
-    else
-      gold_unreachable();
-  }
-
   bool
   do_find_special_sections(Read_symbols_data* sd);
 
@@ -722,7 +713,7 @@ Powerpc_relobj<size, big_endian>::do_fin
       if (s != NULL)
 	{
 	  unsigned int ndx = (s - pshdrs) / elfcpp::Elf_sizes<size>::shdr_size;
-	  this->set_got2_shndx(ndx);
+	  this->got2_section_ = ndx;
 	}
     }
   return Sized_relobj_file<size, big_endian>::do_find_special_sections(sd);
@@ -1117,11 +1108,11 @@ class Output_data_glink : public Output_
   // Add an entry
   void
   add_entry(const Symbol*, const elfcpp::Rela<size, big_endian>&,
-	    const Sized_relobj<size, big_endian>*, unsigned int);
+	    const Sized_relobj<size, big_endian>*);
 
   unsigned int
   find_entry(const Symbol*, const elfcpp::Rela<size, big_endian>&,
-	     const Sized_relobj<size, big_endian>*, unsigned int) const;
+	     const Sized_relobj<size, big_endian>*) const;
 
   unsigned int
   glink_entry_size() const
@@ -1150,54 +1141,50 @@ class Output_data_glink : public Output_
   void
   do_write(Output_file*);
 
-  struct Glink_sym_ent
+  class Glink_sym_ent
   {
-    Glink_sym_ent(const Symbol *sym,
+  public:
+    Glink_sym_ent(const Symbol* sym,
 		  const elfcpp::Rela<size, big_endian>& reloc,
-		  const Sized_relobj<size, big_endian>* object,
-		  unsigned int shndx)
-      : sym_(sym), object_(0), shndx_(0), addend_(0)
+		  const Sized_relobj<size, big_endian>* object)
+      : sym_(sym), object_(0), addend_(0)
     {
       if (size != 32)
 	this->addend_ = reloc.get_r_addend();
-      else if (parameters->options().output_is_position_independent())
+      else if (parameters->options().output_is_position_independent()
+	       && (elfcpp::elf_r_type<size>(reloc.get_r_info())
+		   == elfcpp::R_PPC_PLTREL24))
 	{
-	  if (object != NULL && shndx != 0)
-	    this->addend_ = reloc.get_r_addend();
+	  this->addend_ = reloc.get_r_addend();
 	  if (this->addend_ != 0)
-	    {
-	      this->object_ = object;
-	      this->shndx_ = shndx;
-	    }
+	    this->object_ = object;
 	}
     }
 
-    const Symbol *sym_;
+    const Symbol* sym_;
     const Sized_relobj<size, big_endian>* object_;
-    unsigned int shndx_;
     unsigned int addend_;
 
     bool operator==(const Glink_sym_ent& that) const
     {
       return (this->sym_ == that.sym_
 	      && this->object_ == that.object_
-              && this->shndx_ == that.shndx_
-              && this->addend_ == that.addend_);
+	      && this->addend_ == that.addend_);
     }
   };
 
-  struct Glink_sym_ent_hash
+  class Glink_sym_ent_hash
   {
+  public:
     size_t operator()(const Glink_sym_ent& ent) const
     {
       return (reinterpret_cast<uintptr_t>(ent.sym_)
 	      ^ reinterpret_cast<uintptr_t>(ent.object_)
-	      ^ ent.shndx_
 	      ^ ent.addend_);
     }
   };
 
-  // Set of sym/shndx/addend entries.
+  // Map sym/object/addend to index.
   typedef Unordered_map<Glink_sym_ent, unsigned int,
 			Glink_sym_ent_hash> Glink_entries;
   Glink_entries glink_entries_;
@@ -1220,17 +1207,16 @@ Output_data_glink<size, big_endian>::Out
 }
 
 // Add an entry to glink, if we do not already have one for this
-// sym/addend/shndx combo.
+// sym/object/addend combo.
 
 template<int size, bool big_endian>
 void
 Output_data_glink<size, big_endian>::add_entry(
     const Symbol* gsym,
     const elfcpp::Rela<size, big_endian>& reloc,
-    const Sized_relobj<size, big_endian>* object,
-    unsigned int shndx)
+    const Sized_relobj<size, big_endian>* object)
 {
-  Glink_sym_ent ent(gsym, reloc, object, shndx);
+  Glink_sym_ent ent(gsym, reloc, object);
   unsigned int indx = this->glink_entries_.size();
   this->glink_entries_.insert(std::make_pair(ent, indx));
 }
@@ -1240,10 +1226,9 @@ unsigned int
 Output_data_glink<size, big_endian>::find_entry(
     const Symbol* gsym,
     const elfcpp::Rela<size, big_endian>& reloc,
-    const Sized_relobj<size, big_endian>* object,
-    unsigned int shndx) const
+    const Sized_relobj<size, big_endian>* object) const
 {
-  Glink_sym_ent ent(gsym, reloc, object, shndx);
+  Glink_sym_ent ent(gsym, reloc, object);
   typename Glink_entries::const_iterator p = this->glink_entries_.find(ent);
   gold_assert(p != this->glink_entries_.end());
   return p->second;
@@ -1433,11 +1418,15 @@ Output_data_glink<size, big_endian>::do_
 	  p = oview + g->second * this->glink_entry_size();
 	  if (parameters->options().output_is_position_independent())
 	    {
-	      unsigned int got2 = g->first.shndx_;
-	      if (got2)
-		got_addr = (g->first.object_->output_section(got2)->address()
-			    + g->first.object_->output_section_offset(got2)
-			    + g->first.addend_);
+	      const Powerpc_relobj<size, big_endian>* object = static_cast
+		<const Powerpc_relobj<size, big_endian>*>(g->first.object_);
+	      if (object != NULL)
+		{
+		  unsigned int got2 = object->got2_shndx();
+		  got_addr = (g->first.object_->output_section(got2)->address()
+			      + g->first.object_->output_section_offset(got2)
+			      + g->first.addend_);
+		}
 	      else
 		got_addr = g_o_t;
 
@@ -1572,14 +1561,7 @@ Target_powerpc<size, big_endian>::make_p
 
   this->plt_->add_entry(gsym);
 
-  unsigned int got2_shndx = 0;
-  if (size == 32 && object != NULL)
-    {
-      const Powerpc_relobj<size, big_endian>* ppc_obj
-	= static_cast<const Powerpc_relobj<size, big_endian>*>(object);
-      got2_shndx = ppc_obj->got2_shndx();
-    }
-  this->glink_->add_entry(gsym, reloc, object, got2_shndx);
+  this->glink_->add_entry(gsym, reloc, object);
 }
 
 // Return the number of entries in the PLT.
@@ -2046,12 +2028,7 @@ Target_powerpc<size, big_endian>::Scan::
 		 && !(gsym->is_defined()
 		      && !gsym->is_from_dynobj()
 		      && !gsym->is_preemptible())))
-	  {
-	    if (r_type == elfcpp::R_PPC_PLTREL24)
-	      target->make_plt_entry(layout, gsym, reloc, object);
-	    else
-	      target->make_plt_entry(layout, gsym, reloc, 0);
-	  }
+	  target->make_plt_entry(layout, gsym, reloc, object);
 	// Make a dynamic relocation if necessary.
 	if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
 	  {
@@ -2328,10 +2305,7 @@ Target_powerpc<size, big_endian>::Reloca
       const Output_data_glink<size, big_endian>* glink;
 
       glink = target->glink_section();
-      unsigned int shndx = 0;
-      if (size == 32 && r_type == elfcpp::R_PPC_PLTREL24)
-	shndx = object->got2_shndx();
-      unsigned int glink_index = glink->find_entry(gsym, rela, object, shndx);
+      unsigned int glink_index = glink->find_entry(gsym, rela, object);
       value = glink->address() + glink_index * glink->glink_entry_size();
     }
   else

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [GOLD] tidy powerpc Glink_sym_ent
  2012-08-13 14:24 [GOLD] tidy powerpc Glink_sym_ent Alan Modra
@ 2012-08-13 16:11 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2012-08-13 16:11 UTC (permalink / raw)
  To: binutils

On Mon, Aug 13, 2012 at 7:11 AM, Alan Modra <amodra@gmail.com> wrote:
>
>         * powerpc.cc (Powerpc_relobj::set_got2_shndx): Delete.
>         (Powerpc_relobj::do_find_special_sections): Don't use set_got2_shndx.
>         (Output_data_glink::add_entry,find_entry): Remove shndx param.
>         (class Glink_sym_ent): Rename from struct Glink_sym_ent.  Remove
>         all references to shndx_.  Handle special case for R_PPC_PLTREL24
>         here.
>         (class Glink_sym_ent_hash): Rename from struct Glink_sym_ent_hash.
>         (Output_data_glink::do_write): Retrieve got2_shdnx from object.
>         (Target_powerpc::make_plt_entry): Don't special case R_PPC_PLTREL24
>         here.
>         (Target_powerpc::Scan::global): Nor on make_plt_entry call.
>         (Target_powerpc::Relocate::relocate): Nor on glink->find_entry call.

This is OK.

Thanks.

In general, please feel free to commit changes to gold/powerpc.cc
without prior review.  I would prefer to review patches to the other
files in gold, though.  Of course I'm happy to look at any patch to
powerpc.cc if you aren't sure about it.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-13 16:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-13 14:24 [GOLD] tidy powerpc Glink_sym_ent Alan Modra
2012-08-13 16:11 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).