diff mbox series

[bpf-next,v1,2/2] selftests/bpf: Fix error linking uprobe_multi on mips

Message ID 7eeb1a1a9910b30782adba9eb5cc47c6ce075223.1721541467.git.tony.ambardar@gmail.com (mailing list archive)
State New
Headers show
Series selftests/bpf: Add support for MIPS systems | expand

Commit Message

Tony Ambardar July 21, 2024, 7:50 a.m. UTC
Linking uprobe_multi.c on mips64el fails due to relocation overflows, when
the GOT entries required exceeds the default maximum. Add a specific CFLAGS
(-mxgot) for uprobe_multi.c on MIPS that allows using a larger GOT and
avoids errors such as:

  /tmp/ccBTNQzv.o: in function `bench':
  uprobe_multi.c:49:(.text+0x1d7720): relocation truncated to fit: R_MIPS_GOT_DISP against `uprobe_multi_func_08188'
  uprobe_multi.c:49:(.text+0x1d7730): relocation truncated to fit: R_MIPS_GOT_DISP against `uprobe_multi_func_08189'
  ...
  collect2: error: ld returned 1 exit status

Fixes: 519dfeaf5119 ("selftests/bpf: Add uprobe_multi test program")
Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
---
 tools/testing/selftests/bpf/Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Andrii Nakryiko July 22, 2024, 9:22 p.m. UTC | #1
On Sun, Jul 21, 2024 at 12:51 AM Tony Ambardar <tony.ambardar@gmail.com> wrote:
>
> Linking uprobe_multi.c on mips64el fails due to relocation overflows, when
> the GOT entries required exceeds the default maximum. Add a specific CFLAGS
> (-mxgot) for uprobe_multi.c on MIPS that allows using a larger GOT and
> avoids errors such as:
>
>   /tmp/ccBTNQzv.o: in function `bench':
>   uprobe_multi.c:49:(.text+0x1d7720): relocation truncated to fit: R_MIPS_GOT_DISP against `uprobe_multi_func_08188'
>   uprobe_multi.c:49:(.text+0x1d7730): relocation truncated to fit: R_MIPS_GOT_DISP against `uprobe_multi_func_08189'
>   ...
>   collect2: error: ld returned 1 exit status
>
> Fixes: 519dfeaf5119 ("selftests/bpf: Add uprobe_multi test program")
> Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
> ---
>  tools/testing/selftests/bpf/Makefile | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index a9c447c63fee..0b4bfbc0ef68 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -784,9 +784,12 @@ $(OUTPUT)/veristat: $(OUTPUT)/veristat.o
>         $(call msg,BINARY,,$@)
>         $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
>
> +# Linking uprobe_multi can fail due to relocation overflows on mips.
> +uprobe_multi.c-CFLAGS := $(if $(filter mips, $(ARCH)),-mxgot)
> +
>  $(OUTPUT)/uprobe_multi: uprobe_multi.c
>         $(call msg,BINARY,,$@)
> -       $(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
> +       $(Q)$(CC) $(CFLAGS) $($<-CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@

this $($<-CFLAGS) approach is fragile, non-obvious and will break. But
there is also no need for this, see:

$(OUTPUT)/bench: LDLIBS += -lm

make allows to override envvars on a per-target basis, so all you
should need is:


$(OUTPUT)/uprobe_multi: CFLAGS += $(if $(filter mips, $(ARCH)),-mxgot)
$(OUTPUT)/uprobe_multi: uprobe_multi.c
   ... the rest is the same with no change whatsoever ...

>
>  EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)                      \
>         prog_tests/tests.h map_tests/tests.h verifier/tests.h           \
> --
> 2.34.1
>
Tony Ambardar July 23, 2024, 12:04 a.m. UTC | #2
On Mon, Jul 22, 2024 at 02:22:53PM -0700, Andrii Nakryiko wrote:
> On Sun, Jul 21, 2024 at 12:51 AM Tony Ambardar <tony.ambardar@gmail.com> wrote:

[...]

> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -784,9 +784,12 @@ $(OUTPUT)/veristat: $(OUTPUT)/veristat.o
> >         $(call msg,BINARY,,$@)
> >         $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
> >
> > +# Linking uprobe_multi can fail due to relocation overflows on mips.
> > +uprobe_multi.c-CFLAGS := $(if $(filter mips, $(ARCH)),-mxgot)
> > +
> >  $(OUTPUT)/uprobe_multi: uprobe_multi.c
> >         $(call msg,BINARY,,$@)
> > -       $(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
> > +       $(Q)$(CC) $(CFLAGS) $($<-CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
> 
> this $($<-CFLAGS) approach is fragile, non-obvious and will break. But
> there is also no need for this, see:
> 
> $(OUTPUT)/bench: LDLIBS += -lm
> 
> make allows to override envvars on a per-target basis, so all you
> should need is:
> 
> 
> $(OUTPUT)/uprobe_multi: CFLAGS += $(if $(filter mips, $(ARCH)),-mxgot)
> $(OUTPUT)/uprobe_multi: uprobe_multi.c
>    ... the rest is the same with no change whatsoever ...
> 

Great suggestion, thanks for pointing that out! I'll update and send v2.

> >
> >  EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)                      \
> >         prog_tests/tests.h map_tests/tests.h verifier/tests.h           \
> > --
> > 2.34.1
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index a9c447c63fee..0b4bfbc0ef68 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -784,9 +784,12 @@  $(OUTPUT)/veristat: $(OUTPUT)/veristat.o
 	$(call msg,BINARY,,$@)
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
 
+# Linking uprobe_multi can fail due to relocation overflows on mips.
+uprobe_multi.c-CFLAGS := $(if $(filter mips, $(ARCH)),-mxgot)
+
 $(OUTPUT)/uprobe_multi: uprobe_multi.c
 	$(call msg,BINARY,,$@)
-	$(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
+	$(Q)$(CC) $(CFLAGS) $($<-CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
 
 EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)			\
 	prog_tests/tests.h map_tests/tests.h verifier/tests.h		\