Refactor gold to enable support for MIPS-64 relocation format.
[deliverable/binutils-gdb.git] / gold / x86_64.cc
index c48a513e2f4acb776a257128e055c4752201de15..3cfc064d4b467de85c2c30dd1ac6dfbb4cfe9959 100644 (file)
@@ -496,6 +496,21 @@ class Target_x86_64 : public Sized_target<size, false>
                          const unsigned char* plocal_symbols,
                          Relocatable_relocs*);
 
+  // Scan the relocs for --emit-relocs.
+  void
+  emit_relocs_scan(Symbol_table* symtab,
+                  Layout* layout,
+                  Sized_relobj_file<size, false>* object,
+                  unsigned int data_shndx,
+                  unsigned int sh_type,
+                  const unsigned char* prelocs,
+                  size_t reloc_count,
+                  Output_section* output_section,
+                  bool needs_special_offset_handling,
+                  size_t local_symbol_count,
+                  const unsigned char* plocal_syms,
+                  Relocatable_relocs* rr);
+
   // Emit relocations for a section.
   void
   relocate_relocs(
@@ -859,15 +874,6 @@ class Target_x86_64 : public Sized_target<size, false>
     bool skip_call_tls_get_addr_;
   };
 
-  // A class which returns the size required for a relocation type,
-  // used while scanning relocs during a relocatable link.
-  class Relocatable_size_for_reloc
-  {
-   public:
-    unsigned int
-    get_size_for_reloc(unsigned int, Relobj*);
-  };
-
   // Check if relocation against this symbol is a candidate for
   // conversion from
   // mov foo@GOTPCREL(%rip), %reg
