[PATCH] tools/nolibc: always disable stack protector for tests
From: Thomas Weißschuh
Date: Tue Feb 21 2023 - 12:51:03 EST
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@xxxxxxxxxxxxxx>
---
tools/testing/selftests/nolibc/Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index 22f1e1d73fa8..ec724e445b5a 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -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),)
@@ -63,6 +65,7 @@ Q=@
endif
CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables
+CFLAGS += $(call cc-option,-fno-stack-protector)
LDFLAGS := -s
help:
---
base-commit: 3f0b0903fde584a7398f82fc00bf4f8138610b87
change-id: 20230221-nolibc-no-stack-protector-5b54d2be4c61
Best regards,
--
Thomas Weißschuh <linux@xxxxxxxxxxxxxx>