[PATCH] [PECOFF] Fill size field of IMAGE_DATA_DIRECTORY

Patch by Ron Ofir.

llvm-svn: 187262
This commit is contained in:
Rui Ueyama 2013-07-26 22:33:28 +00:00
parent 2a2a0973b8
commit 3939101d6f
3 changed files with 13 additions and 5 deletions

View File

@ -241,8 +241,8 @@ private:
// 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,12 @@ public:
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;
};

View File

@ -281,12 +281,14 @@ private:
/// 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);
}

View File

@ -384,7 +384,7 @@ public:
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));
}