This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] Do MinGW specific entry/subsystem inference
ClosedPublic

Authored by mstorsjo on Oct 5 2018, 4:30 AM.

Details

Summary

ld.bfd doesn't do any inference of subsystem; unless the windows subsystem is specified, the console subsystem is used.

For the console subsystem, the entry point is called mainCRTStartup, regardless of whether the the user code entry point is main or wmain. The same goes for the windows subsystem, where the entry point always is WinMainCRTStartup, for both WinMain and wWinMain in user code.

One detail that we don't emulate, is that if the inferred entry point is undefined, ld.bfd silently just sets the entry point to the start of the image. And if an explicit entry point is set, but it is undefined, the link still succeeds but the linker warns about the entry point not being found.

Diff Detail

Event Timeline

mstorsjo created this revision.Oct 5 2018, 4:30 AM
ruiu added a comment.Oct 5 2018, 10:10 AM

This function is called only when you did not pass /entry:.

If MinGW uses only mainCRTStartup or WinMainCRTStartup, can you determine which is the case just by looking at a command line? If so, I'd always explicitly pass /entry: to the lld-link driver from the mingw driver.

This function is called only when you did not pass /entry:.

If MinGW uses only mainCRTStartup or WinMainCRTStartup, can you determine which is the case just by looking at a command line? If so, I'd always explicitly pass /entry: to the lld-link driver from the mingw driver.

We could do that, but that departs a bit from what the gcc driver passes to ld.bfd. However I took a closer look at what ld.bfd actually does wrt this, and we can emulate it much better.

mstorsjo updated this revision to Diff 168506.Oct 5 2018, 12:37 PM
mstorsjo retitled this revision from [LLD] [COFF] Don't warn about both main and wmain in MinGW configurations to [LLD] [COFF] Do MinGW specific entry/subsystem inference.
mstorsjo edited the summary of this revision. (Show Details)

Emulating the ld.bfd behaviour much more closely.

ruiu accepted this revision.Oct 5 2018, 12:39 PM

LGTM

This revision is now accepted and ready to land.Oct 5 2018, 12:39 PM
This revision was automatically updated to reflect the committed changes.