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]

[patch] Remove is_merge_section_for


Hi Cary,

Now that Input_merge_map has an Output_section_data, we can use it in
implementing find_merge_section and replace the only use of
is_merge_section_for with it.

This simplifies the code a bit and is faster. Linking chromium goes from

  6173.193320      task-clock (msec)         #    0.999 CPUs utilized
          ( +-  0.62% )

to

 5693.481663      task-clock (msec)         #    0.999 CPUs utilized
         ( +-  0.49% )

Cheers,
Rafael
diff --git a/gold/merge.cc b/gold/merge.cc
index 5d93c74..547aa44 100644
--- a/gold/merge.cc
+++ b/gold/merge.cc
@@ -179,12 +179,13 @@ Object_merge_map::get_output_offset(unsigned int shndx,
 
 // Return whether this is the merge map for section SHNDX.
 
-bool
-Object_merge_map::is_merge_section_for(const Output_section_data* output_data,
-				       unsigned int shndx)
-{
-  Input_merge_map* map = this->get_input_merge_map(shndx);
-  return map != NULL && map->output_data == output_data;
+const Output_section_data*
+Object_merge_map::find_merge_section(unsigned int shndx) const {
+  const Object_merge_map::Input_merge_map* map =
+    this->get_input_merge_map(shndx);
+  if (map == NULL)
+    return NULL;
+  return map->output_data;
 }
 
 // Initialize a mapping from input offsets to output addresses.
diff --git a/gold/merge.h b/gold/merge.h
index 3e500bc..5b127e9 100644
--- a/gold/merge.h
+++ b/gold/merge.h
@@ -71,9 +71,8 @@ class Object_merge_map
 		    section_offset_type offset,
 		    section_offset_type* output_offset);
 
-  // Return whether this is the merge map for section SHNDX.
-  bool
-  is_merge_section_for(const Output_section_data*, unsigned int shndx);
+  const Output_section_data*
+  find_merge_section(unsigned int shndx) const;
 
   // Initialize an mapping from input offsets to output addresses for
   // section SHNDX.  STARTING_ADDRESS is the output address of the
@@ -151,6 +150,11 @@ class Object_merge_map
   Input_merge_map*
   get_input_merge_map(unsigned int shndx);
 
+  const Input_merge_map*
+  get_input_merge_map(unsigned int shndx) const {
+    return const_cast<Object_merge_map*>(this)->get_input_merge_map(shndx);
+  }
+
   // Get or make the Input_merge_map to use for the section SHNDX
   // with MERGE_MAP.
   Input_merge_map*
diff --git a/gold/object.cc b/gold/object.cc
index 84e4568..f6c7a37 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -303,14 +303,12 @@ Relobj::merge_output_offset(unsigned int shndx, section_offset_type offset,
   return object_merge_map->get_output_offset(shndx, offset, poutput);
 }
 
-bool
-Relobj::is_merge_section_for(const Output_section_data* output_data,
-                             unsigned int shndx) const {
+const Output_section_data*
+Relobj::find_merge_section(unsigned int shndx) const {
   Object_merge_map* object_merge_map = this->object_merge_map_;
   if (object_merge_map == NULL)
-    return false;
-  return object_merge_map->is_merge_section_for(output_data, shndx);
-
+    return NULL;
+  return object_merge_map->find_merge_section(shndx);
 }
 
 // To copy the symbols data read from the file to a local data structure.
diff --git a/gold/object.h b/gold/object.h
index 126bff5..48ec9bb 100644
--- a/gold/object.h
+++ b/gold/object.h
@@ -1218,9 +1218,8 @@ class Relobj : public Object
   merge_output_offset(unsigned int shndx, section_offset_type offset,
                       section_offset_type *poutput) const;
 
-  bool
-  is_merge_section_for(const Output_section_data* output_data,
-                       unsigned int shndx) const;
+  const Output_section_data*
+  find_merge_section(unsigned int shndx) const;
 
   // Record the relocatable reloc info for an input reloc section.
   void
diff --git a/gold/output.cc b/gold/output.cc
index 8faa040..5200756 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -2201,18 +2201,6 @@ Output_section::Input_section::output_offset(
     }
 }
 
-// Return whether this is the merge section for the input section
-// SHNDX in OBJECT.
-
-inline bool
-Output_section::Input_section::is_merge_section_for(const Relobj* object,
-						    unsigned int shndx) const
-{
-  if (this->is_input_section())
-    return false;
-  return object->is_merge_section_for(this->u2_.posd, shndx);
-}
-
 // Write out the data.  We don't have to do anything for an input
 // section--they are handled via Object::relocate--but this is where
 // we write out the data for an Output_section_data.
@@ -2698,9 +2686,6 @@ Output_section::add_merge_input_section(Relobj* object, unsigned int shndx,
 	  this->lookup_maps_->add_merge_section(msp, pomb);
 	}
 
-      // Add input section to new merge section and link input section to new
-      // merge section in map.
-      this->lookup_maps_->add_merge_input_section(object, shndx, pomb);
       return true;
     }
   else
