summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/MC/WinCOFFObjectWriter.cpp11
-rw-r--r--llvm/test/MC/COFF/directive-section-characteristics.ll6
2 files changed, 15 insertions, 2 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index e3985815e45..ce6dcfda8ff 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -939,7 +939,8 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
Sec->Header.SizeOfRawData = Layout.getSectionAddressSize(&Section);
if (IsPhysicalSection(Sec)) {
- Sec->Header.PointerToRawData = offset;
+ // Align the section data to a four byte boundary.
+ Sec->Header.PointerToRawData = RoundUpToAlignment(offset, 4);
offset += Sec->Header.SizeOfRawData;
}
@@ -1009,9 +1010,15 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
continue;
if ((*i)->Header.PointerToRawData != 0) {
- assert(OS.tell() == (*i)->Header.PointerToRawData &&
+ assert(OS.tell() <= (*i)->Header.PointerToRawData &&
"Section::PointerToRawData is insane!");
+ unsigned SectionDataPadding = (*i)->Header.PointerToRawData - OS.tell();
+ assert(SectionDataPadding < 4 &&
+ "Should only need at most three bytes of padding!");
+
+ WriteZeros(SectionDataPadding);
+
Asm.writeSectionData(j, Layout);
}
diff --git a/llvm/test/MC/COFF/directive-section-characteristics.ll b/llvm/test/MC/COFF/directive-section-characteristics.ll
index ca8102af641..a44c81d2262 100644
--- a/llvm/test/MC/COFF/directive-section-characteristics.ll
+++ b/llvm/test/MC/COFF/directive-section-characteristics.ll
@@ -7,7 +7,13 @@ entry:
}
; CHECK: Section {
+; CHECK: Name: .text
+; CHECK: PointerToRawData: 0xB4
+; CHECK: }
+
+; CHECK: Section {
; CHECK: Name: .drectve
+; CHECK: PointerToRawData: 0xB8
; CHECK: Characteristics [
; CHECK: IMAGE_SCN_ALIGN_1BYTES
; CHECK: IMAGE_SCN_LNK_INFO
OpenPOWER on IntegriCloud