Skip to content

Commit 6cf17f6

Browse files
Linux build: handle CONFIG_OBJTOOL_WERROR=y
Linux 5.16 by default fails the build on objtool warnings. We have known and understood objtool warnings we can't fix without involving Linux maintainers. To work around this we introduce an objtool wrapper script which removes the `--Werror` flag. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Attila Fülöp <[email protected]> Closes #17456
1 parent bd27b75 commit 6cf17f6

File tree

7 files changed

+98
-0
lines changed

7 files changed

+98
-0
lines changed

config/kernel-objtool.m4

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_OBJTOOL], [
4949
#error "STACK_FRAME_NON_STANDARD is not defined."
5050
#endif
5151
])
52+
53+
dnl # 6.15 made CONFIG_OBJTOOL_WERROR=y the default. We need to handle
54+
dnl # this or our build will fail.
55+
ZFS_LINUX_TEST_SRC([config_objtool_werror], [
56+
#if !defined(CONFIG_OBJTOOL_WERROR)
57+
#error "CONFIG_OBJTOOL_WERROR is not defined."
58+
#endif
59+
])
60+
5261
])
5362

5463
AC_DEFUN([ZFS_AC_KERNEL_OBJTOOL], [
@@ -84,6 +93,14 @@ AC_DEFUN([ZFS_AC_KERNEL_OBJTOOL], [
8493
],[
8594
AC_MSG_RESULT(no)
8695
])
96+
97+
AC_MSG_CHECKING([whether CONFIG_OBJTOOL_WERROR is defined])
98+
ZFS_LINUX_TEST_RESULT([config_objtool_werror],[
99+
AC_MSG_RESULT(yes)
100+
CONFIG_OBJTOOL_WERROR_DEFINED=yes
101+
],[
102+
AC_MSG_RESULT(no)
103+
])
87104
],[
88105
AC_MSG_RESULT(no)
89106
])

config/zfs-build.m4

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,46 @@ AC_DEFUN([ZFS_AC_DEBUG_INVARIANTS], [
205205
AC_MSG_RESULT([$enable_invariants])
206206
])
207207

208+
dnl # Disabled by default. If enabled allows a configured "turn objtools
209+
dnl # warnings into errors" (CONFIG_OBJTOOL_WERROR) behavior to take effect.
210+
dnl # If disabled, objtool warnings are never turned into errors. It can't
211+
dnl # be enabled if the kernel wasn't compiled with CONFIG_OBJTOOL_WERROR=y.
212+
dnl #
213+
AC_DEFUN([ZFS_AC_OBJTOOL_WERROR], [
214+
AC_MSG_CHECKING([whether objtool error on warning behavior is enabled])
215+
AC_ARG_ENABLE([objtool-werror],
216+
[AS_HELP_STRING([--enable-objtool-werror],
217+
[Enable objtool's error on warning behaviour if present @<:@default=no@:>@])],
218+
[enable_objtool_werror=$enableval],
219+
[enable_objtool_werror=no])
220+
AC_MSG_RESULT([$enable_objtool_werror])
221+
222+
AS_IF([test x$CONFIG_OBJTOOL_WERROR_DEFINED = xyes],[
223+
AS_IF([test x$enable_objtool_werror = xyes],[
224+
AC_MSG_NOTICE([enable-objtool-werror defined, keeping -Werror ])
225+
],[
226+
AC_MSG_NOTICE([enable-objtool-werror undefined, disabling -Werror ])
227+
OBJTOOL_DISABLE_WERROR=y
228+
abs_objtool_binary=$kernelsrc/tools/objtool/objtool
229+
AS_IF([test -x $abs_objtool_binary],[],[
230+
AC_MSG_ERROR([*** objtool binary $abs_objtool_binary not found])
231+
])
232+
dnl # The path to the wrapper is defined in modules/Makefile.in.
233+
])
234+
],[
235+
dnl # We can't enable --Werror if it's not there.
236+
AS_IF([test x$enable_objtool_werror = xyes],[
237+
AC_MSG_ERROR([
238+
*** Cannot enable objtool-werror,
239+
*** a kernel built with CONFIG_OBJTOOL_WERROR=y is required.
240+
])
241+
],[])
242+
])
243+
244+
AC_SUBST(OBJTOOL_DISABLE_WERROR)
245+
AC_SUBST(abs_objtool_binary)
246+
])
247+
208248
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
209249
AX_COUNT_CPUS([])
210250
AC_SUBST(CPU_COUNT)

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ZFS_AC_DEBUGINFO
6565
ZFS_AC_DEBUG_KMEM
6666
ZFS_AC_DEBUG_KMEM_TRACKING
6767
ZFS_AC_DEBUG_INVARIANTS
68+
ZFS_AC_OBJTOOL_WERROR
6869

6970
AC_CONFIG_FILES([
7071
contrib/debian/rules
@@ -86,6 +87,7 @@ AC_CONFIG_FILES([
8687
zfs.release
8788
])
8889

90+
AC_CONFIG_FILES([scripts/objtool-wrapper], [chmod +x scripts/objtool-wrapper])
8991

9092
AC_OUTPUT
9193

module/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ modules-Linux:
5757
$(if @KERNEL_LD@,LD=@KERNEL_LD@) $(if @KERNEL_LLVM@,LLVM=@KERNEL_LLVM@) \
5858
$(if @KERNEL_CROSS_COMPILE@,CROSS_COMPILE=@KERNEL_CROSS_COMPILE@) \
5959
$(if @KERNEL_ARCH@,ARCH=@KERNEL_ARCH@) \
60+
$(if @OBJTOOL_DISABLE_WERROR@,objtool=@top_builddir@/scripts/objtool-wrapper) \
6061
M="$$PWD" @KERNEL_MAKE@ CONFIG_ZFS=m modules
6162

6263
modules-FreeBSD:

scripts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
common.sh
2+
objtool-wrapper

scripts/objtool-wrapper.in

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
# SPDX-License-Identifier: MIT
4+
#
5+
# Copyright (c) 2025 Attila Fülöp <[email protected]>
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to
9+
# deal in the Software without restriction, including without limitation the
10+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11+
# sell copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23+
# IN THE SOFTWARE.
24+
25+
# Filter out objtools '--Werror' flag.
26+
27+
objtool="@abs_objtool_binary@"
28+
args=$(echo "$*" | sed s/--Werror//)
29+
30+
if [ -z "$objtool" ]; then
31+
echo "$(basename "$0"): No objtool binary configured" 1>&2
32+
exit 1;
33+
fi
34+
35+
# shellcheck disable=SC2086
36+
exec "$objtool" $args

scripts/spdxcheck.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
etc/init.d/zfs-share.in
9595
etc/init.d/zfs-zed.in
9696
etc/zfs/zfs-functions.in
97+
scripts/objtool-wrapper.in
9798
9899
# Misc items that have clear licensing info but aren't easily matched,
99100
# or are the first of a class that we aren't ready to match yet.

0 commit comments

Comments
 (0)