* [PATCH] bpf: Added linker support for R_BPF_64_NODYLD32. @ 2023-12-20 13:23 Cupertino Miranda 2024-01-03 10:34 ` Jose E. Marchesi 0 siblings, 1 reply; 5+ messages in thread From: Cupertino Miranda @ 2023-12-20 13:23 UTC (permalink / raw) To: binutils; +Cc: nickc, elena.zannoni, jose.marchesi, Cupertino Miranda Hi everyone, This patch is in context of Nick Cliftons request in thread: https://sourceware.org/pipermail/binutils/2023-October/130194.html due to bug reported in: https://bugzilla.redhat.com/show_bug.cgi?id=2245296 For the time being the linker is not used in BPF infrastructure. Considering that and without a proper way to validate the code, the following patch is what I think is missing in order to add linker support for the particular relocation. Looking forward to your review. Best regards, Cupertino 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. --- bfd/elf64-bpf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bfd/elf64-bpf.c b/bfd/elf64-bpf.c index aefad7da5ac..5820dd3d7d4 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; -- 2.30.2 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bpf: Added linker support for R_BPF_64_NODYLD32. 2023-12-20 13:23 [PATCH] bpf: Added linker support for R_BPF_64_NODYLD32 Cupertino Miranda @ 2024-01-03 10:34 ` Jose E. Marchesi 2024-01-08 10:16 ` Cupertino Miranda 0 siblings, 1 reply; 5+ messages in thread From: Jose E. Marchesi @ 2024-01-03 10:34 UTC (permalink / raw) To: Cupertino Miranda; +Cc: binutils, nickc, elena.zannoni Hi Cuper. > Hi everyone, > > This patch is in context of Nick Cliftons request in thread: > https://sourceware.org/pipermail/binutils/2023-October/130194.html > due to bug reported in: > https://bugzilla.redhat.com/show_bug.cgi?id=2245296 > > For the time being the linker is not used in BPF infrastructure. > Considering that and without a proper way to validate the code, the > following patch is what I think is missing in order to add linker > support for the particular relocation. > > Looking forward to your review. > > Best regards, > Cupertino > > 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. > --- > bfd/elf64-bpf.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/bfd/elf64-bpf.c b/bfd/elf64-bpf.c > index aefad7da5ac..5820dd3d7d4 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: I would add here a comment explaining that R_BPF_64_NODYLD32 shall be handled/resolved like R_BPF_64_ABS32 and that it differs from ABS32 only in that the LLVM execution engine is not supposed to resolve it. Given that, the patch is OK. Thanks! > { > addend = bfd_get (howto->bitsize, input_bfd, where); > relocation += addend; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bpf: Added linker support for R_BPF_64_NODYLD32. 2024-01-03 10:34 ` Jose E. Marchesi @ 2024-01-08 10:16 ` Cupertino Miranda 2024-01-08 18:45 ` Jose E. Marchesi 0 siblings, 1 reply; 5+ messages in thread From: Cupertino Miranda @ 2024-01-08 10:16 UTC (permalink / raw) To: Jose E. Marchesi; +Cc: binutils, nickc, elena.zannoni [-- Attachment #1: Type: text/plain, Size: 288 bytes --] Hi Jose, Thanks for your review. I realized I missed to update the macro for the relocation where the properties like size, overflow check, (etc.) are defined. I have added the comment near the relocation macro definition. Sending the patch for review once again. Regards, Cupertino [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-bpf-Added-linker-support-for-R_BPF_64_NODYLD32.patch --] [-- Type: text/x-diff, Size: 2137 bytes --] From bb8afde9a8f17d42393067c3a667bec1f08b252a Mon Sep 17 00:00:00 2001 From: Cupertino Miranda <cupertino.miranda@oracle.com> Date: Wed, 20 Dec 2023 12:24:03 +0000 Subject: [PATCH] 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. --- 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; -- 2.39.2 [-- Attachment #3: Type: text/plain, Size: 1559 bytes --] Jose E. Marchesi writes: > Hi Cuper. > >> Hi everyone, >> >> This patch is in context of Nick Cliftons request in thread: >> https://sourceware.org/pipermail/binutils/2023-October/130194.html >> due to bug reported in: >> https://bugzilla.redhat.com/show_bug.cgi?id=2245296 >> >> For the time being the linker is not used in BPF infrastructure. >> Considering that and without a proper way to validate the code, the >> following patch is what I think is missing in order to add linker >> support for the particular relocation. >> >> Looking forward to your review. >> >> Best regards, >> Cupertino >> >> 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. >> --- >> bfd/elf64-bpf.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/bfd/elf64-bpf.c b/bfd/elf64-bpf.c >> index aefad7da5ac..5820dd3d7d4 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: > > I would add here a comment explaining that R_BPF_64_NODYLD32 shall be > handled/resolved like R_BPF_64_ABS32 and that it differs from ABS32 only > in that the LLVM execution engine is not supposed to resolve it. > > Given that, the patch is OK. > Thanks! > >> { >> addend = bfd_get (howto->bitsize, input_bfd, where); >> relocation += addend; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bpf: Added linker support for R_BPF_64_NODYLD32. 2024-01-08 10:16 ` Cupertino Miranda @ 2024-01-08 18:45 ` Jose E. Marchesi 2024-01-08 20:45 ` Cupertino Miranda 0 siblings, 1 reply; 5+ messages in thread From: Jose E. Marchesi @ 2024-01-08 18:45 UTC (permalink / raw) To: Cupertino Miranda; +Cc: binutils, nickc, elena.zannoni Hi Cuper. OK, thanks. > Hi Jose, > > Thanks for your review. > I realized I missed to update the macro for the relocation where the > properties like size, overflow check, (etc.) are defined. > I have added the comment near the relocation macro definition. > > Sending the patch for review once again. > > Regards, > Cupertino > > From bb8afde9a8f17d42393067c3a667bec1f08b252a Mon Sep 17 00:00:00 2001 > From: Cupertino Miranda <cupertino.miranda@oracle.com> > Date: Wed, 20 Dec 2023 12:24:03 +0000 > Subject: [PATCH] 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. > --- > 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; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bpf: Added linker support for R_BPF_64_NODYLD32. 2024-01-08 18:45 ` Jose E. Marchesi @ 2024-01-08 20:45 ` Cupertino Miranda 0 siblings, 0 replies; 5+ messages in thread From: Cupertino Miranda @ 2024-01-08 20:45 UTC (permalink / raw) To: Jose E. Marchesi; +Cc: binutils, nickc, elena.zannoni Thanks! Committed. Jose E. Marchesi writes: > Hi Cuper. > OK, thanks. > >> Hi Jose, >> >> Thanks for your review. >> I realized I missed to update the macro for the relocation where the >> properties like size, overflow check, (etc.) are defined. >> I have added the comment near the relocation macro definition. >> >> Sending the patch for review once again. >> >> Regards, >> Cupertino >> >> From bb8afde9a8f17d42393067c3a667bec1f08b252a Mon Sep 17 00:00:00 2001 >> From: Cupertino Miranda <cupertino.miranda@oracle.com> >> Date: Wed, 20 Dec 2023 12:24:03 +0000 >> Subject: [PATCH] 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. >> --- >> 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; ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-01-08 20:45 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-12-20 13:23 [PATCH] bpf: Added linker support for R_BPF_64_NODYLD32 Cupertino Miranda 2024-01-03 10:34 ` Jose E. Marchesi 2024-01-08 10:16 ` Cupertino Miranda 2024-01-08 18:45 ` Jose E. Marchesi 2024-01-08 20:45 ` Cupertino Miranda
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).