aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <rafael.espindola@gmail.com>2015-03-23 09:16:49 -0400
committerRafael Ávila de Espíndola <rafael.espindola@gmail.com>2015-03-23 09:16:49 -0400
commit67f95b96b4d5e8e19520d94bebae92db2f67af74 (patch)
treec98a68289748714bf336f1e5797718ce3e27cbca /gold
parent99067e2973a6bb1d3a52caafb479ebdc1a420580 (diff)
downloadfsf-binutils-gdb-67f95b96b4d5e8e19520d94bebae92db2f67af74.zip
fsf-binutils-gdb-67f95b96b4d5e8e19520d94bebae92db2f67af74.tar.gz
fsf-binutils-gdb-67f95b96b4d5e8e19520d94bebae92db2f67af74.tar.bz2
Remove is_merge_section_for.
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.
Diffstat (limited to 'gold')
-rw-r--r--gold/ChangeLog31
-rw-r--r--gold/merge.cc17
-rw-r--r--gold/merge.h15
-rw-r--r--gold/object.cc10
-rw-r--r--gold/object.h5
-rw-r--r--gold/output.cc68
-rw-r--r--gold/output.h40
7 files changed, 71 insertions, 115 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 71887d3..600802d 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -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
diff --git a/gold/merge.cc b/gold/merge.cc
index 5d93c74..a579445 100644
--- a/gold/merge.cc
+++ b/gold/merge.cc
@@ -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.
diff --git a/gold/merge.h b/gold/merge.h
index 3e500bc..62efa13 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
@@ -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.
diff --git a/gold/object.cc b/gold/object.cc
index f983b66..cbe73ca 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 1e62c12..c26acf3 100644
--- a/gold/object.h
+++ b/gold/object.h
@@ -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
diff --git a/gold/output.cc b/gold/output.cc
index 516e01d..ee6c475 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,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(),
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.