Boaz Harrosh wrote:
Danny Smith wrote:
Boaz Harrosh wrote:
[Q] I'm (well ATL is) using __attribute__((weak)) (translated from __declspec( selectany) ) for instantiation of members and variables in headers. I had no problem with it On GCC in Linux (gcc 3.2.2). On MinGW
IMAGE_COMDAT_SELECT_ANY is not quite same as PECOFF version of "weak" , but AFAICT is equivalent to the GCC section flag ".linkonce discard". I don't think there is a way for the user to specify that for data using an attribute, but it could be done with asm statements.
.weak directive is partially supported in current binutils CVS. __attribute__((weak)) is not supported by GCC-3.4.x but will be in the next major GCC release (4.0.0).
Sorry, that was unclear. I should have qualified with "on windows targets"
The semantics of weak for PECOFF differ from that on Linux.See the PECOFF60 specs (Microsoft Portable Executable and Common Object File Format Specification) section on weak externals
Danny
(binutils at sources dot redhat dot com please also cc me as I'm not on the list)
Attached is a proof (See fooInt.h) that gcc (gcc version 3.2 (mingw special 20020817-1)) has support for weak symbols. Just not with the regular syntax. But when templates are used duplicate symbols are merged by the linker.
What would be the assembler magic to cram into the __WEAK__ definition that would make this project link?
I am currently testing a patch to GCC to add an __attribute__ ((selectany)) that would work the way it is discribed in MS docs and in the spec of IMAGE_COMDAT_SELECT_ANY in PECOFF doc. Basically it puts the symbol into its own section with ".linkonce discard" charcteristics.
__declspec (selectany) int foo = 1;
becomes:
.globl _foo .section .data$foo,"w" .linkonce discard .align 4 _foo: .long 1
So far the only problem I've seen is that, although it works for global objects with non-trivial constructors
eg:
struct X { static int s; int m; X(int _i) : m(_i) { m++; } };
__declspec(selectany) int X::s = -1; // OK __declspec(selectany) X x(1); // This is OK but app will be bloated with // duplicate initialization code. . I haven't figured out how to get rid of the duplicated inititialization code
I will submit the patch for comment once GCC trunk branches.
Danny
Free Life Boaz