Make output views accessible to Target during do_relocate().
authorCary Coutant <ccoutant@gmail.com>
Fri, 11 Dec 2015 22:01:22 +0000 (14:01 -0800)
committerCary Coutant <ccoutant@gmail.com>
Fri, 11 Dec 2015 22:23:58 +0000 (14:23 -0800)
gold/
* object.cc (Sized_relobj_file::Sized_relobj_file): Initialize
output_views_.
* object.h (Object::get_output_view): New function.
(Object::do_get_output_view): New function.
(Sized_relobj_file::do_get_output_view): New function.
(Sized_relobj_file::output_views_): New data member.
* reloc.cc: (Sized_relobj_file::do_relocate): Store pointer to
output views in class object.
(Sized_relobj_file::do_get_output_view): New function.

gold/ChangeLog
gold/object.cc
gold/object.h
gold/reloc.cc

index a76fed941ac8a8467d04db336dce84fd2131c82a..fb1d3d08db04cd27dc220e6408b48cc421e2c847 100644 (file)
@@ -1,3 +1,15 @@
+2015-12-11  Cary Coutant  <ccoutant@gmail.com>
+
+       * object.cc (Sized_relobj_file::Sized_relobj_file): Initialize
+       output_views_.
+       * object.h (Object::get_output_view): New function.
+       (Object::do_get_output_view): New function.
+       (Sized_relobj_file::do_get_output_view): New function.
+       (Sized_relobj_file::output_views_): New data member.    
+       * reloc.cc: (Sized_relobj_file::do_relocate): Store pointer to
+       output views in class object.
+       (Sized_relobj_file::do_get_output_view): New function.
+
 2015-12-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/19317
index 54b76bd0b201411537b0ab76818dfb3b586460ea..c1947bc63eb10351198c9ef1b803b221c3fa0ddd 100644 (file)
@@ -479,7 +479,8 @@ Sized_relobj_file<size, big_endian>::Sized_relobj_file(
     discarded_eh_frame_shndx_(-1U),
     is_deferred_layout_(false),
     deferred_layout_(),
-    deferred_layout_relocs_()
+    deferred_layout_relocs_(),
+    output_views_(NULL)
 {
   this->e_type_ = ehdr.get_e_type();
 }
index f408408d28a793ce3d736a35552ade9c5f4add30..6cb82c7633842ba7fee82cc62581dfbbffe7bc3a 100644 (file)
@@ -844,6 +844,11 @@ class Object
   get_incremental_reloc_count(unsigned int symndx) const
   { return this->do_get_incremental_reloc_count(symndx); }
 
+  // Return the output view for section SHNDX.
+  const unsigned char*
+  get_output_view(unsigned int shndx, section_size_type* plen) const
+  { return this->do_get_output_view(shndx, plen); }
+
  protected:
   // Returns NULL for Objects that are not dynamic objects.  This method
   // is overridden in the Dynobj class.
@@ -1029,6 +1034,11 @@ class Object
   do_get_incremental_reloc_count(unsigned int) const
   { gold_unreachable(); }
 
+  // Return the output view for a section.
+  virtual const unsigned char*
+  do_get_output_view(unsigned int, section_size_type*) const
+  { gold_unreachable(); }
+
   void
   set_compressed_sections(Compressed_section_map* compressed_sections)
   { this->compressed_sections_ = compressed_sections; }
@@ -2563,6 +2573,10 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
   set_output_local_symbol_count(unsigned int value)
   { this->output_local_symbol_count_ = value; }
 
+  // Return the output view for a section.
+  const unsigned char*
+  do_get_output_view(unsigned int, section_size_type*) const;
+
  private:
   // For convenience.
   typedef Sized_relobj_file<size, big_endian> This;
@@ -2829,6 +2843,8 @@ class Sized_relobj_file : public Sized_relobj<size, big_endian>
   std::vector<Deferred_layout> deferred_layout_;
   // The list of relocation sections whose layout was deferred.
   std::vector<Deferred_layout> deferred_layout_relocs_;
+  // Pointer to the list of output views; valid only during do_relocate().
+  const Views* output_views_;
 };
 
 // A class to manage the list of all objects.
index f18f43220125065c3c6932f25e1f1adad33f02f8..b83a9629d77a711292e6d8de3e562acd214490fd 100644 (file)
@@ -665,6 +665,24 @@ Sized_relobj_file<size, big_endian>::do_relocate(const Symbol_table* symtab,
   // input offsets to output addresses.
   this->initialize_input_to_output_maps();
 
+  // Make the views available through get_output_view() for the duration
+  // of this routine.  This RAII class will reset output_views_ to NULL
+  // when the views go out of scope.
+  struct Set_output_views
+  {
+    Set_output_views(const Views** ppviews, const Views* pviews)
+    {
+      ppviews_ = ppviews;
+      *ppviews = pviews;
+    }
+
+    ~Set_output_views()
+    { *ppviews_ = NULL; }
+
+    const Views** ppviews_;
+  };
+  Set_output_views set_output_views(&this->output_views_, &views);
+
   // Apply relocations.
 
   this->relocate_sections(symtab, layout, pshdrs, of, &views);
@@ -1040,6 +1058,21 @@ Sized_relobj_file<size, big_endian>::do_relocate_sections(
     }
 }
 
+// Return the output view for section SHNDX.
+
+template<int size, bool big_endian>
+const unsigned char*
+Sized_relobj_file<size, big_endian>::do_get_output_view(
+    unsigned int shndx,
+    section_size_type* plen) const
+{
+  gold_assert(this->output_views_ != NULL);
+  gold_assert(shndx < this->output_views_->size());
+  const View_size& v = (*this->output_views_)[shndx];
+  *plen = v.view_size;
+  return v.view;
+}
+
 // Write the incremental relocs.
 
 template<int size, bool big_endian>
@@ -1739,6 +1772,12 @@ Sized_relobj_file<32, false>::do_relocate_sections(
     const unsigned char* pshdrs,
     Output_file* of,
     Views* pviews);
+
+template
+const unsigned char*
+Sized_relobj_file<32, false>::do_get_output_view(
+    unsigned int shndx,
+    section_size_type* plen) const;
 #endif
 
 #ifdef HAVE_TARGET_32_BIG
@@ -1750,6 +1789,12 @@ Sized_relobj_file<32, true>::do_relocate_sections(
     const unsigned char* pshdrs,
     Output_file* of,
     Views* pviews);
+
+template
+const unsigned char*
+Sized_relobj_file<32, true>::do_get_output_view(
+    unsigned int shndx,
+    section_size_type* plen) const;
 #endif
 
 #ifdef HAVE_TARGET_64_LITTLE
@@ -1761,6 +1806,12 @@ Sized_relobj_file<64, false>::do_relocate_sections(
     const unsigned char* pshdrs,
     Output_file* of,
     Views* pviews);
+
+template
+const unsigned char*
+Sized_relobj_file<64, false>::do_get_output_view(
+    unsigned int shndx,
+    section_size_type* plen) const;
 #endif
 
 #ifdef HAVE_TARGET_64_BIG
@@ -1772,6 +1823,12 @@ Sized_relobj_file<64, true>::do_relocate_sections(
     const unsigned char* pshdrs,
     Output_file* of,
     Views* pviews);
+
+template
+const unsigned char*
+Sized_relobj_file<64, true>::do_get_output_view(
+    unsigned int shndx,
+    section_size_type* plen) const;
 #endif
 
 #ifdef HAVE_TARGET_32_LITTLE