This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR middle-end/15486


Hi,

This PR is about the effect of -fdata-sections on common variables: up to 
3.2.x, they were still emitted in .comm.  Starting with 3.3.x, they are 
emitted in .bss (.bss.variable_name subsection).

First of all, reading the various comments in the audit trail, it is not clear 
whether this is a problem at all.  But in any cases, this appears to be an 
unintended consequence of
  http://gcc.gnu.org/ml/gcc-patches/2002-03/msg00921.html
so I think it warrants a resolution.

Jason suggested to revert his patch and see what happens.  However, I think 
the problem that prompted him to write it would pop up again, namely that 
variables that want to go in separate sections may end up in .bss instead.
So I reverted the patch and added an additional condition to the test that 
guards the call to asm_emit_uninitialised, modelled on the test present in 
resolve_unique_section.

The effect of this is to revert to the 3.2.x behaviour for -fdata-sections: 
regular variables that would go in .bss or .comm without -fdata-sections are 
still emitted in those sections; variables that would go in .data are emitted 
in .data.variable_name.

Bootstrapped/regtested on amd64-mandrake-linux-gnu.


2004-12-12  Eric Botcazou  <ebotcazou@libertysurf.fr>

	PR middle-end/15486
	* varasm.c (assemble_variable): Revert 2002-03-15 patch.
	Do not call asm_emit_uninitialised if the variable is DECL_ONE_ONLY.


2004-12-12  Eric Botcazou  <ebotcazou@libertysurf.fr>

	* gcc.dg/fdata-sections-1.c: New test.


-- 
Eric Botcazou
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.405.2.4
diff -u -p -r1.405.2.4 varasm.c
--- varasm.c	31 Oct 2004 09:10:03 -0000	1.405.2.4
+++ varasm.c	13 Dec 2004 09:02:04 -0000
@@ -1457,21 +1457,13 @@ assemble_variable (tree decl, int top_le
   if (TREE_PUBLIC (decl))
     maybe_assemble_visibility (decl);
 
-  /* Output any data that we will need to use the address of.  */
-  if (DECL_INITIAL (decl) == error_mark_node)
-    reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
-  else if (DECL_INITIAL (decl))
-    {
-      reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
-      output_addressed_constants (DECL_INITIAL (decl));
-    }
-  resolve_unique_section (decl, reloc, flag_data_sections);
-
   /* Handle uninitialized definitions.  */
 
-  /* If the decl has been given an explicit section name, then it
-     isn't common, and shouldn't be handled as such.  */
-  if (DECL_SECTION_NAME (decl) || dont_output_data)
+  /* If the decl has been given an explicit section name or wants one,
+     then it isn't common, and shouldn't be handled as such.  */
+  if (DECL_SECTION_NAME (decl)
+      || (targetm.have_named_sections && DECL_ONE_ONLY (decl))
+      || dont_output_data)
     ;
   /* We don't implement common thread-local data at present.  */
   else if (DECL_THREAD_LOCAL (decl))
@@ -1520,7 +1512,17 @@ assemble_variable (tree decl, int top_le
   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
     globalize_decl (decl);
 
+  /* Output any data that we will need to use the address of.  */
+  if (DECL_INITIAL (decl) == error_mark_node)
+    reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
+  else if (DECL_INITIAL (decl))
+    {
+      reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
+      output_addressed_constants (DECL_INITIAL (decl));
+    }
+
   /* Switch to the appropriate section.  */
+  resolve_unique_section (decl, reloc, flag_data_sections);
   variable_section (decl, reloc);
 
   /* dbxout.c needs to know this.  */
/* PR middle-end/15486 */
/* Origin: Jonathan Larmour <jifl-bugzilla@jifvik.org> */

/* { dg-do compile { target *-*-linux* } } */
/* { dg-options "-fdata-sections" } */

int x;

/* { dg-final { scan-assembler "comm" } } */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]