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
This commit is contained in:
David Majnemer 2015-02-11 22:22:30 +00:00
parent b357516cb4
commit f50e261e1e
2 changed files with 15 additions and 2 deletions

View 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);
}

View 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