From 3a3f472cb457eab29563ff4afd3ae61511eed71a Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 8 Mar 2010 22:03:42 +0000 Subject: [PATCH] MC/Macho-O: Align the zerofill section itself to the maximum alignment. llvm-svn: 97991 --- llvm/lib/MC/MCAssembler.cpp | 10 ++++++++++ llvm/test/MC/MachO/zerofill-4.s | 2 +- llvm/test/MC/MachO/zerofill-sect-align.s | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 llvm/test/MC/MachO/zerofill-sect-align.s diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 1ec1d815de46..4b78dc034fcf 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -1279,9 +1279,19 @@ void MCAssembler::Finish() { if (!isVirtualSection(SD.getSection())) continue; + // Align this section if necessary by adding padding bytes to the previous + // section. + if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment())) { + assert(Prev && "Missing prev section!"); + Prev->setFileSize(Prev->getFileSize() + Pad); + Address += Pad; + } + SD.setAddress(Address); LayoutSection(SD); Address += SD.getSize(); + + Prev = &SD; } DEBUG_WITH_TYPE("mc-dump", { diff --git a/llvm/test/MC/MachO/zerofill-4.s b/llvm/test/MC/MachO/zerofill-4.s index 3513be443781..d9c987c9b65a 100644 --- a/llvm/test/MC/MachO/zerofill-4.s +++ b/llvm/test/MC/MachO/zerofill-4.s @@ -1,4 +1,4 @@ -// RUN: llvm-mc -triple i386-apple-darwin9 %s -filetype=obj -o - | macho-dump --dump-section-data | FileCheck %s +// RUN: llvm-mc -triple i386-apple-darwin9 %s -filetype=obj -o - | macho-dump | FileCheck %s .zerofill __DATA,__bss,_fill0,1,0 .zerofill __DATA,__bss,_a,4,2 diff --git a/llvm/test/MC/MachO/zerofill-sect-align.s b/llvm/test/MC/MachO/zerofill-sect-align.s new file mode 100644 index 000000000000..5d7730f439e9 --- /dev/null +++ b/llvm/test/MC/MachO/zerofill-sect-align.s @@ -0,0 +1,15 @@ +// RUN: llvm-mc -triple i386-apple-darwin9 %s -filetype=obj -o - | macho-dump | FileCheck %s +// +// Check that the section itself is aligned. + + .byte 0 + +.zerofill __DATA,__bss,_a,1,0 +.zerofill __DATA,__bss,_b,4,4 + +// CHECK: # Symbol 0 +// CHECK: ('n_value', 16) +// CHECK: ('_string', '_a') +// CHECK: # Symbol 1 +// CHECK: ('n_value', 32) +// CHECK: ('_string', '_b') -- GitLab