Fix MPX tests on systems with MPX disabled
authorAndi Kleen <ak@linux.intel.com>
Wed, 6 Jul 2016 02:38:49 +0000 (02:38 +0000)
committerAndi Kleen <ak@gcc.gnu.org>
Wed, 6 Jul 2016 02:38:49 +0000 (02:38 +0000)
I have a Skylake system with MPX in the CPU, but MPX is disabled
in the kernel configuration.

This makes all the MPX tests fail because they assume if MPX
is in CPUID it works

Check the output of XGETBV too to detect non MPX kernels.

gcc/testsuite/:

2016-07-05  Andi Kleen  <ak@linux.intel.com>

* gcc.target/i386/mpx/mpx-check.h: Check XGETBV output
if kernel supports MPX.

From-SVN: r238031

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/mpx/mpx-check.h

index 5b2fda832b709cfc5e02033ad1ae252b8bd2e889..15231dc82b2ee1c5d000855e31068408b0304d3c 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-05  Andi Kleen  <ak@linux.intel.com>
+
+       * gcc.target/i386/mpx/mpx-check.h: Check XGETBV output
+       if kernel supports MPX.
+
 2016-07-05  Kito Cheng <kito.cheng@gmail.com>
 
        * gcc.c-torture/compile/pr69102.c: Require fpic support.
index 3afa46093d1e538cfee03a5e1206070a74b662de..73aa01f2565bb168208cdec618e89b5a1d0de7a5 100644 (file)
@@ -16,6 +16,16 @@ mpx_test (int, const char **);
 
 #define DEBUG
 
+#define XSTATE_BNDREGS (1 << 3)
+
+/* This should be an intrinsic, but isn't.  */
+static int xgetbv (unsigned x)
+{
+   unsigned eax, edx;
+   asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (x)); 
+   return eax;
+}
+
 int
 main (int argc, const char **argv)
 {
@@ -27,7 +37,7 @@ main (int argc, const char **argv)
   __cpuid_count (7, 0, eax, ebx, ecx, edx);
 
   /* Run MPX test only if host has MPX support.  */
-  if (ebx & bit_MPX)
+  if ((ebx & bit_MPX) && (xgetbv (0) & XSTATE_BNDREGS))
     mpx_test (argc, argv);
   else
     {