]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix GCC 12 compilation errors
authorszubersk <szuberskidamian@gmail.com>
Wed, 30 Nov 2022 10:27:28 +0000 (20:27 +1000)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 30 Nov 2022 21:45:53 +0000 (13:45 -0800)
Squelch false positives reported by GCC 12 with UBSan.

Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: szubersk <szuberskidamian@gmail.com>
Closes #14150

cmd/zfs/zfs_main.c
cmd/zpool/zpool_main.c
config/always-compiler-options.m4
config/zfs-build.m4
lib/libnvpair/libnvpair.c
lib/libzfs/libzfs_sendrecv.c
module/icp/algs/blake3/blake3.c
module/lua/ldo.c
module/os/linux/zfs/zio_crypt.c

index 2d644c5de16ba96f8b65cb10ed01a50bd5d08345..03640a4cdced0d2eadd867d724ef6670429d80bd 100644 (file)
@@ -548,7 +548,7 @@ usage(boolean_t requested)
                show_properties = B_TRUE;
 
        if (show_properties) {
-               (void) fprintf(fp,
+               (void) fprintf(fp, "%s",
                    gettext("\nThe following properties are supported:\n"));
 
                (void) fprintf(fp, "\n\t%-14s %s  %s   %s\n\n",
index 8a4f3dd162711c6b8437d1f5262fab1795b03c80..0b55bf21f448d7f73a9519b65bce7ab5e253b3ee 100644 (file)
@@ -548,7 +548,7 @@ usage(boolean_t requested)
            (strcmp(current_command->name, "get") == 0) ||
            (strcmp(current_command->name, "list") == 0))) {
 
-               (void) fprintf(fp,
+               (void) fprintf(fp, "%s",
                    gettext("\nthe following properties are supported:\n"));
 
                (void) fprintf(fp, "\n\t%-19s  %s   %s\n\n",
index a67319691523d1f973d54002a40b2d931bc2607d..1e7ec3db9f631fda61f3bde550bedf015c0b0a10 100644 (file)
@@ -227,6 +227,62 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_INFINITE_RECURSION], [
        AC_SUBST([INFINITE_RECURSION])
 ])
 
+dnl #
+dnl # Check if kernel cc supports -Winfinite-recursion option.
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_INFINITE_RECURSION], [
+       AC_MSG_CHECKING([whether $KERNEL_CC supports -Winfinite-recursion])
+
+       saved_cc="$CC"
+       saved_flags="$CFLAGS"
+       CC="gcc"
+       CFLAGS="$CFLAGS -Werror -Winfinite-recursion"
+
+       AS_IF([ test -n "$KERNEL_CC" ], [
+               CC="$KERNEL_CC"
+       ])
+       AS_IF([ test -n "$KERNEL_LLVM" ], [
+               CC="clang"
+       ])
+
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
+               KERNEL_INFINITE_RECURSION=-Winfinite-recursion
+               AC_DEFINE([HAVE_KERNEL_INFINITE_RECURSION], 1,
+                       [Define if compiler supports -Winfinite-recursion])
+               AC_MSG_RESULT([yes])
+       ], [
+               KERNEL_INFINITE_RECURSION=
+               AC_MSG_RESULT([no])
+       ])
+
+       CC="$saved_cc"
+       CFLAGS="$saved_flags"
+       AC_SUBST([KERNEL_INFINITE_RECURSION])
+])
+
+dnl #
+dnl # Check if cc supports -Wformat-overflow option.
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW], [
+       AC_MSG_CHECKING([whether $CC supports -Wformat-overflow])
+
+       saved_flags="$CFLAGS"
+       CFLAGS="$CFLAGS -Werror -Wformat-overflow"
+
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
+               FORMAT_OVERFLOW=-Wformat-overflow
+               AC_DEFINE([HAVE_FORMAT_OVERFLOW], 1,
+                       [Define if compiler supports -Wformat-overflow])
+               AC_MSG_RESULT([yes])
+       ], [
+               FORMAT_OVERFLOW=
+               AC_MSG_RESULT([no])
+       ])
+
+       CFLAGS="$saved_flags"
+       AC_SUBST([FORMAT_OVERFLOW])
+])
+
 dnl #
 dnl # Check if cc supports -fno-omit-frame-pointer option.
 dnl #
index d14a6bb7ac9fd6fe653194b32a30e3ff9aaec41c..bb10bec0401773837399446e8ddf9d3db491d39b 100644 (file)
@@ -211,10 +211,12 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
 
        ZFS_AC_CONFIG_ALWAYS_CC_NO_CLOBBERED
        ZFS_AC_CONFIG_ALWAYS_CC_INFINITE_RECURSION
+       ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_INFINITE_RECURSION
        ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH
        ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN
        ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION
        ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH
+       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_CC_ASAN
index 48423226743a7fd3d74121a2be1505fd8a2efc61..a75e7316739f06a60dba35e9f9982972b6033ce8 100644 (file)
@@ -199,6 +199,17 @@ nvprint_##type_and_variant(nvlist_prtctl_t pctl, void *private, \
        return (1); \
 }
 
