[GOLD] PowerPC move plt indx_ out of unordered map key
authorAlan Modra <amodra@gmail.com>
Wed, 21 Jun 2017 00:40:00 +0000 (10:10 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 21 Jun 2017 13:15:15 +0000 (22:45 +0930)
I was lazy when adding indx_ to Plt_stub_ent.  The field isn't part of
the key, so ought to be part of the mapped type.  Make it so.

* powerpc.cc (Plt_stub_key): Rename from Plt_stub_ent.  Remove indx_.
(Plt_stub_key_hash): Rename from Plt_stub_ent_hash.
(struct Plt_stub_ent): New.
(Plt_stub_entries): Map from Plt_stub_key to Plt_stub_ent.  Adjust
use throughout file.

gold/ChangeLog
gold/powerpc.cc

index d6bcff8c8db3e2557d98c01e563914237c98eaf4..c6ebaa60e9fd7a33d5a667c7806507f21dd879dd 100644 (file)
@@ -1,3 +1,11 @@
+2017-06-21  Alan Modra  <amodra@gmail.com>
+
+       * powerpc.cc (Plt_stub_key): Rename from Plt_stub_ent.  Remove indx_.
+       (Plt_stub_key_hash): Rename from Plt_stub_ent_hash.
+       (struct Plt_stub_ent): New.
+       (Plt_stub_entries): Map from Plt_stub_key to Plt_stub_ent.  Adjust
+       use throughout file.
+
 2017-06-20  Eric Christopher  <echristo@gmail.com>
 
        * aarch64.cc (scan_reloc_for_stub): Use plt_address_for_global to
index a448efbc9440608aa847ae03a9c0f89944f1a3f9..3bd646748f507e07fd012377925dbbc690ebab5a 100644 (file)
@@ -4117,10 +4117,19 @@ class Stub_table : public Output_relaxed_input_section
   { return targ_; }
 
  private:
-  class Plt_stub_ent;
-  class Plt_stub_ent_hash;
-  typedef Unordered_map<Plt_stub_ent, unsigned int,
-                       Plt_stub_ent_hash> Plt_stub_entries;
+  class Plt_stub_key;
+  class Plt_stub_key_hash;
+  struct Plt_stub_ent
+  {
+    Plt_stub_ent(unsigned int off, unsigned int indx)
+      : off_(off), indx_(indx)
+    { }
+
+    unsigned int off_;
+    unsigned int indx_;
+  };
+  typedef Unordered_map<Plt_stub_key, Plt_stub_ent,
+                       Plt_stub_key_hash> Plt_stub_entries;
   class Branch_stub_ent;
   class Branch_stub_ent_hash;
   typedef Unordered_map<Branch_stub_ent, unsigned int,
@@ -4208,19 +4217,19 @@ class Stub_table : public Output_relaxed_input_section
   do_write(Output_file*);
 
   // Plt call stub keys.
-  class Plt_stub_ent
+  class Plt_stub_key
   {
   public:
-    Plt_stub_ent(const Symbol* sym)
+    Plt_stub_key(const Symbol* sym)
       : sym_(sym), object_(0), addend_(0), locsym_(0)
     { }
 
-    Plt_stub_ent(const Sized_relobj_file<size, big_endian>* object,
+    Plt_stub_key(const Sized_relobj_file<size, big_endian>* object,
                 unsigned int locsym_index)
       : sym_(NULL), object_(object), addend_(0), locsym_(locsym_index)
     { }
 
-    Plt_stub_ent(const Sized_relobj_file<size, big_endian>* object,
+    Plt_stub_key(const Sized_relobj_file<size, big_endian>* object,
                 const Symbol* sym,
                 unsigned int r_type,
                 Address addend)
@@ -4237,7 +4246,7 @@ class Stub_table : public Output_relaxed_input_section
        }
     }
 
-    Plt_stub_ent(const Sized_relobj_file<size, big_endian>* object,
+    Plt_stub_key(const Sized_relobj_file<size, big_endian>* object,
                 unsigned int locsym_index,
                 unsigned int r_type,
                 Address addend)
@@ -4250,7 +4259,7 @@ class Stub_table : public Output_relaxed_input_section
        this->addend_ = addend;
     }
 
-    bool operator==(const Plt_stub_ent& that) const
+    bool operator==(const Plt_stub_key& that) const
     {
       return (this->sym_ == that.sym_
              && this->object_ == that.object_
@@ -4262,13 +4271,12 @@ class Stub_table : public Output_relaxed_input_section
     const Sized_relobj_file<size, big_endian>* object_;
     typename elfcpp::Elf_types<size>::Elf_Addr addend_;
     unsigned int locsym_;
-    unsigned int indx_;
   };
 
-  class Plt_stub_ent_hash
+  class Plt_stub_key_hash
   {
   public:
-    size_t operator()(const Plt_stub_ent& ent) const
+    size_t operator()(const Plt_stub_key& ent) const
     {
       return (reinterpret_cast<uintptr_t>(ent.sym_)
              ^ reinterpret_cast<uintptr_t>(ent.object_)
@@ -4346,14 +4354,13 @@ Stub_table<size, big_endian>::add_plt_call_entry(
     unsigned int r_type,
     Address addend)
 {
-  Plt_stub_ent ent(object, gsym, r_type, addend);
-  unsigned int off = this->plt_size_;
-  ent.indx_ = this->plt_call_stubs_.size();
+  Plt_stub_key key(object, gsym, r_type, addend);
+  Plt_stub_ent ent(this->plt_size_, this->plt_call_stubs_.size());
   std::pair<typename Plt_stub_entries::iterator, bool> p
-    = this->plt_call_stubs_.insert(std::make_pair(ent, off));
+    = this->plt_call_stubs_.insert(std::make_pair(key, ent));
   if (p.second)
-    this->plt_size_ = off + this->plt_call_size(p.first);
-  return this->can_reach_stub(from, off, r_type);
+    this->plt_size_ = ent.off_ + this->plt_call_size(p.first);
+  return this->can_reach_stub(from, ent.off_, r_type);
 }
 
 template<int size, bool big_endian>
@@ -4365,14 +4372,13 @@ Stub_table<size, big_endian>::add_plt_call_entry(
     unsigned int r_type,
     Address addend)
 {
-  Plt_stub_ent ent(object, locsym_index, r_type, addend);
-  unsigned int off = this->plt_size_;
-  ent.indx_ = this->plt_call_stubs_.size();
+  Plt_stub_key key(object, locsym_index, r_type, addend);
+  Plt_stub_ent ent(this->plt_size_, this->plt_call_stubs_.size());
   std::pair<typename Plt_stub_entries::iterator, bool> p
-    = this->plt_call_stubs_.insert(std::make_pair(ent, off));
+    = this->plt_call_stubs_.insert(std::make_pair(key, ent));
   if (p.second)
-    this->plt_size_ = off + this->plt_call_size(p.first);
-  return this->can_reach_stub(from, off, r_type);
+    this->plt_size_ = ent.off_ + this->plt_call_size(p.first);
+  return this->can_reach_stub(from, ent.off_, r_type);
 }
 
 // Find a plt call stub.
@@ -4385,18 +4391,20 @@ Stub_table<size, big_endian>::find_plt_call_entry(
     unsigned int r_type,
     Address addend) const
 {
-  Plt_stub_ent ent(object, gsym, r_type, addend);
-  typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(ent);
-  return p == this->plt_call_stubs_.end() ? invalid_address : p->second;
+  Plt_stub_key key(object, gsym, r_type, addend);
+  typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(key);
+  if (p == this->plt_call_stubs_.end())
+    return invalid_address;
+  return p->second.off_;
 }
 
 template<int size, bool big_endian>
 typename Stub_table<size, big_endian>::Address
 Stub_table<size, big_endian>::find_plt_call_entry(const Symbol* gsym) const
 {
-  Plt_stub_ent ent(gsym);
-  typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(ent);
-  return p == this->plt_call_stubs_.end() ? invalid_address : p->second;
+  Plt_stub_key key(gsym);
+  typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(key);
+  return p == this->plt_call_stubs_.end() ? invalid_address : p->second.off_;
 }
 
 template<int size, bool big_endian>
@@ -4407,9 +4415,11 @@ Stub_table<size, big_endian>::find_plt_call_entry(
     unsigned int r_type,
     Address addend) const
 {
-  Plt_stub_ent ent(object, locsym_index, r_type, addend);
-  typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(ent);
-  return p == this->plt_call_stubs_.end() ? invalid_address : p->second;
+  Plt_stub_key key(object, locsym_index, r_type, addend);
+  typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(key);
+  if (p == this->plt_call_stubs_.end())
+    return invalid_address;
+  return p->second.off_;
 }
 
 template<int size, bool big_endian>
@@ -4418,9 +4428,9 @@ Stub_table<size, big_endian>::find_plt_call_entry(
     const Sized_relobj_file<size, big_endian>* object,
     unsigned int locsym_index) const
 {
-  Plt_stub_ent ent(object, locsym_index);
-  typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(ent);
-  return p == this->plt_call_stubs_.end() ? invalid_address : p->second;
+  Plt_stub_key key(object, locsym_index);
+  typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(key);
+  return p == this->plt_call_stubs_.end() ? invalid_address : p->second.off_;
 }
 
 // Add a long branch stub if we don't already have one to given
@@ -4647,7 +4657,7 @@ Stub_table<size, big_endian>::define_stub_syms(Symbol_table* symtab)
       for (plt_iter cs = this->plt_call_stubs_.begin();
           cs != this->plt_call_stubs_.end();
           ++cs)
-       sorted[cs->first.indx_] = cs;
+       sorted[cs->second.indx_] = cs;
 
       for (unsigned int i = 0; i < this->plt_call_stubs_.size(); ++i)
        {
@@ -4675,7 +4685,8 @@ Stub_table<size, big_endian>::define_stub_syms(Symbol_table* symtab)
            symname = cs->first.sym_->name();
          char* name = new char[8 + 10 + strlen(obj) + strlen(symname) + strlen(add) + 1];
          sprintf(name, "%08x.plt_call.%s%s%s", this->uniq_, obj, symname, add);
-         Address value = this->stub_address() - this->address() + cs->second;
+         Address value
+           = this->stub_address() - this->address() + cs->second.off_;
          unsigned int stub_size = this->plt_call_size(cs);
          this->targ_->define_local(symtab, name, this, value, stub_size);
        }
@@ -4775,7 +4786,7 @@ Stub_table<size, big_endian>::do_write(Output_file* of)
                  Address to
                    = this->targ_->glink_section()->address() + glinkoff;
                  Address from
-                   = (this->stub_address() + cs->second + 24
+                   = (this->stub_address() + cs->second.off_ + 24
                       + 4 * (ha(off) != 0)
                       + 4 * (ha(off + 8 + 8 * static_chain) != ha(off))
                       + 4 * static_chain);
@@ -4783,7 +4794,7 @@ Stub_table<size, big_endian>::do_write(Output_file* of)
                  use_fake_dep = cmp_branch_off + (1 << 25) >= (1 << 26);
                }
 
-             p = oview + cs->second;
+             p = oview + cs->second.off_;
              if (ha(off) != 0)
                {
                  write_insn<big_endian>(p, std_2_1 + this->targ_->stk_toc());
@@ -4937,7 +4948,7 @@ Stub_table<size, big_endian>::do_write(Output_file* of)
              else
                plt_addr += plt_base;
 
-             p = oview + cs->second;
+             p = oview + cs->second.off_;
              if (parameters->options().output_is_position_independent())
                {
                  Address got_addr;