Backport from GCC mainline.
authorIvan Baravy <i.baravy@samsung.com>
Mon, 27 Feb 2017 07:52:50 +0000 (10:52 +0300)
committerIvan Baravy <i.baravy@samsung.com>
Mon, 27 Feb 2017 07:52:50 +0000 (10:52 +0300)
2016-06-10  Maxim Ostapenko  <m.ostapenko@samsung.com>

    PR sanitizer/71480
    * varasm.c (place_block_symbol): Adjust alignment for asan protected
    STRING_CSTs even if TREE_CONSTANT_POOL_ADDRESS_P.

    * c-c++-common/asan/pr71480.c: New test.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/asan/pr71480.c [new file with mode: 0644]
gcc/varasm.c

index ac448c3..b765c86 100644 (file)
        * tree-ssa-tail-merge.c (same_succ::equal): Check pointer eq
        equality first.
 
+2016-06-10  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       PR sanitizer/71480
+       * varasm.c (place_block_symbol): Adjust alignment for asan protected
+       STRING_CSTs even if TREE_CONSTANT_POOL_ADDRESS_P.
+
 2016-06-09  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        Back port from trunk
index 63e81e8..e9cf664 100644 (file)
        * gfortran.dg/goacc/cray.f95: Likewise.
        * gfortran.dg/goacc/loop-1.f95: Likewise.
 
+2016-06-10  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       PR sanitizer/71480
+       * c-c++-common/asan/pr71480.c: New test.
+
 2016-06-09  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        Back port from trunk
diff --git a/gcc/testsuite/c-c++-common/asan/pr71480.c b/gcc/testsuite/c-c++-common/asan/pr71480.c
new file mode 100644 (file)
index 0000000..c23ea53
--- /dev/null
@@ -0,0 +1,42 @@
+/* { dg-do run } */
+
+__attribute__ ((noinline, noclone)) int
+foo (char *c)
+{
+  asm volatile ("" : : "r" (c) : "memory");
+  return 1;
+}
+
+__attribute__ ((noinline, noclone)) void
+bar (char *c)
+{
+  asm volatile ("" : : "r" (c) : "memory");
+}
+
+int main ()
+{
+  char tpl[20] = "/tmp/test.XXXXXX";
+  char tpl2[20] = "/tmp/test.XXXXXX";
+  int fd = foo (tpl);
+  int fd2 = foo (tpl2);
+  if (fd == -1)
+    {
+      if (fd2 != -1)
+        bar (tpl2);
+      return 1;
+    }
+
+  if (fd2 == -1)
+    return 1;
+
+  bar (tpl);
+  bar (tpl2);
+
+  if (__builtin_strcmp (tpl, "/tmp/test.XXXXXX") != 0)
+    return 1;
+
+  if (__builtin_strcmp (tpl, tpl2) != 0)
+    return 1;
+
+   return 0;
+}
index d766aea..da88f5b 100644 (file)
@@ -7206,7 +7206,11 @@ place_block_symbol (rtx symbol)
       if ((flag_sanitize & SANITIZE_ADDRESS)
          && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
          && asan_protect_global (DECL_INITIAL (decl)))
-       size += asan_red_zone_size (size);
+       {
+         size += asan_red_zone_size (size);
+         alignment = MAX (alignment,
+                          ASAN_RED_ZONE_SIZE * BITS_PER_UNIT);
+       }
     }
   else
     {