@@ -2857,16 +2842,14 @@ Output_section::update_flags_for_input_section(elfcpp::Elf_Xword flags)
 // Find the merge section into which an input section with index SHNDX in
 // OBJECT has been added.  Return NULL if none found.
 
-Output_section_data*
+const Output_section_data*
 Output_section::find_merge_section(const Relobj* object,
 				   unsigned int shndx) const
 {
-  if (!this->lookup_maps_->is_valid())
-    this->build_lookup_maps();
-  return this->lookup_maps_->find_merge_section(object, shndx);
+  return object->find_merge_section(shndx);
 }
 
-// Build the lookup maps for merge and relaxed sections.  This is needs
+// Build the lookup maps for relaxed sections.  This is needs
 // to be declared as a const methods so that it is callable with a const
 // Output_section pointer.  The method only updates states of the maps.
 
@@ -2878,24 +2861,7 @@ Output_section::build_lookup_maps() const
        p != this->input_sections_.end();
        ++p)
     {
-      if (p->is_merge_section())
-	{
-	  Output_merge_base* pomb = p->output_merge_base();
-	  Merge_section_properties msp(pomb->is_string(), pomb->entsize(),
-				       pomb->addralign());
-	  this->lookup_maps_->add_merge_section(msp, pomb);
-	  for (Output_merge_base::Input_sections::const_iterator is =
-		 pomb->input_sections_begin();
-	       is != pomb->input_sections_end();
-	       ++is)
-	    {
-	      const Const_section_id& csid = *is;
-	    this->lookup_maps_->add_merge_input_section(csid.first,
-							csid.second, pomb);
-	    }
-
-	}
-      else if (p->is_relaxed_input_section())
+      if (p->is_relaxed_input_section())
 	{
 	  Output_relaxed_input_section* poris = p->relaxed_input_section();
 	  this->lookup_maps_->add_relaxed_input_section(poris->relobj(),
@@ -2935,7 +2901,8 @@ Output_section::is_input_address_mapped(const Relobj* object,
     {
       section_offset_type output_offset;
       bool found = posd->output_offset(object, shndx, offset, &output_offset);
-      gold_assert(found);
+      if (!found)
+        return false;
       return output_offset != -1;
     }
 
@@ -3045,6 +3012,10 @@ Output_section::find_starting_output_address(const Relobj* object,
 					     unsigned int shndx,
 					     uint64_t* paddr) const
 {
+  const Output_section_data* data = this->find_merge_section(object, shndx);
+  if (!data)
+    return false;
+
   // FIXME: This becomes a bottle-neck if we have many relaxed sections.
   // Looking up the merge section map does not always work as we sometimes
   // find a merge section without its address set.
@@ -3059,7 +3030,7 @@ Output_section::find_starting_output_address(const Relobj* object,
       // method to get the output offset of input offset 0.
       // Unfortunately we don't know for sure that input offset 0 is
       // mapped at all.
-      if (p->is_merge_section_for(object, shndx))
+      if (!p->is_input_section() && p->output_section_data() == data)
 	{
 	  *paddr = addr;
 	  return true;
@@ -3885,20 +3856,7 @@ Output_section::add_script_input_section(const Input_section& sis)
   // Update fast lookup maps if necessary.
   if (this->lookup_maps_->is_valid())
     {
-      if (sis.is_merge_section())
-	{
-	  Output_merge_base* pomb = sis.output_merge_base();
-	  Merge_section_properties msp(pomb->is_string(), pomb->entsize(),
-				       pomb->addralign());
-	  this->lookup_maps_->add_merge_section(msp, pomb);
-	  for (Output_merge_base::Input_sections::const_iterator p =
-		 pomb->input_sections_begin();
-	       p != pomb->input_sections_end();
-	       ++p)
-	    this->lookup_maps_->add_merge_input_section(p->first, p->second,
-							pomb);
-	}
-      else if (sis.is_relaxed_input_section())
+      if (sis.is_relaxed_input_section())
 	{
 	  Output_relaxed_input_section* poris = sis.relaxed_input_section();
 	  this->lookup_maps_->add_relaxed_input_section(poris->relobj(),
diff --git a/gold/output.h b/gold/output.h
index dc11c8f..318af36 100644
--- a/gold/output.h
+++ b/gold/output.h
@@ -2857,7 +2857,7 @@ class Output_section_lookup_maps
  public:
   Output_section_lookup_maps()
     : is_valid_(true), merge_sections_by_properties_(),
-      merge_sections_by_id_(), relaxed_input_sections_by_id_()
+      relaxed_input_sections_by_id_()
   { }
 
   // Whether the maps are valid.
@@ -2875,7 +2875,6 @@ class Output_section_lookup_maps
   clear()
   {
     this->merge_sections_by_properties_.clear();
-    this->merge_sections_by_id_.clear();
     this->relaxed_input_sections_by_id_.clear();
     // A cleared map is valid.
     this->is_valid_ = true;
@@ -2892,17 +2891,6 @@ class Output_section_lookup_maps
     return p != this->merge_sections_by_properties_.end() ? p->second : NULL;
   }
 
-  // Find a merge section by section ID of a merge input section.  Return NULL
-  // if none is found.
-  Output_merge_base*
-  find_merge_section(const Object* object, unsigned int shndx) const
-  {
-    gold_assert(this->is_valid_);
-    Merge_sections_by_id::const_iterator p =
-      this->merge_sections_by_id_.find(Const_section_id(object, shndx));
-    return p != this->merge_sections_by_id_.end() ? p->second : NULL;
-  }
-
   // Add a merge section pointed by POMB with properties MSP.
   void
   add_merge_section(const Merge_section_properties& msp,
@@ -2914,19 +2902,6 @@ class Output_section_lookup_maps
     gold_assert(result.second);
   }
 
-  // Add a mapping from a merged input section in OBJECT with index SHNDX
-  // to a merge output section pointed by POMB.
-  void
-  add_merge_input_section(const Object* object, unsigned int shndx,
-			  Output_merge_base* pomb)
-  {
-    Const_section_id csid(object, shndx);
-    std::pair<Const_section_id, Output_merge_base*> value(csid, pomb);
-    std::pair<Merge_sections_by_id::iterator, bool> result =
-      this->merge_sections_by_id_.insert(value);
-    gold_assert(result.second);
-  }
-
   // Find a relaxed input section of OBJECT with index SHNDX.
   Output_relaxed_input_section*
   find_relaxed_input_section(const Object* object, unsigned int shndx) const
@@ -2952,10 +2927,6 @@ class Output_section_lookup_maps
   }
 
  private:
-  typedef Unordered_map<Const_section_id, Output_merge_base*,
-			Const_section_id_hash>
-    Merge_sections_by_id;
-
   typedef Unordered_map<Merge_section_properties, Output_merge_base*,
 			Merge_section_properties::hash,
 			Merge_section_properties::equal_to>
@@ -2969,8 +2940,6 @@ class Output_section_lookup_maps
   bool is_valid_;
   // Merge sections by merge section properties.
   Merge_sections_by_properties merge_sections_by_properties_;
-  // Merge sections by section IDs.
-  Merge_sections_by_id merge_sections_by_id_;
   // Relaxed sections by section IDs.
   Relaxed_input_sections_by_id relaxed_input_sections_by_id_;
 };
@@ -3761,11 +3730,6 @@ class Output_section : public Output_data
 		  section_offset_type offset,
 		  section_offset_type* poutput) const;
 
-    // Return whether this is the merge section for the input section
-    // SHNDX in OBJECT.
-    bool
-    is_merge_section_for(const Relobj* object, unsigned int shndx) const;
-
     // Write out the data.  This does nothing for an input section.
     void
     write(Output_file*);
@@ -4290,7 +4254,7 @@ class Output_section : public Output_data
 
   // Find the merge section into which an input section with index SHNDX in
   // OBJECT has been added.  Return NULL if none found.
-  Output_section_data*
+  const Output_section_data*
   find_merge_section(const Relobj* object, unsigned int shndx) const;
 
   // Build a relaxation map.

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