Remove is_merge_section_for.
authorRafael Ávila de Espíndola <rafael.espindola@gmail.com>
Mon, 23 Mar 2015 13:16:49 +0000 (09:16 -0400)
committerRafael Ávila de Espíndola <rafael.espindola@gmail.com>
Mon, 23 Mar 2015 13:16:49 +0000 (09:16 -0400)
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.

gold/ChangeLog
gold/merge.cc
gold/merge.h
gold/object.cc
gold/object.h
gold/output.cc
gold/output.h

index 71887d3300b34d4eb943da026e4004c568c56115..600802db46cac47e98a64cfcaff1b318cecda92b 100644 (file)
@@ -1,3 +1,34 @@
+2015-03-23  Rafael Ávila de Espíndola <rafael.espindola@gmail.com>
+
+       * merge.cc (Object_merge_map::get_input_merge_map): Make it const.
+       (Object_merge_map::is_merge_section_for): Remove.
+       (Object_merge_map::find_merge_section): New.
+       * merge.h (Object_merge_map::is_merge_section_for): Remove.
+       (Object_merge_map::find_merge_section): New.
+       (Object_merge_map::get_input_merge_map): Add a const version.
+       * object.cc (Relobj::is_merge_section_for): Remove.
+       (Relobj::find_merge_section): New.
+       * object.h (Relobj::is_merge_section_for): Remove.
+       (Relobj::find_merge_section): New.
+       * output.cc
+       (Output_section::Input_section::is_merge_section_for): Remove.
+       (Output_section::add_merge_input_section): Don't call
+       add_merge_input_section.
+       (Output_section::find_merge_section): Return const. Use
+       object->find_merge_section.
+       (Output_section::build_lookup_maps): Don't build a map for
+       merge sections.
+       (Output_section::is_input_address_mapped): Return false if
+       section is not found.
+       (Output_section::find_starting_output_address): Use
+       find_merge_section instead of is_merge_section_for.
+       (Output_section::add_script_input_section):  Don't build a map for
+       merge sections.
+       * output.h (Output_section_lookup_maps::merge_sections_by_id_): Remove.
+       (Output_section_lookup_maps::find_merge_section): Remove.
+       (Output_section_lookup_maps::add_merge_input_section) Remove.
+       (Output_section::find_merge_section): Return const.
+
 2015-03-22  Cary Coutant  <cary@google.com>
 
        PR gold/18106
index 5d93c74ce4b0bd310650fdb0965b9ffb25b190af..a579445beb22057b2d47b4e2777a0179b26f9e3f 100644 (file)
@@ -45,8 +45,8 @@ Object_merge_map::~Object_merge_map()
 
 // Get the Input_merge_map to use for an input section, or NULL.
 
-Object_merge_map::Input_merge_map*
-Object_merge_map::get_input_merge_map(unsigned int shndx)
+const Object_merge_map::Input_merge_map*
+Object_merge_map::get_input_merge_map(unsigned int shndx) const
 {
   gold_assert(shndx != -1U);
   if (shndx == this->first_shnum_)
@@ -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.
index 3e500bc186de6d84f5ac5e550cb9e13631a425fe..62efa130163562779b08a2d6ce1d18631d94bc4b 100644 (file)
@@ -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
@@ -148,8 +147,14 @@ class Object_merge_map
 
   // Return a pointer to the Input_merge_map to use for the input
   // section SHNDX, or NULL.
-  Input_merge_map*
-  get_input_merge_map(unsigned int shndx);
+  const Input_merge_map*
+  get_input_merge_map(unsigned int shndx) const;
+
+  Input_merge_map *
+  get_input_merge_map(unsigned int shndx) {
+    return const_cast<Input_merge_map *>(static_cast<const 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.
index f983b6603ee70d7e6bac3891b4fe429e0b25de6e..cbe73caba2823518d983b749f795699944168e1f 100644 (file)
@@ -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.
index 1e62c1279208e8eb22ab353a4fe0be50e0eadf6b..c26acf39eddb56fbe5d214a1c63df51bfce8eb5e 100644 (file)
@@ -1232,9 +1232,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
index 516e01daff1e8de30a737b01be218168f5d4da6a..ee6c475542904a0c757ac5ab5bc072b1d5fe6cc6 100644 (file)
@@ -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,17 +2842,15 @@ 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
-// to be declared as a const methods so that it is callable with a const
+// Build the lookup maps for relaxed sections.  This needs
+// to be declared as a const method so that it is callable with a const
 // Output_section pointer.  The method only updates states of the maps.
 
 void
@@ -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 == NULL)
+    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(),
index dc11c8fd82995342058bb706bd4664f5e7463497..318af363249bfc2a51bb471e1784be9ac02a68ab 100644 (file)
@@ -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.