diff mbox series

[bpf-next] bpf, vmtest: Build test_progs and friends as statically linked

Message ID 05b5dd79465be41ff8cf8b56b694118a0aa7ae12.1685140942.git.daniel@iogearbox.net (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next] bpf, vmtest: Build test_progs and friends as statically linked | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 12 maintainers not CCed: yhs@fb.com kpsingh@kernel.org martin.lau@linux.dev john.fastabend@gmail.com song@kernel.org sdf@google.com shuah@kernel.org mykolal@fb.com linux-kselftest@vger.kernel.org jolsa@kernel.org haoluo@google.com ast@kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest fail Script vmtest.sh not found in tools/testing/selftests/bpf/Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs on s390x with gcc

Commit Message

Daniel Borkmann May 26, 2023, 10:47 p.m. UTC
Small fix for vmtest.sh that I've been carrying locally for quite a while
now in order to work around the following linker issue:

  # ./vmtest.sh -- ./test_progs -t lsm
  [...]
  + ip link set lo up
  + [ -x /etc/rcS.d/S50-startup ]
  + /etc/rcS.d/S50-startup
  ./test_progs -t lsm
  ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./test_progs)
  ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./test_progs)
  [    1.356497] ACPI: PM: Preparing to enter system sleep state S5
  [    1.358950] reboot: Power down
  [...]

With the specified TRUNNER_LDFLAGS out of vmtest to force static linking
runners like test_progs/test_maps/etc work just fine.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 tools/testing/selftests/bpf/Makefile  | 2 +-
 tools/testing/selftests/bpf/vmtest.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko May 31, 2023, 7:02 p.m. UTC | #1
On Fri, May 26, 2023 at 3:47 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> Small fix for vmtest.sh that I've been carrying locally for quite a while
> now in order to work around the following linker issue:
>
>   # ./vmtest.sh -- ./test_progs -t lsm
>   [...]
>   + ip link set lo up
>   + [ -x /etc/rcS.d/S50-startup ]
>   + /etc/rcS.d/S50-startup
>   ./test_progs -t lsm
>   ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./test_progs)
>   ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./test_progs)
>   [    1.356497] ACPI: PM: Preparing to enter system sleep state S5
>   [    1.358950] reboot: Power down
>   [...]
>
> With the specified TRUNNER_LDFLAGS out of vmtest to force static linking
> runners like test_progs/test_maps/etc work just fine.
>

Should we make this a command line option to the vmtest.sh script
instead? I, for one, can't even successfully build on my machine with
this, probably due to missing some -static library package (though I
did install libzstd-static). I'm getting:

make: *** [Makefile:598:
/data/users/andriin/linux/tools/testing/selftests/bpf/test_maps] Error
1
make: *** Waiting for unfinished jobs....
/opt/rh/gcc-toolset-11/root/usr/bin/ld:
/lib/../lib64/libelf.a(elf_compress.o): in function
`__libelf_compress':
(.text[.text.group]+0x2c1): undefined reference to `ZSTD_createCCtx'
/opt/rh/gcc-toolset-11/root/usr/bin/ld: (.text[.text.group]+0x436):
undefined reference to `ZSTD_compressStream2'
/opt/rh/gcc-toolset-11/root/usr/bin/ld: (.text[.text.group]+0x441):
undefined reference to `ZSTD_isError'
/opt/rh/gcc-toolset-11/root/usr/bin/ld: (.text[.text.group]+0x468):
undefined reference to `ZSTD_freeCCtx'
/opt/rh/gcc-toolset-11/root/usr/bin/ld: (.text[.text.group]+0x626):
undefined reference to `ZSTD_freeCCtx'
/opt/rh/gcc-toolset-11/root/usr/bin/ld: (.text[.text.group]+0x6a1):
undefined reference to `ZSTD_freeCCtx'
/opt/rh/gcc-toolset-11/root/usr/bin/ld: (.text[.text.group]+0x6d1):
undefined reference to `ZSTD_freeCCtx'
/opt/rh/gcc-toolset-11/root/usr/bin/ld: (.text[.text.group]+0x6fd):
undefined reference to `ZSTD_freeCCtx'
/opt/rh/gcc-toolset-11/root/usr/bin/ld:
/lib/../lib64/libelf.a(elf_compress.o):(.text[.text.group]+0x771):
more undefined references to `ZSTD_freeCCtx' follow
/opt/rh/gcc-toolset-11/root/usr/bin/ld:
/lib/../lib64/libelf.a(elf_compress.o): in function
`__libelf_decompress':
(.text[.text.group]+0xa42): undefined reference to `ZSTD_decompress'



> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
> ---
>  tools/testing/selftests/bpf/Makefile  | 2 +-
>  tools/testing/selftests/bpf/vmtest.sh | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index cd2426cca3d0..4005d001f46c 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -547,7 +547,7 @@ $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS)                   \
>                              $(TRUNNER_BPFTOOL)                         \
>                              | $(TRUNNER_BINARY)-extras
>         $$(call msg,BINARY,,$$@)
> -       $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
> +       $(Q)$$(CC) $$(CFLAGS) $(TRUNNER_LDFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
>         $(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@
>         $(Q)ln -sf $(if $2,..,.)/tools/build/bpftool/$(USE_BOOTSTRAP)bpftool \
>                    $(OUTPUT)/$(if $2,$2/)bpftool
> diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh
> index 685034528018..455518745cf9 100755
> --- a/tools/testing/selftests/bpf/vmtest.sh
> +++ b/tools/testing/selftests/bpf/vmtest.sh
> @@ -160,7 +160,7 @@ update_selftests()
>         local selftests_dir="${kernel_checkout}/tools/testing/selftests/bpf"
>
>         cd "${selftests_dir}"
> -       ${make_command}
> +       TRUNNER_LDFLAGS=-static ${make_command}
>
>         # Mount the image and copy the selftests to the image.
>         mount_image
> --
> 2.21.0
>
>
Daniel Borkmann May 31, 2023, 7:53 p.m. UTC | #2
On 5/31/23 9:02 PM, Andrii Nakryiko wrote:
> On Fri, May 26, 2023 at 3:47 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>>
>> Small fix for vmtest.sh that I've been carrying locally for quite a while
>> now in order to work around the following linker issue:
>>
>>    # ./vmtest.sh -- ./test_progs -t lsm
>>    [...]
>>    + ip link set lo up
>>    + [ -x /etc/rcS.d/S50-startup ]
>>    + /etc/rcS.d/S50-startup
>>    ./test_progs -t lsm
>>    ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./test_progs)
>>    ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./test_progs)
>>    [    1.356497] ACPI: PM: Preparing to enter system sleep state S5
>>    [    1.358950] reboot: Power down
>>    [...]
>>
>> With the specified TRUNNER_LDFLAGS out of vmtest to force static linking
>> runners like test_progs/test_maps/etc work just fine.
> 
> Should we make this a command line option to the vmtest.sh script
> instead? I, for one, can't even successfully build on my machine with
> this, probably due to missing some -static library package (though I
> did install libzstd-static). I'm getting:

Interesting, in my case it's the other way round, but yeah that could work
as well.

Thanks,
Daniel
Daniel Xu July 11, 2023, 8:15 p.m. UTC | #3
Hi,

On Wed, May 31, 2023 at 09:53:57PM +0200, Daniel Borkmann wrote:
> On 5/31/23 9:02 PM, Andrii Nakryiko wrote:
> > On Fri, May 26, 2023 at 3:47 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
> > > 
> > > Small fix for vmtest.sh that I've been carrying locally for quite a while
> > > now in order to work around the following linker issue:
> > > 
> > >    # ./vmtest.sh -- ./test_progs -t lsm
> > >    [...]
> > >    + ip link set lo up
> > >    + [ -x /etc/rcS.d/S50-startup ]
> > >    + /etc/rcS.d/S50-startup
> > >    ./test_progs -t lsm
> > >    ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./test_progs)
> > >    ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./test_progs)
> > >    [    1.356497] ACPI: PM: Preparing to enter system sleep state S5
> > >    [    1.358950] reboot: Power down
> > >    [...]
> > > 
> > > With the specified TRUNNER_LDFLAGS out of vmtest to force static linking
> > > runners like test_progs/test_maps/etc work just fine.
> > 
> > Should we make this a command line option to the vmtest.sh script
> > instead? I, for one, can't even successfully build on my machine with
> > this, probably due to missing some -static library package (though I
> > did install libzstd-static). I'm getting:
> 
> Interesting, in my case it's the other way round, but yeah that could work
> as well.
> 
> Thanks,
> Daniel
> 

