[llvm] r306035 - Add a common error checking for some invalid expressions.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 22 10:25:35 PDT 2017
Author: rafael
Date: Thu Jun 22 12:25:35 2017
New Revision: 306035
URL: http://llvm.org/viewvc/llvm-project?rev=306035&view=rev
Log:
Add a common error checking for some invalid expressions.
This refactors a bit of duplicated code and fixes an assertion failure
on ELF.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
llvm/trunk/test/MC/AArch64/label-arithmetic-diags-darwin.s
llvm/trunk/test/MC/ELF/bad-expr.s
llvm/trunk/test/MC/X86/macho-reloc-errors-x86_64.s
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=306035&r1=306034&r2=306035&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu Jun 22 12:25:35 2017
@@ -633,9 +633,6 @@ void ELFObjectWriter::recordRelocation(M
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).
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=306035&r1=306034&r2=306035&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Thu Jun 22 12:25:35 2017
@@ -193,14 +193,23 @@ bool MCAssembler::evaluateFixup(const MC
// 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;
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp?rev=306035&r1=306034&r2=306035&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp Thu Jun 22 12:25:35 2017
@@ -153,8 +153,7 @@ void X86MachObjectWriter::RecordX86_64Re
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;
Modified: llvm/trunk/test/MC/AArch64/label-arithmetic-diags-darwin.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/label-arithmetic-diags-darwin.s?rev=306035&r1=306034&r2=306035&view=diff
==============================================================================
--- llvm/trunk/test/MC/AArch64/label-arithmetic-diags-darwin.s (original)
+++ llvm/trunk/test/MC/AArch64/label-arithmetic-diags-darwin.s Thu Jun 22 12:25:35 2017
@@ -15,10 +15,10 @@ Lend:
add w0, w1, #(Lend - var at TLVPPAGEOFF)
cmp w0, #(Lend - var at TLVPPAGEOFF)
- // CHECK: error: unknown AArch64 fixup kind!
+ // CHECK: error: unsupported subtraction of qualified symbol
// CHECK-NEXT: add w0, w1, #(Lend - var at TLVPPAGEOFF)
// CHECK-NEXT: ^
- // CHECK: error: unknown AArch64 fixup kind!
+ // CHECK: error: unsupported subtraction of qualified symbol
// CHECK-NEXT: cmp w0, #(Lend - var at TLVPPAGEOFF)
// CHECK-NEXT: ^
Modified: llvm/trunk/test/MC/ELF/bad-expr.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/bad-expr.s?rev=306035&r1=306034&r2=306035&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/bad-expr.s (original)
+++ llvm/trunk/test/MC/ELF/bad-expr.s Thu Jun 22 12:25:35 2017
@@ -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 at got
+foo:
Modified: llvm/trunk/test/MC/X86/macho-reloc-errors-x86_64.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/macho-reloc-errors-x86_64.s?rev=306035&r1=306034&r2=306035&view=diff
==============================================================================
--- llvm/trunk/test/MC/X86/macho-reloc-errors-x86_64.s (original)
+++ llvm/trunk/test/MC/X86/macho-reloc-errors-x86_64.s Thu Jun 22 12:25:35 2017
@@ -10,7 +10,7 @@
mov %rax, thing at 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
More information about the llvm-commits
mailing list