[llvm] r201803 - Object/COFF: Fix possible truncation bug.
Rui Ueyama
ruiu at google.com
Thu Feb 20 11:14:56 PST 2014
Author: ruiu
Date: Thu Feb 20 13:14:56 2014
New Revision: 201803
URL: http://llvm.org/viewvc/llvm-project?rev=201803&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/lib/Object/COFFObjectFile.cpp
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=201803&r1=201802&r2=201803&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Thu Feb 20 13:14:56 2014
@@ -397,7 +397,7 @@ public:
error_code getSectionContents(const coff_section *Sec,
ArrayRef<uint8_t> &Res) const;
- error_code getVaPtr(uint32_t Rva, uintptr_t &Res) const;
+ error_code getVaPtr(uint64_t VA, uintptr_t &Res) const;
error_code getRvaPtr(uint32_t Rva, uintptr_t &Res) const;
error_code getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const;
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=201803&r1=201802&r2=201803&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Thu Feb 20 13:14:56 2014
@@ -19,6 +19,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <cctype>
+#include <cstdint>
using namespace llvm;
using namespace object;
@@ -382,9 +383,11 @@ error_code COFFObjectFile::initSymbolTab
}
// 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.
More information about the llvm-commits
mailing list