Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASLR is now enabled for GCC binaries and it breaks PCH #5719

Closed
bustercopley opened this issue Aug 14, 2019 · 4 comments
Closed

ASLR is now enabled for GCC binaries and it breaks PCH #5719

bustercopley opened this issue Aug 14, 2019 · 4 comments

Comments

@bustercopley
Copy link
Contributor

bustercopley commented Aug 14, 2019

The binaries in the new gcc-9.2.0-1 packages have ASLR enabled in their PE headers. This breaks using precompiled headers, as they can no longer be mapped at a predictable address. The previous package had 'good' binaries, with ASLR disabled. (This isn't a change in the package itself. I rebuilt the 9.1.0-3 package, and the resulting binaries were 'bad'.)
I raised this on the GCC bug tracker[1].

For the GCC 9.1.0-3 packages (assuming they're still in your cache):

pacman -U /var/cache/pacman/pkg/mingw-w64-x86_64-{gcc-9.1.0-3,gcc-libs-9.1.0-3}-any.pkg.tar.xz --noconfirm
objdump -p /mingw64/lib/gcc/x86_64-w64-mingw32/9.1.0/cc1.exe | grep DllCharacteristics

Output:

DllCharacteristics	00000000

For the GCC 9.2.0-1 packages:

pacman -U /var/cache/pacman/pkg/mingw-w64-x86_64-{gcc-9.2.0-1,gcc-libs-9.2.0-1}-any.pkg.tar.xz --noconfirm
objdump -p /mingw64/lib/gcc/x86_64-w64-mingw32/9.2.0/cc1.exe | grep DllCharacteristics

Output:

DllCharacteristics	00000160

Hex 160 means[2]:
0x040 (IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) (i.e., ASLR enabled)
| 0x100 (IMAGE_DLLCHARACTERISTICS_NX_COMPAT) (i.e., DEP enabled)
| 0x020 (??)

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91440
[2] https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_optional_header32

@Alexpux
Copy link
Member

Alexpux commented Aug 15, 2019

@bustercopley fixed by 2602139

@Lord-Nightmare
Copy link

Lord-Nightmare commented Aug 28, 2019

@bustercopley fixed by 2602139

This did not fix the PCH issues encountered by the MAME project, as far as I can tell. This changed the ASLR/DEP build flags for binutils, but the issue remains with PCH not functioning with the mingw-w64-x86_64-gcc-9.2.0-1-any.pkg.tar.xz package. Everything works fine with gcc 9.1.0-3 x86_64

"
Compiling src/mame/drivers/aristmk5.cpp...
internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.c:186: MapViewOfFileEx: Attempt to access invalid address.
: fatal error: had to relocate PCH
compilation terminated.
"

@bustercopley
Copy link
Contributor Author

bustercopley commented Aug 28, 2019

Until a new release of the gcc package comes out, workarounds are to remove the ASLR flag from cc1.exe and cc1plus.exe (e.g., using setdllcharacteristics, which you might prefer to compile for yourself) or rebuild gcc from the existing PKGBUILD script (having updated your binutils).

@Lord-Nightmare
Copy link

With the updated gcc-9.2.0-2 packages released on 20190829, this is now fixed, at least for my workload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants