[PATCH] D97501: [ARM] support symbolic expressions as branch target
Jian Cai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 25 14:32:55 PST 2021
jcai19 created this revision.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
jcai19 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Currently ARM backend validates the range of branch targets before the
layout of fragments is finalized. This causes build failure if symbolic
expressions are used, with the exception of a single symbolic value.
For example, "b.w ." works but "b.w . + 2" currently fails to
assemble. This fixes the issue by delaying this check (in
ARMAsmParser::validateInstruction) until the symbolic values are
resolved (in ARMAsmBackend::adjustFixupValue).
Link:
https://github.com/ClangBuiltLinux/linux/issues/1286
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97501
Files:
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/test/MC/ARM/thumb2-b.w-target.s
llvm/test/MC/ARM/thumb2-branch-ranges.s
Index: llvm/test/MC/ARM/thumb2-branch-ranges.s
===================================================================
--- llvm/test/MC/ARM/thumb2-branch-ranges.s
+++ llvm/test/MC/ARM/thumb2-branch-ranges.s
@@ -94,3 +94,10 @@
// CHECK: [[@LINE+2]]:{{[0-9]}}: error: Relocation out of range
// CHECK-LABEL: beq.w start6
beq.w start6
+
+start7:
+// branch to thumb function resolved at assembly time
+// CHECK-NOT: error
+// CHECK: [[@LINE+1]]:{{[0-9]}}: error: Relocation out of range
+ b.w start8 - start7 + 0x1000000
+start8:
Index: llvm/test/MC/ARM/thumb2-b.w-target.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ARM/thumb2-b.w-target.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc -triple=thumbv7 -filetype=obj %s | llvm-objdump -d - | FileCheck %s
+
+.syntax unified
+
+// arm-linux-gnueabihf-objdump produced
+// 0: f000 b803 b.w a <.text+0xa>
+// 4: f3ff 97fa b.w fffff8 <.text+0xfffff8>
+
+// llvm-objdump produced the following
+// CHECK: 0: 00 <unknown>
+// CHECK-NEXT: 1: f0 03 lsls r0, r6, #15
+// CHECK-NEXT: 3: b8 <unknown>
+// CHECK-NEXT: 4: ff <unknown>
+// CHECK-NEXT: 5: f3 <unknown>
+// CHECK-NEXT: 6: fa 97 str r7, [sp, #1000]
+1:
+ b.w . + (2f - 1b + 2)
+ b.w 1b - 2f + 0x1000000
+2:
+
+
+
Index: llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
===================================================================
--- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -1069,7 +1069,6 @@
template<unsigned width, unsigned scale>
bool isSignedOffset() const {
if (!isImm()) return false;
- if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
int64_t Val = CE->getValue();
int64_t Align = 1LL << scale;
@@ -1077,7 +1076,8 @@
int64_t Min = -Align * (1LL << (width-1));
return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
}
- return false;
+ // Delay the checks of symbolic values until they are resolved
+ return true;
}
// checks whether this operand is an offset suitable for the LE /
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97501.326511.patch
Type: text/x-patch
Size: 2215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210225/2ae9cd13/attachment.bin>
More information about the llvm-commits
mailing list