Skip to contentSkip to conversation

LTP compilation fixes for buildroot toolchains

PATCH In review Petr Vorel 5 participants 9 messages Jun 6, 2022 – Jun 13, 2022

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

cover LTP compilation fixes for buildroot toolchains

Hi all,

this fixes 2 compilation failures of KVM tests reported some time ago [1].

Kind regards,
Petr

[1] https://lore.kernel.org/buildroot/YofzKdQAUOnR2gSW@pevik/

Petr Vorel (2):
kvm: Fix compilation on x86
kvm: Fix undefined reference to __stack_chk_fail()

 testcases/kernel/kvm/Makefile | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Signature · 6 lines
2.36.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
author
#1 lore raw

PATCH 1/2 kvm: Fix compilation on x86

Buildroot supports i386 pentium toolchains (br-i386-pentium-mmx-musl, br-i386-pentium4-full) which fail to compile because as is run without --32.

---
 testcases/kernel/kvm/Makefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/kvm/Makefile +5 -2
index adab56952..8d5193d8e 100644
@@ -17,11 +17,14 @@ FILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86
 ifeq ($(HOST_CPU),x86_64)
 	ifneq (,$(findstring m32,$(CFLAGS)))
 		HOST_CPU = x86
-		GUEST_CFLAGS += -m32
-		ASFLAGS += --32
 	endif
 endif
 
+ifeq ($(HOST_CPU),x86)
+	GUEST_CFLAGS += -m32
+	ASFLAGS += --32
+endif
+
 # Some distros enable -pie by default. That breaks KVM payload linking.
 ifdef LTP_CFLAGS_NOPIE
 	GUEST_CFLAGS += -fno-pie
Signature · 5 lines
2.36.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/2
#2 lore raw

Re: [LTP] [PATCH 1/2] kvm: Fix compilation on x86

Hi!

Quoted 2 lines

Buildroot supports i386 pentium toolchains (br-i386-pentium-mmx-musl, br-i386-pentium4-full) which fail to compile because as is run without --32.

So we have a 32bit compiler but 64bit linker?

I guess that passing -m32 to 32bit compiler is harmless, so this can go in.

Quoted 30 lines
---
 testcases/kernel/kvm/Makefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/kvm/Makefile +5 -2
index adab56952..8d5193d8e 100644
@@ -17,11 +17,14 @@ FILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86
 ifeq ($(HOST_CPU),x86_64)
 	ifneq (,$(findstring m32,$(CFLAGS)))
 		HOST_CPU = x86
-		GUEST_CFLAGS += -m32
-		ASFLAGS += --32
 	endif
 endif
 
+ifeq ($(HOST_CPU),x86)
+	GUEST_CFLAGS += -m32
+	ASFLAGS += --32
+endif
+
 # Some distros enable -pie by default. That breaks KVM payload linking.
 ifdef LTP_CFLAGS_NOPIE
 	GUEST_CFLAGS += -fno-pie
Signature · 1 line
2.36.1
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#3 lore raw

PATCH 2/2 kvm: Fix undefined reference to __stack_chk_fail()

In reply to Petr Vorel

Some x86_64 buildroot toolchains (bootlin-x86-64-glibc, bootlin-x86-64-musl) try to link to __stack_chk_fail(). -nostdlib is not enough, it requires also -fstack-protector.

x86_64-buildroot-linux-gnu/bin/ld: /tmp/ccgBXEoR.o: in function `handle_page_fault':
kvm_pagefault01.c:(.text+0x5d): undefined reference to `__stack_chk_fail'
collect2: error: ld returned 1 exit status

---
 testcases/kernel/kvm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/kvm/Makefile +1 -1
index 8d5193d8e..bce1a4eb5 100644
@@ -9,7 +9,7 @@ ASFLAGS =
 CPPFLAGS += -I$(abs_srcdir)/include
 GUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
 GUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse
-GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none
+GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fstack-protector
 GUEST_LDLIBS =
 
 FILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86
