[lld] r190951 - [PECOFF] Fix base relocation block alignment
Rui Ueyama
ruiu at google.com
Wed Sep 18 11:36:39 PDT 2013
Author: ruiu
Date: Wed Sep 18 13:36:39 2013
New Revision: 190951
URL: http://llvm.org/viewvc/llvm-project?rev=190951&view=rev
Log:
[PECOFF] Fix base relocation block alignment
Base relocation block should be aligned on a 32-bit boundary. While the PECOFF
spec mentions only aligning the blocks, and not padding them, link.exe seems
to add an extra IMAGE_REL_I386_ABSOLUTE entry (just a zeroed WORD) in order to
pad the blocks.
Patch by Ron Ofir.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=190951&r1=190950&r2=190951&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Wed Sep 18 13:36:39 2013
@@ -665,6 +665,7 @@ public:
: COFFLinkerInternalAtom(file, std::move(data)) {}
virtual ContentType contentType() const { return typeData; }
+ virtual Alignment alignment() const { return Alignment(2); }
};
/// A BaseRelocChunk represents ".reloc" section.
@@ -736,8 +737,10 @@ private:
// Create the content of a relocation block.
DefinedAtom *createBaseRelocBlock(const File &file, uint64_t pageAddr,
const std::vector<uint16_t> &offsets) {
- uint32_t size = sizeof(ulittle32_t) * 2
- + sizeof(ulittle16_t) * offsets.size();
+ // Relocation blocks should be padded with IMAGE_REL_I386_ABSOLUTE to be
+ // aligned to a DWORD size boundary.
+ uint32_t size = llvm::RoundUpToAlignment(sizeof(ulittle32_t) * 2
+ + sizeof(ulittle16_t) * offsets.size(), sizeof(ulittle32_t));
std::vector<uint8_t> contents(size);
uint8_t *ptr = &contents[0];
More information about the llvm-commits
mailing list