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