This is an archive of the discontinued LLVM Phabricator instance.

lld-link: Several tweaks to default entry point selection.
ClosedPublic

Authored by thakis on Oct 3 2018, 8:51 AM.

Details

Summary

Three related changes:

First:. link.exe uses the presence of main and wmain to decide if it should call mainCRTStartup or wmainCRTStartup, even if /nodefaultlib is passed. For compatibility, remove FindMain logic.

Second: Default to the non-wide entrypoint if main is not found. This has two effects:

A: In normal links, lld-link now prints

lld-link: error: undefined symbol: _main
>>> referenced by f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:78
>>>               libcmt.lib(exe_main.obj):("int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ))
>>> referenced by f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283
>>>               libcmt.lib(exe_main.obj):("int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ))

instead of

lld-link: error: entry point must be defined

This is arguably a better error message, since it now mentions that _main is missing. (This matches link.exe's diagnostic in this case.)

B: With /nodefautlib, we now default to mainCRTStartup if no main() is present, again matching link.exe. This makes r337407 obsolete.

This means if you have a cc file containing both mainCRTStartup and wmainCRTStartup and you pass /nodefaultlib /subsystem:console, lld-link will now call mainCRTStartup, matching link.exe

Third: Print a warning if both main and wmain are present, similar to link.exe's LNK4067.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

thakis created this revision.Oct 3 2018, 8:51 AM
thakis edited the summary of this revision. (Show Details)
thakis edited the summary of this revision. (Show Details)
thakis edited the summary of this revision. (Show Details)
thakis edited the summary of this revision. (Show Details)
thakis edited the summary of this revision. (Show Details)
thakis edited the summary of this revision. (Show Details)
thakis edited the summary of this revision. (Show Details)Oct 3 2018, 8:54 AM
thakis edited the summary of this revision. (Show Details)
thakis edited the summary of this revision. (Show Details)
ruiu added a comment.Oct 3 2018, 9:20 AM

Can you add a test for the new warning message?

thakis edited the summary of this revision. (Show Details)Oct 3 2018, 9:22 AM
thakis updated this revision to Diff 168127.Oct 3 2018, 9:30 AM

add warning test

ruiu accepted this revision.Oct 3 2018, 9:53 AM

LGTM

This revision is now accepted and ready to land.Oct 3 2018, 9:53 AM
This revision was automatically updated to reflect the committed changes.