libgmp-3.dll relocation problem

Juro Bystricky jurobystricky at
Fri Aug 20 03:25:33 CEST 2004

I just built libgmp-3.dll using the latest MINGW distribution & gmp-4.1.3 sources. 
The build was rather straightforward and completed without errors. Then I created 
libgmp-3.lib as described in the GMP manual and a simple test program GMPTEST.EXE using
Microsoft VC6 to test the freshly build libgmp.dll, something like:

int main (void)
    printf("versionGMP = %s\n",gmp_version);
    some mpz_add_ui etc... 

The program worked well, without any obvious errors.
However, when I tried the libgmp-3.dll in a "real" (more complex) application, libgmp-3.dll would
not even initialize and would fail to load before I had a chance to trace the problem
in a debugger.
After a lot of head scratching I found out the problem:
libgmp-3.dll is not relocatable. It only works when loaded at the precise address as specified
in the dll image base field (0x10000000). This can be proved quite simply by insisting
on the same load address for the program GMPTEST.EXE: with the default base address of
GMPTEST.EXE of 0x400000 the program runs, with explicitely specified base address of 
0x10000000 libgmp-3.dll would not load.
Looking at the libgmp.dll with PEBROWSE.EXE you can see the dll DOES contain
base relocations (fixups), so it SHOULD load at any address.

To make things a little more confusing, I tried GMPTEST.EXE with my "old" gmp-4.1.2 based libgmp-3.dll,
which I built a long time ago with a much older MINGW distribution. This one relocates 
So this is what I suspect has happened: new MINGW distribution contains newer tools and the
GMP configure scripts need some tweaks for the new toolchain.
Just to prove the point, when rebuilding the gmp-4.1.2 with the new MINGW distribution, I ran into the same

Any ideas?

Juro Bystricky
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /list-archives/gmp-discuss/attachments/20040819/dd7297b1/attachment.htm

More information about the gmp-discuss mailing list