From 12a85049d66ffc1da541145a8f93e8ca1570878c Mon Sep 17 00:00:00 2001 From: szubersk Date: Sat, 12 Nov 2022 21:59:12 +1000 Subject: [PATCH] Fix Clang compilation errors on Ubuntu 22.10 - Clang 15 doesn't support `-fno-ipa-sra` anymore. Do a separate check for `-fno-ipa-sra` support by $KERNEL_CC. - Don't enable `-mgeneral-regs-only` for certain module files. Fix #13260 - Scope `GCC diagnostic ignored` statements to GCC only. Clang doesn't need them to compile the code. Signed-off-by: szubersk (cherry picked from commit 8dbeb67fda74b5127bca0badf1e1183353119edf) --- config/always-compiler-options.m4 | 31 +++++++++++++++++++++ config/zfs-build.m4 | 3 +- module/Kbuild.in | 6 ++++ module/icp/algs/blake3/blake3.c | 2 +- module/icp/algs/edonr/edonr.c | 4 ++- module/icp/algs/skein/skein_block.c | 2 ++ module/lua/ldo.c | 3 +- module/os/linux/spl/spl-generic.c | 4 +++ module/zfs/vdev_raidz_math_aarch64_neonx2.c | 4 +++ 9 files changed, 55 insertions(+), 4 deletions(-) diff --git a/config/always-compiler-options.m4 b/config/always-compiler-options.m4 index 1e7ec3db9f63..6383b12506ee 100644 --- a/config/always-compiler-options.m4 +++ b/config/always-compiler-options.m4 @@ -324,3 +324,34 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA], [ CFLAGS="$saved_flags" AC_SUBST([NO_IPA_SRA]) ]) + +dnl # +dnl # Check if kernel cc supports -fno-ipa-sra option. +dnl # +AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA], [ + AC_MSG_CHECKING([whether $KERNEL_CC supports -fno-ipa-sra]) + + saved_cc="$CC" + saved_flags="$CFLAGS" + CC="gcc" + CFLAGS="$CFLAGS -Werror -fno-ipa-sra" + + AS_IF([ test -n "$KERNEL_CC" ], [ + CC="$KERNEL_CC" + ]) + AS_IF([ test -n "$KERNEL_LLVM" ], [ + CC="clang" + ]) + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [ + KERNEL_NO_IPA_SRA=-fno-ipa-sra + AC_MSG_RESULT([yes]) + ], [ + KERNEL_NO_IPA_SRA= + AC_MSG_RESULT([no]) + ]) + + CC="$saved_cc" + CFLAGS="$saved_flags" + AC_SUBST([KERNEL_NO_IPA_SRA]) +]) diff --git a/config/zfs-build.m4 b/config/zfs-build.m4 index bb10bec04017..6355952487f7 100644 --- a/config/zfs-build.m4 +++ b/config/zfs-build.m4 @@ -81,7 +81,7 @@ AC_DEFUN([ZFS_AC_DEBUG], [ AC_DEFUN([ZFS_AC_DEBUGINFO_ENABLE], [ DEBUG_CFLAGS="$DEBUG_CFLAGS -g -fno-inline $NO_IPA_SRA" - KERNEL_DEBUG_CFLAGS="$KERNEL_DEBUG_CFLAGS -fno-inline $NO_IPA_SRA" + KERNEL_DEBUG_CFLAGS="$KERNEL_DEBUG_CFLAGS -fno-inline $KERNEL_NO_IPA_SRA" KERNEL_MAKE="$KERNEL_MAKE CONFIG_DEBUG_INFO=y" DEBUGINFO_ZFS="_with_debuginfo" @@ -219,6 +219,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [ ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA + ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA ZFS_AC_CONFIG_ALWAYS_CC_ASAN ZFS_AC_CONFIG_ALWAYS_CC_UBSAN ZFS_AC_CONFIG_ALWAYS_TOOLCHAIN_SIMD diff --git a/module/Kbuild.in b/module/Kbuild.in index 581d50e64b42..a39f9d9d0500 100644 --- a/module/Kbuild.in +++ b/module/Kbuild.in @@ -42,6 +42,12 @@ endif asflags-y := $(ZFS_MODULE_CFLAGS) $(ZFS_MODULE_CPPFLAGS) ccflags-y := $(ZFS_MODULE_CFLAGS) $(ZFS_MODULE_CPPFLAGS) +ifeq ($(CONFIG_ARM64),y) +CFLAGS_REMOVE_zcommon/zfs_fletcher_aarch64_neon.o += -mgeneral-regs-only +CFLAGS_REMOVE_zfs/vdev_raidz_math_aarch64_neon.o += -mgeneral-regs-only +CFLAGS_REMOVE_zfs/vdev_raidz_math_aarch64_neonx2.o += -mgeneral-regs-only +endif + # Suppress unused-value warnings in sparc64 architecture headers ccflags-$(CONFIG_SPARC64) += -Wno-unused-value diff --git a/module/icp/algs/blake3/blake3.c b/module/icp/algs/blake3/blake3.c index 8e441f454a72..7c7a48754a25 100644 --- a/module/icp/algs/blake3/blake3.c +++ b/module/icp/algs/blake3/blake3.c @@ -34,7 +34,7 @@ * We need 1056 byte stack for blake3_compress_subtree_wide() * - we define this pragma to make gcc happy */ -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic ignored "-Wframe-larger-than=" #endif diff --git a/module/icp/algs/edonr/edonr.c b/module/icp/algs/edonr/edonr.c index 345133d7433a..b1f710cc0439 100644 --- a/module/icp/algs/edonr/edonr.c +++ b/module/icp/algs/edonr/edonr.c @@ -346,9 +346,11 @@ Q256(size_t bitlen, const uint32_t *data, uint32_t *restrict p) * which only goes over it by a hair (1248 bytes on ARM32). */ #include /* for _ILP32 */ -#ifdef _ILP32 /* We're 32-bit, assume small stack frames */ +#if defined(_ILP32) /* We're 32-bit, assume small stack frames */ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic ignored "-Wframe-larger-than=" #endif +#endif #if defined(__IBMC__) && defined(_AIX) && defined(__64BIT__) static inline size_t diff --git a/module/icp/algs/skein/skein_block.c b/module/icp/algs/skein/skein_block.c index 7ba165a48511..3ad52da5f6a3 100644 --- a/module/icp/algs/skein/skein_block.c +++ b/module/icp/algs/skein/skein_block.c @@ -30,7 +30,9 @@ * the #pragma here to ignore the warning. */ #if defined(_ILP32) || defined(__powerpc) /* Assume small stack */ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic ignored "-Wframe-larger-than=" +#endif /* * We're running on 32-bit, don't unroll loops to save stack frame space * diff --git a/module/lua/ldo.c b/module/lua/ldo.c index e2a3d0279d7f..291bca044e7b 100644 --- a/module/lua/ldo.c +++ b/module/lua/ldo.c @@ -197,7 +197,8 @@ l_noret luaD_throw (lua_State *L, int errcode) { } } -#if defined(HAVE_INFINITE_RECURSION) +#if defined(__GNUC__) && !defined(__clang__) && \ + defined(HAVE_INFINITE_RECURSION) #pragma GCC diagnostic pop #endif diff --git a/module/os/linux/spl/spl-generic.c b/module/os/linux/spl/spl-generic.c index 71eedf635f73..38515023e4b8 100644 --- a/module/os/linux/spl/spl-generic.c +++ b/module/os/linux/spl/spl-generic.c @@ -254,8 +254,10 @@ __div_u64(uint64_t u, uint32_t v) * replacements for libgcc-provided functions and will never be called * directly. */ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-prototypes" +#endif /* * Implementation of 64-bit unsigned division for 32-bit machines. @@ -449,7 +451,9 @@ __aeabi_ldivmod(int64_t u, int64_t v) EXPORT_SYMBOL(__aeabi_ldivmod); #endif /* __arm || __arm__ */ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop +#endif #endif /* BITS_PER_LONG */ diff --git a/module/zfs/vdev_raidz_math_aarch64_neonx2.c b/module/zfs/vdev_raidz_math_aarch64_neonx2.c index 0a1f05fd6664..bd9de91a4ba8 100644 --- a/module/zfs/vdev_raidz_math_aarch64_neonx2.c +++ b/module/zfs/vdev_raidz_math_aarch64_neonx2.c @@ -210,9 +210,13 @@ DEFINE_GEN_METHODS(aarch64_neonx2); * If compiled with -O0, gcc doesn't do any stack frame coalescing * and -Wframe-larger-than=1024 is triggered in debug mode. */ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic ignored "-Wframe-larger-than=" +#endif DEFINE_REC_METHODS(aarch64_neonx2); +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop +#endif static boolean_t raidz_will_aarch64_neonx2_work(void)