Signature · 6 lines
2.36.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

Re: [LTP] [PATCH 2/2] kvm: Fix undefined reference to __stack_chk_fail()

Hi!

Quoted 7 lines

Some x86_64 buildroot toolchains (bootlin-x86-64-glibc, bootlin-x86-64-musl) try to link to __stack_chk_fail(). -nostdlib is not enough, it requires also -fstack-protector.

x86_64-buildroot-linux-gnu/bin/ld: /tmp/ccgBXEoR.o: in function `handle_page_fault':
kvm_pagefault01.c:(.text+0x5d): undefined reference to `__stack_chk_fail'
collect2: error: ld returned 1 exit status

I'm still puzzled on why does it try to link it. Why is stack protection turned on for the code. Does buildroot pass -fstack-protector to the CFLAGS?

I guess that -nostdlib causes the libssp (which implements __stack_chk_fail() not to be linked by default, but the __stack_chk_fail() shouldn't be called unless unless the feature is enabled in the first place.

Also does -fno-stack-protector passed in GUEST_CFLAGS make it disappear?

Quoted 21 lines
---
 testcases/kernel/kvm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/kvm/Makefile +1 -1
index 8d5193d8e..bce1a4eb5 100644
@@ -9,7 +9,7 @@ ASFLAGS =
 CPPFLAGS += -I$(abs_srcdir)/include
 GUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
 GUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse
-GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none
+GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fstack-protector
 GUEST_LDLIBS =
 
 FILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86
Signature · 1 line
2.36.1
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH 2/2] kvm: Fix undefined reference to __stack_chk_fail()

In reply to Petr Vorel
Quoted 18 lines · Petr Vorel

Some x86_64 buildroot toolchains (bootlin-x86-64-glibc, bootlin-x86-64-musl) try to link to __stack_chk_fail(). -nostdlib is not enough, it requires also -fstack-protector.

x86_64-buildroot-linux-gnu/bin/ld: /tmp/ccgBXEoR.o: in function `handle_page_fault':
kvm_pagefault01.c:(.text+0x5d): undefined reference to `__stack_chk_fail'
collect2: error: ld returned 1 exit status

---
 testcases/kernel/kvm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/kvm/Makefile +0 -0
index 8d5193d8e..bce1a4eb5 100644

testcases/kernel/kvm/Makefile ASFLAGS = · line 12

Quoted 5 lines
testcases/kernel/kvm/Makefile +1 -1
@@ -9,7 +9,7 @@ ASFLAGS =
 CPPFLAGS += -I$(abs_srcdir)/include
 GUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
 GUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse
-GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none
+GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fstack-protector

We should use -fno-stack-protector here instead. Your patch probably enables linking of libssp despite -nostdlib which we don't want. The GCC stack protector may also break tests because bootstrap initializes stack manually instead of letting GCC handle it.

Quoted 3 lines
testcases/kernel/kvm/Makefile +0 -0
 GUEST_LDLIBS =
 
 FILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86
Signature · 10 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [Buildroot] [PATCH 2/2] kvm: Fix undefined reference to __stack_chk_fail()

Quoted 7 lines · On Thu, 9 Jun 2022 10:26:55 +0200 Martin Doucha <[email protected]> wrote:
Quoted 7 lines
testcases/kernel/kvm/Makefile +0 -0
index 8d5193d8e..bce1a4eb5 100644
@@ -9,7 +9,7 @@ ASFLAGS =
 CPPFLAGS += -I$(abs_srcdir)/include
 GUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
Quoted 8 lines

testcases/kernel/kvm/Makefile ASFLAGS = · line 12

Quoted 3 lines
testcases/kernel/kvm/Makefile +1 -1
 GUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse
-GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none
+GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fstack-protector  

We should use -fno-stack-protector here instead. Your patch probably enables linking of libssp despite -nostdlib which we don't want. The GCC stack protector may also break tests because bootstrap initializes stack manually instead of letting GCC handle it.

