+2021-01-12 Tom de Vries <tdevries@suse.de>
+
+ * gdb.arch/i386-mpx-call.c (have_mpx): Remove.
+ (main): Remove call to have_mpx.
+ * gdb.arch/i386-mpx-call.exp: Use have_mpx.
+ * gdb.arch/i386-mpx-map.c (have_mpx): Remove.
+ (main): Remote call to have_mpx.
+ * gdb.arch/i386-mpx-map.exp: Use have_mpx.
+ * gdb.arch/i386-mpx-sigsegv.c (have_mpx): Remove.
+ (main): Remove call to have_mpx.
+ * gdb.arch/i386-mpx-sigsegv.exp: Use have_mpx.
+ * gdb.arch/i386-mpx-simple_segv.c (have_mpx): Remove.
+ (main): Remove call to have_mpx.
+ * gdb.arch/i386-mpx-simple_segv.exp: Use have_mpx.
+ * gdb.arch/i386-mpx.c (have_mpx): Remove.
+ (main): Remote call to have_mpx.
+ * gdb.arch/i386-mpx.exp: Use have_mpx.
+ * lib/gdb.exp (have_mpx): New proc.
+
2021-01-12 Srinath Parvathaneni <srinath.parvathaneni@arm.com>
* gdb.arch/aarch64-fp.exp: Modify to test bfloat16 support.
#include <stdlib.h>
#include <string.h>
-#include "x86-cpuid.h"
/* Defined size for arrays. */
#define ARRAY_LENGTH 5
-unsigned int
-have_mpx (void)
-{
- unsigned int eax, ebx, ecx, edx;
-
- if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
- return 0;
-
- if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
- {
- if (__get_cpuid_max (0, NULL) < 7)
- return 0;
-
- __cpuid_count (7, 0, eax, ebx, ecx, edx);
-
- if ((ebx & bit_MPX) == bit_MPX)
- return 1;
- else
- return 0;
- }
- return 0;
-}
-
int
upper (int *a, int *b, int *c, int *d, int len)
int
main (void)
{
- if (have_mpx ())
- {
- int sa[ARRAY_LENGTH];
- int sb[ARRAY_LENGTH];
- int sc[ARRAY_LENGTH];
- int sd[ARRAY_LENGTH];
- int *x, *a, *b, *c, *d;
- char mchar;
- char hello[] = "Hello";
-
- x = malloc (sizeof (int) * ARRAY_LENGTH);
- a = malloc (sizeof (int) * ARRAY_LENGTH);
- b = malloc (sizeof (int) * ARRAY_LENGTH);
- c = malloc (sizeof (int) * ARRAY_LENGTH);
- d = malloc (sizeof (int) * ARRAY_LENGTH);
-
- *x = upper (sa, sb, sc, sd, 0); /* bkpt 1. */
- *x = lower (a, b, c, d, 0);
-
- mchar = char_upper (hello, 10);
- mchar = char_lower (hello, 10);
-
- free (x);
- free (a);
- free (b);
- free (c);
- free (d);
- }
+ int sa[ARRAY_LENGTH];
+ int sb[ARRAY_LENGTH];
+ int sc[ARRAY_LENGTH];
+ int sd[ARRAY_LENGTH];
+ int *x, *a, *b, *c, *d;
+ char mchar;
+ char hello[] = "Hello";
+
+ x = malloc (sizeof (int) * ARRAY_LENGTH);
+ a = malloc (sizeof (int) * ARRAY_LENGTH);
+ b = malloc (sizeof (int) * ARRAY_LENGTH);
+ c = malloc (sizeof (int) * ARRAY_LENGTH);
+ d = malloc (sizeof (int) * ARRAY_LENGTH);
+
+ *x = upper (sa, sb, sc, sd, 0); /* bkpt 1. */
+ *x = lower (a, b, c, d, 0);
+
+ mchar = char_upper (hello, 10);
+ mchar = char_lower (hello, 10);
+
+ free (x);
+ free (a);
+ free (b);
+ free (c);
+ free (d);
+
return 0;
}
return -1
}
+if { ![have_mpx] } {
+ unsupported "processor does not support MPX"
+ return -1
+}
+
set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat"
if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
return -1
}
-set test "check whether processor supports MPX"
-gdb_test_multiple "print have_mpx ()" $test {
- -re ".*= 1\r\n$gdb_prompt " {
- pass $test
- }
- -re ".*= 0\r\n$gdb_prompt " {
- pass $test
- untested "processor does not support MPX; skipping tests"
- return
- }
-}
-
set bounds_table 0
gdb_test_multiple "disassemble upper" "" {
-re -wrap "bndldx.*" {
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
-#include "x86-cpuid.h"
-
-#ifndef NOINLINE
-#define NOINLINE __attribute__ ((noinline))
-#endif
-
#define SIZE 5
typedef int T;
-unsigned int have_mpx (void) NOINLINE;
-
-unsigned int NOINLINE
-have_mpx (void)
-{
- unsigned int eax, ebx, ecx, edx;
-
- if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
- return 0;
-
- if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
- {
- if (__get_cpuid_max (0, NULL) < 7)
- return 0;
-
- __cpuid_count (7, 0, eax, ebx, ecx, edx);
-
- if ((ebx & bit_MPX) == bit_MPX)
- return 1;
- else
- return 0;
- }
- return 0;
-}
-
void
foo (T *p)
{
int
main (void)
{
- if (have_mpx ())
- {
- T *a = NULL;
+ T *a = NULL;
- a = calloc (SIZE, sizeof (T)); /* after-decl */
+ a = calloc (SIZE, sizeof (T)); /* after-decl */
#if defined __GNUC__ && !defined __INTEL_COMPILER
- __bnd_store_ptr_bounds (a, &a);
+ __bnd_store_ptr_bounds (a, &a);
#endif
- foo (a); /* after-alloc */
- free (a);
- }
+ foo (a); /* after-alloc */
+ free (a);
+
return 0;
}
return -1
}
+if { ![have_mpx] } {
+ unsupported "processor does not support MPX"
+ return -1
+}
+
set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat/"
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
return -1
}
-set supports_mpx 0
-set test "probe MPX support"
-
-gdb_test_multiple "print have_mpx()" $test {
- -re ".. = 1\r\n$gdb_prompt $" {
- pass $test
- set supports_mpx 1
- }
- -re ".. = 0\r\n$gdb_prompt $" {
- pass $test
- }
-}
-
-if { !$supports_mpx } {
- unsupported "processor does not support MPX"
- return
-}
-
gdb_breakpoint [ gdb_get_line_number "after-decl" ]
gdb_breakpoint [ gdb_get_line_number "after-alloc" ]
gdb_breakpoint [ gdb_get_line_number "after-assign" ]
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "x86-cpuid.h"
-#include <stdio.h>
-
#define OUR_SIZE 5
int gx[OUR_SIZE];
int gc[OUR_SIZE];
int gd[OUR_SIZE];
-unsigned int
-have_mpx (void)
-{
- unsigned int eax, ebx, ecx, edx;
-
- if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
- return 0;
-
- if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
- {
- if (__get_cpuid_max (0, NULL) < 7)
- return 0;
-
- __cpuid_count (7, 0, eax, ebx, ecx, edx);
-
- if ((ebx & bit_MPX) == bit_MPX)
- return 1;
- else
- return 0;
- }
- return 0;
-}
-
int
bp1 (int value)
{
int
main (void)
{
- if (have_mpx ())
- {
- int sx[OUR_SIZE];
- int sa[OUR_SIZE];
- int sb[OUR_SIZE];
- int sc[OUR_SIZE];
- int sd[OUR_SIZE];
- int *x, *a, *b, *c, *d;
-
- x = calloc (OUR_SIZE, sizeof (int));
- a = calloc (OUR_SIZE, sizeof (int));
- b = calloc (OUR_SIZE, sizeof (int));
- c = calloc (OUR_SIZE, sizeof (int));
- d = calloc (OUR_SIZE, sizeof (int));
-
- upper (x, a, b, c, d, OUR_SIZE + 2);
- upper (sx, sa, sb, sc, sd, OUR_SIZE + 2);
- upper (gx, ga, gb, gc, gd, OUR_SIZE + 2);
- lower (x, a, b, c, d, 1);
- lower (sx, sa, sb, sc, sd, 1);
- bp1 (*x);
- lower (gx, ga, gb, gc, gd, 1);
+ int sx[OUR_SIZE];
+ int sa[OUR_SIZE];
+ int sb[OUR_SIZE];
+ int sc[OUR_SIZE];
+ int sd[OUR_SIZE];
+ int *x, *a, *b, *c, *d;
+
+ x = calloc (OUR_SIZE, sizeof (int));
+ a = calloc (OUR_SIZE, sizeof (int));
+ b = calloc (OUR_SIZE, sizeof (int));
+ c = calloc (OUR_SIZE, sizeof (int));
+ d = calloc (OUR_SIZE, sizeof (int));
+
+ upper (x, a, b, c, d, OUR_SIZE + 2);
+ upper (sx, sa, sb, sc, sd, OUR_SIZE + 2);
+ upper (gx, ga, gb, gc, gd, OUR_SIZE + 2);
+ lower (x, a, b, c, d, 1);
+ lower (sx, sa, sb, sc, sd, 1);
+ bp1 (*x);
+ lower (gx, ga, gb, gc, gd, 1);
+
+ free (x);
+ free (a);
+ free (b);
+ free (c);
+ free (d);
- free (x);
- free (a);
- free (b);
- free (c);
- free (d);
- }
return 0;
}
return -1
}
+if { ![have_mpx] } {
+ unsupported "processor does not support MPX"
+ return -1
+}
+
set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat/"
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
return -1
}
-gdb_test_multiple "print have_mpx ()" "have mpx" {
- -re ".. = 1\r\n$gdb_prompt " {
- pass "check whether processor supports MPX"
- }
- -re ".. = 0\r\n$gdb_prompt " {
- verbose "processor does not support MPX; skipping MPX tests"
- return
- }
-}
-
set u_fault [multi_line "Program received signal SIGSEGV, Segmentation fault" \
"Upper bound violation while accessing address $hex" \
"Bounds: \\\[lower = $hex, upper = $hex\\\]"]
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "x86-cpuid.h"
-#include <stdio.h>
-
#define OUR_SIZE 5
-unsigned int
-have_mpx (void)
-{
- unsigned int eax, ebx, ecx, edx;
-
- if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
- return 0;
-
- if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
- {
- if (__get_cpuid_max (0, NULL) < 7)
- return 0;
-
- __cpuid_count (7, 0, eax, ebx, ecx, edx);
-
- if ((ebx & bit_MPX) == bit_MPX)
- return 1;
- else
- return 0;
- }
- return 0;
-}
-
void
upper (int * p, int len)
{
int
main (void)
{
- if (have_mpx ())
- {
- int a = 0; /* Dummy variable for debugging purposes. */
- int sx[OUR_SIZE];
- a++; /* register-eval. */
- upper (sx, OUR_SIZE + 2);
- return sx[1];
- }
- return 0;
+ int a = 0; /* Dummy variable for debugging purposes. */
+ int sx[OUR_SIZE];
+ a++; /* register-eval. */
+ upper (sx, OUR_SIZE + 2);
+ return sx[1];
}
return -1
}
+if { ![have_mpx] } {
+ unsupported "processor does not support MPX"
+ return -1
+}
+
set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat/"
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
return -1
}
-gdb_test_multiple "print have_mpx ()" "have mpx" {
- -re ".. = 1\r\n$gdb_prompt " {
- pass "check whether processor supports MPX"
- }
- -re ".. = 0\r\n$gdb_prompt " {
- verbose "processor does not support MPX; skipping MPX tests"
- return
- }
-}
-
set violation [multi_line "Program received signal SIGSEGV, Segmentation fault" \
"Upper bound violation while accessing address $hex" \
"Bounds: \\\[lower = $hex, upper = $hex\\\]"]
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include <stdio.h>
-#include "x86-cpuid.h"
-
-#ifndef NOINLINE
-#define NOINLINE __attribute__ ((noinline))
-#endif
-
-unsigned int have_mpx (void) NOINLINE;
-
-unsigned int NOINLINE
-have_mpx (void)
-{
- unsigned int eax, ebx, ecx, edx;
-
- if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
- return 0;
-
- if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
- {
- if (__get_cpuid_max (0, NULL) < 7)
- return 0;
-
- __cpuid_count (7, 0, eax, ebx, ecx, edx);
-
- if ((ebx & bit_MPX) == bit_MPX)
- return 1;
- else
- return 0;
- }
- return 0;
-}
-
int
main (int argc, char **argv)
{
- if (have_mpx ())
- {
#ifdef __x86_64__
- asm ("mov $10, %rax\n\t"
- "mov $9, %rdx\n\t"
- "bndmk (%rax,%rdx), %bnd0\n\t"
- "mov $20, %rax\n\t"
- "mov $9, %rdx\n\t"
- "bndmk (%rax,%rdx), %bnd1\n\t"
- "mov $30, %rax\n\t"
- "mov $9, %rdx\n\t"
- "bndmk (%rax,%rdx), %bnd2\n\t"
- "mov $40, %rax\n\t"
- "mov $9, %rdx\n\t"
- "bndmk (%rax,%rdx), %bnd3\n\t"
- "bndstx %bnd3, (%rax) \n\t"
- "nop\n\t"
- );
+ asm ("mov $10, %rax\n\t"
+ "mov $9, %rdx\n\t"
+ "bndmk (%rax,%rdx), %bnd0\n\t"
+ "mov $20, %rax\n\t"
+ "mov $9, %rdx\n\t"
+ "bndmk (%rax,%rdx), %bnd1\n\t"
+ "mov $30, %rax\n\t"
+ "mov $9, %rdx\n\t"
+ "bndmk (%rax,%rdx), %bnd2\n\t"
+ "mov $40, %rax\n\t"
+ "mov $9, %rdx\n\t"
+ "bndmk (%rax,%rdx), %bnd3\n\t"
+ "bndstx %bnd3, (%rax) \n\t"
+ "nop\n\t"
+ );
#else
- asm ("mov $10, %eax\n\t"
- "mov $9, %edx\n\t"
- "bndmk (%eax,%edx), %bnd0\n\t"
- "mov $20, %eax\n\t"
- "mov $9, %edx\n\t"
- "bndmk (%eax,%edx), %bnd1\n\t"
- "mov $30, %eax\n\t"
- "mov $9, %edx\n\t"
- "bndmk (%eax,%edx), %bnd2\n\t"
- "mov $40, %eax\n\t"
- "mov $9, %edx\n\t"
- "bndmk (%eax,%edx), %bnd3\n\t"
- "bndstx %bnd3, (%eax)\n\t"
- "nop\n\t"
- );
+ asm ("mov $10, %eax\n\t"
+ "mov $9, %edx\n\t"
+ "bndmk (%eax,%edx), %bnd0\n\t"
+ "mov $20, %eax\n\t"
+ "mov $9, %edx\n\t"
+ "bndmk (%eax,%edx), %bnd1\n\t"
+ "mov $30, %eax\n\t"
+ "mov $9, %edx\n\t"
+ "bndmk (%eax,%edx), %bnd2\n\t"
+ "mov $40, %eax\n\t"
+ "mov $9, %edx\n\t"
+ "bndmk (%eax,%edx), %bnd3\n\t"
+ "bndstx %bnd3, (%eax)\n\t"
+ "nop\n\t"
+ );
#endif
- asm ("nop\n\t"); /* break here. */
- }
+ asm ("nop\n\t"); /* break here. */
+
return 0;
}
return -1
}
+if { ![have_mpx] } {
+ unsupported "processor does not support MPX"
+ return -1
+}
+
set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat/"
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
return -1
}
-set supports_mpx 0
-set test "probe MPX support"
-gdb_test_multiple "print have_mpx()" $test {
- -re ".. = 1\r\n$gdb_prompt $" {
- pass $test
- set supports_mpx 1
- }
- -re ".. = 0\r\n$gdb_prompt $" {
- pass $test
- }
-}
-
-if { !$supports_mpx } {
- unsupported "processor does not support MPX"
- return
-}
-
# Test bndcfg register and bndstatus at startup
set test_string "\\\{raw = 0x\[0-9a-f\]+, config = \\\{base = \[0-9\]+,\
reserved = \[0-9\]+, preserved = \[0-9\]+, enabled = \[0-9\]+\\\}\\\}"
return [gdb_simple_compile $me $src object ""]
}
+# Return 1 if target supports mpx, otherwise return 0.
+gdb_caching_proc have_mpx {
+ global srcdir
+
+ set me "have_mpx"
+ if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
+ verbose "$me: target does not support mpx, returning 0" 2
+ return 0
+ }
+
+ # Compile a test program.
+ set src {
+ #include "nat/x86-cpuid.h"
+
+ int main() {
+ unsigned int eax, ebx, ecx, edx;
+
+ if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
+ return 0;
+
+ if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
+ {
+ if (__get_cpuid_max (0, (void *)0) < 7)
+ return 0;
+
+ __cpuid_count (7, 0, eax, ebx, ecx, edx);
+
+ if ((ebx & bit_MPX) == bit_MPX)
+ return 1;
+
+ }
+ return 0;
+ }
+ }
+ set compile_flags "incdir=${srcdir}/.."
+ if {![gdb_simple_compile $me $src executable $compile_flags]} {
+ return 0
+ }
+
+ set result [remote_exec target $obj]
+ set status [lindex $result 0]
+ set output [lindex $result 1]
+ if { $output != "" } {
+ set status 0
+ }
+
+ remote_file build delete $obj
+
+ verbose "$me: returning $status" 2
+ return $status
+}
+
# Always load compatibility stuff.
load_lib future.exp