Skip to content

Commit

Permalink
Object/COFF: Fix possible truncation bug.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rui314 committed Feb 20, 2014
1 parent 3e552a3 commit f41901d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/llvm/Object/COFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class COFFObjectFile : public ObjectFile {
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;

Expand Down
9 changes: 6 additions & 3 deletions lib/Object/COFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f41901d

Please sign in to comment.