On second thought
Here is another approach that you can try: With it and 3.2.2 RC the
testcase actually ran
and returned 2. Maybe forcing the dllimport decoration on in system
objs is not a bad idea: at least it makes sure we are using standard
runtime functions
gcc-3.3 -Wl,--allow-multiple-definition -Wl,-Map=map.txt test.c
(the Map switch is just to see where symbols were coming from)
There is a short form of the --allow-multiple-definition switch, but I
can't recall it offhand.
Danny
----- Original Message -----
From: "Mike Thomas" <miketh@...>
To: "Danny Smith" <danny_r_smith_2001@...>
Sent: Wednesday, 19 February 2003 01:09
Subject: RE: [Mingw-users] GCC 3.2.2 RC - link problems
> Much appreciated Danny.
>
> | -----Original Message-----
> | From: mingw-users-admin@...
> | [mailto:mingw-users-admin@... Behalf Of Danny
Smith
> | Sent: Wednesday, February 19, 2003 10:50 AM
> | To: Mike Thomas; mingw-users@...
> | Subject: Re: [Mingw-users] GCC 3.2.2 RC - link problems
> |
> |
> | --- Mike Thomas <miketh@...> wrote: > Hi
there.
> | >
> | > My intuition tells me I've done something silly here (not
> | counting using my
> | > own version of malloc() as this problem arose building GCL which
does
> | > precisely that), however...
> | >
> | > -----------------------------
> | > $ cat test.c
> | > int malloc ( int i )
> | > {
> | > return i;
> | > }
> | >
> | > int main ( char **argv, int argc )
> | > {
> | > int i = malloc ( 2 );
> | > return i;
> | > }
> | > -----------------------------
> | >
> | > Compiling with the release candidate gcc.exe (GCC) 3.2.2 (mingw
special
> | > 20030208-1), and GNU ld version 2.13.90 20030111:
> | >
> | > $ gcc -g test.c -o test.exe
> | >
> | c:/lang/mingw32/bin/../lib/gcc-lib/mingw32/3.2.2/../../../libmsvcr
> | t.a(ds0060
> | > 3.o)
> | > (.text+0x0): multiple definition of `malloc'
> | >
> | C:\DOCUME~1\miketh\LOCALS~1\Temp/ccGYbaaa.o(.text+0x0):c:/cvs/gcl/
> test.c:2:
> | > first defined here
> |
> | Thanks for this report. I'm pretty sure I know what the problem
> | is. When I
> | built libgcc.a I used headers that had CRT functions qualified with
> | __declspec(dllimport). Now the startup code has a constructor that
calls
> | __w32_eh_shared_initialize (in libgcc.a) which in turn calls malloc
(or
> | rather, after qualification *_imp__malloc). The constructor gets
> | called from
> | main. _malloc and __imp__malloc are tied together into an object
> | in the import
> | lib, so a reference to _imp__malloc ties in the import lib's
> | malloc as well.
> | When you defined malloc in the same module as main, you get
> | multiple definition
> | problems.
> |
> | I'll rebuild the standard system libaries and startups with
dllimport
> | qualification disabled for functions, and see if that fixes the
multiple
> | definition problem, but.....
> |
> |
> | > -----------------------------
> | >
> | > Now, with gcc.exe (GCC) 3.2.1 (MinGW special 20021202-2) and
> | GNU ld version
> | > 2.13.90 20021209 I get a link but the program doesn't work:
> | >
> | > $ gcc -g test.c -o test.exe
> | >
> | > miketh@... /c/cvs/gcl
> | > $ ./test
> | >
> | > -----------------------------
> | > At which point the program hangs. If run under gdb:
> | >
> | > (gdb) r
> | > Starting program: c:\cvs\gcl/./test.exe
> | >
> | > Program received signal SIGSEGV, Segmentation fault.
> | > 0x004013ef in __w32_eh_shared_initialize ()
> | >
> |
> | then this will bite again after that fix, unless you rename
> | _your_ malloc to
> | my_malloc and #define malloc my_malloc
> |
> |
> | > -----------------------------
> | >
> | > The program also hangs when built with VC++ 6. Any help
> | appreciated thanks.
> | >
> |
> | I suspect the VC startup code also calls malloc. But it will
> | call your one,
> | which may not do the right thing.
> |
> | Danny
> |
> | > Cheers
> | >
> | > Mike Thomas.
> | >
> | >
> | >
> | >
> | > -------------------------------------------------------
> | > This sf.net email is sponsored by:ThinkGeek
> | > Welcome to geek heaven.
> | > http://thinkgeek.com/sf
> | > _______________________________________________
> | > MinGW-users mailing list
> | > MinGW-users@...
> | >
> | > You may change your MinGW Account Options or unsubscribe at:
> | > https://lists.sourceforge.net/lists/listinfo/mingw-users
> |
> | http://mobile.yahoo.com.au - Yahoo! Mobile
> | - Exchange IMs with Messenger friends on your Telstra or Vodafone
> | mobile phone.
> |
> |
> | -------------------------------------------------------
> | This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
> | The most comprehensive and flexible code editor you can use.
> | Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day
Trial.
> | http://www.slickedit.com/sourceforge
> | _______________________________________________
> | MinGW-users mailing list
> | MinGW-users@...
> |
> | You may change your MinGW Account Options or unsubscribe at:
> | https://lists.sourceforge.net/lists/listinfo/mingw-users
> |
> |
>
|