[llvm] r306078 - COFF: handle "undef - ." expressions.

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


Author: rafael
Date: Thu Jun 22 21:15:56 2017
New Revision: 306078

URL: http://llvm.org/viewvc/llvm-project?rev=306078&view=rev
Log:
COFF: handle "undef - ." expressions.

This is another thing that the ELF implementation can do but is
missing from COFF.

Modified:
    llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
    llvm/trunk/test/MC/COFF/bad-expr.s
    llvm/trunk/test/MC/COFF/cross-section-relative.s

Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=306078&r1=306077&r2=306078&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Thu Jun 22 21:15:56 2017
@@ -746,17 +746,6 @@ void WinCOFFObjectWriter::recordRelocati
       return;
     }
 
-    if (!A.getFragment()) {
-      Asm.getContext().reportError(
-          Fixup.getLoc(),
-          Twine("symbol '") + A.getName() +
-              "' can not be undefined in a subtraction expression");
-      return;
-    }
-
-    assert(&A.getSection() != &B->getSection() &&
-           "This doesn't need a relocation");
-
     // Offset of the symbol in the section
     int64_t OffsetOfB = Layout.getSymbolOffset(*B);
 

Modified: llvm/trunk/test/MC/COFF/bad-expr.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/bad-expr.s?rev=306078&r1=306077&r2=306078&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/bad-expr.s (original)
+++ llvm/trunk/test/MC/COFF/bad-expr.s Thu Jun 22 21:15:56 2017
@@ -1,9 +1,7 @@
 // RUN: not llvm-mc -filetype=obj -triple i386-pc-win32 %s 2>&1 | FileCheck %s
 
 // CHECK: symbol '__ImageBase' can not be undefined in a subtraction expression
-// CHECK: symbol '__ImageBase' can not be undefined in a subtraction expression
 
         .data
 _x:
         .long   _x-__ImageBase
-        .long   __ImageBase-_x

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=306078&r1=306077&r2=306078&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/cross-section-relative.s (original)
+++ llvm/trunk/test/MC/COFF/cross-section-relative.s Thu Jun 22 21:15:56 2017
@@ -58,17 +58,18 @@ t6:
 	.long	g3-(t6+16)
 	.zero	4
 
+.long foobar - .
 
 // READOBJ:  Section {
 // READOBJ:    Number: 5
 // READOBJ:    Name: .fix (2E 66 69 78 00 00 00 00)
 // READOBJ:    VirtualSize: 0x0
 // READOBJ:    VirtualAddress: 0x0
-// READOBJ:    RawDataSize: 56
+// READOBJ:    RawDataSize:
 // READOBJ:    PointerToRawData: 0xEC
-// READOBJ:    PointerToRelocations: 0x124
+// READOBJ:    PointerToRelocations:
 // READOBJ:    PointerToLineNumbers: 0x0
-// READOBJ:    RelocationCount: 6
+// READOBJ:    RelocationCount:
 // READOBJ:    LineNumberCount: 0
 // READOBJ:    Characteristics [ (0xC0500040)
 // READOBJ:      IMAGE_SCN_ALIGN_16BYTES (0x500000)
@@ -80,7 +81,7 @@ t6:
 // READOBJ:      0000: 08000000 00000000 04000000 00000000  |................|
 // READOBJ:      0010: 00000000 00000000 04000000 00000000  |................|
 // READOBJ:      0020: 01020000 00000000 00010000 00000000  |................|
-// READOBJ:      0030: 04000000 00000000                    |........|
+// READOBJ:      0030: 04000000 00000000 04000000           |............|
 // READOBJ:    )
 // READOBJ:  }
 // READOBJ:  ]
@@ -116,3 +117,8 @@ t6:
 // READOBJ:      Type: IMAGE_REL_AMD64_REL32 (4)
 // READOBJ:      Symbol: g3
 // READOBJ:    }
+// READOBJ:    Relocation {
+// READOBJ:      Offset: 0x38
+// READOBJ:      Type: IMAGE_REL_AMD64_REL32 (4)
+// READOBJ:      Symbol: foobar
+// READOBJ:    }




More information about the llvm-commits mailing list