This is the mail archive of the binutils-cvs@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]

[binutils-gdb] Make output views accessible to Target during do_relocate().


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6b2353a53a621680dc839366f4b2b4f96eccb6da

commit 6b2353a53a621680dc839366f4b2b4f96eccb6da
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Fri Dec 11 14:01:22 2015 -0800

    Make output views accessible to Target during do_relocate().
    
    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.

Diff:
---
 gold/ChangeLog | 12 ++++++++++++
 gold/object.cc |  3 ++-
 gold/object.h  | 16 ++++++++++++++++
 gold/reloc.cc  | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/gold/ChangeLog b/gold/ChangeLog
index a76fed9..fb1d3d0 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -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
diff --git a/gold/object.cc b/gold/object.cc
index 54b76bd..c1947bc 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -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();
 }
diff --git a/gold/object.h b/gold/object.h
index f408408..6cb82c7 100644
--- a/gold/object.h
+++ b/gold/object.h
@@ -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.
diff --git a/gold/reloc.cc b/gold/reloc.cc
index f18f432..b83a962 100644
--- a/gold/reloc.cc
+++ b/gold/reloc.cc
@@ -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


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