Skip to content

Conversation

@robn
Copy link
Member

@robn robn commented Nov 19, 2025

Motivation and Context

Recent Clang is a little upset with a handful of things on the Linux side. This sorts it out.

Fixes #17951
Fixes #17959

Description

See commit messages. Summary:

  • Linux: don't explicitly declare -std=gnu99
  • zvol_id: make array length properly known at compile time
  • config/kmap_atomic: initialise test data

How Has This Been Tested?

Compiled and basic sanity runs done with GCC 14.2 and Clang 17, 19 and 22 against Linux 6.1.x, 6.16.x and 6.18-rc.

Not my usual comprehensive set, but recompiling kernels as well adds a lot of time and building with Clang is more difficult the older they get.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

module/Kbuild.in Outdated
# any of the other module initialization functions which depend on it.

ZFS_MODULE_CFLAGS += -std=gnu99 -Wno-declaration-after-statement
ZFS_MODULE_CFLAGS += -Wno-declaration-after-statement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, this breaks the build on almalinux8. I haven't looked closely but it sure looks like it's defaulting to C89/C90 here.

   /tmp/zfs-build-zfs-DRBBnzeA/BUILD/zfs-2.4.99/module/os/linux/spl/spl-kmem-cache.c: In function 'spl_slab_alloc':
  /tmp/zfs-build-zfs-DRBBnzeA/BUILD/zfs-2.4.99/module/os/linux/spl/spl-kmem-cache.c:272:2: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    for (int i = 0; i < sks->sks_objs; i++) {
    ^~~
  /tmp/zfs-build-zfs-DRBBnzeA/BUILD/zfs-2.4.99/module/os/linux/spl/spl-kmem-cache.c:272:2: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
  /tmp/zfs-build-zfs-DRBBnzeA/BUILD/zfs-2.4.99/module/os/linux/spl/spl-kmem-cache.c: In function 'spl_cache_flush':
  /tmp/zfs-build-zfs-DRBBnzeA/BUILD/zfs-2.4.99/module/os/linux/spl/spl-kmem-cache.c:500:2: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    for (int i = 0; i < count; i++)
    ^~~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, interesting, I'd missed a detail. Kernel changed to gnu11 in 5.18.x, before that it was gnu89, far too old.

Last push changes that commit to force gnu11 for us instead. Seems to build ok on 4.19 with GCC. Well see what the builders make of it.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Nov 19, 2025
robn added 3 commits November 20, 2025 08:27
Linux switched from -std=gnu89 to -std=gnu11 in 5.18
(torvalds/linux@e8c07082a810f). We've always overridden that with gnu99
because we use some newer features.

More recent kernels are using C11 features in headers that we include.
GCC generally doesn't seem to care, but more recent versions of Clang
seem to be enforcing our gnu99 override more strictly, which breaks the
build in some configurations.

Just bumping our "override" to match the kernel seems to be the easiest
workaround. It's an effective no-op since 5.18, while still allowing us
to build on older kernels.

Sponsored-by: https://despairlabs.com/sponsor/
Signed-off-by: Rob Norris <robn@despairlabs.com>
Using strlen() in an static array declaration is a GCC extension. Clang
calls it "gnu-folding-constant" and warns about it, which breaks the
build. If it were widespread we could just turn off the warning, but
since there's only one case, lets just change the array to an explicit
size.

Sponsored-by: https://despairlabs.com/sponsor/
Signed-off-by: Rob Norris <robn@despairlabs.com>
6.18 changes kmap_atomic() to take a const pointer. This is no problem
for the places we use it, but Clang fails the test due to a warning
about being unable to guarantee that uninitialised data will definitely
not change. Easily solved by forcibly initialising it.

Sponsored-by: https://despairlabs.com/sponsor/
Signed-off-by: Rob Norris <robn@despairlabs.com>
@robn robn force-pushed the clang-build-fixes branch from fc9e6bb to 8fbbeab Compare November 19, 2025 21:33
@JohnyPeaN
Copy link

Tested it without the -std=gnu99 and now with -std=gnu11 change and both work. Solves the #17951, thanks.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the CI gives it a clean bill of health this looks good.

@alex-moch
Copy link

This does not fix #17959 for me. #17684 fixes the build with LLVM/Clang 21 on 2.2.9 and 2.3.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Code Review Needed Ready for review and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zfs 2.3.5: compilation error with clang compat 6.18 clang - build failing

5 participants