aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/COFFObjectFile.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-11-14 08:15:42 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-11-14 08:15:42 +0000
commitf69b0585c1aa802a496737fa93443d4a215ae641 (patch)
tree8b8173c48e8746547b5f4f6f56865069d7310d17 /llvm/lib/Object/COFFObjectFile.cpp
parent55c2699d29730d767def564befd2bf4ffbf9a3fe (diff)
downloadllvm-f69b0585c1aa802a496737fa93443d4a215ae641.zip
llvm-f69b0585c1aa802a496737fa93443d4a215ae641.tar.gz
llvm-f69b0585c1aa802a496737fa93443d4a215ae641.tar.bz2
obj2yaml, yaml2obj: Add support for COFF executables
In support of serializing executables, obj2yaml now records the virtual address and size of sections. It also serializes whatever we strictly need from the PE header, it expects that it can reconstitute everything else via inference. yaml2obj can reconstitute a fully linked executable. In order to get executables correctly serialized/deserialized, other bugs were fixed as a circumstance. We now properly respect file and section alignments. We also avoid writing out string tables unless they are strictly necessary. llvm-svn: 221975
Diffstat (limited to 'llvm/lib/Object/COFFObjectFile.cpp')
-rw-r--r--llvm/lib/Object/COFFObjectFile.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index 68bf7fd..a1fc51a 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -460,9 +460,9 @@ std::error_code COFFObjectFile::initSymbolTablePtr() {
// Find string table. The first four byte of the string table contains the
// total size of the string table, including the size field itself. If the
// string table is empty, the value of the first four byte would be 4.
- const uint8_t *StringTableAddr =
- base() + getPointerToSymbolTable() +
- getNumberOfSymbols() * getSymbolTableEntrySize();
+ uint32_t StringTableOffset = getPointerToSymbolTable() +
+ getNumberOfSymbols() * getSymbolTableEntrySize();
+ const uint8_t *StringTableAddr = base() + StringTableOffset;
const ulittle32_t *StringTableSizePtr;
if (std::error_code EC = getObject(StringTableSizePtr, Data, StringTableAddr))
return EC;
@@ -826,13 +826,17 @@ std::error_code
COFFObjectFile::getDataDirectory(uint32_t Index,
const data_directory *&Res) const {
// Error if if there's no data directory or the index is out of range.
- if (!DataDirectory)
+ if (!DataDirectory) {
+ Res = nullptr;
return object_error::parse_failed;
+ }
assert(PE32Header || PE32PlusHeader);
uint32_t NumEnt = PE32Header ? PE32Header->NumberOfRvaAndSize
: PE32PlusHeader->NumberOfRvaAndSize;
- if (Index > NumEnt)
+ if (Index >= NumEnt) {
+ Res = nullptr;
return object_error::parse_failed;
+ }
Res = &DataDirectory[Index];
return object_error::success;
}