diff mbox

[v2,PR,lto/79061] Fix LTO plus ASAN fails with "AddressSanitizer: initialization-order-fiasco".

Message ID 58872826.1050301@samsung.com
State New
Headers show

Commit Message

Maxim Ostapenko Jan. 24, 2017, 10:10 a.m. UTC
Hi,

as Richard pointed out in previous mail, v1 patch regresses compile-time 
by 100% on some fortran cases (PR 79165).
Doing the linemap operation in build_translation_unit_decl confuses the 
linemap code too much, thus we propagate main_input_filename through 
DECL_NAME of TRANSLATION_UNIT_DECL instead of creating new source location.
OK to install if regtest and bootstrap complete successfully? I've also 
checked that new patch doesn't introduce compile-time regression on 
aermod.f90 testcase.

Thanks,
-Maxim

Comments

Richard Biener Jan. 24, 2017, 10:20 a.m. UTC | #1
On Tue, 24 Jan 2017, Maxim Ostapenko wrote:

> Hi,
> 
> as Richard pointed out in previous mail, v1 patch regresses compile-time by
> 100% on some fortran cases (PR 79165).
> Doing the linemap operation in build_translation_unit_decl confuses the
> linemap code too much, thus we propagate main_input_filename through DECL_NAME
> of TRANSLATION_UNIT_DECL instead of creating new source location.
> OK to install if regtest and bootstrap complete successfully? I've also
> checked that new patch doesn't introduce compile-time regression on aermod.f90
> testcase.

+      const_tree translation_unit_decl = get_translation_unit_decl 
(decl);
+      if (translation_unit_decl)
+       filename = IDENTIFIER_POINTER (DECL_NAME (translation_unit_decl));

please also check DECL_NAME is not NULL.

Ok with that change.

Thanks,
Richard.
 
> Thanks,
> -Maxim
>
Jakub Jelinek Jan. 24, 2017, 10:24 a.m. UTC | #2
On Tue, Jan 24, 2017 at 01:10:46PM +0300, Maxim Ostapenko wrote:
> gcc/fortran/ChangeLog:
> 
> 2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>
> 
> 	* f95-lang.c (gfc_create_decls): Include stringpool.h.
> 	Pass main_input_filename to build_translation_unit_decl.
> 
> gcc/ada/ChangeLog:
> 
> 2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>
> 
> 	* gcc-interface/utils.c (get_global_context): pass main_input_filename
> 	to build_translation_unit_decl.

s/pass/Pass/, after ): ChangeLog entries start with capital letter.

> gcc/c/ChangeLog:
> 
> 2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>
> 
> 	* c-decl.c (pop_scope): pass main_input_filename to
> 	build_translation_unit_decl.
> 
> gcc/cp/ChangeLog:
> 
> 2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>
> 
> 	* decl.c (cxx_init_decl_processing): pass main_input_filename
> 	to build_translation_unit_decl.

Likewise 2x.
> 
> gcc/ChangeLog:
> 
> 2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>
> 
> 	* asan.c (get_translation_unit_decl): New function.
> 	(asan_add_global): Extract modules file name from globals
> 	TRANSLATION_UNIT_DECL name.

Ok for trunk with that.

	Jakub
diff mbox

Patch

gcc/fortran/ChangeLog:

2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>

	* f95-lang.c (gfc_create_decls): Include stringpool.h.
	Pass main_input_filename to build_translation_unit_decl.

gcc/ada/ChangeLog:

2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>

	* gcc-interface/utils.c (get_global_context): pass main_input_filename
	to build_translation_unit_decl.

gcc/c/ChangeLog:

2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>

	* c-decl.c (pop_scope): pass main_input_filename to
	build_translation_unit_decl.

gcc/cp/ChangeLog:

2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>

	* decl.c (cxx_init_decl_processing): pass main_input_filename
	to build_translation_unit_decl.

gcc/ChangeLog:

2017-01-24  Maxim Ostapenko  <m.ostapenko@samsung.com>

	* asan.c (get_translation_unit_decl): New function.
	(asan_add_global): Extract modules file name from globals
	TRANSLATION_UNIT_DECL name.

diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index 0ae381f..3cda631 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 486ebfd..e1475bd 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)
+	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/c-decl.c b/gcc/c/c-decl.c
index 2f91e70..32edacc 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/decl.c b/gcc/cp/decl.c
index 792ebcc..af74dcd 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/f95-lang.c b/gcc/fortran/f95-lang.c
index 98ef837..44bd8dc 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);
 }