Skip to content

Commit 3bb5bd5

Browse files
committed
Fix GCC and Clang errors on Ubuntu 22.10
Make the code compile on Ubuntu Kinetic. - Clang 15 doesn't support `-fno-ipa-sra` anymore. - Squelch false positives. Signed-off-by: szubersk <[email protected]>
1 parent 945b407 commit 3bb5bd5

File tree

13 files changed

+111
-8
lines changed

13 files changed

+111
-8
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
@@ -548,7 +548,7 @@ usage(boolean_t requested)
548548
(strcmp(current_command->name, "get") == 0) ||
549549
(strcmp(current_command->name, "list") == 0))) {
550550

551-
(void) fprintf(fp,
551+
(void) fprintf(fp, "%s",
552552
gettext("\nthe following properties are supported:\n"));
553553

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

config/always-compiler-options.m4

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

230+
dnl #
231+
dnl # Check if cc supports -Wformat-overflow option.
232+
dnl #
233+
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW], [
234+
AC_MSG_CHECKING([whether $CC supports -Wformat-overflow])
235+
236+
saved_flags="$CFLAGS"
237+
CFLAGS="$CFLAGS -Werror -Wformat-overflow"
238+
239+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
240+
FORMAT_OVERFLOW=-Wformat-overflow
241+
AC_DEFINE([HAVE_FORMAT_OVERFLOW], 1,
242+
[Define if compiler supports -Wformat-overflow])
243+
AC_MSG_RESULT([yes])
244+
], [
245+
FORMAT_OVERFLOW=
246+
AC_MSG_RESULT([no])
247+
])
248+
249+
CFLAGS="$saved_flags"
250+
AC_SUBST([FORMAT_OVERFLOW])
251+
])
252+
230253
dnl #
231254
dnl # Check if cc supports -fno-omit-frame-pointer option.
232255
dnl #
@@ -268,3 +291,33 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA], [
268291
CFLAGS="$saved_flags"
269292
AC_SUBST([NO_IPA_SRA])
270293
])
294+
295+
dnl #
296+
dnl # Check if kernel cc supports -fno-ipa-sra option.
297+
dnl #
298+
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA], [
299+
AC_MSG_CHECKING([whether $KERNEL_CC supports -fno-ipa-sra])
300+
301+
saved_cc="$CC"
302+
saved_flags="$CFLAGS"
303+
CFLAGS="$CFLAGS -Werror -fno-ipa-sra"
304+
305+
AS_IF([ test -n "$KERNEL_CC" ], [
306+
CC="$KERNEL_CC"
307+
])
308+
AS_IF([ test -n "$KERNEL_LLVM" ], [
309+
CC="clang"
310+
])
311+
312+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
313+
KERNEL_NO_IPA_SRA=-fno-ipa-sra
314+
AC_MSG_RESULT([yes])
315+
], [
316+
KERNEL_NO_IPA_SRA=
317+
AC_MSG_RESULT([no])
318+
])
319+
320+
CC="$saved_cc"
321+
CFLAGS="$saved_flags"
322+
AC_SUBST([KERNEL_NO_IPA_SRA])
323+
])

