[llvm] r369239 - [MC] Delete unnecessary diagnostic: "No relocation available to represent this relative expression"

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 00:59:36 PDT 2019


Author: maskray
Date: Mon Aug 19 00:59:35 2019
New Revision: 369239

URL: http://llvm.org/viewvc/llvm-project?rev=369239&view=rev
Log:
[MC] Delete unnecessary diagnostic: "No relocation available to represent this relative expression"

Replace

- error: No relocation available to represent this relative expression

with

+ error: symbol 'undef' can not be undefined in a subtraction expression

or

+ error: Cannot represent a difference across sections

Keep !IsPcRel as an assertion after the two diagnostic checks are done.

Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/test/MC/AArch64/adr-diagnostics.s
    llvm/trunk/test/MC/AArch64/error-location.s
    llvm/trunk/test/MC/ARM/error-location.s
    llvm/trunk/test/MC/ELF/bad-expr2.s

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=369239&r1=369238&r2=369239&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Mon Aug 19 00:59:35 2019
@@ -1441,22 +1441,7 @@ void ELFObjectWriter::recordRelocation(M
   MCContext &Ctx = Asm.getContext();
 
   if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
-    // Let A, B and C being the components of Target and R be the location of
-    // the fixup. If the fixup is not pcrel, we want to compute (A - B + C).
-    // If it is pcrel, we want to compute (A - B + C - R).
-
-    // In general, ELF has no relocations for -B. It can only represent (A + C)
-    // or (A + C - R). If B = R + K and the relocation is not pcrel, we can
-    // replace B to implement it: (A - R - K + C)
-    if (IsPCRel) {
-      Ctx.reportError(
-          Fixup.getLoc(),
-          "No relocation available to represent this relative expression");
-      return;
-    }
-
     const auto &SymB = cast<MCSymbolELF>(RefB->getSymbol());
-
     if (SymB.isUndefined()) {
       Ctx.reportError(Fixup.getLoc(),
                       Twine("symbol '") + SymB.getName() +
@@ -1474,6 +1459,7 @@ void ELFObjectWriter::recordRelocation(M
 
     uint64_t SymBOffset = Layout.getSymbolOffset(SymB);
     uint64_t K = SymBOffset - FixupOffset;
+    assert(!IsPCRel && "should have been folded");
     IsPCRel = true;
     C -= K;
   }

Modified: llvm/trunk/test/MC/AArch64/adr-diagnostics.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/adr-diagnostics.s?rev=369239&r1=369238&r2=369239&view=diff
==============================================================================
--- llvm/trunk/test/MC/AArch64/adr-diagnostics.s (original)
+++ llvm/trunk/test/MC/AArch64/adr-diagnostics.s Mon Aug 19 00:59:35 2019
@@ -17,7 +17,7 @@
 // CHECK-NEXT:   adr x3, (end + start)
 // CHECK-NEXT:   ^
   adr x4, #(end - start)
-// CHECK: error: No relocation available to represent this relative expression
+// CHECK: error: symbol 'start' can not be undefined in a subtraction expression
 // CHECK-NEXT:   adr x4, #(end - start)
 // CHECK-NEXT:   ^
 
@@ -38,6 +38,6 @@
 // CHECK-NEXT:   adrp x3, (end + start)
 // CHECK-NEXT:   ^
   adrp x4, #(end - start)
-// CHECK: error: No relocation available to represent this relative expression
+// CHECK: error: symbol 'start' can not be undefined in a subtraction expression
 // CHECK-NEXT:   adrp x4, #(end - start)
 // CHECK-NEXT:   ^

Modified: llvm/trunk/test/MC/AArch64/error-location.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/error-location.s?rev=369239&r1=369238&r2=369239&view=diff
==============================================================================
--- llvm/trunk/test/MC/AArch64/error-location.s (original)
+++ llvm/trunk/test/MC/AArch64/error-location.s Mon Aug 19 00:59:35 2019
@@ -10,7 +10,7 @@
 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: expected relocatable expression
   .word -undef
 
-// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: No relocation available to represent this relative expression
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: symbol 'undef' can not be undefined in a subtraction expression
   adr x0, #a-undef
 
 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot represent a difference across sections

Modified: llvm/trunk/test/MC/ARM/error-location.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/error-location.s?rev=369239&r1=369238&r2=369239&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/error-location.s (original)
+++ llvm/trunk/test/MC/ARM/error-location.s Mon Aug 19 00:59:35 2019
@@ -10,7 +10,7 @@
 @ CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: expected relocatable expression
   .word -undef
 
-@ CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: No relocation available to represent this relative expression
+@ CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: symbol 'undef' can not be undefined in a subtraction expression
   adr r0, #a-undef
 
 @ CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot represent a difference across sections

Modified: llvm/trunk/test/MC/ELF/bad-expr2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/bad-expr2.s?rev=369239&r1=369238&r2=369239&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/bad-expr2.s (original)
+++ llvm/trunk/test/MC/ELF/bad-expr2.s Mon Aug 19 00:59:35 2019
@@ -1,7 +1,7 @@
 // RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o /dev/null \
 // RUN: 2>&1 | FileCheck %s
 
-// CHECK: [[@LINE+2]]:{{[0-9]+}}: error: No relocation available to represent this relative expression
+// CHECK: [[@LINE+2]]:{{[0-9]+}}: error: Cannot represent a difference across sections
 // CHECK-NEXT: call foo - bar
         call foo - bar
 




More information about the llvm-commits mailing list