summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-09-30 21:39:49 +0000
committerRui Ueyama <ruiu@google.com>2014-09-30 21:39:49 +0000
commit07fae9691b9abccb1b1ad8bdfee5933e6e75287d (patch)
tree2f67d81b3736df6e2189c7ca5bfa526aac8cf439
parentdbddf11649b891119ad04addb34e4957d796fbb7 (diff)
downloadbcm5719-llvm-07fae9691b9abccb1b1ad8bdfee5933e6e75287d.tar.gz
bcm5719-llvm-07fae9691b9abccb1b1ad8bdfee5933e6e75287d.zip
[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
-rw-r--r--lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h13
-rw-r--r--lld/test/pecoff/Inputs/entry.obj.yaml7
-rw-r--r--lld/test/pecoff/entry.test5
3 files changed, 22 insertions, 3 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
index 33667ad2b20..4a667db6d46 100644
--- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
+++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
@@ -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";
diff --git a/lld/test/pecoff/Inputs/entry.obj.yaml b/lld/test/pecoff/Inputs/entry.obj.yaml
index ba4d5b2002e..35eae143c43 100644
--- a/lld/test/pecoff/Inputs/entry.obj.yaml
+++ b/lld/test/pecoff/Inputs/entry.obj.yaml
@@ -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
...
diff --git a/lld/test/pecoff/entry.test b/lld/test/pecoff/entry.test
index f4472d8bae8..fd0e1833b24 100644
--- a/lld/test/pecoff/entry.test
+++ b/lld/test/pecoff/entry.test
@@ -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
OpenPOWER on IntegriCloud