Re: [PATCH bpf-next] libbpf: fix internal USDT address translation logic for shared libraries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 20, 2022 at 11:37 AM Jakub Sitnicki <jakub@xxxxxxxxxxxxxx> wrote:
>
> On Wed, Jul 20, 2022 at 05:32 PM +02, Jakub Sitnicki wrote:
>
> [...]
>
> >> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> >> index 8ad7a733a505..e08e8e34e793 100644
> >> --- a/tools/testing/selftests/bpf/Makefile
> >> +++ b/tools/testing/selftests/bpf/Makefile
> >> @@ -172,13 +172,15 @@ $(OUTPUT)/%:%.c
> >>  # do not fail. Static builds leave urandom_read relying on system-wide shared libraries.
> >>  $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c
> >>      $(call msg,LIB,,$@)
> >> -    $(Q)$(CC) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $^ $(LDLIBS) -fPIC -shared -o $@
> >> +    $(Q)$(CLANG) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $^ $(LDLIBS)   \
> >> +                 -fuse-ld=lld -Wl,-znoseparate-code -fPIC -shared -o $@
> >>
> >>  $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so
> >>      $(call msg,BINARY,,$@)
> >> -    $(Q)$(CC) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^)  \
> >> -              liburandom_read.so $(LDLIBS)                                 \
> >> -              -Wl,-rpath=. -Wl,--build-id=sha1 -o $@
> >> +    $(Q)$(CLANG) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \
> >> +                 liburandom_read.so $(LDLIBS)                              \
> >> +                 -fuse-ld=lld -Wl,-znoseparate-code                        \
> >> +                 -Wl,-rpath=. -Wl,--build-id=sha1 -o $@
> >
> > [...]
> >
> > Not sure if this was considered - adding a dependency on Clang for the
> > target platform makes cross-compiling bpf selftests much harder than it
> > was.
> >
> > Maybe we could use $(CLANG) only when not cross-compiling, and execute
> > $(CC) like before otherwise?
>
> OTOH, there seems to be nothing Clang specific about the build
> recipe. We just want t use LLVM lld. GCC accepts -fuse-ld as well (bfd
> vs lld).
>
> Perhaps we could partially revert to something as below? It "fixes" the
> cross-compilation build of bpf selftests for arm64 for me.
>
> WDYT?
>
> --8<--
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 8d59ec7f4c2d..541e2b0de27a 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -170,24 +170,24 @@ $(OUTPUT)/%:%.c
>
>  # LLVM's ld.lld doesn't support all the architectures, so use it only on x86
>  ifeq ($(SRCARCH),x86)
> -LLD := lld
> +ALT_LD := lld
>  else
> -LLD := ld
> +ALT_LD := bfd
>  endif
>
>  # Filter out -static for liburandom_read.so and its dependent targets so that static builds
>  # do not fail. Static builds leave urandom_read relying on system-wide shared libraries.
>  $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c
>         $(call msg,LIB,,$@)
> -       $(Q)$(CLANG) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $^ $(LDLIBS)   \
> -                    -fuse-ld=$(LLD) -Wl,-znoseparate-code -fPIC -shared -o $@
> +       $(Q)$(CC) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $^ $(LDLIBS)       \
> +                 -fuse-ld=$(ALT_LD) -Wl,-znoseparate-code -fPIC -shared -o $@
>
>  $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so
>         $(call msg,BINARY,,$@)
> -       $(Q)$(CLANG) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \
> -                    liburandom_read.so $(LDLIBS)                              \
> -                    -fuse-ld=$(LLD) -Wl,-znoseparate-code                     \
> -                    -Wl,-rpath=. -Wl,--build-id=sha1 -o $@
> +       $(Q)$(CC) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^)   \
> +                 liburandom_read.so $(LDLIBS)                                  \
> +                 -fuse-ld=$(ALT_LD) -Wl,-znoseparate-code                      \
> +                 -Wl,-rpath=. -Wl,--build-id=sha1 -o $@
>

I tried building with CC locally and I still see ELF layout that would
exercise the logic that was fixed with my original patchset:

$ readelf -l liburandom_read.so | grep LOAD -A1
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000000005ec 0x00000000000005ec  R      0x1000
  LOAD           0x00000000000005f0 0x00000000000015f0 0x00000000000015f0
                 0x0000000000000130 0x0000000000000130  R E    0x1000
  LOAD           0x0000000000000720 0x0000000000002720 0x0000000000002720
                 0x0000000000000200 0x0000000000000200  RW     0x1000
  LOAD           0x0000000000000920 0x0000000000003920 0x0000000000003920
                 0x0000000000000028 0x0000000000000029  RW     0x1000

So sure, sounds good to me, please send a patch with a change.



>  $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch])
>         $(call msg,MOD,,$@)



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux