Skip to content

Commit ee1040b

Browse files
authored
[llvm-objdump][BPF] --symbolize-operands: infer local labels for BPF (#100550)
Enable local labels computation for BPF disassembly when `--symbolize-operands` 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-operands` option is set). See https://reviews.llvm.org/D84191 for the main part of the `--symbolize-operands` implementation logic.
1 parent 7a80c86 commit ee1040b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
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, when
4+
## --symbolize-operands option is specified.
5+
6+
# RUN: llvm-mc -triple=bpfel %s -filetype=obj -o %t
7+
# RUN: llvm-objdump -d --symbolize-operands --no-show-raw-insn --no-leading-addr %t | \
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,9 +1484,11 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, MCInstrAnalysis *MIA,
14841484
const MCSubtargetInfo *STI, uint64_t SectionAddr,
14851485
uint64_t Start, uint64_t End,
14861486
std::unordered_map<uint64_t, std::string> &Labels) {
1487-
// So far only supports PowerPC and X86.
1487+
// Supported by certain targets.
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)