In file included from ../arch/powerpc/kernel/crash.c:25:
../arch/powerpc/include/asm/setjmp.h:10:13: error: declaration of built-in function 'setjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header <setjmp.h>. [-Werror,-Wincomplete-setjmp-declaration]
extern long setjmp(long *);
^
../arch/powerpc/include/asm/setjmp.h:11:13: error: declaration of built-in function 'longjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header <setjmp.h>. [-Werror,-Wincomplete-setjmp-declaration]
extern void longjmp(long *, long);
^
2 errors generated.
By default, this breaks the build for PowerPC because of -Werror but this won't hit CI right away because we need a clang uprev which hasn't happened for a bit from https://apt.llvm.org.
This is extremely similar to #59, the fix for which is actually mentioned in r367387. Should we just disable the warning like we did for #59, add the declaration, or report this as a regression in clang?
Adding the declaration results in another set of warnings:
diff --git a/arch/powerpc/include/asm/setjmp.h b/arch/powerpc/include/asm/setjmp.h
index d995061f5f86..498d58d71eb3 100644
--- a/arch/powerpc/include/asm/setjmp.h
+++ b/arch/powerpc/include/asm/setjmp.h
@@ -7,6 +7,8 @@
#define JMP_BUF_LEN 23
+typedef long jmp_buf;
+
extern long setjmp(long *);
extern void longjmp(long *, long);
In file included from /home/nathan/cbl/linux/arch/powerpc/kernel/crash.c:25:
/home/nathan/cbl/linux/arch/powerpc/include/asm/setjmp.h:12:13: warning: incompatible redeclaration of library function 'setjmp' [-Wincompatible-library-redeclaration]
extern long setjmp(long *);
^
/home/nathan/cbl/linux/arch/powerpc/include/asm/setjmp.h:12:13: note: 'setjmp' is a builtin with type 'int (jmp_buf)' (aka 'int (long)')
/home/nathan/cbl/linux/arch/powerpc/include/asm/setjmp.h:13:13: warning: incompatible redeclaration of library function 'longjmp' [-Wincompatible-library-redeclaration]
extern void longjmp(long *, long);
^
/home/nathan/cbl/linux/arch/powerpc/include/asm/setjmp.h:13:13: note: 'longjmp' is a builtin with type 'void (jmp_buf, int) __attribute__((noreturn))' (aka 'void (long, int) __attribute__((noreturn))')
2 warnings generated.
Maybe we want something like this?
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ea0c69236789..ae0983c11659 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -6,7 +6,7 @@
CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"'
# Disable clang warning for using setjmp without setjmp.h header
-CFLAGS_crash.o += $(call cc-disable-warning, builtin-requires-header)
+CFLAGS_crash.o += -ffreestanding
ifdef CONFIG_PPC64
CFLAGS_prom_init.o += $(NO_MINIMAL_TOC)
diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
index f142570ad860..5f389fd42103 100644
--- a/arch/powerpc/xmon/Makefile
+++ b/arch/powerpc/xmon/Makefile
@@ -2,7 +2,7 @@
# Makefile for xmon
# Disable clang warning for using setjmp without setjmp.h header
-subdir-ccflags-y := $(call cc-disable-warning, builtin-requires-header)
+subdir-ccflags-y := -ffreestanding
GCOV_PROFILE := n
KCOV_INSTRUMENT := n
cc @stephenhines since you commented on #59 and @shenki because you created #59.
Super conservative patch (it's probably okay for GCC too):
From 05ccc58137e71744e1c5b6aa054111215fac0996 Mon Sep 17 00:00:00 2001
From: Nathan Chancellor <[email protected]>
Date: Wed, 7 Aug 2019 13:11:48 -0700
Subject: [PATCH] powerpc: Avoid clang warnings around setjmp and longjmp
Commit aea447141c7e ("powerpc: Disable -Wbuiltin-requires-header when
setjmp is used") disabled -Wbuiltin-requires-header because of a warning
about the setjmp and longjmp declarations.
r367387 in clang added another diagnostic around this, complaining that
there is no jmp_buf declaration.
In file included from ../arch/powerpc/xmon/xmon.c:47:
../arch/powerpc/include/asm/setjmp.h:10:13: error: declaration of
built-in function 'setjmp' requires the declaration of the 'jmp_buf'
type, commonly provided in the header <setjmp.h>.
[-Werror,-Wincomplete-setjmp-declaration]
extern long setjmp(long *);
^
../arch/powerpc/include/asm/setjmp.h:11:13: error: declaration of
built-in function 'longjmp' requires the declaration of the 'jmp_buf'
type, commonly provided in the header <setjmp.h>.
[-Werror,-Wincomplete-setjmp-declaration]
extern void longjmp(long *, long);
^
2 errors generated.
To avoid all of this, tell clang that we are not using the built-in
longjmp and setjmp functions. This is a more conservative approach; a
more aggressive one might be -fno-builtin or -ffreestanding.
Link: https://github.com/ClangBuiltLinux/linux/issues/625
Link: https://github.com/llvm/llvm-project/commit/3be25e79477db2d31ac46493d97eca8c20592b07
Signed-off-by: Nathan Chancellor <[email protected]>
---
arch/powerpc/kernel/Makefile | 6 ++++--
arch/powerpc/xmon/Makefile | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index ea0c69236789..7c4488fad9ce 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -5,8 +5,10 @@
CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"'
-# Disable clang warning for using setjmp without setjmp.h header
-CFLAGS_crash.o += $(call cc-disable-warning, builtin-requires-header)
+# Avoid clang warnings about longjmp and setjmp built-ins (inclusion of setjmp.h and declaration of jmp_buf type)
+ifdef CONFIG_CC_IS_CLANG
+CFLAGS_crash.o += -fno-builtin-longjmp -fno-builtin-setjmp
+endif
ifdef CONFIG_PPC64
CFLAGS_prom_init.o += $(NO_MINIMAL_TOC)
diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
index f142570ad860..18fd737eca28 100644
--- a/arch/powerpc/xmon/Makefile
+++ b/arch/powerpc/xmon/Makefile
@@ -1,8 +1,10 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for xmon
-# Disable clang warning for using setjmp without setjmp.h header
-subdir-ccflags-y := $(call cc-disable-warning, builtin-requires-header)
+# Avoid clang warnings about longjmp and setjmp built-ins (inclusion of setjmp.h and declaration of jmp_buf type)
+ifdef CONFIG_CC_IS_CLANG
+subdir-ccflags-y := -fno-builtin-longjmp -fno-builtin-setjmp
+endif
GCOV_PROFILE := n
KCOV_INSTRUMENT := n
--
2.23.0.rc1
I agree let's disable in the kernel, but I'd disable the warnings via cc-disable-warning, that way they're not compiler specific (should GCC or any other compiler choose to implement -Wincompatible-library-redeclaration.
The root cause of the warning is clang trying to use built-in longjmp/setjmp, no? Wouldn鈥檛 it be wiser to let clang know that isn鈥檛 the case so that warnings of these variety don鈥檛 continue to crop up?
I鈥檓 fine with changing it but I don鈥檛 want to have to continue to play wack-a-mole with warnings :)
clang trying to use built-in longjmp/setjmp, no?
Dunno, does Clang emit some sort of builtin for these calls? What does that even mean to do a setjmp/longjmp in the kernel?
Dunno, does Clang emit some sort of builtin for these calls?
Not sure how to test if it actually emits them or not (the kernel defined ones are written in assembly in arch/powerpc/kernel/misc.S) but the builtins are defined in clang/include/clang/Basic/Builtins.def.
What does that even mean to do a setjmp/longjmp in the kernel?
Not sure, they are used quite a bit in arch/powerpc/xmon.
rg results
$ rg -n "setjmp|longjmp" arch/powerpc
arch/powerpc/kernel/crash.c:25:#include <asm/setjmp.h>
arch/powerpc/kernel/crash.c:63: longjmp(crash_shutdown_buf, 1);
arch/powerpc/kernel/crash.c:149: * The primary CPU returns here via setjmp, and the secondary
arch/powerpc/kernel/crash.c:156: if (setjmp(crash_shutdown_buf) == 0) {
arch/powerpc/kernel/crash.c:357: if (setjmp(crash_shutdown_buf) == 0) {
arch/powerpc/xmon/Makefile:4:# Disable clang warning for using setjmp without setjmp.h header
arch/powerpc/xmon/xmon.c:47:#include <asm/setjmp.h>
arch/powerpc/xmon/xmon.c:489: longjmp(bus_error_jmp, 1);
arch/powerpc/xmon/xmon.c:496: longjmp(xmon_fault_jmp[cpu], 1);
arch/powerpc/xmon/xmon.c:499: if (setjmp(recurse_jmp) != 0) {
arch/powerpc/xmon/xmon.c:621: longjmp(xmon_fault_jmp[0], 1);
arch/powerpc/xmon/xmon.c:623: if (setjmp(recurse_jmp) == 0) {
arch/powerpc/xmon/xmon.c:928: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:1498: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:1682: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:1748: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:1775: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:1798: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:2000: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:2043: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:2094: longjmp(bus_error_jmp, 1);
arch/powerpc/xmon/xmon.c:2369: if (setjmp(bus_error_jmp) != 0) {
arch/powerpc/xmon/xmon.c:2545: if (setjmp(bus_error_jmp) != 0) {
arch/powerpc/xmon/xmon.c:2830: if (setjmp(bus_error_jmp) != 0) {
arch/powerpc/xmon/xmon.c:2864: if (setjmp(bus_error_jmp) != 0) {
arch/powerpc/xmon/xmon.c:3073: if (setjmp(bus_error_jmp) != 0) {
arch/powerpc/xmon/xmon.c:3159: if (setjmp(bus_error_jmp) != 0) {
arch/powerpc/xmon/xmon.c:3202: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:3306: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:3420: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:3435: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:3474: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:3898: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:3944: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/xmon/xmon.c:3968: if (setjmp(bus_error_jmp) == 0) { \
arch/powerpc/xmon/xmon.c:4032: if (setjmp(bus_error_jmp) == 0) {
arch/powerpc/kernel/misc.S:11: * setjmp/longjmp code by Paul Mackerras.
arch/powerpc/kernel/misc.S:43:_GLOBAL(setjmp)
arch/powerpc/kernel/misc.S:77:_GLOBAL(longjmp)
arch/powerpc/kernel/Makefile:8:# Disable clang warning for using setjmp without setjmp.h header
arch/powerpc/include/asm/setjmp.h:10:extern long setjmp(long *);
arch/powerpc/include/asm/setjmp.h:11:extern void longjmp(long *, long);
More conservative patch sent first: https://lore.kernel.org/lkml/[email protected]/
Merged into mainline: https://git.kernel.org/linus/c9029ef9c95765e7b63c4d9aa780674447db1ec0