+/*
+ * Workaround for GCC 12+ with UBSan enabled deficencies.
+ *
+ * GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code
+ * below as violating -Wformat-overflow.
+ */
+#if defined(__GNUC__) && !defined(__clang__) && \
+       defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-overflow"
+#endif
 NVLIST_PRTFUNC(boolean, int, int, "%d")
 NVLIST_PRTFUNC(boolean_value, boolean_t, int, "%d")
 NVLIST_PRTFUNC(byte, uchar_t, uchar_t, "0x%2.2x")
@@ -213,6 +224,10 @@ NVLIST_PRTFUNC(uint64, uint64_t, u_longlong_t, "0x%llx")
 NVLIST_PRTFUNC(double, double, double, "0x%f")
 NVLIST_PRTFUNC(string, char *, char *, "%s")
 NVLIST_PRTFUNC(hrtime, hrtime_t, hrtime_t, "0x%llx")
+#if defined(__GNUC__) && !defined(__clang__) && \
+       defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
+#pragma GCC diagnostic pop
+#endif
 
 /*
  * Generate functions to print array-valued nvlist members.
index 3e9f637774248b05f478da5850498cfd885b4d23..b53acdcea73e1ca85e16978bdf5e9ad1877bde18 100644 (file)
@@ -1007,8 +1007,23 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap,
                        (void) fprintf(fout, dgettext(TEXT_DOMAIN,
                            "incremental\t%s\t%s"), fromsnap, tosnap);
                } else {
+/*
+ * Workaround for GCC 12+ with UBSan enabled deficencies.
+ *
+ * GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code
+ * below as violating -Wformat-overflow.
+ */
+#if defined(__GNUC__) && !defined(__clang__) && \
+       defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-overflow"
+#endif
                        (void) fprintf(fout, dgettext(TEXT_DOMAIN,
                            "full\t%s"), tosnap);
+#if defined(__GNUC__) && !defined(__clang__) && \
+       defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
+#pragma GCC diagnostic pop
+#endif
                }
                (void) fprintf(fout, "\t%llu", (longlong_t)size);
        } else {
@@ -1028,8 +1043,23 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap,
                if (size != 0) {
                        char buf[16];
                        zfs_nicebytes(size, buf, sizeof (buf));
+/*
+ * Workaround for GCC 12+ with UBSan enabled deficencies.
+ *
+ * GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code
+ * below as violating -Wformat-overflow.
+ */
+#if defined(__GNUC__) && !defined(__clang__) && \
+       defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-overflow"
+#endif
                        (void) fprintf(fout, dgettext(TEXT_DOMAIN,
                            " estimated size is %s"), buf);
+#if defined(__GNUC__) && !defined(__clang__) && \
+       defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
+#pragma GCC diagnostic pop
+#endif
                }
        }
        (void) fprintf(fout, "\n");
index 604e05847ee6cb983f6397196a742a875250688a..8e441f454a725bc1cf829e69e76bbe2c30230618 100644 (file)
@@ -276,7 +276,7 @@ static size_t compress_parents_parallel(const blake3_ops_t *ops,
     const uint8_t *child_chaining_values, size_t num_chaining_values,
     const uint32_t key[8], uint8_t flags, uint8_t *out)
 {
-       const uint8_t *parents_array[MAX_SIMD_DEGREE_OR_2];
+       const uint8_t *parents_array[MAX_SIMD_DEGREE_OR_2] = {0};
        size_t parents_array_len = 0;
 
        while (num_chaining_values - (2 * parents_array_len) >= 2) {
index 6bef80514ce2b8f13e979104c4d7a3f0bec3cf4c..e2a3d0279d7fb41688355a909e5b0fe45edf64f0 100644 (file)
@@ -170,7 +170,8 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
 /*
  * Silence infinite recursion warning which was added to -Wall in gcc 12.1
  */
-#if defined(HAVE_INFINITE_RECURSION)
+#if defined(__GNUC__) && !defined(__clang__) && \
+       defined(HAVE_KERNEL_INFINITE_RECURSION)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Winfinite-recursion"
 #endif
index 6f2bf7ed75699c1b7760256ab51383f5660f1aba..a9043ae4dc7d6364e295b1369230baa0688f097d 100644 (file)
@@ -229,7 +229,24 @@ zio_crypt_key_init(uint64_t crypt, zio_crypt_key_t *key)
        ASSERT(key != NULL);
        ASSERT3U(crypt, <, ZIO_CRYPT_FUNCTIONS);
 
+/*
+ * Workaround for GCC 12+ with UBSan enabled deficencies.
+ *
+ * GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code
+ * below as violating -Warray-bounds
+ */
+#if defined(__GNUC__) && !defined(__clang__) && \
+       ((!defined(_KERNEL) && defined(ZFS_UBSAN_ENABLED)) || \
+           defined(CONFIG_UBSAN))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
        keydata_len = zio_crypt_table[crypt].ci_keylen;
+#if defined(__GNUC__) && !defined(__clang__) && \
+       ((!defined(_KERNEL) && defined(ZFS_UBSAN_ENABLED)) || \
+           defined(CONFIG_UBSAN))
+#pragma GCC diagnostic pop
+#endif
        memset(key, 0, sizeof (zio_crypt_key_t));
        rw_init(&key->zk_salt_lock, NULL, RW_DEFAULT, NULL);