From e5e391d630476b0ea2ff2dc01db7f8dfcb037974 Mon Sep 17 00:00:00 2001 From: Maxim Ostapenko Date: Wed, 25 Jan 2017 07:45:40 +0000 Subject: [PATCH] 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 --- gcc/ChangeLog | 7 +++++++ gcc/ada/ChangeLog | 6 ++++++ gcc/ada/gcc-interface/utils.c | 3 ++- gcc/asan.c | 25 ++++++++++++++++++++++++- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-decl.c | 3 ++- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 3 ++- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/f95-lang.c | 4 +++- 10 files changed, 64 insertions(+), 5 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c2962bb248f..6c41705f50c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-01-25 Maxim Ostapenko + + PR lto/79061 + * asan.c (get_translation_unit_decl): New function. + (asan_add_global): Extract modules file name from globals + TRANSLATION_UNIT_DECL name. + 2017-01-24 Eric Botcazou PR target/77439 diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 674ca6fd1c1..8f394b03ca9 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2017-01-25 Maxim Ostapenko + + PR lto/79061 + * gcc-interface/utils.c (get_global_context): Pass main_input_filename + to build_translation_unit_decl. + 2017-01-23 Javier Miranda * sem_util.adb (New_Copy_Tree): Code cleanup: diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 0ae381fea05..3cda63196e7 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -666,7 +666,8 @@ get_global_context (void) { if (!global_context) { - global_context = build_translation_unit_decl (NULL_TREE); + global_context + = build_translation_unit_decl (get_identifier (main_input_filename)); debug_hooks->register_main_translation_unit (global_context); } 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 *v) pp_string (&asan_pp, ""); 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)) diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index b17c179616d..16fb6f8a9f9 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2017-01-25 Maxim Ostapenko + + PR lto/79061 + * c-decl.c (pop_scope): Pass main_input_filename to + build_translation_unit_decl. + 2017-01-24 David Malcolm * c-parser.c: Include "read-rtl-function.h" and diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 2f91e706b4c..32edaccb51b 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -1177,7 +1177,8 @@ pop_scope (void) context = current_function_decl; else if (scope == file_scope) { - tree file_decl = build_translation_unit_decl (NULL_TREE); + tree file_decl + = build_translation_unit_decl (get_identifier (main_input_filename)); context = file_decl; debug_hooks->register_main_translation_unit (file_decl); } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 05c6b609888..47eaa55032f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-01-25 Maxim Ostapenko + + PR lto/79061 + * decl.c (cxx_init_decl_processing): Pass main_input_filename + to build_translation_unit_decl. + 2017-01-24 Jakub Jelinek PR c++/79205 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 792ebcc978c..af74dcdb705 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4071,7 +4071,8 @@ cxx_init_decl_processing (void) gcc_assert (global_namespace == NULL_TREE); global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name, void_type_node); - DECL_CONTEXT (global_namespace) = build_translation_unit_decl (NULL_TREE); + DECL_CONTEXT (global_namespace) + = build_translation_unit_decl (get_identifier (main_input_filename)); debug_hooks->register_main_translation_unit (DECL_CONTEXT (global_namespace)); TREE_PUBLIC (global_namespace) = 1; diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d6ebd797b8c..ff47dc4d1ba 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-01-25 Maxim Ostapenko + + PR lto/79061 + * f95-lang.c (gfc_create_decls): Include stringpool.h. + Pass main_input_filename to build_translation_unit_decl. + 2017-01-23 Thomas Koenig * arith.c (arith_power): If simplifying integer power expression diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index 98ef837cd07..44bd8dcc2ad 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "gfortran.h" #include "trans.h" +#include "stringpool.h" #include "diagnostic.h" /* For errorcount/warningcount */ #include "langhooks.h" #include "langhooks-def.h" @@ -190,7 +191,8 @@ gfc_create_decls (void) gfc_init_constants (); /* Build our translation-unit decl. */ - current_translation_unit = build_translation_unit_decl (NULL_TREE); + current_translation_unit + = build_translation_unit_decl (get_identifier (main_input_filename)); debug_hooks->register_main_translation_unit (current_translation_unit); } -- 2.30.2