summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-07-23 20:51:04 +0000
committerRui Ueyama <ruiu@google.com>2014-07-23 20:51:04 +0000
commit23314e1ca628594504347dc42f3728d8285c8dee (patch)
tree10f41bfdc2ea515c370a790b5e22defe34a64c90
parentd3c7942f4a3372cf8b2caf2fa8e14dbbf8610043 (diff)
downloadbcm5719-llvm-23314e1ca628594504347dc42f3728d8285c8dee.tar.gz
bcm5719-llvm-23314e1ca628594504347dc42f3728d8285c8dee.zip
[PECOFF] Fix entry point address.
Because of a bug, the entry point address in the PE/COFF header was not correct. llvm-svn: 213802
-rw-r--r--lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h2
-rw-r--r--lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp8
-rw-r--r--lld/test/pecoff/Inputs/entry.obj.yaml7
-rw-r--r--lld/test/pecoff/entry.test6
4 files changed, 19 insertions, 4 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
index 9d5c37937f2..57aae835c25 100644
--- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
+++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
@@ -303,6 +303,8 @@ private:
StringRef entrySym = _ctx->allocate(_ctx->decorateSymbol(getEntry()));
_undefinedAtoms._atoms.push_back(
new (_alloc) SimpleUndefinedAtom(*this, entrySym));
+ _ctx->setHasEntry(true);
+ _ctx->setEntrySymbolName(entrySym);
if (_ctx->deadStrip())
_ctx->addDeadStripRoot(entrySym);
}
diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
index 73fa4f7195e..22dd2f01ca9 100644
--- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -968,14 +968,14 @@ void PECOFFWriter::build(const File &linkedFile) {
// Find the virtual address of the entry point symbol if any. PECOFF spec
// says that entry point for dll images is optional, in which case it must
// be set to 0.
- if (_ctx.entrySymbolName().empty() && _ctx.isDll()) {
- peHeader->setAddressOfEntryPoint(0);
- } else {
+ if (_ctx.hasEntry()) {
uint64_t entryPointAddress =
dyn_cast<AtomChunk>(section)
- ->getAtomVirtualAddress(_ctx.entrySymbolName());
+ ->getAtomVirtualAddress(_ctx.getEntrySymbolName());
if (entryPointAddress != 0)
peHeader->setAddressOfEntryPoint(entryPointAddress);
+ } else {
+ peHeader->setAddressOfEntryPoint(0);
}
}
if (section->getSectionName() == ".data")
diff --git a/lld/test/pecoff/Inputs/entry.obj.yaml b/lld/test/pecoff/Inputs/entry.obj.yaml
index 595ea18fc9f..ba4d5b2002e 100644
--- a/lld/test/pecoff/Inputs/entry.obj.yaml
+++ b/lld/test/pecoff/Inputs/entry.obj.yaml
@@ -23,4 +23,11 @@ symbols:
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+
+ - Name: _bar
+ 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 404cf431ea5..f4472d8bae8 100644
--- a/lld/test/pecoff/entry.test
+++ b/lld/test/pecoff/entry.test
@@ -25,3 +25,9 @@ WINMAIN: _WinMainCRTStartup
# RUN: FileCheck -check-prefix=WWINMAIN %s < %t.log
WWINMAIN: _wWinMainCRTStartup
+
+# RUN: lld -flavor link /out:%t.exe /alternatename:_main=_foo \
+# RUN: /alternatename:_mainCRTStartup=_bar -- %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=MAINADDR %s
+
+MAINADDR: AddressOfEntryPoint: 0x1004
OpenPOWER on IntegriCloud