MC/Mach-O: Fix address compution for zero fill sections.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 8 Mar 2010 21:10:42 +0000 (21:10 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 8 Mar 2010 21:10:42 +0000 (21:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97984 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 3f40a6d6a4c1f68d48be187bd5cd19cf167fbb5f..1ec1d815de46b2555b3fe87568499635101e114a 100644 (file)
@@ -1049,8 +1049,8 @@ void MCAssembler::LayoutSection(MCSectionData &SD) {
 
       // Align the fragment offset; it is safe to adjust the offset freely since
       // this is only in virtual sections.
-      uint64_t Aligned = RoundUpToAlignment(Address, ZFF.getAlignment());
-      F.setOffset(Aligned - SD.getAddress());
+      Address = RoundUpToAlignment(Address, ZFF.getAlignment());
+      F.setOffset(Address - SD.getAddress());
 
       // FIXME: This is misnamed.
       F.setFileSize(ZFF.getSize());
diff --git a/test/MC/MachO/zerofill-4.s b/test/MC/MachO/zerofill-4.s
new file mode 100644 (file)
index 0000000..3513be4
--- /dev/null
@@ -0,0 +1,35 @@
+// RUN: llvm-mc -triple i386-apple-darwin9 %s -filetype=obj -o - | macho-dump --dump-section-data | FileCheck %s
+
+.zerofill __DATA,__bss,_fill0,1,0
+.zerofill __DATA,__bss,_a,4,2
+.zerofill __DATA,__bss,_fill1,1,0
+.zerofill __DATA,__bss,_b,4,3
+.zerofill __DATA,__bss,_fill2,1,0
+.zerofill __DATA,__bss,_c,4,4
+.zerofill __DATA,__bss,_fill3,1,0
+.zerofill __DATA,__bss,_d,4,5
+
+// CHECK: # Symbol 0
+// CHECK: ('n_value', 0)
+// CHECK: ('_string', '_fill0')
+// CHECK: # Symbol 1
+// CHECK: ('n_value', 4)
+// CHECK: ('_string', '_a')
+// CHECK: # Symbol 2
+// CHECK: ('n_value', 8)
+// CHECK: ('_string', '_fill1')
+// CHECK: # Symbol 3
+// CHECK: ('n_value', 16)
+// CHECK: ('_string', '_b')
+// CHECK: # Symbol 4
+// CHECK: ('n_value', 20)
+// CHECK: ('_string', '_fill2')
+// CHECK: # Symbol 5
+// CHECK: ('n_value', 32)
+// CHECK: ('_string', '_c')
+// CHECK: # Symbol 6
+// CHECK: ('n_value', 36)
+// CHECK: ('_string', '_fill3')
+// CHECK: # Symbol 7
+// CHECK: ('n_value', 64)
+// CHECK: ('_string', '_d')