[PATCH] [PECOFF] Fill size field of IMAGE_DATA_DIRECTORY
Ron Ofir
ron.ofir at gmail.com
Fri Jul 26 14:47:22 PDT 2013
Updated working copy
Hi LegalizeAdulthood, ruiu,
http://llvm-reviews.chandlerc.com/D1228
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1228?vs=3037&id=3043#toc
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(uint32_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
@@ -384,7 +384,7 @@
void setBaseRelocField(uint32_t addr, uint32_t size) {
auto *atom = new (_alloc) coff::COFFDataDirectoryAtom(
- _file, llvm::COFF::DataDirectoryIndex::BASE_RELOCATION_TABLE);
+ _file, llvm::COFF::DataDirectoryIndex::BASE_RELOCATION_TABLE, 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.3.patch
Type: text/x-patch
Size: 2422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130726/b5e7fdff/attachment.bin>
More information about the llvm-commits
mailing list