From: Jakub Jelinek Date: Tue, 30 May 2017 07:34:46 +0000 (+0200) Subject: backport: re PR sanitizer/66343 ("Error: .Lubsan_type3 already defined" with UBSan... X-Git-Tag: releases/gcc-5.5.0~294 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39d9411b3946897ecdcf44437d987297b3df59c8;p=thirdparty%2Fgcc.git backport: re PR sanitizer/66343 ("Error: .Lubsan_type3 already defined" with UBSan and precompiled headers) Backported from mainline 2016-10-05 Jakub Jelinek PR sanitizer/66343 * ubsan.c (ubsan_ids): New GTY(()) array. (ubsan_type_descriptor, ubsan_create_data): Use ubsan_ids instead of static local counters. * gcc.dg/pch/pr66343-1.c: New test. * gcc.dg/pch/pr66343-1.hs: New file. * gcc.dg/pch/pr66343-2.c: New test. * gcc.dg/pch/pr66343-2.hs: New file. From-SVN: r248616 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2469b119dd49..91ed67aba02c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,13 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2016-10-05 Jakub Jelinek + + PR sanitizer/66343 + * ubsan.c (ubsan_ids): New GTY(()) array. + (ubsan_type_descriptor, ubsan_create_data): Use ubsan_ids + instead of static local counters. + 2016-09-22 Jakub Jelinek PR fortran/77665 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5afc61bdade3..6bf50d262f59 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,14 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2016-10-05 Jakub Jelinek + + PR sanitizer/66343 + * gcc.dg/pch/pr66343-1.c: New test. + * gcc.dg/pch/pr66343-1.hs: New file. + * gcc.dg/pch/pr66343-2.c: New test. + * gcc.dg/pch/pr66343-2.hs: New file. + 2016-09-28 Jakub Jelinek PR c++/77467 diff --git a/gcc/testsuite/gcc.dg/pch/pr66343-1.c b/gcc/testsuite/gcc.dg/pch/pr66343-1.c new file mode 100644 index 000000000000..851f6d9493f5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/pr66343-1.c @@ -0,0 +1,15 @@ +/* PR sanitizer/66343 */ +/* { dg-do assemble } */ +/* { dg-options "-fsanitize=undefined" } */ + +#include "pr66343-1.h" + +void +bar (int a, int b) +{ + a / b; +} + +/* Hack to turn off PCH assembly comparison, as it is incompatible + with dg-do assemble. The target condition will be always false. */ +/* { dg-error "" "" { target { lp64 && { ! lp64 } } } } */ diff --git a/gcc/testsuite/gcc.dg/pch/pr66343-1.hs b/gcc/testsuite/gcc.dg/pch/pr66343-1.hs new file mode 100644 index 000000000000..643a821d5cef --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/pr66343-1.hs @@ -0,0 +1,8 @@ +/* PR sanitizer/66343 */ +/* { dg-options "-fsanitize=undefined" } */ + +void +foo (int a, int b) +{ + a / b; +} diff --git a/gcc/testsuite/gcc.dg/pch/pr66343-2.c b/gcc/testsuite/gcc.dg/pch/pr66343-2.c new file mode 100644 index 000000000000..a86e61d1fe62 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/pr66343-2.c @@ -0,0 +1,10 @@ +/* PR sanitizer/66343 */ +/* { dg-options "-fsanitize=undefined" } */ + +#include "pr66343-2.h" + +void +bar (int a, int b) +{ + a / b; +} diff --git a/gcc/testsuite/gcc.dg/pch/pr66343-2.hs b/gcc/testsuite/gcc.dg/pch/pr66343-2.hs new file mode 100644 index 000000000000..643a821d5cef --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/pr66343-2.hs @@ -0,0 +1,8 @@ +/* PR sanitizer/66343 */ +/* { dg-options "-fsanitize=undefined" } */ + +void +foo (int a, int b) +{ + a / b; +} diff --git a/gcc/ubsan.c b/gcc/ubsan.c index ab563d7a9216..d471afc0334d 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -365,6 +365,10 @@ get_ubsan_type_info_for_type (tree type) return 0; } +/* Counters for internal labels. ubsan_ids[0] for Lubsan_type, + ubsan_ids[1] for Lubsan_data labels. */ +static GTY(()) unsigned int ubsan_ids[2]; + /* Helper routine that returns ADDR_EXPR of a VAR_DECL of a type descriptor. It first looks into the hash table; if not found, create the VAR_DECL, put it into the hash table and return the @@ -512,10 +516,9 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle) TREE_STATIC (str) = 1; char tmp_name[32]; - static unsigned int type_var_id_num; - ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_type", type_var_id_num++); + ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_type", ubsan_ids[0]++); decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name), - dtype); + dtype); TREE_STATIC (decl) = 1; TREE_PUBLIC (decl) = 0; DECL_ARTIFICIAL (decl) = 1; @@ -615,8 +618,7 @@ ubsan_create_data (const char *name, int loccnt, const location_t *ploc, ...) /* Now, fill in the type. */ char tmp_name[32]; - static unsigned int ubsan_var_id_num; - ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_data", ubsan_var_id_num++); + ASM_GENERATE_INTERNAL_LABEL (tmp_name, "Lubsan_data", ubsan_ids[1]++); tree var = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (tmp_name), ret); TREE_STATIC (var) = 1;