Don't crash if we change the address of the .eh_frame section after we
authorIan Lance Taylor <iant@google.com>
Thu, 13 Mar 2008 20:58:11 +0000 (20:58 +0000)
committerIan Lance Taylor <iant@google.com>
Thu, 13 Mar 2008 20:58:11 +0000 (20:58 +0000)
find its size.

gold/ehframe.cc
gold/ehframe.h
gold/merge.cc

index df9448897fe9289eb76e6db825ba30e1b3bc91f4..a3a24e51346b2f5877521a7bb45115348c5f4b04 100644 (file)
@@ -487,7 +487,9 @@ Eh_frame::Eh_frame()
     eh_frame_hdr_(NULL),
     cie_offsets_(),
     unmergeable_cie_offsets_(),
-    merge_map_()
+    merge_map_(),
+    mappings_are_done_(false),
+    final_data_size_(0)
 {
 }
 
@@ -1011,6 +1013,15 @@ Eh_frame::fde_count() const
 void
 Eh_frame::set_final_data_size()
 {
+  // We can be called more than once if Layout::set_segment_offsets
+  // finds a better mapping.  We don't want to add all the mappings
+  // again.
+  if (this->mappings_are_done_)
+    {
+      this->set_data_size(this->final_data_size_);
+      return;
+    }
+
   section_offset_type output_offset = 0;
 
   for (Unmergeable_cie_offsets::iterator p =
@@ -1028,6 +1039,9 @@ Eh_frame::set_final_data_size()
                                            this->addralign(),
                                            &this->merge_map_);
 
+  this->mappings_are_done_ = true;
+  this->final_data_size_ = output_offset;
+
   gold_assert((output_offset & (this->addralign() - 1)) == 0);
   this->set_data_size(output_offset);
 }
index cf3b738567e5ce941571cdb2c1173e40b663fe3a..8ff456b9082101be91fa6788d3aef2f4de787b37 100644 (file)
@@ -427,6 +427,11 @@ class Eh_frame : public Output_section_data
   Unmergeable_cie_offsets unmergeable_cie_offsets_;
   // A mapping from input sections to the output section.
   Merge_map merge_map_;
+  // Whether we have created the mappings to the output section.
+  bool mappings_are_done_;
+  // The final data size.  This is only set if mappings_are_done_ is
+  // true.
+  section_size_type final_data_size_;
 };
 
 } // End namespace gold.
index 75a3eeea924f48978174dfc52e0d63a5e96c6ef8..192d6a408ef560686f0493e76d1968a84e2a4606 100644 (file)
@@ -528,7 +528,9 @@ Output_merge_string<Char_type>::finalize_merged_data()
       this->add_mapping(p->object, p->shndx, p->offset, p->length, offset);
     }
 
-  // Save some memory.
+  // Save some memory.  This also ensures that this function will work
+  // if called twice, as may happen if Layout::set_segment_offsets
+  // finds a better alignment.
   this->merged_strings_.clear();
 
   return this->stringpool_.get_strtab_size();
This page took 0.025535 seconds and 4 git commands to generate.