diff mbox

Go patch committed: Set TREE_PUBLIC reliably

Message ID mcr4na99v7v.fsf@iant-glaptop.roam.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Aug. 29, 2013, 12:49 a.m. UTC
Uros tracked down a problem with the section used for immutable structs:
the value of compute_reloc_for_constant would change between the time
immutable_struct_set_init would call it and the time that
get_variable_section would call it, for the same decl and the same decl
initializer.  He identified the problem: TREE_PUBLIC was set in the
latter case but not the former.  This patch fixes the problem.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.8 branch.

Ian


2013-08-28  Ian Lance Taylor  <iant@google.com>

	* go-gcc.cc (Gcc_backend::immutable_struct): Set TREE_PUBLIC if
	the struct is not hidden.
	(Gcc_backend::immutable_struct_set_init): Don't set TREE_PUBLIC.

Comments

Uros Bizjak Aug. 29, 2013, 7:50 p.m. UTC | #1
On Thu, Aug 29, 2013 at 2:49 AM, Ian Lance Taylor <iant@google.com> wrote:
> Uros tracked down a problem with the section used for immutable structs:
> the value of compute_reloc_for_constant would change between the time
> immutable_struct_set_init would call it and the time that
> get_variable_section would call it, for the same decl and the same decl
> initializer.  He identified the problem: TREE_PUBLIC was set in the
> latter case but not the former.  This patch fixes the problem.
> Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
> Committed to mainline and 4.8 branch.

I can confirm that there is no invalid section flags warning in the
libgo testsuite on alpha.

Thanks,
Uros.
diff mbox

Patch

Index: go-gcc.cc
===================================================================
--- go-gcc.cc	(revision 201932)
+++ go-gcc.cc	(working copy)
@@ -1475,8 +1475,8 @@  Gcc_backend::temporary_variable(Bfunctio
 // Create a named immutable initialized data structure.
 
 Bvariable*
-Gcc_backend::immutable_struct(const std::string& name, bool, bool,
-			      Btype* btype, Location location)
+Gcc_backend::immutable_struct(const std::string& name, bool is_hidden,
+			      bool, Btype* btype, Location location)
 {
   tree type_tree = btype->get_tree();
   if (type_tree == error_mark_node)
@@ -1490,6 +1490,8 @@  Gcc_backend::immutable_struct(const std:
   TREE_CONSTANT(decl) = 1;
   TREE_USED(decl) = 1;
   DECL_ARTIFICIAL(decl) = 1;
+  if (!is_hidden)
+    TREE_PUBLIC(decl) = 1;
 
   // We don't call rest_of_decl_compilation until we have the
   // initializer.
@@ -1503,8 +1505,7 @@  Gcc_backend::immutable_struct(const std:
 
 void
 Gcc_backend::immutable_struct_set_init(Bvariable* var, const std::string&,
-				       bool is_hidden, bool is_common, Btype*,
-				       Location,
+				       bool, bool is_common, Btype*, Location,
 				       Bexpression* initializer)
 {
   tree decl = var->get_tree();
@@ -1515,12 +1516,7 @@  Gcc_backend::immutable_struct_set_init(B
   DECL_INITIAL(decl) = init_tree;
 
   // We can't call make_decl_one_only until we set DECL_INITIAL.
-  if (!is_common)
-    {
-      if (!is_hidden)
-	TREE_PUBLIC(decl) = 1;
-    }
-  else
+  if (is_common)
     make_decl_one_only(decl, DECL_ASSEMBLER_NAME(decl));
 
   // These variables are often unneeded in the final program, so put