The method implicit_variable_reference in the interface used between
the Go frontend and GCC proper creates a reference to a variable in a
different object file.  Unfortunately, ever since it was introduced,
it has incorrectly cleared DECL_EXTERNAL and set TREE_STATIC.  I'm not
entirely sure why this has been working.  However, it does break LTO,
as seen in PR 64238.  It is fixed by this simple patch.  Bootstrapped
and ran Go testsuite on x86_64-pc-linux-gnu.  Applied to mainline and
GCC 7 and 6 branches.

Ian

2017-05-11  Ian Lance Taylor  <i...@google.com>

PR go/64238
* go-gcc.cc (Gcc_backend::implicit_variable_reference): Set
DECL_EXTERNAL, clear TREE_STATIC.
Index: gcc/go/go-gcc.cc
===================================================================
--- gcc/go/go-gcc.cc    (revision 247848)
+++ gcc/go/go-gcc.cc    (working copy)
@@ -2822,9 +2822,9 @@ Gcc_backend::implicit_variable_reference
 
   tree decl = build_decl(BUILTINS_LOCATION, VAR_DECL,
                          get_identifier_from_string(name), type_tree);
-  DECL_EXTERNAL(decl) = 0;
+  DECL_EXTERNAL(decl) = 1;
   TREE_PUBLIC(decl) = 1;
-  TREE_STATIC(decl) = 1;
+  TREE_STATIC(decl) = 0;
   DECL_ARTIFICIAL(decl) = 1;
   if (! asm_name.empty())
     SET_DECL_ASSEMBLER_NAME(decl, get_identifier_from_string(asm_name));

Reply via email to