]> git.ipfire.org Git - thirdparty/gcc.git/blob - config/cet.m4
x86: Default CET run-time support to auto
[thirdparty/gcc.git] / config / cet.m4
1 dnl
2 dnl GCC_CET_FLAGS
3 dnl (SHELL-CODE_HANDLER)
4 dnl
5 AC_DEFUN([GCC_CET_FLAGS],[dnl
6 GCC_ENABLE(cet, auto, ,[enable Intel CET in target libraries],
7 permit yes|no|auto)
8 AC_MSG_CHECKING([for CET support])
9
10 case "$host" in
11 i[[34567]]86-*-linux* | x86_64-*-linux*)
12 case "$enable_cet" in
13 auto)
14 # Check if target supports multi-byte NOPs
15 # and if assembler supports CET insn.
16 AC_COMPILE_IFELSE(
17 [AC_LANG_PROGRAM(
18 [],
19 [
20 #if !defined(__SSE2__)
21 #error target does not support multi-byte NOPs
22 #else
23 asm ("setssbsy");
24 #endif
25 ])],
26 [enable_cet=yes],
27 [enable_cet=no])
28 ;;
29 yes)
30 # Check if assembler supports CET.
31 AC_COMPILE_IFELSE(
32 [AC_LANG_PROGRAM(
33 [],
34 [asm ("setssbsy");])],
35 [],
36 [AC_MSG_ERROR([assembler with CET support is required for --enable-cet])])
37 ;;
38 esac
39 ;;
40 *)
41 enable_cet=no
42 ;;
43 esac
44 if test x$enable_cet = xyes; then
45 $1="-fcf-protection -mshstk"
46 AC_MSG_RESULT([yes])
47 else
48 AC_MSG_RESULT([no])
49 fi
50 ])
51
52 dnl
53 dnl GCC_CET_HOST_FLAGS
54 dnl (SHELL-CODE_HANDLER)
55 dnl
56 AC_DEFUN([GCC_CET_HOST_FLAGS],[dnl
57 GCC_ENABLE(cet, auto, ,[enable Intel CET in host libraries],
58 permit yes|no|auto)
59 AC_MSG_CHECKING([for CET support])
60
61 case "$host" in
62 i[[34567]]86-*-linux* | x86_64-*-linux*)
63 may_have_cet=yes
64 save_CFLAGS="$CFLAGS"
65 CFLAGS="$CFLAGS -fcf-protection"
66 case "$enable_cet" in
67 auto)
68 # Check if target supports multi-byte NOPs
69 # and if assembler supports CET insn.
70 AC_COMPILE_IFELSE(
71 [AC_LANG_PROGRAM(
72 [],
73 [
74 #if !defined(__SSE2__)
75 #error target does not support multi-byte NOPs
76 #else
77 asm ("setssbsy");
78 #endif
79 ])],
80 [enable_cet=yes],
81 [enable_cet=no])
82 ;;
83 yes)
84 # Check if assembler supports CET.
85 AC_COMPILE_IFELSE(
86 [AC_LANG_PROGRAM(
87 [],
88 [asm ("setssbsy");])],
89 [],
90 [AC_MSG_ERROR([assembler with CET support is required for --enable-cet])])
91 ;;
92 esac
93 CFLAGS="$save_CFLAGS"
94 ;;
95 *)
96 may_have_cet=no
97 enable_cet=no
98 ;;
99 esac
100
101 save_CFLAGS="$CFLAGS"
102 CFLAGS="$CFLAGS -fcf-protection=none"
103 save_LDFLAGS="$LDFLAGS"
104 LDFLAGS="$LDFLAGS -Wl,-z,ibt,-z,shstk"
105 if test x$may_have_cet = xyes; then
106 # Check whether -fcf-protection=none -Wl,-z,ibt,-z,shstk work.
107 AC_TRY_LINK(
108 [],[return 0;],
109 [may_have_cet=yes],
110 [may_have_cet=no])
111 fi
112
113 if test x$may_have_cet = xyes; then
114 if test x$cross_compiling = xno; then
115 AC_TRY_RUN([
116 static void
117 foo (void)
118 {
119 }
120
121 static void
122 __attribute__ ((noinline, noclone))
123 xxx (void (*f) (void))
124 {
125 f ();
126 }
127
128 static void
129 __attribute__ ((noinline, noclone))
130 bar (void)
131 {
132 xxx (foo);
133 }
134
135 int
136 main ()
137 {
138 bar ();
139 return 0;
140 }
141 ],
142 [have_cet=no],
143 [have_cet=yes])
144 if test x$enable_cet = xno -a x$have_cet = xyes; then
145 AC_MSG_ERROR([Intel CET must be enabled on Intel CET enabled host])
146 fi
147 fi
148 else
149 # Enable CET in cross compiler if possible so that it will run on both
150 # CET and non-CET hosts.
151 have_cet=yes
152 fi
153 if test x$enable_cet = xyes; then
154 $1="-fcf-protection"
155 AC_MSG_RESULT([yes])
156 else
157 AC_MSG_RESULT([no])
158 fi
159 CFLAGS="$save_CFLAGS"
160 LDFLAGS="$save_LDFLAGS"
161 ])