From bffa6b6c6214169d8d10f05a418f9f072235f068 Mon Sep 17 00:00:00 2001 From: Alexander Ivchenko Date: Tue, 27 Dec 2016 15:35:19 +0000 Subject: [PATCH] libtool-version: New version. libmpx/ 2016-12-27 H.J. Lu Alexander Ivchenko * mpxwrap/libtool-version: New version. * mpxwrap/mpx_wrappers.c (__mpx_wrapper_realloc): Make it static with external alias. (__mpx_wrapper_bzero): Ditto. (mpx_wrapper_memcpy): Ditto. (__mpx_wrapper_mempcpy): Ditto. From-SVN: r243942 --- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.target/i386/mpx/memcpy-1.c | 23 +++++++++++++ libmpx/ChangeLog | 10 ++++++ libmpx/mpxwrap/libtool-version | 2 +- libmpx/mpxwrap/mpx_wrappers.c | 35 +++++++++++++------- 5 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/mpx/memcpy-1.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6fb5b258287..fd5ca94eb65 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,10 @@ PR target/78904 * gcc.target/i386/pr78904-3.c: New test. +2016-12-27 Alexander Ivchenko + + * gcc.target/i386/mpx/memcpy-1.c: New test. + 2016-12-27 Alexander Ivchenko * gcc.target/i386/mpx/vla-trailing-1-lbv.c: New test. diff --git a/gcc/testsuite/gcc.target/i386/mpx/memcpy-1.c b/gcc/testsuite/gcc.target/i386/mpx/memcpy-1.c new file mode 100644 index 00000000000..169134829aa --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/mpx/memcpy-1.c @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-shouldfail "bounds violation" } */ +/* { dg-options "-fcheck-pointer-bounds -mmpx" } */ + +/* Fix for PR78631 */ + +#define SHOULDFAIL + +#include +#include + +char s[10]; +char d[10]; +__attribute__((noinline)) + +char* foo(char* dst, char* src, size_t size) { + return memcpy(dst, src, size); +} +int main() { + char* r = foo(d, s, 11); + printf("r = %p\n", r); + return 0; +} diff --git a/libmpx/ChangeLog b/libmpx/ChangeLog index 4f7a68425da..67ae96a352e 100644 --- a/libmpx/ChangeLog +++ b/libmpx/ChangeLog @@ -1,3 +1,13 @@ +2016-12-27 H.J. Lu + Alexander Ivchenko + + * mpxwrap/libtool-version: New version. + * mpxwrap/mpx_wrappers.c (__mpx_wrapper_realloc): Make it + static with external alias. + (__mpx_wrapper_bzero): Ditto. + (mpx_wrapper_memcpy): Ditto. + (__mpx_wrapper_mempcpy): Ditto. + 2016-12-26 Alexander Ivchenko * mpxrt/libtool-version: New version. diff --git a/libmpx/mpxwrap/libtool-version b/libmpx/mpxwrap/libtool-version index fab30fb091d..e241350d23b 100644 --- a/libmpx/mpxwrap/libtool-version +++ b/libmpx/mpxwrap/libtool-version @@ -3,4 +3,4 @@ # a separate file so that version updates don't involve re-running # automake. # CURRENT:REVISION:AGE -2:0:0 +2:1:0 diff --git a/libmpx/mpxwrap/mpx_wrappers.c b/libmpx/mpxwrap/mpx_wrappers.c index 171a780311d..aea0346b933 100644 --- a/libmpx/mpxwrap/mpx_wrappers.c +++ b/libmpx/mpxwrap/mpx_wrappers.c @@ -30,14 +30,20 @@ #include #include "mpxrt/mpxrt.h" -void * -__mpx_wrapper_malloc (size_t size) +/* Since internal MPX wrapper calls must avoid PLT which will clear bound + registers, we make them static with an external alias. */ +#define EXTERN_ALIAS(f) \ + __typeof (f) __##f __attribute__((alias(#f))); + +static void * +mpx_wrapper_malloc (size_t size) { void *p = (void *)malloc (size); if (!p) return __bnd_null_ptr_bounds (p); return __bnd_set_ptr_bounds (p, size); } +EXTERN_ALIAS (mpx_wrapper_malloc) void * __mpx_wrapper_mmap (void *addr, size_t length, int prot, int flags, @@ -52,7 +58,7 @@ void * __mpx_wrapper_realloc (void *ptr, size_t n) { if (!ptr) - return __mpx_wrapper_malloc (n); + return mpx_wrapper_malloc (n); /* We don't kwnow how much data is copied by realloc and therefore may check only lower bounds. */ @@ -74,8 +80,8 @@ __mpx_wrapper_calloc (size_t n_elements, size_t element_size) return __bnd_set_ptr_bounds (p, n_elements * element_size); } -void * -__mpx_wrapper_memset (void *dstpp, int c, size_t len) +static void * +mpx_wrapper_memset (void *dstpp, int c, size_t len) { if (len > 0) { @@ -85,10 +91,12 @@ __mpx_wrapper_memset (void *dstpp, int c, size_t len) return dstpp; } +EXTERN_ALIAS (mpx_wrapper_memset) + void __mpx_wrapper_bzero (void *dst, size_t len) { - __mpx_wrapper_memset (dst, 0, len); + mpx_wrapper_memset (dst, 0, len); } /* The mpx_pointer type is used for getting bits @@ -484,8 +492,8 @@ move_bounds (void *dst, const void *src, size_t n) return; } -void * -__mpx_wrapper_memmove (void *dst, const void *src, size_t n) +static void * +mpx_wrapper_memmove (void *dst, const void *src, size_t n) { if (n == 0) return dst; @@ -513,17 +521,20 @@ __mpx_wrapper_memmove (void *dst, const void *src, size_t n) return dst; } +EXTERN_ALIAS (mpx_wrapper_memmove) -void * -__mpx_wrapper_memcpy (void *dst, const void *src, size_t n) +static void * +mpx_wrapper_memcpy (void *dst, const void *src, size_t n) { - return __mpx_wrapper_memmove (dst, src, n); + return mpx_wrapper_memmove (dst, src, n); } +EXTERN_ALIAS (mpx_wrapper_memcpy) + void * __mpx_wrapper_mempcpy (void *dst, const void *src, size_t n) { - return (char *)__mpx_wrapper_memcpy (dst, src, n) + n; + return (char *)mpx_wrapper_memcpy (dst, src, n) + n; } char * -- 2.30.2