[PATCH] [lld][PECOFF] Fix data directory entry RVA of base relocations section
Ron Ofir
ron.ofir at gmail.com
Mon Sep 23 13:21:15 PDT 2013
Rebased, removed whitespace and fixed according to comments by Rui
Hi ruiu,
http://llvm-reviews.chandlerc.com/D1743
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1743?vs=4445&id=4447#toc
Files:
lib/ReaderWriter/PECOFF/Atoms.h
lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
test/pecoff/base-reloc.test
Index: lib/ReaderWriter/PECOFF/Atoms.h
===================================================================
--- lib/ReaderWriter/PECOFF/Atoms.h
+++ lib/ReaderWriter/PECOFF/Atoms.h
@@ -240,18 +240,20 @@
// COFF header.
class COFFDataDirectoryAtom : public COFFLinkerInternalAtom {
public:
- COFFDataDirectoryAtom(const File &file, uint64_t ordinal, uint32_t entrySize)
- : COFFLinkerInternalAtom(file, assembleRawContent(entrySize)),
+ COFFDataDirectoryAtom(const File &file, uint64_t ordinal, uint32_t entrySize,
+ uint32_t entryAddr = 0)
+ : COFFLinkerInternalAtom(file, assembleRawContent(entrySize, entryAddr)),
_ordinal(ordinal) {}
virtual uint64_t ordinal() const { return _ordinal; }
virtual ContentType contentType() const { return typeDataDirectoryEntry; }
virtual ContentPermissions permissions() const { return permR__; }
private:
- std::vector<uint8_t> assembleRawContent(uint32_t entrySize) {
+ std::vector<uint8_t> assembleRawContent(uint32_t entrySize, uint32_t entryAddr) {
std::vector<uint8_t> data = std::vector<uint8_t>(8, 0);
- *(reinterpret_cast<uint32_t *>(&data[4])) = entrySize;
+ *(reinterpret_cast<llvm::support::ulittle32_t *>(&data[0])) = entryAddr;
+ *(reinterpret_cast<llvm::support::ulittle32_t *>(&data[4])) = entrySize;
return data;
}
Index: lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
===================================================================
--- lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -425,7 +425,8 @@
void setBaseRelocField(uint32_t addr, uint32_t size) {
auto *atom = new (_alloc) coff::COFFDataDirectoryAtom(
- _file, llvm::COFF::DataDirectoryIndex::BASE_RELOCATION_TABLE, size);
+ _file, llvm::COFF::DataDirectoryIndex::BASE_RELOCATION_TABLE, size,
+ addr);
uint64_t offset = atom->ordinal() * sizeof(llvm::object::data_directory);
_atomLayouts.push_back(new (_alloc) AtomLayout(atom, offset, offset));
}
@@ -820,9 +821,9 @@
if (baseReloc) {
baseReloc->setContents(_chunks);
if (baseReloc->size()) {
+ addSectionChunk(baseReloc, sectionTable);
dataDirectory->setBaseRelocField(baseReloc->getSectionRva(),
baseReloc->rawSize());
- addSectionChunk(baseReloc, sectionTable);
}
}
Index: test/pecoff/base-reloc.test
===================================================================
--- test/pecoff/base-reloc.test
+++ test/pecoff/base-reloc.test
@@ -31,6 +31,8 @@
NOBASEREL-HEADER: IMAGE_FILE_RELOCS_STRIPPED
+BASEREL-HEADER: BaseRelocationTableRVA: 0x3000
+BASEREL-HEADER: BaseRelocationTableSize: 0xC
BASEREL-HEADER: Name: .reloc (2E 72 65 6C 6F 63 00 00)
BASEREL-HEADER-NEXT: VirtualSize: 0xC
BASEREL-HEADER-NEXT: VirtualAddress: 0x3000
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1743.2.patch
Type: text/x-patch
Size: 2888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130923/bddae571/attachment.bin>
More information about the llvm-commits
mailing list