MC/Mach-O: PCrel relocations weren't using the right base address, they are
authorDaniel Dunbar <daniel@zuster.org>
Sat, 13 Mar 2010 02:38:00 +0000 (02:38 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 13 Mar 2010 02:38:00 +0000 (02:38 +0000)
relative to the fragment address, not its offset. This was masked by the text
section normally being at address 0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98420 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCAssembler.cpp
test/MC/MachO/reloc-pcrel-offset.s [new file with mode: 0644]

index 88be99cffdd36ec8f1a99ed5aab2237826decae9..29ac8684bde3a0a3197b6d1c92f611661af45b1b 100644 (file)
@@ -1024,7 +1024,7 @@ bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout, MCAsmFixup &Fixup,
   }
 
   if (IsPCRel)
-    Value -= DF->getOffset() + Fixup.Offset;
+    Value -= DF->getAddress() + Fixup.Offset;
 
   return IsResolved;
 }
diff --git a/test/MC/MachO/reloc-pcrel-offset.s b/test/MC/MachO/reloc-pcrel-offset.s
new file mode 100644 (file)
index 0000000..46dc3a9
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -n -triple i386-apple-darwin9 %s -filetype=obj -o - | macho-dump --dump-section-data | FileCheck %s
+
+// CHECK: # Relocation 0
+// CHECK: (('word-0', 0x1),
+// CHECK: ('word-1', 0x5000002)),
+// CHECK-NEXT: ])
+// CHECK: ('_section_data', '\xe8\xfb\xff\xff\xff')
+
+        .data
+        .long 0
+
+        .text
+_a:
+        call _a