I had the same zstd linker error. This hacky change fixes it:

```
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 9706e7e5e698..c0d8809fd002 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -31,7 +31,7 @@ CFLAGS += -g -O0 -rdynamic -Wall -Werror $(GENFLAGS) $(SAN_CFLAGS)    \
          -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)          \
          -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT)
 LDFLAGS += $(SAN_LDFLAGS)
-LDLIBS += -lelf -lz -lrt -lpthread
+LDLIBS += -lelf -lz -lrt -lpthread -lzstd

 # Silence some warnings when compiled with clang
 ifneq ($(LLVM),)
```

Would be good to get some variant of this patch in.

Thanks,
Daniel
Daniel Borkmann July 12, 2023, 12:38 p.m. UTC | #4
On 7/11/23 10:15 PM, Daniel Xu wrote:
> On Wed, May 31, 2023 at 09:53:57PM +0200, Daniel Borkmann wrote:
>> On 5/31/23 9:02 PM, Andrii Nakryiko wrote:
>>> On Fri, May 26, 2023 at 3:47 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>>>>
>>>> Small fix for vmtest.sh that I've been carrying locally for quite a while
>>>> now in order to work around the following linker issue:
>>>>
>>>>     # ./vmtest.sh -- ./test_progs -t lsm
>>>>     [...]
>>>>     + ip link set lo up
>>>>     + [ -x /etc/rcS.d/S50-startup ]
>>>>     + /etc/rcS.d/S50-startup
>>>>     ./test_progs -t lsm
>>>>     ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./test_progs)
>>>>     ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./test_progs)
>>>>     [    1.356497] ACPI: PM: Preparing to enter system sleep state S5
>>>>     [    1.358950] reboot: Power down
>>>>     [...]
>>>>
>>>> With the specified TRUNNER_LDFLAGS out of vmtest to force static linking
>>>> runners like test_progs/test_maps/etc work just fine.
>>>
>>> Should we make this a command line option to the vmtest.sh script
>>> instead? I, for one, can't even successfully build on my machine with
>>> this, probably due to missing some -static library package (though I
>>> did install libzstd-static). I'm getting:
>>
>> Interesting, in my case it's the other way round, but yeah that could work
>> as well.
> 
> I had the same zstd linker error. This hacky change fixes it:
> 
> ```
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 9706e7e5e698..c0d8809fd002 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -31,7 +31,7 @@ CFLAGS += -g -O0 -rdynamic -Wall -Werror $(GENFLAGS) $(SAN_CFLAGS)    \
>            -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)          \
>            -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT)
>   LDFLAGS += $(SAN_LDFLAGS)
> -LDLIBS += -lelf -lz -lrt -lpthread
> +LDLIBS += -lelf -lz -lrt -lpthread -lzstd
> 
>   # Silence some warnings when compiled with clang
>   ifneq ($(LLVM),)
> ```
> 
> Would be good to get some variant of this patch in.

The above doesn't work for my env, getting same error with adding the -lzstd.
Btw, did the patch from above work for you?
Daniel Xu July 12, 2023, 4:42 p.m. UTC | #5
Hi Daniel,

