xref: /src/sys/contrib/openzfs/config/kernel-objtool.m4 (revision 8a62a2a5659d1839d8799b4274c04469d7f17c78)
1dnl # SPDX-License-Identifier: CDDL-1.0
2dnl #
3dnl # Detect objtool functionality.
4dnl #
5
6dnl #
7dnl # Kernel 5.10: linux/frame.h was renamed linux/objtool.h
8dnl #
9AC_DEFUN([ZFS_AC_KERNEL_OBJTOOL_HEADER], [
10	AC_MSG_CHECKING([whether objtool header is available])
11	ZFS_LINUX_TRY_COMPILE([
12		#include <linux/objtool.h>
13	],[
14	],[
15		objtool_header=$LINUX/include/linux/objtool.h
16		AC_DEFINE(HAVE_KERNEL_OBJTOOL_HEADER, 1,
17		    [kernel has linux/objtool.h])
18		AC_MSG_RESULT(linux/objtool.h)
19	],[
20		objtool_header=$LINUX/include/linux/frame.h
21		AC_MSG_RESULT(linux/frame.h)
22	])
23])
24
25dnl #
26dnl # Check for objtool support.
27dnl #
28AC_DEFUN([ZFS_AC_KERNEL_SRC_OBJTOOL], [
29
30	dnl # 4.6 API for compile-time stack validation
31	ZFS_LINUX_TEST_SRC([objtool], [
32		#undef __ASSEMBLY__
33		#include <asm/ptrace.h>
34		#include <asm/frame.h>
35	],[
36		#if !defined(FRAME_BEGIN)
37		#error "FRAME_BEGIN is not defined"
38		#endif
39	])
40
41	dnl # 4.6 API added STACK_FRAME_NON_STANDARD macro
42	ZFS_LINUX_TEST_SRC([stack_frame_non_standard], [
43		#ifdef HAVE_KERNEL_OBJTOOL_HEADER
44		#include <linux/objtool.h>
45		#else
46		#include <linux/frame.h>
47		#endif
48	],[
49		#if !defined(STACK_FRAME_NON_STANDARD)
50		#error "STACK_FRAME_NON_STANDARD is not defined."
51		#endif
52	])
53
54	dnl # 6.15 made CONFIG_OBJTOOL_WERROR=y the default. We need to handle
55	dnl # this or our build will fail.
56	ZFS_LINUX_TEST_SRC([config_objtool_werror], [
57		#if !defined(CONFIG_OBJTOOL_WERROR)
58		#error "CONFIG_OBJTOOL_WERROR is not defined."
59		#endif
60	])
61
62])
63
64AC_DEFUN([ZFS_AC_KERNEL_OBJTOOL], [
65	AC_MSG_CHECKING(
66	    [whether compile-time stack validation (objtool) is available])
67	ZFS_LINUX_TEST_RESULT([objtool], [
68		AC_MSG_RESULT(yes)
69		AC_DEFINE(HAVE_KERNEL_OBJTOOL, 1,
70		    [kernel does stack verification])
71
72		AC_MSG_CHECKING([whether STACK_FRAME_NON_STANDARD is defined])
73		ZFS_LINUX_TEST_RESULT([stack_frame_non_standard], [
74			AC_MSG_RESULT(yes)
75			AC_DEFINE(HAVE_STACK_FRAME_NON_STANDARD, 1,
76			   [STACK_FRAME_NON_STANDARD is defined])
77
78			dnl # Needed for kernels missing the asm macro. We grep
79			dnl # for it in the header file since there is currently
80			dnl # no test to check the result of assembling a file.
81			AC_MSG_CHECKING(
82			    [whether STACK_FRAME_NON_STANDARD asm macro is defined])
83			dnl # Escape square brackets.
84			sp='@<:@@<:@:space:@:>@@:>@'
85			dotmacro='@<:@.@:>@macro'
86			regexp="^$sp*$dotmacro$sp+STACK_FRAME_NON_STANDARD$sp"
87			AS_IF([$EGREP -s -q "$regexp" $objtool_header],[
88				AC_MSG_RESULT(yes)
89				AC_DEFINE(HAVE_STACK_FRAME_NON_STANDARD_ASM, 1,
90				   [STACK_FRAME_NON_STANDARD asm macro is defined])
91			],[
92				AC_MSG_RESULT(no)
93			])
94		],[
95			AC_MSG_RESULT(no)
96		])
97
98		AC_MSG_CHECKING([whether CONFIG_OBJTOOL_WERROR is defined])
99		ZFS_LINUX_TEST_RESULT([config_objtool_werror],[
100			AC_MSG_RESULT(yes)
101			CONFIG_OBJTOOL_WERROR_DEFINED=yes
102		],[
103			AC_MSG_RESULT(no)
104		])
105	],[
106		AC_MSG_RESULT(no)
107	])
108])
109