[PATCH][GOLD] Use a single definition of Section_id and replace Input_section_specifier with Section_id

Doug Kwan (關振德) dougkwan@google.com
Wed Jan 20 06:10:00 GMT 2010


Sorry,  I sent the wrong patch.  Here is the correct one.

-Doug

2010/1/19 Doug Kwan (關振德) <dougkwan@google.com>:
> Hi,
>
>     This patch remove the defintions of Section_id and
> Section_is_hash in gc.h and icf.h and put a single definition of these
> in object.h.  I also remove the Input_section_specifier class, which
> is similar to Section_id but has a slower hash function.   Some users
> of Input_section_specifier require const object pointers.  So I also
> define Const_section_id and Const_section_id_hash.  Previously we used
> Input_section_specifier in maps for look-up only.  So it is safe to
> replace those uses with no problem in repeatability.
>
> -Doug
>
> 2010-01-19  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.
>
-------------- next part --------------
Index: gold/arm.cc
===================================================================
RCS file: /cvs/src/src/gold/arm.cc,v
retrieving revision 1.57
diff -u -u -p -r1.57 arm.cc
--- gold/arm.cc	15 Jan 2010 15:41:42 -0000	1.57
+++ gold/arm.cc	20 Jan 2010 04:32:07 -0000
@@ -2010,10 +2010,9 @@ class Target_arm : public Sized_target<3
   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.
@@ -7315,7 +7314,7 @@ Target_arm<big_endian>::new_arm_input_se
     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);
@@ -7323,7 +7322,7 @@ Target_arm<big_endian>::new_arm_input_se
 
   // 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.
@@ -7341,9 +7340,9 @@ Target_arm<big_endian>::find_arm_input_s
     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: gold/gc.h
===================================================================
RCS file: /cvs/src/src/gold/gc.h,v
retrieving revision 1.8
diff -u -u -p -r1.8 gc.h
--- gold/gc.h	12 Jan 2010 07:22:56 -0000	1.8
+++ gold/gc.h	20 Jan 2010 04:32:07 -0000
@@ -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: gold/icf.h
===================================================================
RCS file: /cvs/src/src/gold/icf.h,v
retrieving revision 1.3
diff -u -u -p -r1.3 icf.h
--- gold/icf.h	4 Jan 2010 19:08:39 -0000	1.3
+++ gold/icf.h	20 Jan 2010 04:32:07 -0000
@@ -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: gold/object.h
===================================================================
RCS file: /cvs/src/src/gold/object.h,v
retrieving revision 1.88
diff -u -u -p -r1.88 object.h
--- gold/object.h	5 Jan 2010 21:52:51 -0000	1.88
+++ gold/object.h	20 Jan 2010 04:32:07 -0000
@@ -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: gold/output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.116
diff -u -u -p -r1.116 output.cc
--- gold/output.cc	19 Jan 2010 17:55:48 -0000	1.116
+++ gold/output.cc	20 Jan 2010 04:32:07 -0000
@@ -2072,8 +2072,8 @@ Output_section::add_relaxed_input_sectio
   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(
 		  && 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(
   // 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_i
   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_t
     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_secti
 	   ++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: gold/output.h
===================================================================
RCS file: /cvs/src/src/gold/output.h,v
retrieving revision 1.97
diff -u -u -p -r1.97 output.h
--- gold/output.h	8 Jan 2010 19:33:18 -0000	1.97
+++ gold/output.h	20 Jan 2010 04:32:07 -0000
@@ -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_dat
 			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


More information about the Binutils mailing list