@@ -3191,15 +3197,16 @@ Target_x86_64<size>::gc_process_relocs(Symbol_table* symtab,
                                       size_t local_symbol_count,
                                       const unsigned char* plocal_symbols)
 {
+  typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, false>
+      Classify_reloc;
 
   if (sh_type == elfcpp::SHT_REL)
     {
       return;
     }
 
-   gold::gc_process_relocs<size, false, Target_x86_64<size>, elfcpp::SHT_RELA,
-                          typename Target_x86_64<size>::Scan,
-                          typename Target_x86_64<size>::Relocatable_size_for_reloc>(
+   gold::gc_process_relocs<size, false, Target_x86_64<size>, Scan,
+                          Classify_reloc>(
     symtab,
     layout,
     this,
@@ -3229,6 +3236,9 @@ Target_x86_64<size>::scan_relocs(Symbol_table* symtab,
                                 size_t local_symbol_count,
                                 const unsigned char* plocal_symbols)
 {
+  typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, false>
+      Classify_reloc;
+
   if (sh_type == elfcpp::SHT_REL)
     {
       gold_error(_("%s: unsupported REL reloc section"),
@@ -3236,8 +3246,7 @@ Target_x86_64<size>::scan_relocs(Symbol_table* symtab,
       return;
     }
 
-  gold::scan_relocs<size, false, Target_x86_64<size>, elfcpp::SHT_RELA,
-      typename Target_x86_64<size>::Scan>(
+  gold::scan_relocs<size, false, Target_x86_64<size>, Scan, Classify_reloc>(
     symtab,
     layout,
     this,
@@ -4268,11 +4277,13 @@ Target_x86_64<size>::relocate_section(
     section_size_type view_size,
     const Reloc_symbol_changes* reloc_symbol_changes)
 {
+  typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, false>
+      Classify_reloc;
+
   gold_assert(sh_type == elfcpp::SHT_RELA);
 
-  gold::relocate_section<size, false, Target_x86_64<size>, elfcpp::SHT_RELA,
-                        typename Target_x86_64<size>::Relocate,
-                        gold::Default_comdat_behavior>(
+  gold::relocate_section<size, false, Target_x86_64<size>, Relocate,
+                        gold::Default_comdat_behavior, Classify_reloc>(
     relinfo,
     this,
     prelocs,
@@ -4313,86 +4324,50 @@ Target_x86_64<size>::apply_relocation(
     view_size);
 }
 
-// Return the size of a relocation while scanning during a relocatable
-// link.
+// Scan the relocs during a relocatable link.
 
 template<int size>
-unsigned int
-Target_x86_64<size>::Relocatable_size_for_reloc::get_size_for_reloc(
-    unsigned int r_type,
-    Relobj* object)
+void
+Target_x86_64<size>::scan_relocatable_relocs(
+    Symbol_table* symtab,
+    Layout* layout,
+    Sized_relobj_file<size, false>* object,
+    unsigned int data_shndx,
+    unsigned int sh_type,
+    const unsigned char* prelocs,
+    size_t reloc_count,
+    Output_section* output_section,
+    bool needs_special_offset_handling,
+    size_t local_symbol_count,
+    const unsigned char* plocal_symbols,
+    Relocatable_relocs* rr)
 {
-  switch (r_type)
-    {
-    case elfcpp::R_X86_64_NONE:
-    case elfcpp::R_X86_64_GNU_VTINHERIT:
-    case elfcpp::R_X86_64_GNU_VTENTRY:
-    case elfcpp::R_X86_64_TLSGD:            // Global-dynamic
-    case elfcpp::R_X86_64_GOTPC32_TLSDESC:  // Global-dynamic (from ~oliva url)
-    case elfcpp::R_X86_64_TLSDESC_CALL:
-    case elfcpp::R_X86_64_TLSLD:            // Local-dynamic
-    case elfcpp::R_X86_64_DTPOFF32:
-    case elfcpp::R_X86_64_DTPOFF64:
-    case elfcpp::R_X86_64_GOTTPOFF:         // Initial-exec
-    case elfcpp::R_X86_64_TPOFF32:          // Local-exec
-      return 0;
+  typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, false>
+      Classify_reloc;
+  typedef gold::Default_scan_relocatable_relocs<Classify_reloc>
+      Scan_relocatable_relocs;
 
-    case elfcpp::R_X86_64_64:
-    case elfcpp::R_X86_64_PC64:
-    case elfcpp::R_X86_64_GOTOFF64:
-    case elfcpp::R_X86_64_GOTPC64:
-    case elfcpp::R_X86_64_PLTOFF64:
-    case elfcpp::R_X86_64_GOT64:
-    case elfcpp::R_X86_64_GOTPCREL64:
-    case elfcpp::R_X86_64_GOTPCREL:
-    case elfcpp::R_X86_64_GOTPCRELX:
-    case elfcpp::R_X86_64_REX_GOTPCRELX:
-    case elfcpp::R_X86_64_GOTPLT64:
-      return 8;
-
-    case elfcpp::R_X86_64_32:
-    case elfcpp::R_X86_64_32S:
-    case elfcpp::R_X86_64_PC32:
-    case elfcpp::R_X86_64_PC32_BND:
-    case elfcpp::R_X86_64_PLT32:
-    case elfcpp::R_X86_64_PLT32_BND:
-    case elfcpp::R_X86_64_GOTPC32:
-    case elfcpp::R_X86_64_GOT32:
-      return 4;
-
-    case elfcpp::R_X86_64_16:
-    case elfcpp::R_X86_64_PC16:
-      return 2;
-
-    case elfcpp::R_X86_64_8:
-    case elfcpp::R_X86_64_PC8:
-      return 1;
-
-    case elfcpp::R_X86_64_COPY:
-    case elfcpp::R_X86_64_GLOB_DAT:
-    case elfcpp::R_X86_64_JUMP_SLOT:
-    case elfcpp::R_X86_64_RELATIVE:
-    case elfcpp::R_X86_64_IRELATIVE:
-      // These are outstanding tls relocs, which are unexpected when linking
-    case elfcpp::R_X86_64_TPOFF64:
-    case elfcpp::R_X86_64_DTPMOD64:
-    case elfcpp::R_X86_64_TLSDESC:
-      object->error(_("unexpected reloc %u in object file"), r_type);
-      return 0;
+  gold_assert(sh_type == elfcpp::SHT_RELA);
 
-    case elfcpp::R_X86_64_SIZE32:
-    case elfcpp::R_X86_64_SIZE64:
-    default:
-      object->error(_("unsupported reloc %u against local symbol"), r_type);
-      return 0;
-    }
+  gold::scan_relocatable_relocs<size, false, Scan_relocatable_relocs>(
+    symtab,
+    layout,
+    object,
+    data_shndx,
+    prelocs,
+    reloc_count,
+    output_section,
+    needs_special_offset_handling,
+    local_symbol_count,
+    plocal_symbols,
+    rr);
 }
 
-// Scan the relocs during a relocatable link.
+// Scan the relocs for --emit-relocs.
 
 template<int size>
 void
-Target_x86_64<size>::scan_relocatable_relocs(
+Target_x86_64<size>::emit_relocs_scan(
     Symbol_table* symtab,
     Layout* layout,
     Sized_relobj_file<size, false>* object,
@@ -4403,16 +4378,17 @@ Target_x86_64<size>::scan_relocatable_relocs(
     Output_section* output_section,
     bool needs_special_offset_handling,
     size_t local_symbol_count,
-    const unsigned char* plocal_symbols,
+    const unsigned char* plocal_syms,
     Relocatable_relocs* rr)
 {
-  gold_assert(sh_type == elfcpp::SHT_RELA);
+  typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, false>
+      Classify_reloc;
+  typedef gold::Default_emit_relocs_strategy<Classify_reloc>
+      Emit_relocs_strategy;
 
-  typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
-    Relocatable_size_for_reloc> Scan_relocatable_relocs;
+  gold_assert(sh_type == elfcpp::SHT_RELA);
 
-  gold::scan_relocatable_relocs<size, false, elfcpp::SHT_RELA,
-      Scan_relocatable_relocs>(
+  gold::scan_relocatable_relocs<size, false, Emit_relocs_strategy>(
     symtab,
     layout,
     object,
@@ -4422,7 +4398,7 @@ Target_x86_64<size>::scan_relocatable_relocs(
     output_section,
     needs_special_offset_handling,
     local_symbol_count,
-    plocal_symbols,
+    plocal_syms,
     rr);
 }
 
@@ -4443,9 +4419,12 @@ Target_x86_64<size>::relocate_relocs(
     unsigned char* reloc_view,
     section_size_type reloc_view_size)
 {
+  typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, false>
+      Classify_reloc;
+
   gold_assert(sh_type == elfcpp::SHT_RELA);
 
-  gold::relocate_relocs<size, false, elfcpp::SHT_RELA>(
+  gold::relocate_relocs<size, false, Classify_reloc>(
     relinfo,
     prelocs,
     reloc_count,
This page took 0.026821 seconds and 4 git commands to generate.