Make bfd_byte an int8_t, flagword a uint32_t
[binutils-gdb.git] / bfd / coff-aarch64.c
index 73fa2442dfe23e6f7d778b97f11caac64803c7e4..659cd4f162d1c920cfa38040093188020e4af701 100644 (file)
@@ -189,9 +189,10 @@ coff_aarch64_addr32nb_reloc (bfd *abfd,
                       + symbol->section->output_section->vma);
       bfd_vma addend = bfd_getl_signed_32 (data + reloc_entry->address);
       relocation += addend;
-      if (bfd_get_flavour (output_bfd) == bfd_target_coff_flavour
-         && obj_pe (output_bfd))
-       relocation -= pe_data (output_bfd)->pe_opthdr.ImageBase;
+      bfd *obfd = input_section->output_section->owner;
+      if (bfd_get_flavour (obfd) == bfd_target_coff_flavour
+         && obj_pe (obfd))
+       relocation -= pe_data (obfd)->pe_opthdr.ImageBase;
       else
        {
          *error_message = "unsupported";
@@ -305,6 +306,10 @@ static const reloc_howto_type arm64_reloc_howto_secrel
 = HOW (IMAGE_REL_ARM64_SECREL,
        0, 4, 32, false, 0, dont, secrel_reloc, 0xffffffff);
 
+static const reloc_howto_type arm64_reloc_howto_secidx
+= HOW (IMAGE_REL_ARM64_SECTION,
+       0, 2, 16, false, 0, dont, NULL, 0xffff);
+
 static const reloc_howto_type* const arm64_howto_table[] = {
      &arm64_reloc_howto_abs,
      &arm64_reloc_howto_64,
@@ -318,7 +323,8 @@ static const reloc_howto_type* const arm64_howto_table[] = {
      &arm64_reloc_howto_branch14,
      &arm64_reloc_howto_pgoff12a,
      &arm64_reloc_howto_32nb,
-     &arm64_reloc_howto_secrel
+     &arm64_reloc_howto_secrel,
+     &arm64_reloc_howto_secidx
 };
 
 /* No adjustment to addends should be needed.  The actual relocation
@@ -372,6 +378,8 @@ coff_aarch64_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real
     return &arm64_reloc_howto_32nb;
   case BFD_RELOC_32_SECREL:
     return &arm64_reloc_howto_secrel;
+  case BFD_RELOC_16_SECIDX:
+    return &arm64_reloc_howto_secidx;
   default:
     BFD_FAIL ();
     return NULL;
@@ -428,6 +436,8 @@ coff_aarch64_rtype_lookup (unsigned int code)
       return &arm64_reloc_howto_32nb;
     case IMAGE_REL_ARM64_SECREL:
       return &arm64_reloc_howto_secrel;
+    case IMAGE_REL_ARM64_SECTION:
+      return &arm64_reloc_howto_secidx;
     default:
       return NULL;
   }
@@ -847,6 +857,31 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
            break;
          }
 
+       case IMAGE_REL_ARM64_SECTION:
+         {
+           uint16_t idx = 0, i = 1;
+           asection *s;
+
+           s = output_bfd->sections;
+           while (s)
+             {
+               if (s == sec->output_section)
+                 {
+                   idx = i;
+                   break;
+                 }
+
+               i++;
+               s = s->next;
+             }
+
+
+           bfd_putl16 (idx, contents + rel->r_vaddr);
+           rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+
+           break;
+         }
+
        default:
          info->callbacks->einfo (_("%F%P: Unhandled relocation type %u\n"),
                                  rel->r_type);