From 47a113429b00669d57bbea6aa84f51e4c4869592 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 5 Apr 2017 15:17:15 +0200 Subject: [PATCH] re PR sanitizer/80308 (asan crash on big-endian powerpc-linux target) PR sanitizer/80308 * asan.c (asan_store_shadow_bytes): Fix location of last_chunk_value for big endian. * c-c++-common/asan/pr80308.c: New test. Co-Authored-By: Bernd Edlinger From-SVN: r246703 --- gcc/ChangeLog | 7 +++++++ gcc/asan.c | 5 ++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/asan/pr80308.c | 25 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/asan/pr80308.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 873d0bcc3e7..0158a389ad7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-04-05 Jakub Jelinek + Bernd Edlinger + + PR sanitizer/80308 + * asan.c (asan_store_shadow_bytes): Fix location of last_chunk_value + for big endian. + 2017-04-05 Eric Botcazou PR target/78002 diff --git a/gcc/asan.c b/gcc/asan.c index f1098cbffac..bf564a46b28 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -2757,10 +2757,13 @@ asan_store_shadow_bytes (gimple_stmt_iterator *iter, location_t loc, unsigned char c = (char) is_clobber ? ASAN_STACK_MAGIC_USE_AFTER_SCOPE : 0; unsigned HOST_WIDE_INT val = 0; + unsigned last_pos = size; + if (last_chunk_size && !is_clobber) + last_pos = BYTES_BIG_ENDIAN ? 0 : size - 1; for (unsigned i = 0; i < size; ++i) { unsigned char shadow_c = c; - if (i == size - 1 && last_chunk_size && !is_clobber) + if (i == last_pos) shadow_c = last_chunk_size; val |= (unsigned HOST_WIDE_INT) shadow_c << (BITS_PER_UNIT * i); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 98aa5c0b6da..b0c764f3949 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-05 Jakub Jelinek + + PR sanitizer/80308 + * c-c++-common/asan/pr80308.c: New test. + 2017-04-05 Dominik Vogt PR target/79890 diff --git a/gcc/testsuite/c-c++-common/asan/pr80308.c b/gcc/testsuite/c-c++-common/asan/pr80308.c new file mode 100644 index 00000000000..bcfa6ae4ab4 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr80308.c @@ -0,0 +1,25 @@ +/* PR sanitizer/80308 */ +/* { dg-do run } */ + +__attribute__((noinline, noclone)) int +foo (char *a) +{ + int i, j = 0; + asm volatile ("" : "+r" (a) : : "memory"); + for (i = 0; i < 12; i++) + j += a[i]; + return j; +} + +int +main () +{ + int i, j = 0; + for (i = 0; i < 4; i++) + { + char a[12]; + __builtin_memset (a, 0, sizeof (a)); + j += foo (a); + } + return j; +} -- 2.30.2