$ cat dlleg.c __attribute((__dllexport__)) void fn () { } static int local; $ cat dlleg2.c __attribute((__dllexport__)) void fn2 () { } static int local; $ cat dllegmain.c __attribute((__dllimport__)) void fn (); __attribute((__dllimport__)) void fn2 (); int main () { fn(); fn2(); return 0; } $ gcc -g -c dlleg.c $ gcc -g -c dlleg2.c $ gcc -g -c dllegmain.c $ # $ # Force clash by omitting -Wl,--enable-auto-image-base $ # $ gcc -shared -o dlleg.dll dlleg.o $ gcc -shared -o dlleg2.dll dlleg2.o $ gcc -o dllegmain dllegmain.o dlleg.dll dlleg2.dll $ gdb dllegmain GNU gdb 2003-02-26-cvs Copyright 2003 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-cygwin"... (gdb) run Starting program: /cygdrive/f/Users/Raoul/gdb/dllegmain.exe Program exited with code 01. (gdb) # (gdb) # DLL info shows that dlleg and dlleg2 were loaded at different (gdb) # addresses, so one got relocated: (gdb) # (gdb) info dll DLL Name Load Address /usr/bin/cygwin1.dll 61001000 /cygdrive/f/WINNT/system32/kernel32.dll 77e81000 /cygdrive/f/Users/Raoul/gdb/dlleg2.dll 10001000 /cygdrive/f/Users/Raoul/gdb/dlleg.dll 00331000 /cygdrive/f/WINNT/system32/advapi32.dll 77db1000 /cygdrive/f/WINNT/system32/rpcrt4.dll 77d41000 /cygdrive/f/WINNT/System32/psapi.dll 690a1000 (gdb) # (gdb) # Dump internal symbol tables (gdb) # (gdb) maint print msymbols reloc.dump (gdb) quit $ # $ # There should be two distinct static_int vars (one $ # relocated). Unpatches gdb doesn't get this right: $ # $ grep static_int reloc.dump [96] d 0x10005020 static_int [115] d 0x10005020 static_int $ # $ # ... and absolute values shouldn't be relocated but are: $ # $ grep os_version reloc.dump [ 3] T 0x0 _minor_os_version__ [ 7] T 0x4 _major_os_version__ [ 3] T 0x0 _minor_os_version__ [ 7] T 0x4 _major_os_version__ [127] T 0xf0330000 _minor_os_version__ [131] T 0xf0330004 _major_os_version__ $ # $ # with the patch, static vars are relocated correctly: $ # $ grep static_int reloc2.dump [96] d 0x10005020 static_int [95] d 0x335020 static_int $ # $ # ... and absolute variables are untouched (note also the "A" $ # type for the minimal symbols instead of "T") $ # $ grep os_version reloc2.dump [ 3] A 0x0 _minor_os_version__ [ 7] A 0x4 _major_os_version__ [ 3] A 0x0 _minor_os_version__ [ 7] A 0x4 _major_os_version__ [ 3] A 0x0 _minor_os_version__ [ 7] A 0x4 _major_os_version__