From f41901d32ca141550e639d875638c828d3d65466 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 20 Feb 2014 19:14:56 +0000 Subject: Object/COFF: Fix possible truncation bug. VA can be 64 bit, as the image base can be larger than 4GB, so we need to handle 64 bit VAs properly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201803 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/COFFObjectFile.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index ede784379f..a3931b3b0e 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include +#include using namespace llvm; using namespace object; @@ -382,9 +383,11 @@ error_code COFFObjectFile::initSymbolTablePtr() { } // Returns the file offset for the given VA. -error_code COFFObjectFile::getVaPtr(uint32_t Addr, uintptr_t &Res) const { - uint32_t ImageBase = PE32Header ? PE32Header->ImageBase : (uint32_t)PE32PlusHeader->ImageBase; - return getRvaPtr(Addr - ImageBase, Res); +error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const { + uint64_t ImageBase = PE32Header ? PE32Header->ImageBase : PE32PlusHeader->ImageBase; + uint64_t Rva = Addr - ImageBase; + assert(Rva <= UINT32_MAX); + return getRvaPtr((uint32_t)Rva, Res); } // Returns the file offset for the given RVA. -- cgit v1.2.3