config/zfs-build.m4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ AC_DEFUN([ZFS_AC_DEBUG], [
8181
AC_DEFUN([ZFS_AC_DEBUGINFO_ENABLE], [
8282
DEBUG_CFLAGS="$DEBUG_CFLAGS -g -fno-inline $NO_IPA_SRA"
8383
84-
KERNEL_DEBUG_CFLAGS="$KERNEL_DEBUG_CFLAGS -fno-inline $NO_IPA_SRA"
84+
KERNEL_DEBUG_CFLAGS="$KERNEL_DEBUG_CFLAGS -fno-inline $KERNEL_NO_IPA_SRA"
8585
KERNEL_MAKE="$KERNEL_MAKE CONFIG_DEBUG_INFO=y"
8686
8787
DEBUGINFO_ZFS="_with_debuginfo"
@@ -215,8 +215,10 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
215215
ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN
216216
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION
217217
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH
218+
ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW
218219
ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER
219220
ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA
221+
ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA
220222
ZFS_AC_CONFIG_ALWAYS_CC_ASAN
221223
ZFS_AC_CONFIG_ALWAYS_CC_UBSAN
222224
ZFS_AC_CONFIG_ALWAYS_TOOLCHAIN_SIMD

lib/libnvpair/libnvpair.c

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

202+
#if defined(__GNUC__) && !defined(__clang__) && \
203+
defined(HAVE_FORMAT_OVERFLOW)
204+
#pragma GCC diagnostic push
205+
#pragma GCC diagnostic ignored "-Wformat-overflow"
206+
#endif
202207
NVLIST_PRTFUNC(boolean, int, int, "%d")
203208
NVLIST_PRTFUNC(boolean_value, boolean_t, int, "%d")
204209
NVLIST_PRTFUNC(byte, uchar_t, uchar_t, "0x%2.2x")
@@ -213,6 +218,10 @@ NVLIST_PRTFUNC(uint64, uint64_t, u_longlong_t, "0x%llx")
213218
NVLIST_PRTFUNC(double, double, double, "0x%f")
214219
NVLIST_PRTFUNC(string, char *, char *, "%s")
215220
NVLIST_PRTFUNC(hrtime, hrtime_t, hrtime_t, "0x%llx")
221+
#if defined(__GNUC__) && !defined(__clang__) && \
222+
defined(HAVE_FORMAT_OVERFLOW)
223+
#pragma GCC diagnostic pop
224+
#endif
216225

217226
/*
218227
* Generate functions to print array-valued nvlist members.

lib/libzfs/libzfs_sendrecv.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,17 @@ 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+
#if defined(__GNUC__) && !defined(__clang__) && \
1011+
defined(HAVE_FORMAT_OVERFLOW)
1012+
#pragma GCC diagnostic push
1013+
#pragma GCC diagnostic ignored "-Wformat-overflow"
1014+
#endif
10101015
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
10111016
"full\t%s"), tosnap);
1017+
#if defined(__GNUC__) && !defined(__clang__) && \
1018+
defined(HAVE_FORMAT_OVERFLOW)
1019+
#pragma GCC diagnostic pop
1020+
#endif
10121021
}
10131022
(void) fprintf(fout, "\t%llu", (longlong_t)size);
10141023
} else {
@@ -1028,8 +1037,17 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap,
10281037
if (size != 0) {
10291038
char buf[16];
10301039
zfs_nicebytes(size, buf, sizeof (buf));
1040+
#if defined(__GNUC__) && !defined(__clang__) && \
1041+
defined(HAVE_FORMAT_OVERFLOW)
1042+
#pragma GCC diagnostic push
1043+
#pragma GCC diagnostic ignored "-Wformat-overflow"
1044+
#endif
10311045
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
10321046
" estimated size is %s"), buf);
1047+
#if defined(__GNUC__) && !defined(__clang__) && \
1048+
defined(HAVE_FORMAT_OVERFLOW)
1049+
#pragma GCC diagnostic pop
1050+
#endif
10331051
}
10341052
}
10351053
(void) fprintf(fout, "\n");

module/icp/algs/blake3/blake3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* We need 1056 byte stack for blake3_compress_subtree_wide()
3535
* - we define this pragma to make gcc happy
3636
*/
37-
#if defined(__GNUC__)
37+
#if defined(__GNUC__) && !defined(__clang__)
3838
#pragma GCC diagnostic ignored "-Wframe-larger-than="
3939
#endif
4040

@@ -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/icp/algs/edonr/edonr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,11 @@ Q256(size_t bitlen, const uint32_t *data, uint32_t *restrict p)
346346
* which only goes over it by a hair (1248 bytes on ARM32).
347347
*/
348348
#include <sys/isa_defs.h> /* for _ILP32 */
349-
#ifdef _ILP32 /* We're 32-bit, assume small stack frames */
349+
#if defined(_ILP32) /* We're 32-bit, assume small stack frames */
350+
#if defined(__GNUC__) && !defined(__clang__)
350351
#pragma GCC diagnostic ignored "-Wframe-larger-than="
351352
#endif
353+
#endif
352354

353355
#if defined(__IBMC__) && defined(_AIX) && defined(__64BIT__)
354356
static inline size_t

module/icp/algs/skein/skein_block.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
* the #pragma here to ignore the warning.
3131
*/
3232
#if defined(_ILP32) || defined(__powerpc) /* Assume small stack */
33+
#if defined(__GNUC__) && !defined(__clang__)
3334
#pragma GCC diagnostic ignored "-Wframe-larger-than="
35+
#endif
3436
/*
3537
* We're running on 32-bit, don't unroll loops to save stack frame space
3638
*

module/lua/ldo.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
170170
/*
171171
* Silence infinite recursion warning which was added to -Wall in gcc 12.1
172172
*/
173-
#if defined(HAVE_INFINITE_RECURSION)
173+
#if defined(__GNUC__) && !defined(__clang__) && \
174+
defined(HAVE_INFINITE_RECURSION)
174175
#pragma GCC diagnostic push
175176
#pragma GCC diagnostic ignored "-Winfinite-recursion"
176177
#endif
@@ -196,7 +197,8 @@ l_noret luaD_throw (lua_State *L, int errcode) {
196197
}
197198
}
198199

199-
#if defined(HAVE_INFINITE_RECURSION)
200+
#if defined(__GNUC__) && !defined(__clang__) && \
201+
defined(HAVE_INFINITE_RECURSION)
200202
#pragma GCC diagnostic pop
201203
#endif
202204

module/os/linux/spl/spl-generic.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,10 @@ __div_u64(uint64_t u, uint32_t v)
254254
* replacements for libgcc-provided functions and will never be called
255255
* directly.
256256
*/
257+
#if defined(__GNUC__) && !defined(__clang__)
257258
#pragma GCC diagnostic push
258259
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
260+
#endif
259261

260262
/*
261263
* Implementation of 64-bit unsigned division for 32-bit machines.
@@ -449,7 +451,9 @@ __aeabi_ldivmod(int64_t u, int64_t v)
449451
EXPORT_SYMBOL(__aeabi_ldivmod);
450452
#endif /* __arm || __arm__ */
451453

454+
#if defined(__GNUC__) && !defined(__clang__)
452455
#pragma GCC diagnostic pop
456+
#endif
453457

454458
#endif /* BITS_PER_LONG */
455459

module/os/linux/zfs/zio_crypt.c

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

232+
#if defined(__GNUC__) && !defined(__clang__)
233+
#pragma GCC diagnostic push
234+
#pragma GCC diagnostic ignored "-Warray-bounds"
235+
#endif
232236
keydata_len = zio_crypt_table[crypt].ci_keylen;
237+
#if defined(__GNUC__) && !defined(__clang__)
238+
#pragma GCC diagnostic pop
239+
#endif
233240
memset(key, 0, sizeof (zio_crypt_key_t));
234241
rw_init(&key->zk_salt_lock, NULL, RW_DEFAULT, NULL);
235242

module/zfs/vdev_raidz_math_aarch64_neonx2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,13 @@ DEFINE_GEN_METHODS(aarch64_neonx2);
210210
* If compiled with -O0, gcc doesn't do any stack frame coalescing
211211
* and -Wframe-larger-than=1024 is triggered in debug mode.
212212
*/
213+
#if defined(__GNUC__) && !defined(__clang__)
213214
#pragma GCC diagnostic ignored "-Wframe-larger-than="
215+
#endif
214216
DEFINE_REC_METHODS(aarch64_neonx2);
217+
#if defined(__GNUC__) && !defined(__clang__)
215218
#pragma GCC diagnostic pop
219+
#endif
216220

217221
static boolean_t
218222
raidz_will_aarch64_neonx2_work(void)

0 commit comments

Comments
 (0)