]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR sanitizer/85018 (Many sanitizer tests ICE since r258681)
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jun 2018 20:51:42 +0000 (22:51 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 20:51:42 +0000 (22:51 +0200)
Backported from mainline
2018-03-22  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/85018
* dwarf2asm.c (dw2_output_indirect_constant_1): Set
DECL_INITIAL (decl) to decl at the end.
* varasm.c (use_blocks_for_decl_p): Revert the 2018-03-20 change,
adjust the comment.

2018-03-20  Jakub Jelinek  <jakub@redhat.com>

PR target/84990
* dwarf2asm.c (dw2_output_indirect_constant_1): Temporarily turn off
flag_section_anchors.
* varasm.c (use_blocks_for_decl_p): Remove hack for
dw2_force_const_mem.

2018-03-19  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/78651
* dwarf2asm.c: Include fold-const.c.
(dw2_output_indirect_constant_1): Set DECL_INITIAL (decl) to ADDR_EXPR
of decl rather than decl itself.

2018-03-19  Maxim Ostapenko  <m.ostapenko@samsung.com>

PR sanitizer/78651
* dwarf2asm.c (dw2_output_indirect_constant_1): Disable ASan before
calling assemble_variable.

* g++.dg/asan/pr78651.C: New test.

From-SVN: r261930

gcc/ChangeLog
gcc/dwarf2asm.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/asan/pr78651.C [new file with mode: 0644]
gcc/varasm.c

index 6ac9e4082516e6a5032420c1465a297f0b08d103..61772122ef37bce54bcc49cda129e271d1e0e32c 100644 (file)
@@ -1,6 +1,35 @@
 2018-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-03-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/85018
+       * dwarf2asm.c (dw2_output_indirect_constant_1): Set
+       DECL_INITIAL (decl) to decl at the end.
+       * varasm.c (use_blocks_for_decl_p): Revert the 2018-03-20 change,
+       adjust the comment.
+
+       2018-03-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/84990
+       * dwarf2asm.c (dw2_output_indirect_constant_1): Temporarily turn off
+       flag_section_anchors.
+       * varasm.c (use_blocks_for_decl_p): Remove hack for
+       dw2_force_const_mem.
+
+       2018-03-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/78651
+       * dwarf2asm.c: Include fold-const.c.
+       (dw2_output_indirect_constant_1): Set DECL_INITIAL (decl) to ADDR_EXPR
+       of decl rather than decl itself.
+
+       2018-03-19  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       PR sanitizer/78651
+       * dwarf2asm.c (dw2_output_indirect_constant_1): Disable ASan before
+       calling assemble_variable.
+
        2018-03-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/84899
index 8e3e86f224c1e02d481a0b4992eaad0b408efe04..d5d0cfb0e8d45b6658900e311878332c5eea26ba 100644 (file)
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dwarf2.h"
 #include "function.h"
 #include "emit-rtl.h"
+#include "fold-const.h"
 
 #ifndef XCOFF_DEBUGGING_INFO
 #define XCOFF_DEBUGGING_INFO 0
@@ -925,7 +926,7 @@ dw2_output_indirect_constant_1 (const char *sym, tree id)
   SET_DECL_ASSEMBLER_NAME (decl, id);
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
-  DECL_INITIAL (decl) = decl;
+  DECL_INITIAL (decl) = build_fold_addr_expr (decl);
   TREE_READONLY (decl) = 1;
   TREE_STATIC (decl) = 1;
 
@@ -938,8 +939,23 @@ dw2_output_indirect_constant_1 (const char *sym, tree id)
     }
 
   sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
+  /* Disable ASan for decl because redzones cause ABI breakage between GCC and
+     libstdc++ for `.LDFCM*' variables.  See PR 78651 for details.  */
+  unsigned int save_flag_sanitize = flag_sanitize;
+  flag_sanitize &= ~(SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS
+                    | SANITIZE_KERNEL_ADDRESS);
+  /* And also temporarily disable -fsection-anchors.  These indirect constants
+     are never referenced from code, so it doesn't make any sense to aggregate
+     them in blocks.  */
+  int save_flag_section_anchors = flag_section_anchors;
+  flag_section_anchors = 0;
   assemble_variable (decl, 1, 1, 1);
+  flag_section_anchors = save_flag_section_anchors;
+  flag_sanitize = save_flag_sanitize;
   assemble_integer (sym_ref, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
+  /* The following is a hack recognized by use_blocks_for_decl_p to disable
+     section anchor handling of the decl.  */
+  DECL_INITIAL (decl) = decl;
 
   return 0;
 }
index 9580923bb6cda3ec1828f4363c5e0963d8fe549e..7fbcb42af6fb623a3b5e73a5112f7a6e6119d725 100644 (file)
@@ -1,6 +1,11 @@
 2018-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-03-19  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       PR sanitizer/78651
+       * g++.dg/asan/pr78651.C: New test.
+
        2018-03-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/84899
diff --git a/gcc/testsuite/g++.dg/asan/pr78651.C b/gcc/testsuite/g++.dg/asan/pr78651.C
new file mode 100644 (file)
index 0000000..09f1be5
--- /dev/null
@@ -0,0 +1,26 @@
+// PR sanitizer/78651
+// { dg-do run }
+// { dg-additional-options "-fpic" { target fpic } }
+
+struct A { };
+
+namespace {
+
+void thisThrows () {
+  throw A();
+}
+
+struct SomeRandomType {};
+}
+
+int main() {
+  try {
+    thisThrows();
+  }
+  catch (SomeRandomType) {
+    throw;
+  }
+  catch (A) {
+  }
+  return 0;
+}
index e240ba7743049b95df560771bb94b55797fa19a4..9ffef8abe3844794e24aa79eddd5d4c47b0478c0 100644 (file)
@@ -1241,10 +1241,9 @@ use_blocks_for_decl_p (tree decl)
   if (!VAR_P (decl) && TREE_CODE (decl) != CONST_DECL)
     return false;
 
-  /* Detect decls created by dw2_force_const_mem.  Such decls are
-     special because DECL_INITIAL doesn't specify the decl's true value.
-     dw2_output_indirect_constants will instead call assemble_variable
-     with dont_output_data set to 1 and then print the contents itself.  */
+  /* DECL_INITIAL (decl) set to decl is a hack used for some decls that
+     are never used from code directly and we never want object block handling
+     for those.  */
   if (DECL_INITIAL (decl) == decl)
     return false;