From f50e261e1e998306d8cce56633f5c2892d6519be Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 11 Feb 2015 22:22:30 +0000 Subject: [PATCH] MC, COFF: Align section contents to a four byte boundary git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228879 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/WinCOFFObjectWriter.cpp | 11 +++++++++-- test/MC/COFF/directive-section-characteristics.ll | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index e3985815e45..ce6dcfda8ff 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/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/test/MC/COFF/directive-section-characteristics.ll b/test/MC/COFF/directive-section-characteristics.ll index ca8102af641..a44c81d2262 100644 --- a/test/MC/COFF/directive-section-characteristics.ll +++ b/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 -- 2.11.0