[PECOFF] Fix /entry option.

This is yet another edge case of ambiguous name resolution.
When a symbol is specified with /entry:SYM, SYM may be resolved
to the C++ mangled function name (?SYM@@YAXXZ).

llvm-svn: 218706
This commit is contained in:
Rui Ueyama 2014-09-30 21:39:49 +00:00
parent dbddf11649
commit 07fae9691b
3 changed files with 22 additions and 3 deletions

View File

@ -298,7 +298,7 @@ private:
_firstTime = false;
if (_ctx->hasEntry()) {
StringRef entrySym = _ctx->allocate(_ctx->decorateSymbol(getEntry()));
StringRef entrySym = _ctx->allocate(getEntry());
_undefinedAtoms._atoms.push_back(
new (_alloc) SimpleUndefinedAtom(*this, entrySym));
_ctx->setHasEntry(true);
@ -313,9 +313,16 @@ private:
// subsystem if it's unknown.
std::string getEntry() const {
StringRef opt = _ctx->getEntrySymbolName();
if (!opt.empty())
return opt;
if (!opt.empty()) {
std::string mangled;
if (findDecoratedSymbol(_ctx, _syms.get(), opt, mangled))
return mangled;
return _ctx->decorateSymbol(opt);
}
return _ctx->decorateSymbol(getDefaultEntry());
}
std::string getDefaultEntry() const {
const std::string wWinMainCRTStartup = "wWinMainCRTStartup";
const std::string WinMainCRTStartup = "WinMainCRTStartup";
const std::string wmainCRTStartup = "wmainCRTStartup";

View File

@ -30,4 +30,11 @@ symbols:
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: "?baz@@YAXXZ"
Value: 4
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
...

View File

@ -31,3 +31,8 @@ WWINMAIN: _wWinMainCRTStartup
# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=MAINADDR %s
MAINADDR: AddressOfEntryPoint: 0x1004
# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:baz -- %t.obj
# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=MANGLE %s
MANGLE: AddressOfEntryPoint: 0x1004