Skip to content

Commit a4f51d3

Browse files
szuberskandrewc12
authored andcommitted
Fix GCC 12 compilation errors
Squelch false positives reported by GCC 12 with UBSan. Reviewed-by: Richard Yao <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: szubersk <[email protected]> Closes openzfs#14150
1 parent cbbd203 commit a4f51d3

File tree

9 files changed

+125
-4
lines changed

9 files changed

+125
-4
lines changed

cmd/zfs/zfs_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ usage(boolean_t requested)
548548
show_properties = B_TRUE;
549549

550550
if (show_properties) {
551-
(void) fprintf(fp,
551+
(void) fprintf(fp, "%s",
552552
gettext("\nThe following properties are supported:\n"));
553553

554554
(void) fprintf(fp, "\n\t%-14s %s %s %s\n\n",

cmd/zpool/zpool_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ usage(boolean_t requested)
550550
(strcmp(current_command->name, "get") == 0) ||
551551
(strcmp(current_command->name, "list") == 0))) {
552552

553-
(void) fprintf(fp,
553+
(void) fprintf(fp, "%s",
554554
gettext("\nthe following properties are supported:\n"));
555555

556556
(void) fprintf(fp, "\n\t%-19s %s %s\n\n",

config/always-compiler-options.m4

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,62 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_INFINITE_RECURSION], [
227227
AC_SUBST([INFINITE_RECURSION])
228228
])
229229

230+
dnl #
231+
dnl # Check if kernel cc supports -Winfinite-recursion option.
232+
dnl #
233+
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_INFINITE_RECURSION], [
234+
AC_MSG_CHECKING([whether $KERNEL_CC supports -Winfinite-recursion])
235+
236+
saved_cc="$CC"
237+
saved_flags="$CFLAGS"
238+
CC="gcc"
239+
CFLAGS="$CFLAGS -Werror -Winfinite-recursion"
240+
241+
AS_IF([ test -n "$KERNEL_CC" ], [
242+
CC="$KERNEL_CC"
243+
])
244+
AS_IF([ test -n "$KERNEL_LLVM" ], [
245+
CC="clang"
246+
])
247+
248+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
249+
KERNEL_INFINITE_RECURSION=-Winfinite-recursion
250+
AC_DEFINE([HAVE_KERNEL_INFINITE_RECURSION], 1,
251+
[Define if compiler supports -Winfinite-recursion])
252+
AC_MSG_RESULT([yes])
253+
], [
254+
KERNEL_INFINITE_RECURSION=
255+
AC_MSG_RESULT([no])
256+
])
257+
258+
CC="$saved_cc"
259+
CFLAGS="$saved_flags"
260+
AC_SUBST([KERNEL_INFINITE_RECURSION])
261+
])
262+
263+
dnl #
264+
dnl # Check if cc supports -Wformat-overflow option.
265+
dnl #
266+
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW], [
267+
AC_MSG_CHECKING([whether $CC supports -Wformat-overflow])
268+
269+
saved_flags="$CFLAGS"
270+
CFLAGS="$CFLAGS -Werror -Wformat-overflow"
271+
272+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
273+
FORMAT_OVERFLOW=-Wformat-overflow
274+
AC_DEFINE([HAVE_FORMAT_OVERFLOW], 1,
275+
[Define if compiler supports -Wformat-overflow])
276+
AC_MSG_RESULT([yes])
277+
], [
278+
FORMAT_OVERFLOW=
279+
AC_MSG_RESULT([no])
280+
])
281+
282+
CFLAGS="$saved_flags"
283+
AC_SUBST([FORMAT_OVERFLOW])
284+
])
285+
230286
dnl #
231287
dnl # Check if cc supports -fno-omit-frame-pointer option.
232288
dnl #

config/zfs-build.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,12 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
211211
212212
ZFS_AC_CONFIG_ALWAYS_CC_NO_CLOBBERED
213213
ZFS_AC_CONFIG_ALWAYS_CC_INFINITE_RECURSION
214+
ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_INFINITE_RECURSION
214215
ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH
215216
ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN
216217
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION
217218
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH
219+
ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW
218220
ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER
219221
ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA
220222
ZFS_AC_CONFIG_ALWAYS_CC_ASAN

lib/libnvpair/libnvpair.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ nvprint_##type_and_variant(nvlist_prtctl_t pctl, void *private, \
199199
return (1); \
200200
}
201201

202+
/*
203+
* Workaround for GCC 12+ with UBSan enabled deficencies.
204+
*
205+
* GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code
206+
* below as violating -Wformat-overflow.
207+
*/
208+
#if defined(__GNUC__) && !defined(__clang__) && \
209+
defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
210+
#pragma GCC diagnostic push
211+
#pragma GCC diagnostic ignored "-Wformat-overflow"
212+
#endif
202213
NVLIST_PRTFUNC(boolean, int, int, "%d")
203214
NVLIST_PRTFUNC(boolean_value, boolean_t, int, "%d")
204215
NVLIST_PRTFUNC(byte, uchar_t, uchar_t, "0x%2.2x")
@@ -213,6 +224,10 @@ NVLIST_PRTFUNC(uint64, uint64_t, u_longlong_t, "0x%llx")
213224
NVLIST_PRTFUNC(double, double, double, "0x%f")
214225
NVLIST_PRTFUNC(string, char *, char *, "%s")
215226
NVLIST_PRTFUNC(hrtime, hrtime_t, hrtime_t, "0x%llx")
227+
#if defined(__GNUC__) && !defined(__clang__) && \
228+
defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
229+
#pragma GCC diagnostic pop
230+
#endif
216231

