]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/elf64-bpf.c
bpf: fix false overflow in eBPF ELF backend linker
[thirdparty/binutils-gdb.git] / bfd / elf64-bpf.c
index c6a726d932431da909a4f0cc627f2e7e350b1873..d5a160f8f14dfcad4a2562fcf02e2ad786f40bde 100644 (file)
@@ -442,10 +442,11 @@ bpf_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
         case R_BPF_INSN_DISP32:
           {
             /* Make the relocation PC-relative, and change its unit to
-               64-bit words.  */
-            relocation -= sec_addr (input_section) + rel->r_offset;
-            /* Make it 64-bit words.  */
-            relocation = relocation / 8;
+               64-bit words.  Note we need *signed* arithmetic
+               here.  */
+            relocation = ((bfd_signed_vma) relocation
+                         - (sec_addr (input_section) + rel->r_offset));
+            relocation = (bfd_signed_vma) relocation / 8;
             
             /* Get the addend from the instruction and apply it.  */
             addend = bfd_get (howto->bitsize, input_bfd,