Automatic date update in version.in
[deliverable/binutils-gdb.git] / config / cet.m4
CommitLineData
bf41f30d
NC
1dnl
2dnl GCC_CET_FLAGS
3dnl (SHELL-CODE_HANDLER)
4dnl
5AC_DEFUN([GCC_CET_FLAGS],[dnl
56770bda 6GCC_ENABLE(cet, auto, ,[enable Intel CET in target libraries],
37f980dc 7 permit yes|no|auto)
552d4da4
L
8AC_MSG_CHECKING([for CET support])
9
727b7b18 10# NB: Avoid nested save_CFLAGS and save_LDFLAGS.
bf41f30d
NC
11case "$host" in
12 i[[34567]]86-*-linux* | x86_64-*-linux*)
13 case "$enable_cet" in
37f980dc 14 auto)
552d4da4 15 # Check if target supports multi-byte NOPs
7ade7fba 16 # and if compiler and assembler support CET insn.
727b7b18 17 cet_save_CFLAGS="$CFLAGS"
56770bda 18 CFLAGS="$CFLAGS -fcf-protection"
bf41f30d
NC
19 AC_COMPILE_IFELSE(
20 [AC_LANG_PROGRAM(
21 [],
552d4da4
L
22 [
23#if !defined(__SSE2__)
24#error target does not support multi-byte NOPs
25#else
26asm ("setssbsy");
27#endif
28 ])],
bf41f30d
NC
29 [enable_cet=yes],
30 [enable_cet=no])
727b7b18 31 CFLAGS="$cet_save_CFLAGS"
bf41f30d
NC
32 ;;
33 yes)
34 # Check if assembler supports CET.
35 AC_COMPILE_IFELSE(
36 [AC_LANG_PROGRAM(
37 [],
38 [asm ("setssbsy");])],
39 [],
40 [AC_MSG_ERROR([assembler with CET support is required for --enable-cet])])
41 ;;
42 esac
43 ;;
44 *)
45 enable_cet=no
46 ;;
47esac
48if test x$enable_cet = xyes; then
37f980dc 49 $1="-fcf-protection -mshstk"
552d4da4
L
50 AC_MSG_RESULT([yes])
51else
52 AC_MSG_RESULT([no])
bf41f30d
NC
53fi
54])
87c66b2e
L
55
56dnl
57dnl GCC_CET_HOST_FLAGS
58dnl (SHELL-CODE_HANDLER)
59dnl
60AC_DEFUN([GCC_CET_HOST_FLAGS],[dnl
61GCC_ENABLE(cet, auto, ,[enable Intel CET in host libraries],
62 permit yes|no|auto)
63AC_MSG_CHECKING([for CET support])
64
65case "$host" in
66 i[[34567]]86-*-linux* | x86_64-*-linux*)
67 may_have_cet=yes
727b7b18 68 cet_save_CFLAGS="$CFLAGS"
87c66b2e
L
69 CFLAGS="$CFLAGS -fcf-protection"
70 case "$enable_cet" in
71 auto)
72 # Check if target supports multi-byte NOPs
7ade7fba 73 # and if compiler and assembler support CET.
87c66b2e
L
74 AC_COMPILE_IFELSE(
75 [AC_LANG_PROGRAM(
76 [],
77 [
78#if !defined(__SSE2__)
79#error target does not support multi-byte NOPs
80#else
81asm ("setssbsy");
82#endif
83 ])],
84 [enable_cet=yes],
85 [enable_cet=no])
86 ;;
87 yes)
7ade7fba 88 # Check if compiler and assembler support CET.
87c66b2e
L
89 AC_COMPILE_IFELSE(
90 [AC_LANG_PROGRAM(
91 [],
92 [asm ("setssbsy");])],
7ade7fba
AM
93 [support_cet=yes],
94 [support_cet=no])
95 if test $support_cet = "no"; then
96 if test x$enable_bootstrap != xno \
97 && test -z "${with_build_subdir}" \
98 && (test ! -f ../stage_current \
99 || test `cat ../stage_current` != "stage1"); then
100 # Require CET support only for the final GCC build.
101 AC_MSG_ERROR([compiler and assembler with CET support are required for --enable-cet])
102 else
103 # Don't enable CET without CET support for non-bootstrap
104 # build, in stage1 nor for build support.
105 enable_cet=no
106 fi
107 fi
87c66b2e
L
108 ;;
109 esac
727b7b18 110 CFLAGS="$cet_save_CFLAGS"
87c66b2e
L
111 ;;
112 *)
113 may_have_cet=no
114 enable_cet=no
115 ;;
116esac
117
727b7b18 118cet_save_CFLAGS="$CFLAGS"
87c66b2e 119CFLAGS="$CFLAGS -fcf-protection=none"
727b7b18 120cet_save_LDFLAGS="$LDFLAGS"
87c66b2e
L
121LDFLAGS="$LDFLAGS -Wl,-z,ibt,-z,shstk"
122if test x$may_have_cet = xyes; then
123 # Check whether -fcf-protection=none -Wl,-z,ibt,-z,shstk work.
124 AC_TRY_LINK(
125 [],[return 0;],
126 [may_have_cet=yes],
127 [may_have_cet=no])
128fi
129
130if test x$may_have_cet = xyes; then
90d00bbd
L
131 if test x$cross_compiling = xno; then
132 AC_TRY_RUN([
538c15fc
L
133int
134main ()
135{
136 asm ("endbr32");
137 return 0;
138}
139 ],
140 [have_multi_byte_nop=yes],
141 [have_multi_byte_nop=no])
142 have_cet=no
143 if test x$have_multi_byte_nop = xyes; then
144 AC_TRY_RUN([
87c66b2e
L
145static void
146foo (void)
147{
148}
149
150static void
151__attribute__ ((noinline, noclone))
152xxx (void (*f) (void))
153{
154 f ();
155}
156
157static void
158__attribute__ ((noinline, noclone))
159bar (void)
160{
161 xxx (foo);
162}
163
164int
165main ()
166{
167 bar ();
168 return 0;
169}
538c15fc
L
170 ],
171 [have_cet=no],
172 [have_cet=yes])
173 fi
90d00bbd
L
174 if test x$enable_cet = xno -a x$have_cet = xyes; then
175 AC_MSG_ERROR([Intel CET must be enabled on Intel CET enabled host])
176 fi
87c66b2e 177 fi
90d00bbd
L
178else
179 # Enable CET in cross compiler if possible so that it will run on both
180 # CET and non-CET hosts.
181 have_cet=yes
87c66b2e
L
182fi
183if test x$enable_cet = xyes; then
184 $1="-fcf-protection"
185 AC_MSG_RESULT([yes])
186else
187 AC_MSG_RESULT([no])
188fi
727b7b18
L
189CFLAGS="$cet_save_CFLAGS"
190LDFLAGS="$cet_save_LDFLAGS"
87c66b2e 191])
This page took 0.172821 seconds and 4 git commands to generate.