diff mbox series

[RFC] kvm: Fix Nix build failure by specifying -fno-stack-protector again

Message ID 20230918112358.25858-1-rpalethorpe@suse.com
State Changes Requested
Headers show
Series [RFC] kvm: Fix Nix build failure by specifying -fno-stack-protector again | expand

Commit Message

Richard Palethorpe Sept. 18, 2023, 11:23 a.m. UTC
Nix uses a binutils wrapper of some sort to allow switching between
toolchains. This seems to be causing a problem for the KVM tests
although it may not be unique to Nix.

gcc -I/home/rich/kernel/ltp/testcases/kernel/kvm/include -DCOMPILE_PAYLOAD -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx\
 -mno-sse -fno-pie -c -o lib_guest.o lib_guest.c
as  -c -o bootstrap_x86_64.o bootstrap_x86_64.S
gcc -I/home/rich/kernel/ltp/testcases/kernel/kvm/include -DCOMPILE_PAYLOAD -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx\
 -mno-sse -fno-pie -c -o lib_x86.o lib_x86.c
gcc -I/home/rich/kernel/ltp/testcases/kernel/kvm/include -I../../../include -I../../../include -I../../../include/old/ -DCOMPILE_PAYLOAD -ff\
reestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse -fno-pie -nostdlib -Wl,--build-id=none -fno-stack-protector -z noexe\
cstack -no-pie -Wl,-T/home/rich/kernel/ltp/testcases/kernel/kvm/linker/x86_64.lds -o kvm_pagefault01-payload.elf kvm_pagefault01.c lib_guest\
.o bootstrap_x86_64.o lib_x86.o
/nix/store/inq79dwl8sz1ygmfbgsmg77i5cwmdjpz-binutils-2.40/bin/ld: lib_x86.o: in function `kvm_init_guest_vmcb':
lib_x86.c:(.text+0x7b3): undefined reference to `__stack_chk_fail'
collect2: error: ld returned 1 exit status
make: *** [Makefile:58: kvm_pagefault01-payload.o] Error 1

IIUC __stack_chk_fail is added to lib_x86.o which means that
-fstack-protector somehow gets added to the compilation of lib_x86.o.

I found that adding the GUEST_LDFLAGS to the lib_*.o compilations
fixes the issue on Nix.
---
 testcases/kernel/kvm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Cyril Hrubis Sept. 18, 2023, 11:44 a.m. UTC | #1
Hi!
> I found that adding the GUEST_LDFLAGS to the lib_*.o compilations
> fixes the issue on Nix.

I suppose that, if nothing else, we should add just -fno-stack-protector
to the GUEST_CFLAGS instead.

> ---
>  testcases/kernel/kvm/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/testcases/kernel/kvm/Makefile b/testcases/kernel/kvm/Makefile
> index d9eb10728..ddb24fabe 100644
> --- a/testcases/kernel/kvm/Makefile
> +++ b/testcases/kernel/kvm/Makefile
> @@ -46,7 +46,7 @@ MAKE_TARGETS =
>  endif
>  
>  lib_guest.o $(ARCH_OBJ): CPPFLAGS	:= $(GUEST_CPPFLAGS)
> -lib_guest.o $(ARCH_OBJ): CFLAGS		:= $(GUEST_CFLAGS)
> +lib_guest.o $(ARCH_OBJ): CFLAGS		:= $(GUEST_CFLAGS) $(GUEST_LDFLAGS)
>  
>  kvm_svm03: CFLAGS += -pthread
>  kvm_svm03: LDLIBS += -pthread
> -- 
> 2.40.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp
Martin Doucha Sept. 18, 2023, 11:49 a.m. UTC | #2
On 18. 09. 23 13:44, Cyril Hrubis wrote:
> Hi!
>> I found that adding the GUEST_LDFLAGS to the lib_*.o compilations
>> fixes the issue on Nix.
> 
> I suppose that, if nothing else, we should add just -fno-stack-protector
> to the GUEST_CFLAGS instead.

+1
diff mbox series

Patch

diff --git a/testcases/kernel/kvm/Makefile b/testcases/kernel/kvm/Makefile
index d9eb10728..ddb24fabe 100644
--- a/testcases/kernel/kvm/Makefile
+++ b/testcases/kernel/kvm/Makefile
@@ -46,7 +46,7 @@  MAKE_TARGETS =
 endif
 
 lib_guest.o $(ARCH_OBJ): CPPFLAGS	:= $(GUEST_CPPFLAGS)
-lib_guest.o $(ARCH_OBJ): CFLAGS		:= $(GUEST_CFLAGS)
+lib_guest.o $(ARCH_OBJ): CFLAGS		:= $(GUEST_CFLAGS) $(GUEST_LDFLAGS)
 
 kvm_svm03: CFLAGS += -pthread
 kvm_svm03: LDLIBS += -pthread