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

MinGW GCC 14.2.0 build bad exe file for x86 #530

Closed
mxlgv opened this issue Aug 9, 2024 · 8 comments
Closed

MinGW GCC 14.2.0 build bad exe file for x86 #530

mxlgv opened this issue Aug 9, 2024 · 8 comments
Labels

Comments

@mxlgv
Copy link

mxlgv commented Aug 9, 2024

Operating system / операционная система

Windows 10 Pro 22H2

Running as service / Запуск программы как сервис

I run it as a regular program / Запускаю программу обычным образом

Describe the bug / Опишите ошибку программы

The linker generates a bad executable file with i686-w64-migw32-gcc v14.2.0, with the warning:

C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.text: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.data: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.rdata: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.eh_fram: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.bss: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.edata: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.idata: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.CRT: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.tls: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.rsrc: section below image base
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: goodbyedpi.exe:.reloc: section below image base

The build was carried out from the MINGW32 (MSYS2) environment.
The file does not run: Windows 10 reports that "The application cannot be run on your PC."

Additional information / Дополнительная информация

The linker has two incompatible options --dynamicbase and --image-base (see https://learn.microsoft.com/en-us/cpp/build/reference/base-base-address?view=msvc-170) which Probably on the older version (which is now in CI) mingw-w64 somehow worked.

In addition, if you use --image-base, then for x86 it should be 0x400000, and for x64 0x140000000.

@mxlgv mxlgv changed the title MinGW GCC 14.2.0 build bad exe file MinGW GCC 14.2.0 build bad exe file for x86 Aug 9, 2024
@ValdikSS
Copy link
Owner

ValdikSS commented Aug 9, 2024

Please paste PE headers of the builds here if you have them on hand.

@ValdikSS ValdikSS added the bug label Aug 9, 2024
@EgorWeders
Copy link
Contributor

Removed --image-base
It builds working artifacts, both x32 and x64 .
Tested on win 10 x64.

@mxlgv
Copy link
Author

mxlgv commented Aug 9, 2024

@ValdikSS

goodbyedpi.exe:     file format pei-i386
goodbyedpi.exe
architecture: i386, flags 0x00000103:
HAS_RELOC, EXEC_P, D_PAGED
start address 0x000013f0

Characteristics 0x30e
	executable
	line numbers stripped
	symbols stripped
	32 bit words
	debugging information removed

Time/Date		Fri Aug 09 13:03:01 2024
Magic			010b	(PE32)
MajorLinkerVersion	2
MinorLinkerVersion	42
SizeOfCode		0000e800
SizeOfInitializedData	0001a600
SizeOfUninitializedData	00000c00
AddressOfEntryPoint	000013f1
BaseOfCode		00001000
BaseOfData		00010001
ImageBase		ffffffff
SectionAlignment	00001000
FileAlignment		00000200
MajorOSystemVersion	4
MinorOSystemVersion	0
MajorImageVersion	1
MinorImageVersion	0
MajorSubsystemVersion	4
MinorSubsystemVersion	0
Win32Version		00000000
SizeOfImage		00023001
SizeOfHeaders		00000400
CheckSum		00020782
Subsystem		00000003	(Windows CUI)
DllCharacteristics	00000140
					DYNAMIC_BASE
					NX_COMPAT
SizeOfStackReserve	00200000
SizeOfStackCommit	00001000
SizeOfHeapReserve	00100000
SizeOfHeapCommit	00001000
LoaderFlags		00000000
NumberOfRvaAndSizes	00000010

This is how I understand the problem ImageBase: ffffffff.

Full log:
goodbyedpi-objdump.log

@mxlgv
Copy link
Author

mxlgv commented Aug 9, 2024

Removed --image-base It builds working artifacts, both x32 and x64 . Tested on win 10 x64.

Sorry, but don't you think that commit messages like "Update makefile" are harmful and do not reflect the essence.

@EgorWeders
Copy link
Contributor

EgorWeders commented Aug 9, 2024

I make it fast in browser for testing and for you, my fault but i cant find how to edit and remove commits on web github))

P.S
I am not author, just using comms for help

@EgorWeders
Copy link
Contributor

Если будешь собирать, то отпиши как что. плз

@mxlgv
Copy link
Author

mxlgv commented Aug 9, 2024

Removed --image-base It builds working artifacts, both x32 and x64 . Tested on win 10 x64.

Yes it works, I made these changes locally. According to Microsoft documentation: "For security reasons, Microsoft recommends you use the /DYNAMICBASE option instead of specifying base addresses for your executables." So it seems unnecessary to specify the base address initially.

@EgorWeders
Copy link
Contributor

EgorWeders commented Aug 9, 2024

#533

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

No branches or pull requests

3 participants