Commit 653b8b8d by Tsvetkova Alexandra Committed by Ilya Enkovich

Makefile.am (libmpx_la_LDFLAGS): Add -version-info option.

libmpx/

2015-12-11  Tsvetkova Alexandra  <aleksandra.tsvetkova@intel.com>

	* mpxrt/Makefile.am (libmpx_la_LDFLAGS): Add -version-info
	option.
	* libmpxwrap/Makefile.am (libmpx_la_LDFLAGS): Likewise and
	fix include path.
	* libmpx/Makefile.in: Regenerate.
	* mpxrt/Makefile.in: Regenerate.
	* libmpxwrap/Makefile.in: Regenerate.
	* mpxrt/libtool-version: New version.
	* libmpxwrap/libtool-version: Likewise.
	* mpxrt/libmpx.map: Add new version and a new symbol.
	* mpxrt/mpxrt.h: New file.
	* mpxrt/mpxrt.c (NUM_L1_BITS): Moved to mpxrt.h.
	(REG_IP_IDX): Moved to mpxrt.h.
	(REX_PREFIX): Moved to mpxrt.h.
	(XSAVE_OFFSET_IN_FPMEM): Moved to mpxrt.h.
	(MPX_L1_SIZE): Moved to mpxrt.h.
	* libmpxwrap/mpx_wrappers.c (mpx_pointer): New type.
	(mpx_bt_entry): New type.
	(alloc_bt): New function.
	(get_bt): New function.
	(copy_if_possible): New function.
	(copy_if_possible_from_end): New function.
	(move_bounds): New function.
	(__mpx_wrapper_memmove): Use move_bounds to copy bounds.

gcc/testsuite/

2015-12-11  Tsvetkova Alexandra  <aleksandra.tsvetkova@intel.com>

	* gcc.target/i386/mpx/memmove-1.c: New test.
	* gcc.target/i386/mpx/memmove-2.c: New test.

From-SVN: r231565
parent a9000e1e
2015-12-11 Tsvetkova Alexandra <aleksandra.tsvetkova@intel.com>
* gcc.target/i386/mpx/memmove-1.c: New test.
* gcc.target/i386/mpx/memmove-2.c: New test.
2015-12-11 Nathan Sidwell <nathan@acm.org>
* gcc.target/nvptx/ary-init.c: Repair dg_final syntax.
......
/* { dg-do run } */
/* { dg-options "-fcheck-pointer-bounds -mmpx" } */
#include <stdint.h>
#include <string.h>
#include "mpx-check.h"
#ifdef __i386__
/* i386 directory size is 4MB. */
#define MPX_NUM_L2_BITS 10
#define MPX_NUM_IGN_BITS 2
#else /* __i386__ */
/* x86_64 directory size is 2GB. */
#define MPX_NUM_L2_BITS 17
#define MPX_NUM_IGN_BITS 3
#endif /* !__i386__ */
/* bt_num_of_elems is the number of elements in bounds table. */
unsigned long bt_num_of_elems = (1UL << MPX_NUM_L2_BITS);
/* Function to test MPX wrapper of memmove function.
src_bigger_dst determines which address is bigger, can be 0 or 1.
src_bt_index and dst_bt index are bt_indexes
from the beginning of the page.
bd_index_end is the bd index of the last element of src if we define
bd index of the first element as 0.
src_bt index_end is bt index of the last element of src.
pointers inside determines if array being copied includes pointers
src_align and dst_align are alignments of src and dst.
Arrays may contain unaligned pointers. */
int
test (int src_bigger_dst, int src_bt_index, int dst_bt_index,
int bd_index_end, int src_bt_index_end, int pointers_inside,
int src_align, int dst_align)
{
const int n =
src_bt_index_end - src_bt_index + bd_index_end * bt_num_of_elems;
if (n < 0)
{
return 0;
}
const int num_of_pointers = (bd_index_end + 2) * bt_num_of_elems;
void **arr = 0;
posix_memalign ((void **) (&arr),
1UL << (MPX_NUM_L2_BITS + MPX_NUM_IGN_BITS),
num_of_pointers * sizeof (void *));
void **src = arr, **dst = arr;
if ((src_bigger_dst) && (src_bt_index < dst_bt_index))
src_bt_index += bt_num_of_elems;
if (!(src_bigger_dst) && (src_bt_index > dst_bt_index))
dst_bt_index += bt_num_of_elems;
src += src_bt_index;
dst += dst_bt_index;
char *realign = (char *) src;
realign += src_align;
src = (void **) realign;
realign = (char *) dst;
realign += src_align;
dst = (void **) realign;
if (pointers_inside)
{
for (int i = 0; i < n; i++)
src[i] = __bnd_set_ptr_bounds (arr + i, i * sizeof (void *) + 1);
}
memmove (dst, src, n * sizeof (void *));
if (pointers_inside)
{
for (int i = 0; i < n; i++)
{
if (dst[i] != arr + i)
abort ();
if (__bnd_get_ptr_lbound (dst[i]) != arr + i)
abort ();
if (__bnd_get_ptr_ubound (dst[i]) != arr + 2 * i)
abort ();
}
}
free (arr);
return 0;
}
/* Call testall to test common cases of memmove for MPX. */
void
testall ()
{
int align[3];
align[0] = 0;
align[1] = 1;
align[2] = 7;
for (int pointers_inside = 0; pointers_inside < 2; pointers_inside++)
for (int src_bigger_dst = 0; src_bigger_dst < 2; src_bigger_dst++)
for (int src_align = 0; src_align < 3; src_align ++)
for (int dst_align = 0; dst_align < 3; dst_align ++)
for (int pages = 0; pages < 4; pages++)
{
test (src_bigger_dst, 1, 2, pages, 1, pointers_inside,
align[src_align], align[dst_align]);
test (src_bigger_dst, 1, 2, pages, 2, pointers_inside,
align[src_align], align[dst_align]);
test (src_bigger_dst, 2, 1, pages, 12, pointers_inside,
align[src_align], align[dst_align]);
test (src_bigger_dst, 2, 1, pages, 1, pointers_inside,
align[src_align], align[dst_align]);
test (src_bigger_dst, 2, 3, pages, 12, pointers_inside,
align[src_align], align[dst_align]);
test (src_bigger_dst, 1, bt_num_of_elems - 2, pages, 2,
pointers_inside, align[src_align], align[dst_align]);
}
};
int
mpx_test (int argc, const char **argv)
{
testall ();
return 0;
}
/* { dg-do run } */
/* { dg-options "-fcheck-pointer-bounds -mmpx" } */
#include <stdint.h>
#include <string.h>
#include "mpx-check.h"
#ifdef __i386__
/* i386 directory size is 4MB. */
#define MPX_NUM_L2_BITS 10
#define MPX_NUM_IGN_BITS 2
#else /* __i386__ */
/* x86_64 directory size is 2GB. */
#define MPX_NUM_L2_BITS 17
#define MPX_NUM_IGN_BITS 3
#endif /* !__i386__ */
/* bt_num_of_elems is the number of elements in bounds table. */
unsigned long bt_num_of_elems = (1UL << MPX_NUM_L2_BITS);
/* Function to test MPX wrapper of memmove function.
Check case with no BT allocated for data. */
int
mpx_test (int argc, const char **argv)
{
void **arr = 0;
posix_memalign ((void **) (&arr),
1UL << (MPX_NUM_L2_BITS + MPX_NUM_IGN_BITS),
2 * bt_num_of_elems * sizeof (void *));
void **src = arr, **dst = arr, **ptr = arr;
src += 10;
dst += 1;
ptr += bt_num_of_elems + 100;
ptr[0] = __bnd_set_ptr_bounds (arr + 1, sizeof (void *) + 1);
memmove (dst, src, 5 * sizeof (void *));
return 0;
}
2015-12-11 Tsvetkova Alexandra <aleksandra.tsvetkova@intel.com>
* mpxrt/Makefile.am (libmpx_la_LDFLAGS): Add -version-info
option.
* libmpxwrap/Makefile.am (libmpx_la_LDFLAGS): Likewise and
fix include path.
* libmpx/Makefile.in: Regenerate.
* mpxrt/Makefile.in: Regenerate.
* libmpxwrap/Makefile.in: Regenerate.
* mpxrt/libtool-version: New version.
* libmpxwrap/libtool-version: Likewise.
* mpxrt/libmpx.map: Add new version and a new symbol.
* mpxrt/mpxrt.h: New file.
* mpxrt/mpxrt.c (NUM_L1_BITS): Moved to mpxrt.h.
(REG_IP_IDX): Moved to mpxrt.h.
(REX_PREFIX): Moved to mpxrt.h.
(XSAVE_OFFSET_IN_FPMEM): Moved to mpxrt.h.
(MPX_L1_SIZE): Moved to mpxrt.h.
* libmpxwrap/mpx_wrappers.c (mpx_pointer): New type.
(mpx_bt_entry): New type.
(alloc_bt): New function.
(get_bt): New function.
(copy_if_possible): New function.
(copy_if_possible_from_end): New function.
(move_bounds): New function.
(__mpx_wrapper_memmove): Use move_bounds to copy bounds.
2015-10-15 Ilya Enkovich <enkovich.gnu@gmail.com>
PR other/66887
......
......@@ -228,7 +228,6 @@ install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
link_libmpx = @link_libmpx@
link_mpx = @link_mpx@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
......
......@@ -13,7 +13,8 @@ libmpx_la_SOURCES = mpxrt.c mpxrt-utils.c
libmpx_la_CFLAGS = -fPIC
libmpx_la_DEPENDENCIES = libmpx.map
libmpx_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpx.map $(link_libmpx)
libmpx_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpx.map $(link_libmpx) \
-version-info `grep -v '^\#' $(srcdir)/libtool-version`
mpxrt.lo: mpxrt-utils.h
mpxrt-utils.lo: mpxrt-utils.h
......
......@@ -222,7 +222,6 @@ install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
link_libmpx = @link_libmpx@
link_mpx = @link_mpx@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
......@@ -257,7 +256,9 @@ ACLOCAL_AMFLAGS = -I $(top_srcdir) -I $(top_srcdir)/config
@LIBMPX_SUPPORTED_TRUE@libmpx_la_SOURCES = mpxrt.c mpxrt-utils.c
@LIBMPX_SUPPORTED_TRUE@libmpx_la_CFLAGS = -fPIC
@LIBMPX_SUPPORTED_TRUE@libmpx_la_DEPENDENCIES = libmpx.map
@LIBMPX_SUPPORTED_TRUE@libmpx_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpx.map $(link_libmpx)
@LIBMPX_SUPPORTED_TRUE@libmpx_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpx.map $(link_libmpx) \
@LIBMPX_SUPPORTED_TRUE@ -version-info `grep -v '^\#' $(srcdir)/libtool-version`
# Work around what appears to be a GNU make bug handling MAKEFLAGS
# values defined in terms of make variables, as is the case for CC and
......
......@@ -3,3 +3,8 @@ LIBMPX_1.0
local:
*;
};
LIBMPX_2.0
{
global:
get_bd;
} LIBMPX_1.0;
......@@ -3,4 +3,4 @@
# a separate file so that version updates don't involve re-running
# automake.
# CURRENT:REVISION:AGE
1:0:0
2:0:0
......@@ -51,34 +51,11 @@
#include <sys/prctl.h>
#include <cpuid.h>
#include "mpxrt-utils.h"
#ifdef __i386__
/* i386 directory size is 4MB */
#define NUM_L1_BITS 20
#define REG_IP_IDX REG_EIP
#define REX_PREFIX
#define XSAVE_OFFSET_IN_FPMEM sizeof (struct _libc_fpstate)
#else /* __i386__ */
/* x86_64 directory size is 2GB */
#define NUM_L1_BITS 28
#define REG_IP_IDX REG_RIP
#define REX_PREFIX "0x48, "
#define XSAVE_OFFSET_IN_FPMEM 0
#endif /* !__i386__ */
#include "mpxrt.h"
#define MPX_ENABLE_BIT_NO 0
#define BNDPRESERVE_BIT_NO 1
const size_t MPX_L1_SIZE = (1UL << NUM_L1_BITS) * sizeof (void *);
struct xsave_hdr_struct
{
uint64_t xstate_bv;
......@@ -508,3 +485,10 @@ mpxrt_cleanup (void)
__mpxrt_utils_free ();
process_specific_finish ();
}
/* Get address of bounds directory. */
void *
get_bd ()
{
return l1base;
}
/* mpxrt.h -*-C++-*-
*
*************************************************************************
*
* @copyright
* Copyright (C) 2015, Intel Corporation
* All rights reserved.
*
* @copyright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* @copyright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************/
#ifdef __i386__
/* i386 directory size is 4MB. */
#define NUM_L1_BITS 20
#define NUM_L2_BITS 10
#define NUM_IGN_BITS 2
#define MPX_L1_ADDR_MASK 0xfffff000UL
#define MPX_L2_ADDR_MASK 0xfffffffcUL
#define MPX_L2_VALID_MASK 0x00000001UL
#define REG_IP_IDX REG_EIP
#define REX_PREFIX
#define XSAVE_OFFSET_IN_FPMEM sizeof (struct _libc_fpstate)
#else /* __i386__ */
/* x86_64 directory size is 2GB. */
#define NUM_L1_BITS 28
#define NUM_L2_BITS 17
#define NUM_IGN_BITS 3
#define MPX_L1_ADDR_MASK 0xfffffffffffff000ULL
#define MPX_L2_ADDR_MASK 0xfffffffffffffff8ULL
#define MPX_L2_VALID_MASK 0x0000000000000001ULL
#define REG_IP_IDX REG_RIP
#define REX_PREFIX "0x48, "
#define XSAVE_OFFSET_IN_FPMEM 0
#endif /* !__i386__ */
#define MPX_L1_SIZE ((1UL << NUM_L1_BITS) * sizeof (void *))
/* Get address of bounds directory. */
void *
get_bd ();
ALCLOCAL_AMFLAGS = -I .. -I ../config
AM_CPPFLAGS = -I $(top_srcdir)
# May be used by toolexeclibdir.
gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
......@@ -6,7 +7,8 @@ gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
libmpxwrappers_la_CFLAGS = -fcheck-pointer-bounds -mmpx -fno-chkp-check-read \
-fno-chkp-check-write -fno-chkp-use-wrappers -fPIC
libmpxwrappers_la_DEPENDENCIES = libmpxwrappers.map
libmpxwrappers_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpxwrappers.map
libmpxwrappers_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpxwrappers.map \
-version-info `grep -v '^\#' $(srcdir)/libtool-version`
toolexeclib_LTLIBRARIES = libmpxwrappers.la
......
......@@ -221,7 +221,6 @@ install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
link_libmpx = @link_libmpx@
link_mpx = @link_mpx@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
......@@ -247,6 +246,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
ALCLOCAL_AMFLAGS = -I .. -I ../config
AM_CPPFLAGS = -I $(top_srcdir)
# May be used by toolexeclibdir.
gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
......@@ -254,7 +254,9 @@ libmpxwrappers_la_CFLAGS = -fcheck-pointer-bounds -mmpx -fno-chkp-check-read \
-fno-chkp-check-write -fno-chkp-use-wrappers -fPIC
libmpxwrappers_la_DEPENDENCIES = libmpxwrappers.map
libmpxwrappers_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpxwrappers.map
libmpxwrappers_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpxwrappers.map \
-version-info `grep -v '^\#' $(srcdir)/libtool-version`
toolexeclib_LTLIBRARIES = libmpxwrappers.la
libmpxwrappers_la_SOURCES = mpx_wrappers.c
......
......@@ -3,4 +3,4 @@
# a separate file so that version updates don't involve re-running
# automake.
# CURRENT:REVISION:AGE
1:0:0
2:0:0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment