public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix asan create_odr_indicator (PR sanitizer/81923)
@ 2017-09-01 11:48 Jakub Jelinek
  2017-09-01 12:29 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-09-01 11:48 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

glibc fails to build with -fsanitize=address, because DECL_ASSEMBLER_NAME
on some variables starts with the * character (e.g. for vars with __asm
specified names).  We need to strip name encoding from those before
appending after __odr_asan. Fixed thusly, bootstrapped/regtested on
x86_64-linux and i686-linux, ok for trunk?

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_.

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

--- gcc/asan.c.jj	2017-08-10 02:31:21.000000000 +0200
+++ gcc/asan.c	2017-08-29 17:25:58.337595628 +0200
@@ -2529,9 +2529,12 @@ create_odr_indicator (tree decl, tree ty
   /* 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)
--- gcc/testsuite/gcc.dg/asan/pr81923.c.jj	2017-08-29 18:08:59.183881570 +0200
+++ gcc/testsuite/gcc.dg/asan/pr81923.c	2017-08-29 18:09:27.643550083 +0200
@@ -0,0 +1,10 @@
+/* PR sanitizer/81923 */
+/* { dg-do link } */
+
+int foobar __asm (__USER_LABEL_PREFIX__ "barbaz") = 34;
+
+int
+main ()
+{
+  return 0;
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix asan create_odr_indicator (PR sanitizer/81923)
  2017-09-01 11:48 [PATCH] Fix asan create_odr_indicator (PR sanitizer/81923) Jakub Jelinek
@ 2017-09-01 12:29 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-09-01 12:29 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On September 1, 2017 1:48:04 PM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>glibc fails to build with -fsanitize=address, because
>DECL_ASSEMBLER_NAME
>on some variables starts with the * character (e.g. for vars with __asm
>specified names).  We need to strip name encoding from those before
>appending after __odr_asan. Fixed thusly, bootstrapped/regtested on
>x86_64-linux and i686-linux, ok for trunk?

OK. 

Richard. 

>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_.
>
>	* gcc.dg/asan/pr81923.c: New test.
>
>--- gcc/asan.c.jj	2017-08-10 02:31:21.000000000 +0200
>+++ gcc/asan.c	2017-08-29 17:25:58.337595628 +0200
>@@ -2529,9 +2529,12 @@ create_odr_indicator (tree decl, tree ty
>/* 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)
>--- gcc/testsuite/gcc.dg/asan/pr81923.c.jj	2017-08-29
>18:08:59.183881570 +0200
>+++ gcc/testsuite/gcc.dg/asan/pr81923.c	2017-08-29 18:09:27.643550083
>+0200
>@@ -0,0 +1,10 @@
>+/* PR sanitizer/81923 */
>+/* { dg-do link } */
>+
>+int foobar __asm (__USER_LABEL_PREFIX__ "barbaz") = 34;
>+
>+int
>+main ()
>+{
>+  return 0;
>+}
>
>	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-01 12:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-01 11:48 [PATCH] Fix asan create_odr_indicator (PR sanitizer/81923) Jakub Jelinek
2017-09-01 12:29 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).