re PR lto/79061 ([LTO][ASAN] LTO plus ASAN fails with "AddressSanitizer: initializati...
authorMaxim Ostapenko <m.ostapenko@samsung.com>
Wed, 25 Jan 2017 07:45:40 +0000 (07:45 +0000)
committerMaxim Ostapenko <chefmax@gcc.gnu.org>
Wed, 25 Jan 2017 07:45:40 +0000 (09:45 +0200)
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
gcc/ada/ChangeLog
gcc/ada/gcc-interface/utils.c
gcc/asan.c
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/fortran/ChangeLog
gcc/fortran/f95-lang.c

index c2962bb248f5c31b3a5ec1f6b0af295d1103e538..6c41705f50c7cbccf90562deb2e0e3e5e677d335 100644 (file)
@@ -1,3 +1,10 @@
+2017-01-25  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       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  <ebotcazou@adacore.com>
 
        PR target/77439
index 674ca6fd1c1eb8d8a5b8e3dbfb9a3bf6e880cc30..8f394b03ca902448f575c263ab924b5d38e7c9c2 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-25  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       PR lto/79061
+       * gcc-interface/utils.c (get_global_context): Pass main_input_filename
+       to build_translation_unit_decl.
+
 2017-01-23  Javier Miranda  <miranda@adacore.com>
 
        * sem_util.adb (New_Copy_Tree): Code cleanup:
index 0ae381fea05bb50755e49e423def52ce8c7f5ead..3cda63196e7e4a2a56a82c5b8c89f3ed14fe7754 100644 (file)
@@ -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);
     }
 
index 486ebfdb6af1603aee1f5ec2670d9781eb47b1d1..9098121be8bcaaa197ce778d227ca646c09568b1 100644 (file)
@@ -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))
index b17c179616d620cdff13df1cf324648575f613f1..16fb6f8a9f98c51dcbc68618b89be03500dd951c 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-25  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       PR lto/79061
+       * c-decl.c (pop_scope): Pass main_input_filename to
+       build_translation_unit_decl.
+
 2017-01-24  David Malcolm  <dmalcolm@redhat.com>
 
        * c-parser.c: Include "read-rtl-function.h" and
index 2f91e706b4c54ac48ca7e2585d84b7dfee8a88ae..32edaccb51bfc26dc009da7956ba18fea85de3d3 100644 (file)
@@ -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);
     }
index 05c6b6098882f68cbb59c58e5b6733a5a4d19b8a..47eaa55032fb0d155a8b193fbaf6441071a828e3 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-25  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       PR lto/79061
+       * decl.c (cxx_init_decl_processing): Pass main_input_filename
+       to build_translation_unit_decl.
+
 2017-01-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79205
index 792ebcc978c09810b42658c2ee4c73fc1e3d10ea..af74dcdb7059ee48f5ee8a1a4f5a2cf0a347f21e 100644 (file)
@@ -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;
index d6ebd797b8c97a70b35591867fa16587ebeb7be8..ff47dc4d1bad479a38106e46acd11fa4dbd37a13 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-25  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       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  <tkoenig@netcologne.de>
 
        * arith.c (arith_power):  If simplifying integer power expression
index 98ef837cd07f1a14741c993cd9dcadad4071bae5..44bd8dcc2ad028a8e1ec1cd477d9e8dc1790fb57 100644 (file)
@@ -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);
 }