i386-opc.tbl: Add a blank line
[deliverable/binutils-gdb.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 # NB: Avoid nested save_CFLAGS and save_LDFLAGS.
11 case "$host" in
12 i[[34567]]86-*-linux* | x86_64-*-linux*)
13 case "$enable_cet" in
14 auto)
15 # Check if target supports multi-byte NOPs
16 # and if assembler supports CET insn.
17 cet_save_CFLAGS="$CFLAGS"
18 CFLAGS="$CFLAGS -fcf-protection"
19 AC_COMPILE_IFELSE(
20 [AC_LANG_PROGRAM(
21 [],
22 [
23 #if !defined(__SSE2__)
24 #error target does not support multi-byte NOPs
25 #else
26 asm ("setssbsy");
27 #endif
28 ])],
29 [enable_cet=yes],
30 [enable_cet=no])
31 CFLAGS="$cet_save_CFLAGS"
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 ;;
47 esac
48 if test x$enable_cet = xyes; then
49 $1="-fcf-protection -mshstk"
50 AC_MSG_RESULT([yes])
51 else
52 AC_MSG_RESULT([no])
53 fi
54 ])
55
56 dnl
57 dnl GCC_CET_HOST_FLAGS
58 dnl (SHELL-CODE_HANDLER)
59 dnl
60 AC_DEFUN([GCC_CET_HOST_FLAGS],[dnl
61 GCC_ENABLE(cet, auto, ,[enable Intel CET in host libraries],
62 permit yes|no|auto)
63 AC_MSG_CHECKING([for CET support])
64
65 case "$host" in
66 i[[34567]]86-*-linux* | x86_64-*-linux*)
67 may_have_cet=yes
68 cet_save_CFLAGS="$CFLAGS"
69 CFLAGS="$CFLAGS -fcf-protection"
70 case "$enable_cet" in
71 auto)
72 # Check if target supports multi-byte NOPs
73 # and if assembler supports CET insn.
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
81 asm ("setssbsy");
82 #endif
83 ])],
84 [enable_cet=yes],
85 [enable_cet=no])
86 ;;
87 yes)
88 # Check if assembler supports CET.
89 AC_COMPILE_IFELSE(
90 [AC_LANG_PROGRAM(
91 [],
92 [asm ("setssbsy");])],
93 [],
94 [AC_MSG_ERROR([assembler with CET support is required for --enable-cet])])
95 ;;
96 esac
97 CFLAGS="$cet_save_CFLAGS"
98 ;;
99 *)
100 may_have_cet=no
101 enable_cet=no
102 ;;
103 esac
104
105 cet_save_CFLAGS="$CFLAGS"
106 CFLAGS="$CFLAGS -fcf-protection=none"
107 cet_save_LDFLAGS="$LDFLAGS"
108 LDFLAGS="$LDFLAGS -Wl,-z,ibt,-z,shstk"
109 if test x$may_have_cet = xyes; then
110 # Check whether -fcf-protection=none -Wl,-z,ibt,-z,shstk work.
111 AC_TRY_LINK(
112 [],[return 0;],
113 [may_have_cet=yes],
114 [may_have_cet=no])
115 fi
116
117 if test x$may_have_cet = xyes; then
118 if test x$cross_compiling = xno; then
119 AC_TRY_RUN([
120 static void
121 foo (void)
122 {
123 }
124
125 static void
126 __attribute__ ((noinline, noclone))
127 xxx (void (*f) (void))
128 {
129 f ();
130 }
131
132 static void
133 __attribute__ ((noinline, noclone))
134 bar (void)
135 {
136 xxx (foo);
137 }
138
139 int
140 main ()
141 {
142 bar ();
143 return 0;
144 }
145 ],
146 [have_cet=no],
147 [have_cet=yes])
148 if test x$enable_cet = xno -a x$have_cet = xyes; then
149 AC_MSG_ERROR([Intel CET must be enabled on Intel CET enabled host])
150 fi
151 fi
152 else
153 # Enable CET in cross compiler if possible so that it will run on both
154 # CET and non-CET hosts.
155 have_cet=yes
156 fi
157 if test x$enable_cet = xyes; then
158 $1="-fcf-protection"
159 AC_MSG_RESULT([yes])
160 else
161 AC_MSG_RESULT([no])
162 fi
163 CFLAGS="$cet_save_CFLAGS"
164 LDFLAGS="$cet_save_LDFLAGS"
165 ])
This page took 0.037817 seconds and 4 git commands to generate.