tools/nolibc: always disable stack protector for tests
authorThomas Weißschuh <linux@weissschuh.net>
Sun, 19 Mar 2023 13:51:00 +0000 (14:51 +0100)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 20 Mar 2023 15:44:02 +0000 (08:44 -0700)
Stack protectors need support from libc.
This support is not provided by nolibc which leads to compiler errors
when stack protectors are enabled by default in a compiler:

      CC      nolibc-test
    /usr/bin/ld: /tmp/ccqbHEPk.o: in function `stat':
    nolibc-test.c:(.text+0x1d1): undefined reference to `__stack_chk_fail'
    /usr/bin/ld: /tmp/ccqbHEPk.o: in function `poll.constprop.0':
    nolibc-test.c:(.text+0x37b): undefined reference to `__stack_chk_fail'
    /usr/bin/ld: /tmp/ccqbHEPk.o: in function `vfprintf.constprop.0':
    nolibc-test.c:(.text+0x712): undefined reference to `__stack_chk_fail'
    /usr/bin/ld: /tmp/ccqbHEPk.o: in function `pad_spc.constprop.0':
    nolibc-test.c:(.text+0x80d): undefined reference to `__stack_chk_fail'
    /usr/bin/ld: /tmp/ccqbHEPk.o: in function `printf':
    nolibc-test.c:(.text+0x8c4): undefined reference to `__stack_chk_fail'
    /usr/bin/ld: /tmp/ccqbHEPk.o:nolibc-test.c:(.text+0x12d4): more undefined references to `__stack_chk_fail' follow
    collect2: error: ld returned 1 exit status

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/testing/selftests/nolibc/Makefile

index 8fe61d3e3cce0a8f4beda0640f05f49ffc5eb721..874d141da8c4cf2aba20eff04e5814a9bb12988a 100644 (file)
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for nolibc tests
 include ../../../scripts/Makefile.include
+# We need this for the "cc-option" macro.
+include ../../../build/Build.include
 
 # we're in ".../tools/testing/selftests/nolibc"
 ifeq ($(srctree),)
@@ -72,6 +74,7 @@ endif
 
 CFLAGS_s390 = -m64
 CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables $(CFLAGS_$(ARCH))
+CFLAGS  += $(call cc-option,-fno-stack-protector)
 LDFLAGS := -s
 
 help: