]> granicus.if.org Git - llvm/commitdiff
[MC] Delete unnecessary diagnostic: "No relocation available to represent this relati...
authorFangrui Song <maskray@google.com>
Mon, 19 Aug 2019 07:59:35 +0000 (07:59 +0000)
committerFangrui Song <maskray@google.com>
Mon, 19 Aug 2019 07:59:35 +0000 (07:59 +0000)
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.

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

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

index 111ba3fab39723addec4e47ca4c454fb448f19cb..97607b43295d3a375d2131c4609e81dac2c0c171 100644 (file)
@@ -1441,22 +1441,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
   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(MCAssembler &Asm,
 
     uint64_t SymBOffset = Layout.getSymbolOffset(SymB);
     uint64_t K = SymBOffset - FixupOffset;
+    assert(!IsPCRel && "should have been folded");
     IsPCRel = true;
     C -= K;
   }
index 3ca1681f547ed1cfa0d2376b98f0843d1792bd5d..ef9b07aca53fe030feb7e3aacb8963081768f333 100644 (file)
@@ -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:   ^
index a8f9a7df6d30c4d3181c914047cad238b7188bf5..f870b04edd4a7e28f53a9c265cef7861b7ef813e 100644 (file)
@@ -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
index 652de296f6e4548d711f4fe2eac37e14b433f471..29bb5fe1b62c1092a7399debe5a8bb1f7f3c39c2 100644 (file)
@@ -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
index dad7431b13c7933c1f522fceb4ec6ffbc08d5186..1ca8e90c76f9f0e999fd644cac61b301497ac6fe 100644 (file)
@@ -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