Boaz Harrosh (boaz@hishome.net) wrote:
background: I have managed to compile ATL/WTL from MSVC6. I will have available a public patch-file for patching ATL/WTL to compile under wine, Once I have every thing running
Question: All symbols and functions declared __declspec(selectany) show up as "duplicate symbols" errors on the linker. Eliminating it has the same results.
I have searched in google and the few lines I found is that GCC will accept __declspec(selectany) if "-fms-extensions" is used. Well it will accept it but will only ignore it all together.
Does any body know how to properly merge duplicate definitions of symbols in GCC?
Yes, I think it's attribute((weak)).
(before I go and change the code) maybe a command line switch to the compiler or linker can do the trick ?
Part of the solution might be to apply the following patch to the gcc-3.3 source tree:
Index: linux.h =================================================================== RCS file: /cvsroot/gcc/gcc/gcc/config/i386/linux.h,v retrieving revision 1.42 diff -u -d -u -r1.42 linux.h --- linux.h 15 Nov 2002 14:57:12 -0000 1.42 +++ linux.h 5 Aug 2003 21:33:39 -0000 @@ -82,6 +82,14 @@ builtin_define ("__ELF__"); \ builtin_define ("__gnu_linux__"); \ builtin_assert ("system=posix"); \ + builtin_define ("__stdcall=__attribute__((__stdcall__))"); \ + builtin_define ("__cdecl=__attribute__((__cdecl__))"); \ + builtin_define ("__declspec(x)=__attribute__((x))"); \ + if (!flag_iso) \ + { \ + builtin_define ("_stdcall=__attribute__((__stdcall__))"); \ + builtin_define ("_cdecl=__attribute__((__cdecl__))"); \ + } \ if (flag_pic) \ { \ builtin_define ("__PIC__"); \
but I'm sure more is needed; I haven't tested this at all. (gcc/doc/extend.texi would need updating, too, at least, and maybe whatever code implements -fms-extensions.) I suspect the folks who did the original ms-extensions for gcc never figured we'd be compiling Windows source code on Linux, but here we are... - Dan
On 05-Aug-2003, Dan Kegel dank@kegel.com wrote:
Part of the solution might be to apply the following patch to the gcc-3.3 source tree:
Rather than patching gcc, an easier solution would be to put the corresponding #defines for _cdecl etc. in a header file called say "ms_extensions.h", and then compile with "gcc -include ms_extensions.h ..." so that these #defines get automatically included in every compilation unit.
Fergus Henderson wrote:
On 05-Aug-2003, Dan Kegel dank@kegel.com wrote:
Part of the solution might be to apply the following patch to the gcc-3.3 source tree:
Rather than patching gcc, an easier solution would be to put the corresponding #defines for _cdecl etc. in a header file called say "ms_extensions.h", and then compile with "gcc -include ms_extensions.h ..." so that these #defines get automatically included in every compilation unit.
Silly me. For some reason I thought the builtin declarations were magic. Here's a little demo that might show the basic idea. Does this do what you needed, Boaz? - Dan
$ gcc -include msextensions.h foo.c bar.c $ ./a.out Value of x is 7
$ gcc -include msextensions.h bar.c foo.c $ ./a.out Value of x is 1
:::::::::::::: msextensions.h :::::::::::::: #define __declspec(x) __attribute__((x)) #define selectany weak
:::::::::::::: foo.c :::::::::::::: int __declspec(selectany) x = 7;
:::::::::::::: bar.c :::::::::::::: #include <stdio.h>
int __declspec(selectany) x = 1;
int main() { printf("Value of x is %d\n", x); }
On August 6, 2003 12:12 am, Dan Kegel wrote:
Silly me. For some reason I thought the builtin declarations were magic. Here's a little demo that might show the basic idea.
winegcc already defines these things:
gcc_argv[i++] = "-D__stdcall=__attribute__((__stdcall__))"; gcc_argv[i++] = "-D__cdecl=__attribute__((__cdecl__))"; gcc_argv[i++] = "-D__fastcall=__attribute__((__fastcall__))"; gcc_argv[i++] = "-D_stdcall=__attribute__((__stdcall__))"; gcc_argv[i++] = "-D_cdecl=__attribute__((__cdecl__))"; gcc_argv[i++] = "-D_fastcall=__attribute__((__fastcall__))"; gcc_argv[i++] = "-D__declspec(x)=__attribute__((x))";
Dimitrie O. Paun wrote:
On August 6, 2003 12:12 am, Dan Kegel wrote:
Silly me. For some reason I thought the builtin declarations were magic. Here's a little demo that might show the basic idea.
winegcc already defines these things:
gcc_argv[i++] = "-D__stdcall=__attribute__((__stdcall__))"; gcc_argv[i++] = "-D__cdecl=__attribute__((__cdecl__))"; gcc_argv[i++] = "-D__fastcall=__attribute__((__fastcall__))"; gcc_argv[i++] = "-D_stdcall=__attribute__((__stdcall__))"; gcc_argv[i++] = "-D_cdecl=__attribute__((__cdecl__))"; gcc_argv[i++] = "-D_fastcall=__attribute__((__fastcall__))"; gcc_argv[i++] = "-D__declspec(x)=__attribute__((x))";
I looked at http://cvs.winehq.com/cvsweb/wine/tools/winegcc.c?rev=1.16 and see you don't have
#define selectany weak
Without that, you get compilation errors on my demo (and presumably on the original poster's source code):
[dank@krunch dank]$ gcc -include msextensions.h bar.c foo.c bar.c:3: warning: `selectany' attribute directive ignored foo.c:1: warning: `selectany' attribute directive ignored /tmp/ccFjkSf7.o(.data+0x0): multiple definition of `x' /tmp/ccDWXV71.o(.data+0x0): first defined here collect2: ld returned 1 exit status
Think winegcc should do -Dselectany=weak?
- Dan
On August 6, 2003 01:14 am, Dan Kegel wrote:
I looked at http://cvs.winehq.com/cvsweb/wine/tools/winegcc.c?rev=1.16 and see you don't have
#define selectany weak
That's right, it doesn't.
Think winegcc should do -Dselectany=weak?
I don't know -- it's easy enough to add, but it's also quite dangerous it seems. It would seem that a gcc patch to teach it to recognize selectany as an attribute is the way to go. I think people that need selectany to work should explicitly define it, so they are aware of the potential problems, no?
Dimitrie O. Paun wrote:
is the way to go. I think people that need selectany to work should explicitly define it, so they are aware of the potential problems, no?
On the other hand, they already are explicitly using it. It's not like selectany is going to be a common word in code, so if __declspec(selectany) appears, it's pretty likely the relevant party knows what they're up to?
-- Jon Bright Lead Programmer, Silicon Circus Ltd. http://www.siliconcircus.com
Dimitrie O. Paun wrote:
On August 6, 2003 01:14 am, Dan Kegel wrote:
I looked at http://cvs.winehq.com/cvsweb/wine/tools/winegcc.c?rev=1.16 and see you don't have
#define selectany weak
That's right, it doesn't.
Think winegcc should do -Dselectany=weak?
I don't know -- it's easy enough to add, but it's also quite dangerous it seems. It would seem that a gcc patch to teach it to recognize selectany as an attribute is the way to go. I think people that need selectany to work should explicitly define it, so they are aware of the potential problems, no?
Thank you all for the help. It works like charm. ( needed both defines )
I agree with Dimitrie. “selectany” should only be defined on a “per project”. In the MS compiler it is only reserved when used inside a declspec . It can freely be used as an Identifier. So is weak in GCC. Above define will break that.
Save from a GCC patch, the only right solution is to enhance winemaker, so just as it changes the #pragma( pack ) things it can also change the __declespec( selectany ) to something like __declespec__selectany__ and now a global define is less dangerous.
Sorry for the late response, the time difference, when you type a way I was already in the pub.
ons, 06.08.2003 kl. 07.03 skrev Dimitrie O. Paun:
On August 6, 2003 01:14 am, Dan Kegel wrote:
I looked at http://cvs.winehq.com/cvsweb/wine/tools/winegcc.c?rev=1.16 and see you don't have
#define selectany weak
That's right, it doesn't.
Think winegcc should do -Dselectany=weak?
I don't know -- it's easy enough to add, but it's also quite dangerous it seems. It would seem that a gcc patch to teach it to recognize selectany as an attribute is the way to go.
You can try
#define __declspec_selectany __attribute__((weak)) #define __declspec_whatever __attribute__((whatever)) #define __declspec(x) __declspec_##x
On 6 Aug 2003, Ove Kaaven wrote:
You can try
#define __declspec_selectany __attribute__((weak)) #define __declspec_whatever __attribute__((whatever)) #define __declspec(x) __declspec_##x
Brilliant, thank you!