diff options
| author | Rui Ueyama <ruiu@google.com> | 2014-02-20 19:14:56 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2014-02-20 19:14:56 +0000 |
| commit | b7a40081e99391d3d7ed406bd9dfb6b921ce74cc (patch) | |
| tree | 6b5825eeadcaf4d7df7a705b784e0f81db0de687 | |
| parent | 4fe0aba12b2f98aaa5af1384fec535fc911493f2 (diff) | |
| download | bcm5719-llvm-b7a40081e99391d3d7ed406bd9dfb6b921ce74cc.tar.gz bcm5719-llvm-b7a40081e99391d3d7ed406bd9dfb6b921ce74cc.zip | |
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.
llvm-svn: 201803
| -rw-r--r-- | llvm/include/llvm/Object/COFF.h | 2 | ||||
| -rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h index dd36067485f..d38ed2e0969 100644 --- a/llvm/include/llvm/Object/COFF.h +++ b/llvm/include/llvm/Object/COFF.h @@ -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; diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index ede784379f2..a3931b3b0e9 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -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::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. |

