[binutils-gdb] bpf: Added linker support for R_BPF_64_NODYLD32.

Cupertino Miranda cupermir@sourceware.org
Mon Jan 8 20:45:04 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ad4e57ab110aba9cd90a76539ed480e9d1f8cfa5

commit ad4e57ab110aba9cd90a76539ed480e9d1f8cfa5
Author: Cupertino Miranda <cupertino.miranda@oracle.com>
Date:   Wed Dec 20 12:24:03 2023 +0000

    bpf: Added linker support for R_BPF_64_NODYLD32.
    
    This patch adds linker support to patch R_BPF_64_NODYLD32 relocations.
    The implementation was based on comments and code in LLVM, as the GNU
    toolchain does not uses this relocation type.

Diff:
---
 bfd/bpf-reloc.def | 17 ++++++++++-------
 bfd/elf64-bpf.c   |  1 +
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/bfd/bpf-reloc.def b/bfd/bpf-reloc.def
index 7e7497892fa..42ba1a169ea 100644
--- a/bfd/bpf-reloc.def
+++ b/bfd/bpf-reloc.def
@@ -90,17 +90,20 @@
 
   /* R_BPF_64_NODYLD32 is not used by GNU tools - but it is generated by LLVM.
      We provide an entry here so that tools like strip can safely handle BPF
-     binaries generated by other tools.  */
+     binaries generated by other tools.
+     R_BPF_64_NODYLD32 should be fixed at linker like a R_BPF_64_ABS32.
+     The difference to ABS32 is that LLVM execution engine does not resolve
+     R_BPF_64_NODYLD32 relocations.  */
   BPF_HOWTO (R_BPF_64_NODYLD32,	/* type */
 	 0,			/* rightshift */
-	 0,			/* size */
-	 0,			/* bitsize */
+	 4,			/* size */
+	 32,			/* bitsize */
 	 false,			/* pc_relative */
 	 0,			/* bitpos */
-	 complain_overflow_dont, /* complain_on_overflow */
+	 complain_overflow_bitfield, /* complain_on_overflow */
 	 bpf_elf_generic_reloc, /* special_function */
 	 "R_BPF_64_NODYLD32",	/* name */
 	 false,			/* partial_inplace */
-	 0,			/* src_mask */
-	 0,			/* dst_mask */
-	 false)			/* pcrel_offset */
+	 0xffffffff,		/* src_mask */
+	 0xffffffff,		/* dst_mask */
+	 true)			/* pcrel_offset */
diff --git a/bfd/elf64-bpf.c b/bfd/elf64-bpf.c
index c932a4024ba..0bffe2c5717 100644
--- a/bfd/elf64-bpf.c
+++ b/bfd/elf64-bpf.c
@@ -276,6 +276,7 @@ bpf_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
           }
 	case R_BPF_64_ABS64:
 	case R_BPF_64_ABS32:
+	case R_BPF_64_NODYLD32:
 	  {
 	    addend = bfd_get (howto->bitsize, input_bfd, where);
 	    relocation += addend;


More information about the Binutils-cvs mailing list