Opened 14 years ago
Closed 14 years ago
#6322 closed bug (fixed)
[gcc] Static class field in shared object links to two addresses
Reported by: | Adek336 | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | - General | Version: | R1/alpha2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
/* A.h */ #ifndef A_H #define A_H #include <iostream> class A { public: A() { static int i = 0; std::cerr << (void*)&i << std::endl; } }; #endif
/* x.cc */ #include "A.h" A x; int main() { }
/* y.cc */ #include "A.h" A y;
g++ y.cc -shared -o y.so g++ x.cc y.so LIBRARY_PATH=. ./a.out
results in
0x203ac0 0x201d1c
whereas the addresses should be equal.
hrev37527, gcc4+2 hybrid, VBox 3.1
Change History (3)
comment:1 by , 14 years ago
comment:3 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I don't recall whether I have tested the given code example, but at least with gcc 4 it should now work as expected. With gcc 2 it probably still doesn't, but that's due to the symbolic linking which we probably won't change.
Note:
See TracTickets
for help on using tickets.
This problem already existed under BeOS R5 with gcc 2.9. I don't know whether there are any provisions in gcc 4 that allow to make this work without weak symbol support by the OS. I guess we really should implement it, anyway.