OSDN Git Service

Add a common error checking for some invalid expressions.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 22 Jun 2017 17:25:35 +0000 (17:25 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 22 Jun 2017 17:25:35 +0000 (17:25 +0000)
This refactors a bit of duplicated code and fixes an assertion failure
on ELF.

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

lib/MC/ELFObjectWriter.cpp
lib/MC/MCAssembler.cpp
lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
test/MC/AArch64/label-arithmetic-diags-darwin.s
test/MC/ELF/bad-expr.s
test/MC/X86/macho-reloc-errors-x86_64.s

index 4d13913..30f3578 100644 (file)
@@ -633,9 +633,6 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
   MCContext &Ctx = Asm.getContext();
 
   if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
-    assert(RefB->getKind() == MCSymbolRefExpr::VK_None &&
-           "Should not have constructed this");
-
     // 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).
index 8ccdd3f..758c4c7 100644 (file)
@@ -193,14 +193,23 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
   // FIXME: This code has some duplication with recordRelocation. We should
   // probably merge the two into a single callback that tries to evaluate a
   // fixup and records a relocation if one is needed.
+
+  // On error claim to have completely evaluated the fixup, to prevent any
+  // further processing from being done.
   const MCExpr *Expr = Fixup.getValue();
+  MCContext &Ctx = getContext();
+  Value = 0;
   if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup)) {
-    getContext().reportError(Fixup.getLoc(), "expected relocatable expression");
-    // Claim to have completely evaluated the fixup, to prevent any further
-    // processing from being done.
-    Value = 0;
+    Ctx.reportError(Fixup.getLoc(), "expected relocatable expression");
     return true;
   }
+  if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
+    if (RefB->getKind() != MCSymbolRefExpr::VK_None) {
+      Ctx.reportError(Fixup.getLoc(),
+                      "unsupported subtraction of qualified symbol");
+      return true;
+    }
+  }
 
   bool IsPCRel = Backend.getFixupKindInfo(
     Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsPCRel;
index 4097ef2..caf98bf 100644 (file)
@@ -153,8 +153,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
     const MCSymbol *B_Base = Asm.getAtom(*B);
 
     // Neither symbol can be modified.
-    if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None ||
-        Target.getSymB()->getKind() != MCSymbolRefExpr::VK_None) {
+    if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None) {
       Asm.getContext().reportError(Fixup.getLoc(),
                                    "unsupported relocation of modified symbol");
       return;
index 96b00cd..e32db7c 100644 (file)
@@ -15,10 +15,10 @@ Lend:
 
   add w0, w1, #(Lend - var@TLVPPAGEOFF)
   cmp w0, #(Lend - var@TLVPPAGEOFF)
-  // CHECK: error: unknown AArch64 fixup kind!
+  // CHECK: error: unsupported subtraction of qualified symbol
   // CHECK-NEXT: add w0, w1, #(Lend - var@TLVPPAGEOFF)
   // CHECK-NEXT: ^
-  // CHECK: error: unknown AArch64 fixup kind!
+  // CHECK: error: unsupported subtraction of qualified symbol
   // CHECK-NEXT: cmp w0, #(Lend - var@TLVPPAGEOFF)
   // CHECK-NEXT: ^
 
index 1cad919..5980970 100644 (file)
@@ -1,8 +1,12 @@
 // RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o /dev/null 2>%t
 // RUN: FileCheck --input-file=%t %s
 
-// CHECK: symbol '__executable_start' can not be undefined in a subtraction expression
 
         .data
 x:
+// CHECK: [[@LINE+1]]:{{[0-9]+}}: error: symbol '__executable_start' can not be undefined in a subtraction expression
         .quad   x-__executable_start
+
+// CHECK: [[@LINE+1]]:{{[0-9]+}}: error: unsupported subtraction of qualified symbol
+        .long bar - foo@got
+foo:
index 05f77c4..4498d03 100644 (file)
@@ -10,7 +10,7 @@
         mov %rax, thing@TLVP
 
 // CHECK-ERROR: 3:9: error: 32-bit absolute addressing is not supported in 64-bit mode
-// CHECK-ERROR: 4:9: error: unsupported relocation of modified symbol
+// CHECK-ERROR: 4:9: error: unsupported subtraction of qualified symbol
 // CHECK-ERROR: 5:9: error: unsupported pc-relative relocation of difference
 // CHECK-ERROR: 6:9: error: unsupported relocation with identical base
 // CHECK-ERROR: 7:9: error: unsupported relocation with subtraction expression, symbol 'thing' can not be undefined in a subtraction expression