MC, COFF: Align section contents to a four byte boundary
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 11 Feb 2015 22:22:30 +0000 (22:22 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 11 Feb 2015 22:22:30 +0000 (22:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228879 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/WinCOFFObjectWriter.cpp
test/MC/COFF/directive-section-characteristics.ll

index e3985815e45f32dd1b6cc45be3e0faac928d03a4..ce6dcfda8ff8e1380a274922abb8a5080abdba30 100644 (file)
@@ -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);
       }
 
index ca8102af641d85e6bf54cefa25629def57f1fc72..a44c81d226277f7142287f8d1a368ce95e43dc7a 100644 (file)
@@ -6,8 +6,14 @@ entry:
   ret void
 }
 
+; 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