[llvm] r306063 - Change creation of relative relocations on COFF.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 14:57:04 PDT 2017


Author: rafael
Date: Thu Jun 22 16:57:04 2017
New Revision: 306063

URL: http://llvm.org/viewvc/llvm-project?rev=306063&view=rev
Log:
Change creation of relative relocations on COFF.

For whatever reason, when processing

  .globl foo
foo:
  .data
bar:
  .long foo-bar

llvm-mc creates a relocation with the section:

0x0 IMAGE_REL_I386_REL32 .text

This is different than when the relocation is relative from the
beginning. For example, a file with

call foo

produces

0x0 IMAGE_REL_I386_REL32 foo

I would like to refactor the logic for converting "foo - ." into a
relative relocation so that it is shared with ELF. This is the first
step and just changes the coff implementation to match what ELF (and
COFF in the case of calls) does.

Modified:
    llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
    llvm/trunk/test/MC/COFF/cross-section-relative.s
    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=306063&r1=306062&r2=306063&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Thu Jun 22 16:57:04 2017
@@ -775,7 +775,7 @@ void WinCOFFObjectWriter::recordRelocati
   Reloc.Data.VirtualAddress = Layout.getFragmentOffset(Fragment);
 
   // Turn relocations for temporary symbols into section relocations.
-  if (A.isTemporary() || SymB) {
+  if (A.isTemporary()) {
     MCSection *TargetSection = &A.getSection();
     assert(
         SectionMap.find(TargetSection) != SectionMap.end() &&

Modified: llvm/trunk/test/MC/COFF/cross-section-relative.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/cross-section-relative.s?rev=306063&r1=306062&r2=306063&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/cross-section-relative.s (original)
+++ llvm/trunk/test/MC/COFF/cross-section-relative.s Thu Jun 22 16:57:04 2017
@@ -77,10 +77,10 @@ t6:
 // READOBJ:      IMAGE_SCN_MEM_WRITE (0x80000000)
 // READOBJ:    ]
 // READOBJ:    SectionData (
-// READOBJ:      0000: 10000000 00000000 0C000000 00000000  |................|
-// READOBJ:      0010: 08000000 00000000 0C000000 00000000  |................|
+// READOBJ:      0000: 08000000 00000000 04000000 00000000  |................|
+// READOBJ:      0010: 00000000 00000000 04000000 00000000  |................|
 // READOBJ:      0020: 01020000 00000000 00010000 00000000  |................|
-// READOBJ:      0030: 0C000000 00000000                    |........|
+// READOBJ:      0030: 04000000 00000000                    |........|
 // READOBJ:    )
 // READOBJ:  }
 // READOBJ:  ]
@@ -89,22 +89,22 @@ t6:
 // READOBJ:    Relocation {
 // READOBJ:      Offset: 0x0
 // READOBJ:      Type: IMAGE_REL_AMD64_REL32 (4)
-// READOBJ:      Symbol: .rdata
+// READOBJ:      Symbol: g3
 // READOBJ:    }
 // READOBJ:    Relocation {
 // READOBJ:      Offset: 0x8
 // READOBJ:      Type: IMAGE_REL_AMD64_REL32 (4)
-// READOBJ:      Symbol: .rdata
+// READOBJ:      Symbol: g3
 // READOBJ:    }
 // READOBJ:    Relocation {
 // READOBJ:      Offset: 0x10
 // READOBJ:      Type: IMAGE_REL_AMD64_REL32 (4)
-// READOBJ:      Symbol: .rdata
+// READOBJ:      Symbol: g3
 // READOBJ:    }
 // READOBJ:    Relocation {
 // READOBJ:      Offset: 0x18
 // READOBJ:      Type: IMAGE_REL_AMD64_REL32 (4)
-// READOBJ:      Symbol: .rdata
+// READOBJ:      Symbol: g3
 // READOBJ:    }
 // READOBJ:    Relocation {
 // READOBJ:      Offset: 0x1C
@@ -114,5 +114,5 @@ t6:
 // READOBJ:    Relocation {
 // READOBJ:      Offset: 0x30
 // READOBJ:      Type: IMAGE_REL_AMD64_REL32 (4)
-// READOBJ:      Symbol: .rdata
+// READOBJ:      Symbol: g3
 // READOBJ:    }

Modified: llvm/trunk/test/MC/COFF/diff.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/diff.s?rev=306063&r1=306062&r2=306063&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/diff.s (original)
+++ llvm/trunk/test/MC/COFF/diff.s Thu Jun 22 16:57:04 2017
@@ -42,11 +42,11 @@ _rust_crate:
 // CHECK:        Name: .data
 // CHECK:        Relocations [
 // CHECK-NEXT:     0x4 IMAGE_REL_I386_DIR32 _foobar
-// CHECK-NEXT:     0x8 IMAGE_REL_I386_REL32 .text
-// CHECK-NEXT:     0xC IMAGE_REL_I386_REL32 .text
+// CHECK-NEXT:     0x8 IMAGE_REL_I386_REL32 _foobar
+// CHECK-NEXT:     0xC IMAGE_REL_I386_REL32 _foobar
 // CHECK-NEXT:   ]
 // CHECK:        SectionData (
-// CHECK-NEXT:     0000: 00000000 00000000 1C000000 20000000
+// CHECK-NEXT:     0000: 00000000 00000000 0C000000 10000000
 // CHECK-NEXT:   )
 
 // CHECK:        Name: baz




More information about the llvm-commits mailing list