[PATCH] D97568: [ARM] support symbolic expressions as branch target in b.w

Jian Cai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 26 11:25:36 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) of b.w instructions until the symbol
expressions are resolved (in ARMAsmBackend::adjustFixupValue).

Link:
https://github.com/ClangBuiltLinux/linux/issues/1286


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97568

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,17 @@
+# RUN: llvm-mc -triple=thumbv7 -filetype=obj %s | llvm-objdump --triple=thumbv7 -d - | FileCheck %s
+
+.syntax unified
+
+// arm-linux-gnueabihf-objdump produced
+//	b.w	fffffc <start+0xfffffc>
+//	b.w	a <start+0xa>
+
+// llvm-objdump produced the following
+// CHECK-LABEL: start
+// CHECK-NEXT:	b.w	#16777208 <start+0xfffffc>
+// CHECK-NEXT:  b.w	#2 <start+0xa>
+start:
+  b.w start - 1f + 0x1000000
+1:
+  b.w . + (2f - 1b + 2)
+2:
Index: llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
===================================================================
--- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -7950,7 +7950,10 @@
     break;
   case ARM::t2B: {
     int op = (Operands[2]->isImm()) ? 2 : 3;
-    if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
+    ARMOperand &Operand = static_cast<ARMOperand &>(*Operands[op]);
+    // Delay the checks of symbolic expressions until they are resolved
+    if (dyn_cast<MCConstantExpr>(Operand.getImm()) &&
+        !Operand.isSignedOffset<24, 1>())
       return Error(Operands[op]->getStartLoc(), "branch target out of range");
     break;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97568.326754.patch
Type: text/x-patch
Size: 1899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210226/5af14d97/attachment.bin>


More information about the llvm-commits mailing list