I agree. Assuming -nostdlib means you're building freestanding code, then indeed, -fno-stack-protector is most likely what you want.

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#7 lore raw

Re: [LTP] [PATCH 2/2] kvm: Fix undefined reference to __stack_chk_fail()

In reply to Martin Doucha

Hi,

Am 6/9/2022 um 10:26 AM schrieb Martin Doucha:

Quoted 14 lines · Petr Vorel
Quoted 13 lines

Some x86_64 buildroot toolchains (bootlin-x86-64-glibc, bootlin-x86-64-musl) try to link to __stack_chk_fail(). -nostdlib is not enough, it requires also -fstack-protector.

x86_64-buildroot-linux-gnu/bin/ld: /tmp/ccgBXEoR.o: in function `handle_page_fault':
kvm_pagefault01.c:(.text+0x5d): undefined reference to `__stack_chk_fail'
collect2: error: ld returned 1 exit status

---
 testcases/kernel/kvm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

testcases/kernel/kvm/Makefile ASFLAGS = · line 12

Quoted 10 lines
testcases/kernel/kvm/Makefile +1 -1
index 8d5193d8e..bce1a4eb5 100644
@@ -9,7 +9,7 @@ ASFLAGS =
 CPPFLAGS += -I$(abs_srcdir)/include
 GUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
 GUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse
-GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none
+GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fstack-protector

We should use -fno-stack-protector here instead. Your patch probably enables linking of libssp despite -nostdlib which we don't want. The GCC stack protector may also break tests because bootstrap initializes stack manually instead of letting GCC handle it.

I can confirm, that adding -fno-stack-protector to GUEST_LDFLAGS fixes the linker error.

Quoted 6 lines

testcases/kernel/kvm/Makefile ASFLAGS = · line 15

Quoted 4 lines
testcases/kernel/kvm/Makefile +0 -0
 GUEST_LDLIBS =
 
 FILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86

Joerg

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#8 lore raw

Re: [Buildroot] [LTP] [PATCH 2/2] kvm: Fix undefined reference to __stack_chk_fail()

Hi all,

Quoted 33 lines

Hi,

Am 6/9/2022 um 10:26 AM schrieb Martin Doucha:

Quoted 14 lines · Petr Vorel
Quoted 12 lines

Some x86_64 buildroot toolchains (bootlin-x86-64-glibc, bootlin-x86-64-musl) try to link to __stack_chk_fail(). -nostdlib is not enough, it requires also -fstack-protector.

x86_64-buildroot-linux-gnu/bin/ld: /tmp/ccgBXEoR.o: in function `handle_page_fault':
kvm_pagefault01.c:(.text+0x5d): undefined reference to `__stack_chk_fail'
collect2: error: ld returned 1 exit status

---
 testcases/kernel/kvm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

testcases/kernel/kvm/Makefile ASFLAGS = · line 12

Quoted 10 lines
testcases/kernel/kvm/Makefile +1 -1
index 8d5193d8e..bce1a4eb5 100644
@@ -9,7 +9,7 @@ ASFLAGS =
 CPPFLAGS += -I$(abs_srcdir)/include
 GUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
 GUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse
-GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none
+GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fstack-protector

We should use -fno-stack-protector here instead. Your patch probably enables linking of libssp despite -nostdlib which we don't want. The GCC stack protector may also break tests because bootstrap initializes stack manually instead of letting GCC handle it.

Quoted 2 lines

I can confirm, that adding -fno-stack-protector to GUEST_LDFLAGS fixes the linker error.

Thanks a lot for your input. Martin, thanks a lot for testing.
I also verified that -fno-stack-protector fix compilation, thus patchset merged.

Kind regards,
Petr

Quoted 7 lines
Quoted 3 lines

testcases/kernel/kvm/Makefile ASFLAGS = · line 15

Quoted 3 lines
testcases/kernel/kvm/Makefile +0 -0
 GUEST_LDLIBS =
 
 FILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86

Joerg

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot