Skip to content

Commit

Permalink
[ARM] support symbolic expressions as branch target in b.w
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jcai19 committed Mar 2, 2021
1 parent b17d464 commit c351050
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7950,7 +7950,10 @@ bool ARMAsmParser::validateInstruction(MCInst &Inst,
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 (!isa<MCBinaryExpr>(Operand.getImm()) &&
!Operand.isSignedOffset<24, 1>())
return Error(Operands[op]->getStartLoc(), "branch target out of range");
break;
}
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/MC/ARM/thumb2-b.w-target.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: llvm-mc -triple=thumbv7 -filetype=obj %s | llvm-objdump --triple=thumbv7 -d - | FileCheck %s

.syntax unified

// CHECK-LABEL: start
// CHECK-NEXT: b.w #16777208
// CHECK-NEXT: b.w #2
start:
b.w start - 1f + 0x1000000
1:
b.w . + (2f - 1b + 2)
2:
6 changes: 6 additions & 0 deletions llvm/test/MC/ARM/thumb2-branch-ranges.s
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,9 @@ start6:
// 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: [[#@LINE+1]]:{{[0-9]}}: error: Relocation out of range
b.w start8 - start7 + 0x1000000
start8:

0 comments on commit c351050

Please sign in to comment.