C/C++ PATCH: Fix asm ("...") for variables
Mark Mitchell
mark@codesourcery.com
Sat Oct 28 19:27:00 GMT 2000
I don't understand what I was thinking when I wrote the code below; I
was clobberring DECL_ASSEMBLER_NAME for no apparent reason. The
upshot was that a static variable called `ctors' got put in a section
called `.ctors' when -fdata-sections was used, with predictable results.
Bootstrapped/tested on i686-pc-linux-gnu.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
Index: gcc/testsuite/g++.old-deja/static1.C
===================================================================
RCS file: static1.C
diff -N static1.C
*** /dev/null Tue May 5 13:32:27 1998
--- static1.C Sat Oct 28 19:22:05 2000
***************
*** 0 ****
--- 1,13 ----
+ // Origin: Mark Mitchell <mark@codesourcery.com>
+ // Special g++ Option: -fdata-sections
+
+ void f()
+ {
+ static int ctors[3] = { 0, 0, 0 };
+
+ ctors[2] = 7;
+ }
+
+ int main ()
+ {
+ f ();
+ }
Index: gcc/c-semantics.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-semantics.c,v
retrieving revision 1.9
diff -c -p -r1.9 c-semantics.c
*** c-semantics.c 2000/09/17 07:38:11 1.9
--- c-semantics.c 2000/10/29 02:21:59
*************** make_rtl_for_local_static (decl)
*** 281,294 ****
if (TREE_ASM_WRITTEN (decl))
return;
! if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
! {
! /* The only way this situaton can occur is if the
! user specified a name for this DECL using the
! `attribute' syntax. */
! asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
! DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl);
! }
rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0);
}
--- 281,305 ----
if (TREE_ASM_WRITTEN (decl))
return;
! /* If the DECL_ASSEMBLER_NAME is not the same as the DECL_NAME, then
! either we already created RTL for this DECL (and since it was a
! local variable, its DECL_ASSMEMBLER_NAME got hacked up to prevent
! clashes with other local statics with the same name by a previous
! call to make_decl_rtl), or the user explicitly requested a
! particular assembly name for this variable, using the GNU
! extension for this purpose:
!
! int i asm ("j");
!
! There's no way to know which case we're in, here. But, it turns
! out we're safe. If there's already RTL, then
! rest_of_decl_compilation ignores the ASMSPEC parameter, so we
! may as well not pass it in. If there isn't RTL, then we didn't
! already create RTL, which means that the modification to
! DECL_ASSEMBLER_NAME came only via the explicit extension. */
! if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
! && !DECL_RTL (decl))
! asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0);
}
More information about the Gcc-patches
mailing list