From: Mark Wielaard Date: Fri, 9 May 2014 11:41:46 +0000 (+0000) Subject: Add test for MPX instructions and bnd prefix. Bug #333666. X-Git-Tag: svn/VALGRIND_3_10_0~488 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a07285e39382a6ab46db1206fe69397400a4015e;p=thirdparty%2Fvalgrind.git Add test for MPX instructions and bnd prefix. Bug #333666. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13948 --- diff --git a/NEWS b/NEWS index ac02d09d2e..b0b9e90fa5 100644 --- a/NEWS +++ b/NEWS @@ -98,6 +98,7 @@ where XXXXXX is the bug number as listed below. consistency checks enabled 333230 AAarch64 missing instruction encodings: dc, ic, dsb. 333228 AAarch64 Missing instruction encoding: mrs %[reg], ctr_el0 +333666 Recognize MPX instructions and bnd prefix. n-i-bz Fix KVM_CREATE_IRQCHIP ioctl handling n-i-bz s390x: Fix memory corruption for multithreaded applications n-i-bz vex arm->IR: allow PC as basereg in some LDRD cases diff --git a/configure.ac b/configure.ac index b1e567a541..af4228915a 100644 --- a/configure.ac +++ b/configure.ac @@ -2322,6 +2322,27 @@ AC_MSG_RESULT([no]) AM_CONDITIONAL(BUILD_FMA_TESTS, test x$ac_have_as_fma = xyes) +# does the amd64 assembler understand MPX instructions? +# Note, this doesn't generate a C-level symbol. It generates a +# automake-level symbol (BUILD_MPX_TESTS), used in test Makefile.am's +AC_MSG_CHECKING([if amd64 assembler knows the MPX instructions]) + +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ + asm ("bndmov %bnd0,(%rsp)") +]])], [ +ac_have_as_mpx=yes +AC_MSG_RESULT([yes]) +], [ +ac_have_as_mpx=no +AC_MSG_RESULT([no]) +]) + +AM_CONDITIONAL(BUILD_MPX_TESTS, test x$ac_have_as_mpx = xyes) + + +# Does the C compiler support the "ifunc" attribute +# Note, this doesn't generate a C-level symbol. It generates a +# automake-level symbol (BUILD_IFUNC_TESTS), used in test Makefile.am's # does the x86/amd64 assembler understand MOVBE? # Note, this doesn't generate a C-level symbol. It generates a # automake-level symbol (BUILD_MOVBE_TESTS), used in test Makefile.am's diff --git a/none/tests/amd64/Makefile.am b/none/tests/amd64/Makefile.am index d7ec56abfb..d5f9e48a4a 100644 --- a/none/tests/amd64/Makefile.am +++ b/none/tests/amd64/Makefile.am @@ -56,6 +56,7 @@ EXTRA_DIST = \ loopnel.stderr.exp loopnel.stdout.exp loopnel.vgtest \ lzcnt64.stderr.exp lzcnt64.stdout.exp lzcnt64.vgtest \ movbe.stderr.exp movbe.stdout.exp movbe.vgtest \ + mpx.stderr.exp mpx.stdout.exp mpx.vgtest \ nan80and64.stderr.exp nan80and64.stdout.exp nan80and64.vgtest \ nibz_bennee_mmap.stderr.exp nibz_bennee_mmap.stdout.exp \ nibz_bennee_mmap.vgtest \ @@ -133,6 +134,10 @@ endif if BUILD_MOVBE_TESTS check_PROGRAMS += movbe endif +if BUILD_MPX_TESTS + check_PROGRAMS += mpx +endif + # DDD: these need to be made to work on Darwin like the x86/ ones were. if ! VGCONF_OS_IS_DARWIN diff --git a/none/tests/amd64/mpx.c b/none/tests/amd64/mpx.c new file mode 100644 index 0000000000..ae713d6a88 --- /dev/null +++ b/none/tests/amd64/mpx.c @@ -0,0 +1,38 @@ +int +main (int argc, char **argv) +{ + // Since MPX is disabled all these are just NOPS. + // Some of these instructions are just random. + // Once the GCC support is merged creating real test cases will be easier. + // http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler + + // This is what ld.so does in _dl_runtime_resolve to save the bnds. + asm ("bndmov %bnd0, (%rsp)"); + asm ("bndmov %bnd1, 16(%rsp)"); + asm ("bndmov %bnd2, 32(%rsp)"); + asm ("bndmov %bnd3, 48(%rsp)"); + + // Create a bnd, check lower and upper... + asm ("bndmk (%rax,%rdx), %bnd0"); + asm ("bndcl (%rax,%rdi,4), %bnd0"); + asm ("bndcu 3(%rax,%rdi,4), %bnd0"); + asm ("bndcn 3(%rax,%rdi,4), %bnd0"); + + // Load bnd pointer and update... + asm ("bndldx 3(%rbx,%rdx), %bnd2"); + asm ("bndstx %bnd2, 3(,%r12,1)"); + + // "bnd" prefixed call, return and jmp... + asm ("bnd call foo\n\ + bnd jmp end\n\ + foo: bnd ret\n\ + end: nop"); + + // And set the bnds back... + asm ("bndmov 48(%rsp), %bnd3"); + asm ("bndmov 32(%rsp), %bnd2"); + asm ("bndmov 16(%rsp), %bnd1"); + asm ("bndmov (%rsp), %bnd0"); + + return 0; +} diff --git a/none/tests/amd64/mpx.stderr.exp b/none/tests/amd64/mpx.stderr.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/none/tests/amd64/mpx.stdout.exp b/none/tests/amd64/mpx.stdout.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/none/tests/amd64/mpx.vgtest b/none/tests/amd64/mpx.vgtest new file mode 100644 index 0000000000..ab963556f4 --- /dev/null +++ b/none/tests/amd64/mpx.vgtest @@ -0,0 +1,3 @@ +prog: mpx +prereq: test -x mpx +vgopts: -q