This is an archive of the discontinued LLVM Phabricator instance.

lld-link: Fix subsystem inference for non-console apps on 32-bit, and fix entry point inference on 32-bit with /nodefaultlib
ClosedPublic

Authored by thakis on Aug 2 2018, 7:00 AM.

Details

Reviewers
ruiu
Summary

LinkerDriver::inferSubsystem() used to do Symtab->findUnderscore("WinMain"), but WinMain is stdcall in 32-bit and is hence is called _WinMain@16. Instead, Symtab->findMangle(mangle("WinMain")) needs to be called.

But since LinkerDriver::inferSubsystem() and LinkerDriver::findDefaultEntry() both need to call this, introduce a common helper function for this and call it from both places. (Also call it for "main" for consistency, even though findUnderscore() is enough for main since that's __cdecl on 32-bit).

This also exposed a bug for /nodefaultlib entrypoint inference: The code here called findMangle(Sym) instead of findMangle(mangle(Sym)), again doing the wrong thing on 32-bit. Fix that too.

Diff Detail

Event Timeline

thakis created this revision.Aug 2 2018, 7:00 AM
thakis retitled this revision from lld-link: Fix subsystem inference for non-console apps on 32-bit, an dfix entry point inference on 32-bit with /nodefaultlib to lld-link: Fix subsystem inference for non-console apps on 32-bit, and fix entry point inference on 32-bit with /nodefaultlib.
ruiu accepted this revision.Aug 2 2018, 3:24 PM

LGTM

COFF/Driver.cpp
418

I believe this can be a non-member static function.

This revision is now accepted and ready to land.Aug 2 2018, 3:24 PM
thakis updated this revision to Diff 158852.Aug 2 2018, 3:33 PM

comment

thakis added a comment.Aug 2 2018, 3:34 PM

Thanks!

COFF/Driver.cpp
418

Yes, if I make ::mangle() a local static too (which in return requires moving it up a bit). Want me to do this in this patch? I'm attaching the new diff so that you can see how it looks.

thakis closed this revision.Aug 3 2018, 5:00 AM

Landed 2nd version in r338877.