217232
/*
218233
* Generate functions to print array-valued nvlist members.

lib/libzfs/libzfs_sendrecv.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,23 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap,
10071007
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
10081008
"incremental\t%s\t%s"), fromsnap, tosnap);
10091009
} else {
1010+
/*
1011+
* Workaround for GCC 12+ with UBSan enabled deficencies.
1012+
*
1013+
* GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code
1014+
* below as violating -Wformat-overflow.
1015+
*/
1016+
#if defined(__GNUC__) && !defined(__clang__) && \
1017+
defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
1018+
#pragma GCC diagnostic push
1019+
#pragma GCC diagnostic ignored "-Wformat-overflow"
1020+
#endif
10101021
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
10111022
"full\t%s"), tosnap);
1023+
#if defined(__GNUC__) && !defined(__clang__) && \
1024+
defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
1025+
#pragma GCC diagnostic pop
1026+
#endif
10121027
}
10131028
(void) fprintf(fout, "\t%llu", (longlong_t)size);
10141029
} else {
@@ -1028,8 +1043,23 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap,
10281043
if (size != 0) {
10291044
char buf[16];
10301045
zfs_nicebytes(size, buf, sizeof (buf));
1046+
/*
1047+
* Workaround for GCC 12+ with UBSan enabled deficencies.
1048+
*
1049+
* GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code
1050+
* below as violating -Wformat-overflow.
1051+
*/
1052+
#if defined(__GNUC__) && !defined(__clang__) && \
1053+
defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
1054+
#pragma GCC diagnostic push
1055+
#pragma GCC diagnostic ignored "-Wformat-overflow"
1056+
#endif
10311057
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
10321058
" estimated size is %s"), buf);
1059+
#if defined(__GNUC__) && !defined(__clang__) && \
1060+
defined(ZFS_UBSAN_ENABLED) && defined(HAVE_FORMAT_OVERFLOW)
1061+
#pragma GCC diagnostic pop
1062+
#endif
10331063
}
10341064
}
10351065
(void) fprintf(fout, "\n");

module/icp/algs/blake3/blake3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static size_t compress_parents_parallel(const blake3_ops_t *ops,
276276
const uint8_t *child_chaining_values, size_t num_chaining_values,
277277
const uint32_t key[8], uint8_t flags, uint8_t *out)
278278
{
279-
const uint8_t *parents_array[MAX_SIMD_DEGREE_OR_2];
279+
const uint8_t *parents_array[MAX_SIMD_DEGREE_OR_2] = {0};
280280
size_t parents_array_len = 0;
281281

282282
while (num_chaining_values - (2 * parents_array_len) >= 2) {

module/lua/ldo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
179179
/*
180180
* Silence infinite recursion warning which was added to -Wall in gcc 12.1
181181
*/
182-
#if defined(HAVE_INFINITE_RECURSION)
182+
#if defined(__GNUC__) && !defined(__clang__) && \
183+
defined(HAVE_KERNEL_INFINITE_RECURSION)
183184
#pragma GCC diagnostic push
184185
#pragma GCC diagnostic ignored "-Winfinite-recursion"
185186
#endif

module/os/linux/zfs/zio_crypt.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,24 @@ zio_crypt_key_init(uint64_t crypt, zio_crypt_key_t *key)
229229
ASSERT(key != NULL);
230230
ASSERT3U(crypt, <, ZIO_CRYPT_FUNCTIONS);
231231

232+
/*
233+
* Workaround for GCC 12+ with UBSan enabled deficencies.
234+
*
235+
* GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code
236+
* below as violating -Warray-bounds
237+
*/
238+
#if defined(__GNUC__) && !defined(__clang__) && \
239+
((!defined(_KERNEL) && defined(ZFS_UBSAN_ENABLED)) || \
240+
defined(CONFIG_UBSAN))
241+
#pragma GCC diagnostic push
242+
#pragma GCC diagnostic ignored "-Warray-bounds"
243+
#endif
232244
keydata_len = zio_crypt_table[crypt].ci_keylen;
245+
#if defined(__GNUC__) && !defined(__clang__) && \
246+
((!defined(_KERNEL) && defined(ZFS_UBSAN_ENABLED)) || \
247+
defined(CONFIG_UBSAN))
248+
#pragma GCC diagnostic pop
249+
#endif
233250
memset(key, 0, sizeof (zio_crypt_key_t));
234251
rw_init(&key->zk_salt_lock, NULL, RW_DEFAULT, NULL);
235252

0 commit comments

Comments
 (0)