public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [ros-dev] __attribute__((weak)) - in mingw
       [not found] ` <000d01c5122a$1051f460$2b4861cb@DANNY>
@ 2005-02-15 16:12   ` Boaz Harrosh
  0 siblings, 0 replies; only message in thread
From: Boaz Harrosh @ 2005-02-15 16:12 UTC (permalink / raw)
  To: Danny Smith, ReactOS Development List, aaron98wiridge9, binutils

[-- Attachment #1: Type: text/plain, Size: 1364 bytes --]

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).
>
>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?

Free Life
Boaz

[-- Attachment #2: Makefile.win --]
[-- Type: text/plain, Size: 1202 bytes --]

# Project: Weak
# Makefile created by Dev-C++ 4.9.8.0

CPP  = g++.exe
CC   = gcc.exe
WINDRES = windres.exe --include-dir=D:\Dinosaur\OneSource\NeoWine\msvc\atl\include --include-dir=D:\Dinosaur\OneSource\NeoWine\wine\include
RES  = 
OBJ  = main.o cpp2.o $(RES)
LINKOBJ  = main.o cpp2.o $(RES)
LIBS =  -L"D:/Dinosaur/PTools/Dev-Cpp/lib" 
INCS =  -I"D:/Dinosaur/PTools/Dev-Cpp/include" 
CXXINCS =  -I"D:/Dinosaur/PTools/Dev-Cpp/include/c++"  -I"D:/Dinosaur/PTools/Dev-Cpp/include/c++/mingw32"  -I"D:/Dinosaur/PTools/Dev-Cpp/include/c++/backward"  -I"D:/Dinosaur/OneSource/NeoWine/msvc/include"  -I"D:/Dinosaur/OneSource/NeoWine/msvc/atl/include"  -I"D:/Dinosaur/OneSource/NeoWine/msvc/mfc/include"  -I"D:/Dinosaur/OneSource/NeoWine/wine/include"  -I"D:/Dinosaur/OneSource/NeoWine/wine/include/msvcrt" 
BIN  = Weak.exe
CXXFLAGS = $(CXXINCS) 
CFLAGS = $(INCS) 

.PHONY: all all-before all-after clean clean-custom

all: all-before Weak.exe all-after


clean: clean-custom
	rm -f $(OBJ) $(BIN)

$(BIN): $(LINKOBJ)
	$(CPP) $(LINKOBJ) -o "Weak.exe" $(LIBS)

main.o: main.cpp
	$(CPP) -c main.cpp -o main.o $(CXXFLAGS)

cpp2.o: cpp2.cpp
	$(CPP) -c cpp2.cpp -o cpp2.o $(CXXFLAGS)

[-- Attachment #3: cpp2.cpp --]
[-- Type: text/plain, Size: 101 bytes --]

#include "fooInt.h"

int foo_3()
{
    return fooInt*fooInt*fooInt * Static_T<int>::My ;
}



[-- Attachment #4: fooInt.h --]
[-- Type: text/plain, Size: 855 bytes --]

// the proper way would be
#define __WEAK__ __attribute__((weak))

// I have tried extern ,dllimport, but they are all ignored (and warned) because of the 
// "= 6". If not for the assignment, extern with changing definition of __WEAK__ 
// could work. All modules compiled with "extern" and one with out.
// what could be the defenition of __WEAK__ that will make this project to link?
// I thought that a combination of section and asm() could do it but I cannot 
// figure out what the magig should be. Weak symbles are supported in templates.
// So what is the compiler's magic for weak templates symbles that make the linker
// happy

__WEAK__ int fooInt = 6 ;

extern int foo_2() ;
extern int foo_3() ;

template <typename T>
class Static_T
{
public:
static T My ;
} ;

template <typename T>
T Static_T<T>::My = 17 ;




[-- Attachment #5: main.cpp --]
[-- Type: text/plain, Size: 209 bytes --]

#include <stdio.h>

#include "fooInt.h"

int foo_2()
{
    return fooInt*fooInt*Static_T<int>::My ;
}

int main(int argc, char *argv[])
{
  printf("%d,%d\n" ,foo_2() ,foo_3() ) ;  
  return 0;
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-02-15  9:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <420FDB53.2080406@hishome.net>
     [not found] ` <000d01c5122a$1051f460$2b4861cb@DANNY>
2005-02-15 16:12   ` [ros-dev] __attribute__((weak)) - in mingw Boaz Harrosh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).