Skip to contentSkip to conversation

kstack_erase: Add -mgeneral-regs-only to silence Clang warnings

PATCH In review Kees Cook 2 participants 2 messages Jul 26, 2025 – Jul 27, 2025

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 kstack_erase: Add -mgeneral-regs-only to silence Clang warnings

Once CONFIG_KSTACK_ERASE is enabled with Clang on i386, the build warns:

kernel/kstack_erase.c:168:2: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]

Add -mgeneral-regs-only for the kstack_erase handler, to make Clang feel better (it is effectively a no-op flag for the kernel). No binary changes encountered.

Build & boot tested with Clang 21 on x86_64, and i386. Build tested with GCC 14.2.0 on x86_64, i386, arm64, and arm.

---
 kernel/Makefile | 1 +
 1 file changed, 1 insertion(+)
kernel/Makefile +1 -0
index e4f01f1d4d0c..0ee9afd8b7cf 100644
@@ -140,6 +140,7 @@ obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o
 obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
 
 CFLAGS_kstack_erase.o += $(DISABLE_KSTACK_ERASE)
+CFLAGS_kstack_erase.o += $(call cc-option,-mgeneral-regs-only)
 obj-$(CONFIG_KSTACK_ERASE) += kstack_erase.o
 KASAN_SANITIZE_kstack_erase.o := n
 KCSAN_SANITIZE_kstack_erase.o := n
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Kees Cook

Once CONFIG_KSTACK_ERASE is enabled with Clang on i386, the build warns:

kernel/kstack_erase.c:168:2: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]

Add -mgeneral-regs-only for the kstack_erase handler, to make Clang feel better (it is effectively a no-op flag for the kernel). No binary changes encountered.

Quoted 6 lines

Build & boot tested with Clang 21 on x86_64, and i386. Build tested with GCC 14.2.0 on x86_64, i386, arm64, and arm.

Quoted 19 lines
---
 kernel/Makefile | 1 +
 1 file changed, 1 insertion(+)
kernel/Makefile +1 -0
index e4f01f1d4d0c..0ee9afd8b7cf 100644
@@ -140,6 +140,7 @@ obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o
 obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
 
 CFLAGS_kstack_erase.o += $(DISABLE_KSTACK_ERASE)
+CFLAGS_kstack_erase.o += $(call cc-option,-mgeneral-regs-only)
 obj-$(CONFIG_KSTACK_ERASE) += kstack_erase.o
 KASAN_SANITIZE_kstack_erase.o := n
 KCSAN_SANITIZE_kstack_erase.o := n
Signature · 1 line
2.34.1