Hi Norbert, -Wl,--dynamicbase only sets a flag in the DLL's PE header. But using this flag with EXE builds, the reloc info is still stripped and has no effect. Anyway, it has nothing to do with this bug.
However, I found a bug in crtbegin.o in which the NULL pointers are accidently relocated, resulting: original: mov eax, 0; ...; test eax, eax; je xxx; mov [eax], xxxx relocated: mov eax, 0xBAAD0000; ...; test eax, eax; je xxx; mov [eax], xxxx <- SEGFAULT! Linda Zhang From: Norbert Pfeiler Date: 2017-01-07 11:47 To: mingw-w64-public Subject: Re: [Mingw-w64-public] [HELP] DLL relocation totally broken idk what the default should be or if anything is not working as expected but i use -Wl,--dynamicbase to get a pass in the windows app cert kit regarding ASLR On Sat, Jan 7, 2017 at 4:19 AM Linda Zhang <[email protected]> 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. > > Minimal case: > ===================== > testexe.c > ===================== > #include <stdio.h> > __declspec(dllimport) int a(); > int main() { > a(); > printf("hello world\n"); > return 0; > } > > ===================== > testdll.c > ===================== > __declspec(dllexport) int a() {return 0;} > > ===================== > test.def > ===================== > EXPORTS > a > > ===================== > 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 > dllwrap -o $@ $^ --def test.def --implib libtest.a > -Wl,--image-base,0x400000 > > ===================== > Case end. Also see the attachment. In this case, test.exe refuses to work > with error 0xC0000005 because test.dll fails to load. > > Not only x86-dw2 builds produces the broken DLL, but x86-sjlj, x64-sjlj, > x64-seh, all builds since 2010, that's to say, gcc 4.8.x to 6.2 with > binutils 2.21 to 2.25.1, have the same problem. OH MY GOD. > > For I know, the only working MinGW bundle is the version comes with > Dev-C++ 4.9.9.2 in 2005 (GCC 3.4.2 + binutils 2.15.91 + original MinGW32 + > dw2 + win32). > > Nothing is wrong when using Microsoft Visual C++. > > I don't know what's wrong, GCC or binutils?. I can't submit bug to GCC > bugzilla because it is rejecting new account creation. It's really annoying > to see GCC produced broken DLLs and showing 0xC0000005 frequently and > randomly. Could anyone help me? > > ------------------------------------------------------------------------------ > 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 ------------------------------------------------------------------------------ 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
