Skip to content

Commit d70dda2

Browse files
jcai19memfrob
authored and
memfrob
committed
[ARM] support symbolic expressions as branch target in b.w
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: ClangBuiltLinux/linux#1286 Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D97568
1 parent 1d187f8 commit d70dda2

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7950,7 +7950,10 @@ bool ARMAsmParser::validateInstruction(MCInst &Inst,
79507950
break;
79517951
case ARM::t2B: {
79527952
int op = (Operands[2]->isImm()) ? 2 : 3;
7953-
if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
7953+
ARMOperand &Operand = static_cast<ARMOperand &>(*Operands[op]);
7954+
// Delay the checks of symbolic expressions until they are resolved.
7955+
if (!isa<MCBinaryExpr>(Operand.getImm()) &&
7956+
!Operand.isSignedOffset<24, 1>())
79547957
return Error(Operands[op]->getStartLoc(), "branch target out of range");
79557958
break;
79567959
}

llvm/test/MC/ARM/thumb2-b.w-target.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: llvm-mc -triple=thumbv7 -filetype=obj %s | llvm-objdump --triple=thumbv7 -d - | FileCheck %s
2+
3+
.syntax unified
4+
5+
// CHECK-LABEL: start
6+
// CHECK-NEXT: b.w #16777208
7+
// CHECK-NEXT: b.w #2
8+
start:
9+
b.w start - 1f + 0x1000000
10+
1:
11+
b.w . + (2f - 1b + 2)
12+
2:

llvm/test/MC/ARM/thumb2-branch-ranges.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,9 @@ start6:
9494
// CHECK: [[@LINE+2]]:{{[0-9]}}: error: Relocation out of range
9595
// CHECK-LABEL: beq.w start6
9696
beq.w start6
97+
98+
start7:
99+
// branch to thumb function resolved at assembly time
100+
// CHECK: [[#@LINE+1]]:{{[0-9]}}: error: Relocation out of range
101+
b.w start8 - start7 + 0x1000000
102+
start8:

0 commit comments

Comments
 (0)