[llvm-commits] [llvm] r129923 - in /llvm/trunk: lib/MC/WinCOFFObjectWriter.cpp test/MC/COFF/diff.s

Rafael Espindola rafael.espindola at gmail.com
Thu Apr 21 11:36:51 PDT 2011


Author: rafael
Date: Thu Apr 21 13:36:50 2011
New Revision: 129923

URL: http://llvm.org/viewvc/llvm-project?rev=129923&view=rev
Log:
Fix relative relocations. This is sufficient for running the rust testsuite with
MC :-)

Modified:
    llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
    llvm/trunk/test/MC/COFF/diff.s

Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=129923&r1=129922&r2=129923&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Thu Apr 21 13:36:50 2011
@@ -656,8 +656,13 @@
     const MCSymbol *B = &Target.getSymB()->getSymbol();
     MCSymbolData &B_SD = Asm.getSymbolData(*B);
 
-    FixedValue = Layout.getSymbolOffset(&A_SD) - Layout.getSymbolOffset(&B_SD);
+    // Offset of the symbol in the section
+    int64_t a = Layout.getSymbolOffset(&B_SD);
 
+    // Ofeset of the relocation in the section
+    int64_t b = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
+
+    FixedValue = b - a;
     // In the case where we have SymbA and SymB, we just need to store the delta
     // between the two symbols.  Update FixedValue to account for the delta, and
     // skip recording the relocation.

Modified: llvm/trunk/test/MC/COFF/diff.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/diff.s?rev=129923&r1=129922&r2=129923&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/diff.s (original)
+++ llvm/trunk/test/MC/COFF/diff.s Thu Apr 21 13:36:50 2011
@@ -5,6 +5,7 @@
 	.type	32;
 	.endef
 	.text
+	.long   0
 	.globl	_foobar
 	.align	16, 0x90
 _foobar:                                # @foobar
@@ -15,13 +16,30 @@
 	.globl	_rust_crate             # @rust_crate
 	.align	4
 _rust_crate:
+	.long   0
+	.long   _foobar
+	.long	_foobar-_rust_crate
 	.long	_foobar-_rust_crate
 
-
-// CHECK:       Relocations              = [
+// CHECK:      Name                     = .data
+// CHECK:      SectionData              =
+// CHECK-NEXT:   00 00 00 00 00 00 00 00 - 1C 00 00 00 20 00 00 00 |............ ...|
+// CHECK:        Relocations              = [
 // CHECK-NEXT:   0 = {
-// CHECK-NEXT:     VirtualAddress           = 0x0
+// CHECK-NEXT:     VirtualAddress           = 0x4
 // CHECK-NEXT:     SymbolTableIndex         =
+// CHECK-NEXT:     Type                     = IMAGE_REL_I386_DIR32 (6)
+// CHECK-NEXT:     SymbolName               = _foobar
+// CHECK-NEXT:   }
+// CHECK-NEXT:   1 = {
+// CHECK-NEXT:     VirtualAddress           = 0x8
+// CHECK-NEXT:     SymbolTableIndex         = 0
+// CHECK-NEXT:     Type                     = IMAGE_REL_I386_REL32 (20)
+// CHECK-NEXT:     SymbolName               = .text
+// CHECK-NEXT:   }
+// CHECK-NEXT:   2 = {
+// CHECK-NEXT:     VirtualAddress           = 0xC
+// CHECK-NEXT:     SymbolTableIndex         = 0
 // CHECK-NEXT:     Type                     = IMAGE_REL_I386_REL32 (20)
 // CHECK-NEXT:     SymbolName               = .text
 // CHECK-NEXT:   }





More information about the llvm-commits mailing list