[PATCH 1/6] gold: Add 2 overloaded functions to copy_reloc.

Vladimir Radosavljevic Vladimir.Radosavljevic@imgtec.com
Tue Nov 3 16:15:00 GMT 2015


This is used for Mips64, where Reloc is SHT_RELA type and Output_data_reloc is SHT_REL type.

Regards,
Vladimir

Changelog - 

	* copy-relocs.h (Copy_relocs::copy_reloc): New declaration of overloaded function.
	(Copy_relocs::save): Likewise.
	* copy-relocs.cc (Copy_relocs::copy_reloc): New definition of overloaded function.
        (Copy_relocs::save): Likewise.

Patch - 

 copy-relocs.cc |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 copy-relocs.h  |   24 ++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/gold/copy-relocs.cc b/gold/copy-relocs.cc
index a7824fe..1858d36 100644
--- a/gold/copy-relocs.cc
+++ b/gold/copy-relocs.cc
@@ -55,6 +55,34 @@ Copy_relocs<sh_type, size, big_endian>::copy_reloc(
     }
 }
 
+// Handle a relocation against a symbol which may force us to generate
+// a COPY reloc.
+
+template<int sh_type, int size, bool big_endian>
+void
+Copy_relocs<sh_type, size, big_endian>::copy_reloc(
+    Symbol_table* symtab,
+    Layout* layout,
+    Sized_symbol<size>* sym,
+    Sized_relobj_file<size, big_endian>* object,
+    unsigned int shndx,
+    Output_section* output_section,
+    typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
+    typename elfcpp::Elf_types<size>::Elf_WXword r_info,
+    typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
+    Output_data_reloc<sh_type, true, size, big_endian>* reloc_section)
+{
+  if (this->need_copy_reloc(sym, object, shndx))
+    this->make_copy_reloc(symtab, layout, sym, reloc_section);
+  else
+    {
+      // We may not need a COPY relocation.  Save this relocation to
+      // possibly be emitted later.
+      this->save(sym, object, shndx, output_section, r_offset,
+                 r_info, r_addend);
+    }
+}
+
 // Return whether we need a COPY reloc for a relocation against SYM.
 // The relocation is begin applied to section SHNDX in OBJECT.
 
@@ -186,6 +214,25 @@ Copy_relocs<sh_type, size, big_endian>::save(
 					    addend));
 }
 
+// Save a relocation to possibly be emitted later.
+
+template<int sh_type, int size, bool big_endian>
+void
+Copy_relocs<sh_type, size, big_endian>::save(
+    Symbol* sym,
+    Sized_relobj_file<size, big_endian>* object,
+    unsigned int shndx,
+    Output_section* output_section,
+    typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
+    typename elfcpp::Elf_types<size>::Elf_WXword r_info,
+    typename elfcpp::Elf_types<size>::Elf_Swxword r_addend)
+{
+  unsigned int reloc_type = elfcpp::elf_r_type<size>(r_info);
+  this->entries_.push_back(Copy_reloc_entry(sym, reloc_type, object, shndx,
+					    output_section, r_offset,
+					    r_addend));
+}
+
 // Emit any saved relocs.
 
 template<int sh_type, int size, bool big_endian>
diff --git a/gold/copy-relocs.h b/gold/copy-relocs.h
index 6724fd9..33e4378 100644
--- a/gold/copy-relocs.h
+++ b/gold/copy-relocs.h
@@ -71,6 +71,23 @@ class Copy_relocs
 	     const Reloc& rel,
 	     Output_data_reloc<sh_type, true, size, big_endian>*);
 
+  // This is called while scanning relocs if we see a relocation
+  // against a symbol which may force us to generate a COPY reloc.
+  // SYM is the symbol.  OBJECT is the object whose relocs we are
+  // scanning.  The relocation is being applied to section SHNDX in
+  // OBJECT.  OUTPUT_SECTION is the output section where section SHNDX
+  // will wind up.  r_offset, r_info and r_addend are extracted
+  // from reloc.  The Output_data_reloc section is where the
+  // dynamic relocs are put.
+  void
+  copy_reloc(Symbol_table*, Layout*, Sized_symbol<size>* sym,
+             Sized_relobj_file<size, big_endian>* object,
+	     unsigned int shndx, Output_section* output_section,
+	     typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
+	     typename elfcpp::Elf_types<size>::Elf_WXword r_info,
+	     typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
+	     Output_data_reloc<sh_type, true, size, big_endian>*);
+
   // Return whether there are any saved relocations.
   bool
   any_saved_relocs() const
@@ -138,6 +155,13 @@ class Copy_relocs
   save(Symbol*, Sized_relobj_file<size, big_endian>*, unsigned int shndx,
        Output_section*, const Reloc& rel);
 
+  // Save a reloc against SYM for possible emission later.
+  void
+  save(Symbol*, Sized_relobj_file<size, big_endian>*, unsigned int shndx,
+       Output_section*, typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
+      typename elfcpp::Elf_types<size>::Elf_WXword r_info,
+      typename elfcpp::Elf_types<size>::Elf_Swxword r_addend);
+
   // The target specific relocation type of the COPY relocation.
   const unsigned int copy_reloc_type_;
   // The dynamic BSS data which goes into the .bss section.  This is


More information about the Binutils mailing list