MC/Macho-O: Align the zerofill section itself to the maximum alignment.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 8 Mar 2010 22:03:42 +0000 (22:03 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 8 Mar 2010 22:03:42 +0000 (22:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97991 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCAssembler.cpp
test/MC/MachO/zerofill-4.s
test/MC/MachO/zerofill-sect-align.s [new file with mode: 0644]

index 1ec1d815de46b2555b3fe87568499635101e114a..4b78dc034fcf9cb163c12f608305f7145df6bf36 100644 (file)
@@ -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", {
index 3513be4437813ee7af709e67420e11c8d288d662..d9c987c9b65af04d82dcd4b577979b4ec3ad3ad5 100644 (file)
@@ -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/test/MC/MachO/zerofill-sect-align.s b/test/MC/MachO/zerofill-sect-align.s
new file mode 100644 (file)
index 0000000..5d7730f
--- /dev/null
@@ -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')