Sync config and libiberty with GCC
[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, no, ,[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 AC_TRY_RUN([
115 static void
116 foo (void)
117 {
118 }
119
120 static void
121 __attribute__ ((noinline, noclone))
122 xxx (void (*f) (void))
123 {
124 f ();
125 }
126
127 static void
128 __attribute__ ((noinline, noclone))
129 bar (void)
130 {
131 xxx (foo);
132 }
133
134 int
135 main ()
136 {
137 bar ();
138 return 0;
139 }
140 ],
141 [have_cet=no],
142 [have_cet=yes])
143 if test x$enable_cet = xno -a x$have_cet = xyes; then
144 AC_MSG_ERROR([Intel CET must be enabled on Intel CET enabled host])
145 fi
146 fi
147 if test x$enable_cet = xyes; then
148 $1="-fcf-protection"
149 AC_MSG_RESULT([yes])
150 else
151 AC_MSG_RESULT([no])
152 fi
153 CFLAGS="$save_CFLAGS"
154 LDFLAGS="$save_LDFLAGS"
155 ])
This page took 0.036634 seconds and 5 git commands to generate.