summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-07-26 22:33:28 +0000
committerRui Ueyama <ruiu@google.com>2013-07-26 22:33:28 +0000
commit3939101d6f26b6456a81185d0e4e66cd5e38bfc5 (patch)
treee82615b051be955f2c1241ad9d67168f6b16394d
parent2a2a0973b8d67817c30a0105b7a09f87ec3b4fd1 (diff)
downloadbcm5719-llvm-3939101d6f26b6456a81185d0e4e66cd5e38bfc5.tar.gz
bcm5719-llvm-3939101d6f26b6456a81185d0e4e66cd5e38bfc5.zip
[PATCH] [PECOFF] Fill size field of IMAGE_DATA_DIRECTORY
Patch by Ron Ofir. llvm-svn: 187262
-rw-r--r--lld/lib/ReaderWriter/PECOFF/Atoms.h10
-rw-r--r--lld/lib/ReaderWriter/PECOFF/IdataPass.h6
-rw-r--r--lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp2
3 files changed, 13 insertions, 5 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/Atoms.h b/lld/lib/ReaderWriter/PECOFF/Atoms.h
index 99d57024b69..0db4f3cd8e7 100644
--- a/lld/lib/ReaderWriter/PECOFF/Atoms.h
+++ b/lld/lib/ReaderWriter/PECOFF/Atoms.h
@@ -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;
};
diff --git a/lld/lib/ReaderWriter/PECOFF/IdataPass.h b/lld/lib/ReaderWriter/PECOFF/IdataPass.h
index 4ff59bfc17e..88a84d378d3 100644
--- a/lld/lib/ReaderWriter/PECOFF/IdataPass.h
+++ b/lld/lib/ReaderWriter/PECOFF/IdataPass.h
@@ -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);
}
diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
index dbc965d5628..34dc1fb2c98 100644
--- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -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));
}
OpenPOWER on IntegriCloud