This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ problem with classes and __attribute__(section)
- From: Christopher Faylor <cgf at redhat dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 13 Feb 2002 22:33:02 -0500
- Subject: g++ problem with classes and __attribute__(section)
I think the code below illustrates a problem with g++ and the use
of __attribute__((section("whatever"))) .
As you can see from the assembly language below, there seems to
be two variables occupying the same space. I notice this in cygwin
where the section attribute is used to control what data elements
get copied in a fork.
FWIW, if I remove the section attribute things seem to work ok.
Things also seem to work ok if I comment out the constructor.
This problem is evidenced in a linux x cygwin g++ built from cvs a
couple of minutes ago.
cgf
#include <stdlib.h>
class foo
{
int bar;
public:
foo() : bar(37) {}
int val() {return bar;}
};
int main ()
{
static foo __attribute__((section(".data42"))) blah;
static foo __attribute__((section(".data42"))) blah1;
exit(blah.val () + blah1.val ());
}
.file "tst.cc"
.lcomm __ZGVZ4mainE4blah,16
.lcomm __ZGVZ4mainE5blah1,16
.def ___main; .scl 2; .type 32; .endef
.section .data42,"w"
.align 4
_ZZ4mainE4blah:
.align 4 # note lack of any directive to set aside space
_ZZ4mainE5blah1: # should be one after this, too
.text
.align 2
.p2align 4,,15
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
xorl %eax, %eax
andl $-16, %esp
call __alloca
call ___main
cmpb $0, __ZGVZ4mainE4blah
jne L2
movb $1, __ZGVZ4mainE4blah
movl $37, %eax
movl %eax, _ZZ4mainE4blah
L2:
cmpb $0, __ZGVZ4mainE5blah1
jne L4
movb $1, __ZGVZ4mainE5blah1
movl $37, %ecx
movl %ecx, _ZZ4mainE5blah1
L4:
movl _ZZ4mainE5blah1, %eax
movl _ZZ4mainE4blah, %edx
addl %edx, %eax
movl %eax, (%esp)
call _exit
.def _exit; .scl 3; .type 32; .endef