This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[g++ 2.95.1] linker problem with static variables in classes
- To: bug-gcc at gnu dot org
- Subject: [g++ 2.95.1] linker problem with static variables in classes
- From: Jean-Francois MOINE <d3moine at bst dot bsf dot alcatel dot fr>
- Date: Fri, 26 Nov 1999 15:28:23 +0100 (MET)
- Cc: lasserre at col dot bsf dot alcatel dot fr, lparis at col dot bsf dot alcatel dot fr, vittone at col dot bsf dot alcatel dot fr, d3moine at bst dot bsf dot alcatel dot fr
In the following example, the variables 'cl::a' and 'b' have the same
memory location.
The bug appeared when cross-compiling from Sparc/Solaris to PowerPC.
(it does not exist using g++ and the Sun linker).
The linker map gives:
.sbss 0x0187366c 0x4 f1.o
0x8 (size before relaxing)
0x01873670 cl::a
0x0187366c c
.sbss 0x01873670 0x4 f2.o
0x01873670 b
The problem disappears when either:
- 'int c;' is not there,
or - cl::a is initialized ('cl::a = 0;').
--------- f1.cc ---------
/*
* GNU g++ 2.95.1 - linker problem with static variables in classes.
*
* When a class static variable is not initialized, the linker
* 'relaxes' it, so many variables are at the same location.
*
* This problem did not exist with g++ 2.8.1.
*
* Tools versions:
* gcc version 2.95.1 19990816 (release)
* GNU ld version 2.9 (with BFD 980402)
*
* Generation:
* g++ -c f1.cc -o f1.o
* g++ -c f2.cc -o f2.o
* ld f1.o f2.o -o execfile
*/
#include <stdio.h>
class cl {
public:
static int a;
};
int c;
int cl::a;
extern int b;
int main(int argc, char *argv[])
{
b = 0;
printf("d:%d\n", b);
cl::a = 1;
printf("d:%d\n", b);
}
-------------------------
--------- f2.cc ---------
int b;
-------------------------
--
Ken ar c'hentaƱ ** Breizh ha Linux atav ! **
mailto:Jean-Francois.Moine@bst.bsf.alcatel.fr
Jef (home mailto:moinejf@free.fr)
http://aww.bst.bsf.alcatel.fr/projects/lsd/dhs3/d3moine/