[PATCH] [PECOFF] Fill size field of IMAGE_DATA_DIRECTORY
Ron Ofir
ron.ofir at gmail.com
Fri Jul 26 11:54:48 PDT 2013
Hi ruiu,
This patch adds writing sizes to DataDirectory entries.
http://llvm-reviews.chandlerc.com/D1228
Files:
Atoms.h
IdataPass.h
WriterPECOFF.cpp
Index: Atoms.h
===================================================================
--- Atoms.h
+++ Atoms.h
@@ -241,8 +241,8 @@
// COFF header.
class COFFDataDirectoryAtom : public COFFLinkerInternalAtom {
public:
- COFFDataDirectoryAtom(const File &file, uint64_t ordinal)
- : COFFLinkerInternalAtom(file, std::vector<uint8_t>(8)),
+ COFFDataDirectoryAtom(const File &file, uint64_t ordinal, uint32_t entrySize)
+ : COFFLinkerInternalAtom(file, assembleRawContent(entrySize)),
_ordinal(ordinal) {}
virtual uint64_t ordinal() const { return _ordinal; }
@@ -250,6 +250,13 @@
virtual ContentPermissions permissions() const { return permR__; }
private:
+
+ std::vector<uint8_t> assembleRawContent(uint64_t entrySize) {
+ std::vector<uint8_t> data = std::vector<uint8_t>(8, 0);
+ *(reinterpret_cast<uint32_t *>(&data[4])) = entrySize;
+ return data;
+ }
+
uint64_t _ordinal;
};
Index: IdataPass.h
===================================================================
--- IdataPass.h
+++ IdataPass.h
@@ -281,12 +281,14 @@
/// will be set by the writer.
void createDataDirectoryAtoms(Context &ctx) {
auto *dir = new (_alloc) coff::COFFDataDirectoryAtom(
- ctx.file, llvm::COFF::DataDirectoryIndex::IMPORT_TABLE);
+ ctx.file, llvm::COFF::DataDirectoryIndex::IMPORT_TABLE,
+ ctx.importDirectories.size() * ctx.importDirectories[0]->size());
addDir32NBReloc(dir, ctx.importDirectories[0]);
ctx.file.addAtom(*dir);
auto *iat = new (_alloc) coff::COFFDataDirectoryAtom(
- ctx.file, llvm::COFF::DataDirectoryIndex::IAT);
+ ctx.file, llvm::COFF::DataDirectoryIndex::IAT,
+ ctx.importAddressTables.size() * ctx.importAddressTables[0]->size());
addDir32NBReloc(iat, ctx.importAddressTables[0]);
ctx.file.addAtom(*iat);
}
Index: WriterPECOFF.cpp
===================================================================
--- WriterPECOFF.cpp
+++ WriterPECOFF.cpp
@@ -382,7 +382,7 @@
}
void setBaseRelocField(uint32_t addr, uint32_t size) {
- auto *atom = new (_alloc) coff::COFFDataDirectoryAtom(_file, 5);
+ auto *atom = new (_alloc) coff::COFFDataDirectoryAtom(_file, 5, size);
uint64_t offset = atom->ordinal() * sizeof(llvm::object::data_directory);
_atomLayouts.push_back(new (_alloc) AtomLayout(atom, offset, offset));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1228.1.patch
Type: text/x-patch
Size: 2363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130726/dc402313/attachment.bin>
More information about the llvm-commits
mailing list