[COFF] Consider the ImageBase when reporting section addresses
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 31 Jul 2015 17:40:24 +0000 (17:40 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 31 Jul 2015 17:40:24 +0000 (17:40 +0000)
This lets us reenable the lld test disabled in r243758.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243761 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/COFFObjectFile.cpp

index ed63f3a64e0993cf29017ee46253a4c10074c6d8..d110b9293ba2fc5fe5c96c0a1b470a1e580a9bd9 100644 (file)
@@ -177,7 +177,7 @@ ErrorOr<uint64_t> COFFObjectFile::getSymbolAddress(DataRefImpl Ref) const {
   if (PE32Header)
     Result += PE32Header->ImageBase;
   else if (PE32PlusHeader)
-    Result += PE32Header->ImageBase;
+    Result += PE32PlusHeader->ImageBase;
 
   return Result;
 }
@@ -274,7 +274,15 @@ std::error_code COFFObjectFile::getSectionName(DataRefImpl Ref,
 
 uint64_t COFFObjectFile::getSectionAddress(DataRefImpl Ref) const {
   const coff_section *Sec = toSec(Ref);
-  return Sec->VirtualAddress;
+  uint64_t Result = Sec->VirtualAddress;
+
+  // The section VirtualAddress does not include ImageBase, and we want to
+  // return virtual addresses.
+  if (PE32Header)
+    Result += PE32Header->ImageBase;
+  else if (PE32PlusHeader)
+    Result += PE32PlusHeader->ImageBase;
+  return Result;
 }
 
 uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const {