Hi LRN, Thanks for your information, I've tested that gcc -shared is OK, but dllwrap produced duplicate and wrong relocation info. It looks like dllwrap has been broken for many years. I'm submitting bug there. I've been using dllwrap to compile dll files for so many years because I remember MinGW told me to use it long time ago..... and it provides more link options than gcc -shared....... What a pity...
Linda Zhang From: LRN Date: 2017-01-07 13:22 To: mingw-w64-public Subject: Re: [Mingw-w64-public] [HELP] DLL relocation totally broken On 07.01.2017 6:15, Linda Zhang wrote: > OS: Win7 SP1 > Toolchain: Mingw-w64 i686-6.2.0-release-win32-dwarf-rt_v5-rev1 > GCC: 4.8.x - 6.2.0 > Binutils: 2.21 - 2.25.1 > MinGW: official and w64, 4.x - 5.0.1 > Threading and except: all (dw2/sjlj/seh + win32/posix) > > Consider a dll whose base address is overlapped with an existing module, so > that the operating system must relocate it, or for another word, rebase it, > to work. Relocation is the fundamental part of the security feature ASLR and > is enabled by default since Windows Vista. When ASLR is enabled, all > executables are relocated. > > BUT, After relocation, the compiled DLL fails to load at all. That's to say, > the compiled DLL is broken. > Works for me with this makefile: =================== all: test.dll test.exe clean: rm test.exe test.dll libtest.a test.exe: testexe.c gcc -o $@ $^ libtest.a -Wl,--image-base,0x400000 test.dll: testdll.c gcc -shared -o $@ $^ --def test.def -Wl,--out-implib -Wl,libtest.a -Wl,--image-base,0x400000 =================== To confirm that they have the same image base: $ objdump -x test.dll test.exe | grep image_base [885](sec -1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00400000 __image_base__ [1187](sec -1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00400000 __image_base__ I've also added a pause to the executable and looked at the process at runtime, and the test.dll is relocated as expected. I would also like to note that i have no idea what "dllwrap" is. I see that it's part of binutils, but i've never seen it being used. Its manpage says that it is deprecated. -- O< ascii ribbon - stop html email! - www.asciiribbon.org ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
