[PATCH] D34072: Fix alignment bug in COFF emission.
Eric Beckmann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 9 16:42:14 PDT 2017
ecbeckmann created this revision.
Herald added a subscriber: hiraditya.
Fix alignment issue in https://reviews.llvm.org/D34020, by aligning all sections to 8 bytes.
https://reviews.llvm.org/D34072
Files:
llvm/lib/Object/WindowsResource.cpp
Index: llvm/lib/Object/WindowsResource.cpp
===================================================================
--- llvm/lib/Object/WindowsResource.cpp
+++ llvm/lib/Object/WindowsResource.cpp
@@ -30,6 +30,10 @@
const uint32_t MIN_HEADER_SIZE = 7 * sizeof(uint32_t) + 2 * sizeof(uint16_t);
+// COFF files seem to be inconsistent with alignment between sections, just use
+// 8-byte because it makes everyone happy.
+const uint32_t SECTION_ALIGNMENT = sizeof(uint64_t);
+
static const size_t ResourceMagicSize = 16;
static const size_t NullEntrySize = 16;
@@ -321,9 +325,11 @@
uint64_t FileSize;
uint32_t SymbolTableOffset;
uint32_t SectionOneSize;
+ uint32_t SectionOnePadding;
uint32_t SectionOneOffset;
uint32_t SectionOneRelocations;
uint32_t SectionTwoSize;
+ uint32_t SectionTwoPadding;
uint32_t SectionTwoOffset;
const ArrayRef<std::vector<UTF16>> StringTable;
std::vector<uint32_t> StringTableOffsets;
@@ -386,6 +392,8 @@
FileSize += SectionOneSize;
FileSize += Data.size() *
llvm::COFF::RelocationSize; // one relocation for each resource.
+ SectionOnePadding = OffsetToAlignment(FileSize, SECTION_ALIGNMENT);
+ FileSize += SectionOnePadding;
}
void WindowsResourceCOFFWriter::performSectionTwoLayout() {
@@ -398,6 +406,8 @@
SectionTwoSize += llvm::alignTo(Entry.size(), sizeof(uint64_t));
}
FileSize += SectionTwoSize;
+ SectionTwoPadding = OffsetToAlignment(FileSize, SECTION_ALIGNMENT);
+ FileSize += SectionTwoPadding;
}
static std::time_t getTime() {
@@ -497,14 +507,18 @@
writeDirectoryTree();
writeDirectoryStringTable();
writeFirstSectionRelocations();
+
+ Current += SectionOnePadding;
}
void WindowsResourceCOFFWriter::writeSecondSection() {
// Now write the .rsrc$02 section.
for (auto const &RawDataEntry : Data) {
std::copy(RawDataEntry.begin(), RawDataEntry.end(), Current);
Current += alignTo(RawDataEntry.size(), sizeof(uint64_t));
}
+
+ Current += SectionTwoPadding;
}
void WindowsResourceCOFFWriter::writeSymbolTable() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34072.102098.patch
Type: text/x-patch
Size: 2065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170609/7fa48b68/attachment-0001.bin>
More information about the llvm-commits
mailing list