On Sat, 17 Dec 2022, LIU Hao wrote:
在 2022-12-17 22:22, Pali Rohár 写道:
Currently when linking target application with LTO builds of mingw-w64
libraries, it is needed to manually specify entry point of mingw-w64 crt
startup function via linker flag -Wl,-e,_mainCRTStartup (for console
executables) or -Wl,-e,_WinMainCRTStartup (for GUI executables) or
-Wl,-e,_DllMainCRTStartup@12 (for DLL libraries). Otherwise LTO compiler
drops startup function generates output binary totally broken and
non-working (executable crashes during during startup).
Wouldn't this cause executables to contain all three entry-point functions,
which I think should be avoided?
I believe this patch should be harmless; for regular object file based
linking, __attribute__((used)) shouldn't have any effect across object
file boundaries (it only affects what's emitted and what's optimized out
from within each object file). And for LTO linking, the linking stage
would still pull in the same set of LTO object files from the static
libraries, and this only affects what symbols get emitted from the LTO
code generation step.
So I would be fine with this patch - although I guess I could include it
in a test build run with Clang/LLD.
I guess I'd need to build mingw-w64-crt with -flto in order to reproduce
the situation at hand though. I don't currently have a test setup where I
do that (but iirc Zig builds mingw-w64-crt that way, with optional LTO).
// Martin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public