Message ID | 20170901114804.GI2323@tucnak |
---|---|
State | New |
Headers | show |
Series | Fix asan create_odr_indicator (PR sanitizer/81923) | expand |
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
--- 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; +}