kselftest/arm64: bti: force static linking
PATCH 1/1 kselftest/arm64: bti: force static linking
The "bti" selftests are built with -nostdlib, which apparently automatically creates a statically linked binary, which is what we want and need for BTI (to avoid interactions with the dynamic linker).
However this is not true when building a PIE binary, which some toolchains (Ubuntu) configure as the default.
When compiling btitest with such a toolchain, it will create a dynamically linked binary, which will probably fail some tests, as the dynamic linker might not support BTI:
===================
TAP version 13
1..18
not ok 1 nohint_func/call_using_br_x0
not ok 2 nohint_func/call_using_br_x16
not ok 3 nohint_func/call_using_blr
....
===================
To make sure we create static binaries, add an explicit -static on the linker command line. This forces static linking even if the toolchain defaults to PIE builds, and fixes btitest runs on BTI enabled machines.
--- tools/testing/selftests/arm64/bti/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/arm64/bti/Makefile +2 -2
@@ -39,7 +39,7 @@ BTI_OBJS = \ teststubs-bti.o \ trampoline-bti.o gen/btitest: $(BTI_OBJS) - $(CC) $(CFLAGS_BTI) $(CFLAGS_COMMON) -nostdlib -o $@ $^ + $(CC) $(CFLAGS_BTI) $(CFLAGS_COMMON) -nostdlib -static -o $@ $^ NOBTI_OBJS = \ test-nobti.o \
@@ -50,7 +50,7 @@ NOBTI_OBJS = \ teststubs-nobti.o \ trampoline-nobti.o gen/nobtitest: $(NOBTI_OBJS) - $(CC) $(CFLAGS_BTI) $(CFLAGS_COMMON) -nostdlib -o $@ $^ + $(CC) $(CFLAGS_BTI) $(CFLAGS_COMMON) -nostdlib -static -o $@ $^ # Including KSFT lib.mk here will also mangle the TEST_GEN_PROGS list # to account for any OUTPUT target-dirs optionally provided by
Signature · 1 line
2.25.1
Quoted 3 lines · Andre Przywara
The "bti" selftests are built with -nostdlib, which apparently automatically creates a statically linked binary, which is what we want and need for BTI (to avoid interactions with the dynamic linker).
Catalin Marinas
maintainerQuoted 18 lines · Andre Przywara
The "bti" selftests are built with -nostdlib, which apparently automatically creates a statically linked binary, which is what we want and need for BTI (to avoid interactions with the dynamic linker).
However this is not true when building a PIE binary, which some toolchains (Ubuntu) configure as the default.
When compiling btitest with such a toolchain, it will create a dynamically linked binary, which will probably fail some tests, as the dynamic linker might not support BTI:
===================
TAP version 13
1..18
not ok 1 nohint_func/call_using_br_x0
not ok 2 nohint_func/call_using_br_x16
not ok 3 nohint_func/call_using_blr
....
===================
Quoted 5 lines
To make sure we create static binaries, add an explicit -static on the linker command line. This forces static linking even if the toolchain defaults to PIE builds, and fixes btitest runs on BTI enabled machines.
Signed-off-by Andre Przywara <[email protected]>
Does this need to go in as a fix (cc stable, fixes tag)?
Signature · 1 line
Catalin
On Sun, 15 May 2022 11:05:23 +0100
Catalin Marinas <[email protected]> wrote:
Hi,
Quoted 19 lines · Andre Przywara
Quoted 18 lines
The "bti" selftests are built with -nostdlib, which apparently automatically creates a statically linked binary, which is what we want and need for BTI (to avoid interactions with the dynamic linker).
However this is not true when building a PIE binary, which some toolchains (Ubuntu) configure as the default.
When compiling btitest with such a toolchain, it will create a dynamically linked binary, which will probably fail some tests, as the dynamic linker might not support BTI:
===================
TAP version 13
1..18
not ok 1 nohint_func/call_using_br_x0
not ok 2 nohint_func/call_using_br_x16
not ok 3 nohint_func/call_using_blr
....
===================
Quoted 7 lines
Quoted 5 lines
To make sure we create static binaries, add an explicit -static on the linker command line. This forces static linking even if the toolchain defaults to PIE builds, and fixes btitest runs on BTI enabled machines.
Signed-off-by Andre Przywara <[email protected]>Does this need to go in as a fix (cc stable, fixes tag)?
I dimly remember some discussion about stable fixes not being a real thing for the selftests? In any case:
Cheers,
Andre
Catalin Marinas
maintainerQuoted 25 lines · Andre Przywara
Quoted 23 lines · On Sun, 15 May 2022 11:05:23 +0100 Catalin Marinas <[email protected]>…
Quoted 22 lines · Andre Przywara
The "bti" selftests are built with -nostdlib, which apparently automatically creates a statically linked binary, which is what we want and need for BTI (to avoid interactions with the dynamic linker).
However this is not true when building a PIE binary, which some toolchains (Ubuntu) configure as the default.
When compiling btitest with such a toolchain, it will create a dynamically linked binary, which will probably fail some tests, as the dynamic linker might not support BTI:
===================
TAP version 13
1..18
not ok 1 nohint_func/call_using_br_x0
not ok 2 nohint_func/call_using_br_x16
not ok 3 nohint_func/call_using_blr
....
===================To make sure we create static binaries, add an explicit -static on the linker command line. This forces static linking even if the toolchain defaults to PIE builds, and fixes btitest runs on BTI enabled machines.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Andre Przywara <[email protected]>Does this need to go in as a fix (cc stable, fixes tag)?
I dimly remember some discussion about stable fixes not being a real thing for the selftests? In any case:
Fixes 314bcbf09f14 ("kselftest: arm64: Add BTI tests")
I'll add the fixes tag. I can see the occasional cc stable for kselftest patches.
Signature · 1 line
Catalin
Catalin Marinas
maintainerQuoted 18 lines · Andre Przywara
The "bti" selftests are built with -nostdlib, which apparently automatically creates a statically linked binary, which is what we want and need for BTI (to avoid interactions with the dynamic linker).
However this is not true when building a PIE binary, which some toolchains (Ubuntu) configure as the default.
When compiling btitest with such a toolchain, it will create a dynamically linked binary, which will probably fail some tests, as the dynamic linker might not support BTI:
===================
TAP version 13
1..18
not ok 1 nohint_func/call_using_br_x0
not ok 2 nohint_func/call_using_br_x16
not ok 3 nohint_func/call_using_blr
....
===================
Quoted 1 line
[...]
Applied to arm64 (for-next/kselftest), thanks!
[1/1] kselftest/arm64: bti: force static linking
https://git.kernel.org/arm64/c/d7a49291d786
Signature · 1 line
Catalin