summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-02-20 03:35:59 +0000
committerRui Ueyama <ruiu@google.com>2015-02-20 03:35:59 +0000
commit11f42aa2854bf27a7eb38e3fbfe1fe0f5a24a24a (patch)
tree843036343eb477d73efd4705e76ec69ee8673b95 /lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
parentad6eb127c9e4c48cfdff1f47e5efe83255b15565 (diff)
downloadbcm5719-llvm-11f42aa2854bf27a7eb38e3fbfe1fe0f5a24a24a.tar.gz
bcm5719-llvm-11f42aa2854bf27a7eb38e3fbfe1fe0f5a24a24a.zip
PECOFF: Fix base relocation for ImageBase.
This is yet another edge case of base relocation for symbols. Absolute symbols are in general not target of base relocation because absolute atom is a way to point to a specific memory location. In r229816, I removed entries for absolute atoms from the base relocation table (so that they won't be fixed by the loader). However, there was one exception -- ImageBase. ImageBase points to the start address of the current image in memory. That needs to be fixed up at load time. This patch is to treat the symbol in a special manner. llvm-svn: 229961
Diffstat (limited to 'lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp')
-rw-r--r--lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
index 8dcfcc142a9..6459084d9e5 100644
--- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -784,7 +784,13 @@ void AtomChunk::addBaseRelocations(BaseRelocationList &relocSites) const {
for (const Reference *ref : *atom) {
if (ref->kindNamespace() != Reference::KindNamespace::COFF)
continue;
- if (isa<AbsoluteAtom>(ref->target()))
+
+ // An absolute symbol points to a fixed location in memory. Their
+ // address should not be fixed at load time. One exception is ImageBase
+ // because that's relative to run-time image base address.
+ if (auto *abs = dyn_cast<AbsoluteAtom>(ref->target()))
+ if (!abs->name().equals("__ImageBase") &&
+ !abs->name().equals("___ImageBase"))
continue;
uint64_t address = layout->_virtualAddr + ref->offsetInAtom();
OpenPOWER on IntegriCloud