Skip to content

Commit 40f7711

Browse files
committed
[llvm-objdump][BPF] infer local label names in BPF disassembly
Enable local labels computation for BPF disassembly when --symbolize-address option is specified. This relies on MCInstrAnalysis::evaluateBranch() method, which is already defined in BPFMCInstrAnalysis::evaluateBranch. After this change the assembly code below: if r1 > 42 goto +1 r1 -= 10 ... Would be printed as: if r1 > 42 goto +1 <L0> r1 -= 10 <L0>: ... (when --symbolize-address option is set).
1 parent e894df6 commit 40f7711

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# REQUIRES: bpf-registered-target
2+
3+
## Verify generation of 'Lxx' labels for local jump targets,
4+
## when --symbolize-operands option is specified.
5+
6+
# RUN: llvm-mc -triple=bpfel %s -filetype=obj -o - | \
7+
# RUN: llvm-objdump -d --symbolize-operands --no-show-raw-insn --no-leading-addr - | \
8+
# RUN: FileCheck %s
9+
.text
10+
main:
11+
if r1 > 42 goto +2
12+
r1 -= 10
13+
goto -3
14+
r0 = 0
15+
exit
16+
17+
# CHECK: <main>:
18+
# CHECK-NEXT: <L1>:
19+
# CHECK-NEXT: if r1 > 0x2a goto +0x2 <L0>
20+
# CHECK-NEXT: r1 -= 0xa
21+
# CHECK-NEXT: goto -0x3 <main>
22+
# CHECK-NEXT: <L0>:
23+
# CHECK-NEXT: r0 = 0x0
24+
# CHECK-NEXT: exit

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,9 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, MCInstrAnalysis *MIA,
14861486
std::unordered_map<uint64_t, std::string> &Labels) {
14871487
// So far only supports PowerPC and X86.
14881488
const bool isPPC = STI->getTargetTriple().isPPC();
1489-
if (!isPPC && !STI->getTargetTriple().isX86())
1489+
const bool isX86 = STI->getTargetTriple().isX86();
1490+
const bool isBPF = STI->getTargetTriple().isBPF();
1491+
if (!isPPC && !isX86 && !isBPF)
14901492
return;
14911493

14921494
if (MIA)

0 commit comments

Comments
 (0)