2010-01-20 Doug Kwan <dougkwan@google.com>
authorDoug Kwan <dougkwan@google.com>
Wed, 20 Jan 2010 17:29:52 +0000 (17:29 +0000)
committerDoug Kwan <dougkwan@google.com>
Wed, 20 Jan 2010 17:29:52 +0000 (17:29 +0000)
* arm.cc (Target_arm::Arm_input_section_map): Change key type from
Input_section_specifier to Section_id.
(Target_arm::new_arm_input_section: Adjust code for change of key
type.
(Target_arm::find_arm_input_section): Ditto.
* gc.h (object.h): Include for Section_id nand Section_id_hash.
(Section_id): Remove.
(Garbage_collection::Section_id_hash): Remove.
* icf.h (object.h): Include for Section_id nand Section_id_hash.
(Section_id): Remove.
(Icf::Section_id_hash): Remove.
* object.h (Section_id, Const_section_id, Section_id_hash,
Const_section_id_hash): New type definitions.
* output.cc (Output_section::add_relaxed_input_section): Change to
use Const_section_id instead of Input_section_specifier as key type.
(Output_section::add_merge_input_section): Ditto.
(Output_section::build_relaxation_map): Change to use Section_id
instead of Input_section_specifier as key type.
  (Output_section::convert_input_sections_in_list_to_relaxed_sections):
Ditto.
(Output_section::convert_input_sections_to_relaxed_sections): Change
to use Const_section_id instead of Input_section_specifier as key type.
  (Output_section::find_merge_section): Ditto.
(Output_section::find_relaxed_input_section): Ditto.
* output.h (Input_section_specifier): Remove class.
(Output_section::Output_section_data_by_input_section_map): Change
key type to Const_section_id.
(Output_section::Output_relaxed_input_section_by_input_section_map):
Ditto.
(Output_section::Relaxation_map): Change key type to Section_id.

gold/ChangeLog
gold/arm.cc
gold/gc.h
gold/icf.h
gold/object.h
gold/output.cc
gold/output.h

index 0752d081f571a99974df9a08b80a24b9ca2d2dfc..af6718ab2ac73ac647dd528b74b911f231eec65f 100644 (file)
@@ -1,3 +1,36 @@
+2010-01-20  Doug Kwan  <dougkwan@google.com>
+
+       * arm.cc (Target_arm::Arm_input_section_map): Change key type from
+       Input_section_specifier to Section_id.
+       (Target_arm::new_arm_input_section: Adjust code for change of key
+       type.
+       (Target_arm::find_arm_input_section): Ditto.
+       * gc.h (object.h): Include for Section_id nand Section_id_hash.
+       (Section_id): Remove.
+       (Garbage_collection::Section_id_hash): Remove.
+       * icf.h (object.h): Include for Section_id nand Section_id_hash.
+       (Section_id): Remove.
+       (Icf::Section_id_hash): Remove.
+       * object.h (Section_id, Const_section_id, Section_id_hash,
+       Const_section_id_hash): New type definitions.
+       * output.cc (Output_section::add_relaxed_input_section): Change to
+       use Const_section_id instead of Input_section_specifier as key type.
+       (Output_section::add_merge_input_section): Ditto.
+       (Output_section::build_relaxation_map): Change to use Section_id
+       instead of Input_section_specifier as key type.
+       (Output_section::convert_input_sections_in_list_to_relaxed_sections):
+       Ditto.
+       (Output_section::convert_input_sections_to_relaxed_sections): Change
+       to use Const_section_id instead of Input_section_specifier as key type.
+       (Output_section::find_merge_section): Ditto.
+       (Output_section::find_relaxed_input_section): Ditto.
+       * output.h (Input_section_specifier): Remove class.
+       (Output_section::Output_section_data_by_input_section_map): Change
+       key type to Const_section_id.
+       (Output_section::Output_relaxed_input_section_by_input_section_map):
+       Ditto.
+       (Output_section::Relaxation_map): Change key type to Section_id.
+
 2010-01-20  Viktor Kutuzov  <vkutuzov@accesssoftek.com>
 
        * gold/arm.cc: Added support for R_ARM_V4BX relocation
index 87459a5f134ac1612f786912ec02bbe49ffe8c1f..8e3573f6421fd23f08ca3f003b7b34cae58e296b 100644 (file)
@@ -2114,10 +2114,9 @@ class Target_arm : public Sized_target<32, big_endian>
   typedef typename std::vector<Stub_table<big_endian>*> Stub_table_list;
 
   // Map input section to Arm_input_section.
-  typedef Unordered_map<Input_section_specifier,
+  typedef Unordered_map<Section_id,
                        Arm_input_section<big_endian>*,
-                       Input_section_specifier::hash,
-                       Input_section_specifier::equal_to>
+                       Section_id_hash>
          Arm_input_section_map;
     
   // Map output addresses to relocs for Cortex-A8 erratum.
@@ -7543,7 +7542,7 @@ Target_arm<big_endian>::new_arm_input_section(
     Relobj* relobj,
     unsigned int shndx)
 {
-  Input_section_specifier iss(relobj, shndx);
+  Section_id sid(relobj, shndx);
 
   Arm_input_section<big_endian>* arm_input_section =
     new Arm_input_section<big_endian>(relobj, shndx);
@@ -7551,7 +7550,7 @@ Target_arm<big_endian>::new_arm_input_section(
 
   // Register new Arm_input_section in map for look-up.
   std::pair<typename Arm_input_section_map::iterator, bool> ins =
-    this->arm_input_section_map_.insert(std::make_pair(iss, arm_input_section));
+    this->arm_input_section_map_.insert(std::make_pair(sid, arm_input_section));
 
   // Make sure that it we have not created another Arm_input_section
   // for this input section already.
@@ -7569,9 +7568,9 @@ Target_arm<big_endian>::find_arm_input_section(
     Relobj* relobj,
     unsigned int shndx) const
 {
-  Input_section_specifier iss(relobj, shndx);
+  Section_id sid(relobj, shndx);
   typename Arm_input_section_map::const_iterator p =
-    this->arm_input_section_map_.find(iss);
+    this->arm_input_section_map_.find(sid);
   return (p != this->arm_input_section_map_.end()) ? p->second : NULL;
 }
 
index 3885d1a23a8d3f4763263c4009e5456385b236ed..1ffb590fb72aee4d0c68e4fd6c1f68a94db467b5 100644 (file)
--- a/gold/gc.h
+++ b/gold/gc.h
@@ -28,6 +28,7 @@
 
 #include "elfcpp.h"
 #include "symtab.h"
+#include "object.h"
 #include "icf.h"
 
 namespace gold
@@ -45,16 +46,8 @@ class Output_section;
 class General_options;
 class Layout;
 
-typedef std::pair<Object *, unsigned int> Section_id;
-
 class Garbage_collection
 {
-  struct Section_id_hash
-  {
-    size_t operator()(const Section_id& loc) const
-    { return reinterpret_cast<uintptr_t>(loc.first) ^ loc.second; }
-  };
-
  public:
 
   typedef Unordered_set<Section_id, Section_id_hash> Sections_reachable;
index de0fbe088f53c34546ea941166eee2c45dca3c54..e3365721055d0af1a1daa52f5034744583f46c40 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "elfcpp.h"
 #include "symtab.h"
+#include "object.h"
 
 namespace gold
 {
@@ -35,17 +36,9 @@ class Object;
 class Input_objects;
 class Symbol_table;
 
-typedef std::pair<Object*, unsigned int> Section_id;
-
 class Icf
 {
  public:
-  struct Section_id_hash
-  {
-    size_t operator()(const Section_id& loc) const
-    { return reinterpret_cast<uintptr_t>(loc.first) ^ loc.second; }
-  };
-
   typedef std::vector<Section_id> Sections_reachable_list;
   typedef std::vector<Symbol*> Symbol_info;
   typedef std::vector<std::pair<long long, long long> > Addend_info;
index 26e85f5b6a8373155aa6c6533e96f7e60ec328f1..d0068563b5a15047fdb34a7509fd6c826ea74567 100644 (file)
@@ -2050,6 +2050,31 @@ struct Relocate_info
   location(size_t relnum, off_t reloffset) const;
 };
 
+// This is used to represent a section in an object and is used as the
+// key type for various section maps.
+typedef std::pair<Object*, unsigned int> Section_id;
+
+// This is similar to Section_id but is used when the section
+// pointers are const.
+typedef std::pair<const Object*, unsigned int> Const_section_id;
+
+// The hash value is based on the address of an object in memory during
+// linking.  It is okay to use this for looking up sections but never use
+// this in an unordered container that we want to traverse in a repeatable
+// manner.
+
+struct Section_id_hash
+{
+  size_t operator()(const Section_id& loc) const
+  { return reinterpret_cast<uintptr_t>(loc.first) ^ loc.second; }
+};
+
+struct Const_section_id_hash
+{
+  size_t operator()(const Const_section_id& loc) const
+  { return reinterpret_cast<uintptr_t>(loc.first) ^ loc.second; }
+};
+
 // Return whether INPUT_FILE contains an ELF object start at file
 // offset OFFSET.  This sets *START to point to a view of the start of
 // the file.  It sets *READ_SIZE to the number of bytes in the view.
index 2a97078c7410812581ec7a890bf248bf782d865e..6374895a5e4bb1c6d4ed26d96d485fbf460e4ad4 100644 (file)
@@ -2072,8 +2072,8 @@ Output_section::add_relaxed_input_section(Output_relaxed_input_section* poris)
   this->add_output_section_data(&inp);
   if (this->is_relaxed_input_section_map_valid_)
     {
-      Input_section_specifier iss(poris->relobj(), poris->shndx());
-      this->relaxed_input_section_map_[iss] = poris;
+      Const_section_id csid(poris->relobj(), poris->shndx());
+      this->relaxed_input_section_map_[csid] = poris;
     }
 
   // For a relaxed section, we use the current data size.  Linker scripts
@@ -2145,8 +2145,8 @@ Output_section::add_merge_input_section(Relobj* object, unsigned int shndx,
                  && merge_section->addralign() == addralign);
 
       // Link input section to found merge section.
-      Input_section_specifier iss(object, shndx);
-      this->merge_section_map_[iss] = merge_section;
+      Const_section_id csid(object, shndx);
+      this->merge_section_map_[csid] = merge_section;
       return true;
     }
 
@@ -2181,8 +2181,8 @@ Output_section::add_merge_input_section(Relobj* object, unsigned int shndx,
   // Add input section to new merge section and link input section to new
   // merge section in map.
   pomb->add_input_section(object, shndx);
-  Input_section_specifier iss(object, shndx);
-  this->merge_section_map_[iss] = pomb;
+  Const_section_id csid(object, shndx);
+  this->merge_section_map_[csid] = pomb;
 
   return true;
 }
@@ -2201,15 +2201,15 @@ Output_section::build_relaxation_map(
       const Input_section& is(input_sections[i]);
       if (is.is_input_section() || is.is_relaxed_input_section())
        {
-         Input_section_specifier iss(is.relobj(), is.shndx());
-         (*relaxation_map)[iss] = i;
+         Section_id sid(is.relobj(), is.shndx());
+         (*relaxation_map)[sid] = i;
        }
     }
 }
 
 // Convert regular input sections in INPUT_SECTIONS into relaxed input
-// sections in RELAXED_SECTIONS.  MAP is a prebuilt map from input section
-// specifier to indices of INPUT_SECTIONS.
+// sections in RELAXED_SECTIONS.  MAP is a prebuilt map from section id
+// indices of INPUT_SECTIONS.
 
 void
 Output_section::convert_input_sections_in_list_to_relaxed_sections(
@@ -2220,8 +2220,8 @@ Output_section::convert_input_sections_in_list_to_relaxed_sections(
   for (size_t i = 0; i < relaxed_sections.size(); ++i)
     {
       Output_relaxed_input_section* poris = relaxed_sections[i];
-      Input_section_specifier iss(poris->relobj(), poris->shndx());
-      Relaxation_map::const_iterator p = map.find(iss);
+      Section_id sid(poris->relobj(), poris->shndx());
+      Relaxation_map::const_iterator p = map.find(sid);
       gold_assert(p != map.end());
       gold_assert((*input_sections)[p->second].is_input_section());
       (*input_sections)[p->second] = Input_section(poris);
@@ -2283,8 +2283,8 @@ Output_section::convert_input_sections_to_relaxed_sections(
     for (size_t i = 0; i < relaxed_sections.size(); ++i)
       {
        Output_relaxed_input_section* poris = relaxed_sections[i];
-       Input_section_specifier iss(poris->relobj(), poris->shndx());
-       this->relaxed_input_section_map_[iss] = poris;
+       Const_section_id csid(poris->relobj(), poris->shndx());
+       this->relaxed_input_section_map_[csid] = poris;
       }
 }
 
@@ -2329,9 +2329,9 @@ Output_section_data*
 Output_section::find_merge_section(const Relobj* object,
                                   unsigned int shndx) const
 {
-  Input_section_specifier iss(object, shndx);
+  Const_section_id csid(object, shndx);
   Output_section_data_by_input_section_map::const_iterator p =
-    this->merge_section_map_.find(iss);
+    this->merge_section_map_.find(csid);
   if (p != this->merge_section_map_.end())
     {
       Output_section_data* posd = p->second;
@@ -2360,16 +2360,16 @@ Output_section::find_relaxed_input_section(const Relobj* object,
           ++p)
        if (p->is_relaxed_input_section())
          {
-           Input_section_specifier iss(p->relobj(), p->shndx());
-           this->relaxed_input_section_map_[iss] =
+           Const_section_id csid(p->relobj(), p->shndx());
+           this->relaxed_input_section_map_[csid] =
              p->relaxed_input_section();
          }
       this->is_relaxed_input_section_map_valid_ = true;
     }
 
-  Input_section_specifier iss(object, shndx);
+  Const_section_id csid(object, shndx);
   Output_relaxed_input_section_by_input_section_map::const_iterator p =
-    this->relaxed_input_section_map_.find(iss);
+    this->relaxed_input_section_map_.find(csid);
   if (p != this->relaxed_input_section_map_.end())
     return p->second;
   else
index 7a356526cb61e9232e15a893632eee631b730867..ec16ca3ff550a1ad9a9f57073fac1f67685741e5 100644 (file)
@@ -47,62 +47,6 @@ class Sized_target;
 template<int size, bool big_endian>
 class Sized_relobj;
 
-// This class specifies an input section.  It is used as a key type
-// for maps.
-
-class Input_section_specifier
-{
- public:
-  Input_section_specifier(const Relobj* relobj, unsigned int shndx)
-    : relobj_(relobj), shndx_(shndx)
-  { }
-   
-  // Return Relobj of this.
-  const Relobj*
-  relobj() const
-  { return this->relobj_; }
-
-  // Return section index of this.
-  unsigned int
-  shndx() const
-  { return this->shndx_; }
-
-  // Whether this equals to another specifier ISS.
-  bool
-  eq(const Input_section_specifier& iss) const
-  { return this->relobj_ == iss.relobj_ && this->shndx_ == iss.shndx_; }
-
-  // Compute a hash value of this.
-  size_t
-  hash_value() const
-  {
-     return (gold::string_hash<char>(this->relobj_->name().c_str())
-            ^ this->shndx_);
-   }
-
-  // Functors for containers.
-  struct equal_to
-  {
-    bool
-    operator()(const Input_section_specifier& iss1,
-              const Input_section_specifier& iss2) const
-    { return iss1.eq(iss2); }
-  };
-  struct hash
-  {
-    size_t
-    operator()(const Input_section_specifier& iss) const
-    { return iss.hash_value(); }
-  };
-
- private:
-  // An object.
-  const Relobj* relobj_;
-  // A section index. 
-  unsigned int shndx_;
-};
-
 // An abtract class for data which has to go into the output file.
 
 class Output_data
@@ -3396,25 +3340,20 @@ class Output_section : public Output_data
                        Merge_section_properties::equal_to>
     Merge_section_by_properties_map;
 
-  // Map that link Input_section_specifier to Output_section_data.
-  typedef Unordered_map<Input_section_specifier, Output_section_data*,
-                       Input_section_specifier::hash,
-                       Input_section_specifier::equal_to>
+  // Map that link Const_section_id to Output_section_data.
+  typedef Unordered_map<Const_section_id, Output_section_data*,
+                       Const_section_id_hash>
     Output_section_data_by_input_section_map;
 
-  // Map that link Input_section_specifier to Output_relaxed_input_section.
-  typedef Unordered_map<Input_section_specifier, Output_relaxed_input_section*,
-                       Input_section_specifier::hash,
-                       Input_section_specifier::equal_to>
+  // Map that link Const_section_id to Output_relaxed_input_section.
+  typedef Unordered_map<Const_section_id, Output_relaxed_input_section*,
+                       Const_section_id_hash>
     Output_relaxed_input_section_by_input_section_map;
 
   // Map used during relaxation of existing sections.  This map
-  // an input section specifier to an input section list index.
-  // We assume that Input_section_list is a vector.
-  typedef Unordered_map<Input_section_specifier, size_t,
-                       Input_section_specifier::hash,
-                       Input_section_specifier::equal_to>
-    Relaxation_map;
+  // a section id an input section list index.  We assume that
+  // Input_section_list is a vector.
+  typedef Unordered_map<Section_id, size_t, Section_id_hash> Relaxation_map;
 
   // Add a new output section by Input_section.
   void