summaryrefslogtreecommitdiff
path: root/gcc/asan.c
diff options
context:
space:
mode:
authorMaxim Ostapenko <m.ostapenko@samsung.com>2017-01-25 07:45:40 +0000
committerMaxim Ostapenko <chefmax@gcc.gnu.org>2017-01-25 09:45:40 +0200
commite5e391d630476b0ea2ff2dc01db7f8dfcb037974 (patch)
tree7dea5db302e97ca5ad9684bbe3f3cfc517681e41 /gcc/asan.c
parent98e20758464f5cbfc60bd61a0cadd66ebb900d96 (diff)
downloadgcc-e5e391d630476b0ea2ff2dc01db7f8dfcb037974.tar.gz
re PR lto/79061 ([LTO][ASAN] LTO plus ASAN fails with "AddressSanitizer: initialization-order-fiasco")
PR lto/79061 gcc/ * asan.c (get_translation_unit_decl): New function. (asan_add_global): Extract modules file name from globals TRANSLATION_UNIT_DECL name. gcc/fortran/ * f95-lang.c (gfc_create_decls): Include stringpool.h. Pass main_input_filename to build_translation_unit_decl. gcc/ada/ * gcc-interface/utils.c (get_global_context): Pass main_input_filename to build_translation_unit_decl. gcc/c/ * c-decl.c (pop_scope): Pass main_input_filename to build_translation_unit_decl. gcc/cp/ * decl.c (cxx_init_decl_processing): Pass main_input_filename to build_translation_unit_decl. From-SVN: r244890
Diffstat (limited to 'gcc/asan.c')
-rw-r--r--gcc/asan.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/gcc/asan.c b/gcc/asan.c
index 486ebfdb6af..9098121be8b 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -2373,6 +2373,22 @@ asan_needs_odr_indicator_p (tree decl)
&& TREE_PUBLIC (decl));
}
+/* For given DECL return its corresponding TRANSLATION_UNIT_DECL. */
+
+static const_tree
+get_translation_unit_decl (tree decl)
+{
+ const_tree context = decl;
+ while (context && TREE_CODE (context) != TRANSLATION_UNIT_DECL)
+ {
+ if (TREE_CODE (context) == BLOCK)
+ context = BLOCK_SUPERCONTEXT (context);
+ else
+ context = get_containing_scope (context);
+ }
+ return context;
+}
+
/* Append description of a single global DECL into vector V.
TYPE is __asan_global struct type as returned by asan_global_struct. */
@@ -2392,7 +2408,14 @@ asan_add_global (tree decl, tree type, vec<constructor_elt, va_gc> *v)
pp_string (&asan_pp, "<unknown>");
str_cst = asan_pp_string (&asan_pp);
- pp_string (&module_name_pp, main_input_filename);
+ const char *filename = main_input_filename;
+ if (in_lto_p)
+ {
+ const_tree translation_unit_decl = get_translation_unit_decl (decl);
+ if (translation_unit_decl && DECL_NAME (translation_unit_decl) != NULL)
+ filename = IDENTIFIER_POINTER (DECL_NAME (translation_unit_decl));
+ }
+ pp_string (&module_name_pp, filename);
module_name_cst = asan_pp_string (&module_name_pp);
if (asan_needs_local_alias (decl))