[llvm] r243761 - [COFF] Consider the ImageBase when reporting section addresses

David Majnemer david.majnemer at gmail.com
Fri Jul 31 10:40:25 PDT 2015


Author: majnemer
Date: Fri Jul 31 12:40:24 2015
New Revision: 243761

URL: http://llvm.org/viewvc/llvm-project?rev=243761&view=rev
Log:
[COFF] Consider the ImageBase when reporting section addresses

This lets us reenable the lld test disabled in r243758.

Modified:
    llvm/trunk/lib/Object/COFFObjectFile.cpp

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=243761&r1=243760&r2=243761&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Fri Jul 31 12:40:24 2015
@@ -177,7 +177,7 @@ ErrorOr<uint64_t> COFFObjectFile::getSym
   if (PE32Header)
     Result += PE32Header->ImageBase;
   else if (PE32PlusHeader)
-    Result += PE32Header->ImageBase;
+    Result += PE32PlusHeader->ImageBase;
 
   return Result;
 }
@@ -274,7 +274,15 @@ std::error_code COFFObjectFile::getSecti
 
 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 {





More information about the llvm-commits mailing list