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