]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd: fix handling of R_BPF_INSN_{32,64} relocations.
authorDavid Faust <david.faust@oracle.com>
Thu, 28 May 2020 18:53:29 +0000 (20:53 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 28 May 2020 19:54:46 +0000 (21:54 +0200)
2020-05-28  David Faust  <david.faust@oracle.com>

* elf64-bpf.c (bpf_elf_relocate_section): Fix handling of
R_BPF_INSN_{32,64} relocations.

bfd/ChangeLog
bfd/elf64-bpf.c

index 482bf81e68917075fe64d69d414446697bd0c738..05452c5d46717d254d59c177eb5bb3dcc26fa4ac 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-28  David Faust  <david.faust@oracle.com>
+
+       * elf64-bpf.c (bpf_elf_relocate_section): Fix handling of
+       R_BPF_INSN_{32,64} relocations.
+
 2020-05-28  Stephen Casner  <casner@acm.org>
 
        * pdp11.c: Implement BRD_RELOC_32 to relocate the low 16 bits of
index bf488af81f6409c996052dfaabd20d506b06cbfc..641caa1f058e07a99c3cdb94086fb3586b417d88 100644 (file)
@@ -64,7 +64,7 @@ static reloc_howto_type bpf_elf_howto_table [] =
         MINUS_ONE,             /* dst_mask */
         TRUE),                 /* pcrel_offset */
 
-  /* 32-immediate in LDDW instruction.  */
+  /* 32-immediate in many instructions. Note: handled manually.  */
   HOWTO (R_BPF_INSN_32,                /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
@@ -460,6 +460,31 @@ bpf_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
             r = bfd_reloc_ok;
             break;
           }
+        case R_BPF_INSN_32:
+          {
+            /*  Write relocated value */
+            bfd_put (howto->bitsize, input_bfd, relocation,
+                     contents + rel->r_offset + 4);
+
+            r = bfd_reloc_ok;
+            break;
+          }
+        case R_BPF_INSN_64:
+          {
+            /*
+                LDDW instructions are 128 bits long, with a 64-bit immediate.
+                The lower 32 bits of the immediate are in the same position
+                as the imm32 field of other instructions.
+                The upper 32 bits of the immediate are stored at the end of
+                the instruction.
+             */
+            bfd_put (32, input_bfd, (relocation & 0xFFFFFFFF),
+                     contents + rel->r_offset + 4);
+            bfd_put (32, input_bfd, (relocation >> 32),
+                     contents + rel->r_offset + 12);
+            r = bfd_reloc_ok;
+            break;
+          }
         default:
           r = _bfd_final_link_relocate (howto, input_bfd, input_section,
                                         contents, rel->r_offset, relocation,