re PR sanitizer/81923 ([ASAN] gcc emites wrong odr asan instrumentation for glibc)
authorJakub Jelinek <jakub@redhat.com>
Fri, 1 Sep 2017 13:46:14 +0000 (15:46 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 1 Sep 2017 13:46:14 +0000 (15:46 +0200)
PR sanitizer/81923
* asan.c (create_odr_indicator): Strip name encoding from assembler
name before appending it after __odr_asan_.

* gcc.dg/asan/pr81923.c: New test.

From-SVN: r251595

gcc/ChangeLog
gcc/asan.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/asan/pr81923.c [new file with mode: 0644]

index 125eb928211b386f3840e368d6a543b7e99f48ff..8d36fa6563d6f9d7a7dcb45aba8f274c1d3f4933 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/81923
+       * asan.c (create_odr_indicator): Strip name encoding from assembler
+       name before appending it after __odr_asan_.
+
 2017-09-01  Martin Liska  <mliska@suse.cz>
 
        PR tree-optimization/82059
index ce1e0244ec68791d21b3b9b0c025adc5806d03fb..9f29491a7c39b9b0ae79cee147a8b2aaafa221c5 100644 (file)
@@ -2527,9 +2527,12 @@ create_odr_indicator (tree decl, tree type)
   /* DECL_NAME theoretically might be NULL.  Bail out with 0 in this case.  */
   if (decl_name == NULL_TREE)
     return build_int_cst (uptr, 0);
-  size_t len = strlen (IDENTIFIER_POINTER (decl_name)) + sizeof ("__odr_asan_");
+  const char *dname = IDENTIFIER_POINTER (decl_name);
+  if (HAS_DECL_ASSEMBLER_NAME_P (decl))
+    dname = targetm.strip_name_encoding (dname);
+  size_t len = strlen (dname) + sizeof ("__odr_asan_");
   name = XALLOCAVEC (char, len);
-  snprintf (name, len, "__odr_asan_%s", IDENTIFIER_POINTER (decl_name));
+  snprintf (name, len, "__odr_asan_%s", dname);
 #ifndef NO_DOT_IN_LABEL
   name[sizeof ("__odr_asan") - 1] = '.';
 #elif !defined(NO_DOLLAR_IN_LABEL)
index 0cd2a62e5e5d98fa82d829570738d7f37b76b543..b304563483805d8a1fd4e330d83f6f26673c098a 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/81923
+       * gcc.dg/asan/pr81923.c: New test.
+
 2017-09-01  Martin Liska  <mliska@suse.cz>
 
        PR tree-optimization/82059
diff --git a/gcc/testsuite/gcc.dg/asan/pr81923.c b/gcc/testsuite/gcc.dg/asan/pr81923.c
new file mode 100644 (file)
index 0000000..f81d512
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR sanitizer/81923 */
+/* { dg-do link } */
+
+int foobar __asm (__USER_LABEL_PREFIX__ "barbaz") = 34;
+
+int
+main ()
+{
+  return 0;
+}