On Wed, Jul 12, 2023 at 02:38:50PM +0200, Daniel Borkmann wrote:
> On 7/11/23 10:15 PM, Daniel Xu wrote:
> > On Wed, May 31, 2023 at 09:53:57PM +0200, Daniel Borkmann wrote:
> > > On 5/31/23 9:02 PM, Andrii Nakryiko wrote:
> > > > On Fri, May 26, 2023 at 3:47 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
> > > > > 
> > > > > Small fix for vmtest.sh that I've been carrying locally for quite a while
> > > > > now in order to work around the following linker issue:
> > > > > 
> > > > >     # ./vmtest.sh -- ./test_progs -t lsm
> > > > >     [...]
> > > > >     + ip link set lo up
> > > > >     + [ -x /etc/rcS.d/S50-startup ]
> > > > >     + /etc/rcS.d/S50-startup
> > > > >     ./test_progs -t lsm
> > > > >     ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./test_progs)
> > > > >     ./test_progs: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./test_progs)
> > > > >     [    1.356497] ACPI: PM: Preparing to enter system sleep state S5
> > > > >     [    1.358950] reboot: Power down
> > > > >     [...]
> > > > > 
> > > > > With the specified TRUNNER_LDFLAGS out of vmtest to force static linking
> > > > > runners like test_progs/test_maps/etc work just fine.
> > > > 
> > > > Should we make this a command line option to the vmtest.sh script
> > > > instead? I, for one, can't even successfully build on my machine with
> > > > this, probably due to missing some -static library package (though I
> > > > did install libzstd-static). I'm getting:
> > > 
> > > Interesting, in my case it's the other way round, but yeah that could work
> > > as well.
> > 
> > I had the same zstd linker error. This hacky change fixes it:
> > 
> > ```
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index 9706e7e5e698..c0d8809fd002 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -31,7 +31,7 @@ CFLAGS += -g -O0 -rdynamic -Wall -Werror $(GENFLAGS) $(SAN_CFLAGS)    \
> >            -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)          \
> >            -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT)
> >   LDFLAGS += $(SAN_LDFLAGS)
> > -LDLIBS += -lelf -lz -lrt -lpthread
> > +LDLIBS += -lelf -lz -lrt -lpthread -lzstd
> > 
> >   # Silence some warnings when compiled with clang
> >   ifneq ($(LLVM),)
> > ```
> > 
> > Would be good to get some variant of this patch in.
> 
> The above doesn't work for my env, getting same error with adding the -lzstd.
> Btw, did the patch from above work for you?

Your original patch did not work for me (libelf missing zstd symbols).
But with the patch I sent applied, it builds correctly.

What is the error you're getting with `-lzstd`? My guess is that your
distro's libelf.a has zstd symbols statically linked in already. Perhaps
check what pkg-config says about your libelf? Mine is:

```
$ pkg-config --static --libs libelf
-lelf -lz -lzstd
```

Also, perhaps the build should be using pkg-config instead of hardcoding
deps in LDLIBS. That might make the static build more reliable across
different systems.

Thanks,
Daniel
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index cd2426cca3d0..4005d001f46c 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -547,7 +547,7 @@  $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS)			\
 			     $(TRUNNER_BPFTOOL)				\
 			     | $(TRUNNER_BINARY)-extras
 	$$(call msg,BINARY,,$$@)
-	$(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
+	$(Q)$$(CC) $$(CFLAGS) $(TRUNNER_LDFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
 	$(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@
 	$(Q)ln -sf $(if $2,..,.)/tools/build/bpftool/$(USE_BOOTSTRAP)bpftool \
 		   $(OUTPUT)/$(if $2,$2/)bpftool
diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh
index 685034528018..455518745cf9 100755
--- a/tools/testing/selftests/bpf/vmtest.sh
+++ b/tools/testing/selftests/bpf/vmtest.sh
@@ -160,7 +160,7 @@  update_selftests()
 	local selftests_dir="${kernel_checkout}/tools/testing/selftests/bpf"
 
 	cd "${selftests_dir}"
-	${make_command}
+	TRUNNER_LDFLAGS=-static ${make_command}
 
 	# Mount the image and copy the selftests to the image.
 	mount_image