-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[llvm-objdump][BPF] --symbolize-operands: infer local labels for BPF #100550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm-objdump][BPF] --symbolize-operands: infer local labels for BPF #100550
Conversation
@llvm/pr-subscribers-llvm-binary-utilities Author: None (eddyz87) ChangesEnable local labels computation for BPF disassembly when After this change the assembly code below:
Would be printed as:
(when Full diff: https://github.com/llvm/llvm-project/pull/100550.diff 2 Files Affected:
diff --git a/llvm/test/tools/llvm-objdump/BPF/disassemble-symbolize-operands.s b/llvm/test/tools/llvm-objdump/BPF/disassemble-symbolize-operands.s
new file mode 100644
index 0000000000000..fd4c3d5b2d26e
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/BPF/disassemble-symbolize-operands.s
@@ -0,0 +1,24 @@
+# REQUIRES: bpf-registered-target
+
+## Verify generation of 'Lxx' labels for local jump targets,
+## when --symbolize-operands option is specified.
+
+# RUN: llvm-mc -triple=bpfel %s -filetype=obj -o - | \
+# RUN: llvm-objdump -d --symbolize-operands --no-show-raw-insn --no-leading-addr - | \
+# RUN: FileCheck %s
+ .text
+main:
+ if r1 > 42 goto +2
+ r1 -= 10
+ goto -3
+ r0 = 0
+ exit
+
+# CHECK: <main>:
+# CHECK-NEXT: <L1>:
+# CHECK-NEXT: if r1 > 0x2a goto +0x2 <L0>
+# CHECK-NEXT: r1 -= 0xa
+# CHECK-NEXT: goto -0x3 <main>
+# CHECK-NEXT: <L0>:
+# CHECK-NEXT: r0 = 0x0
+# CHECK-NEXT: exit
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index d1240025625ca..bd8a6b0c91c63 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1486,7 +1486,9 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, MCInstrAnalysis *MIA,
std::unordered_map<uint64_t, std::string> &Labels) {
// So far only supports PowerPC and X86.
const bool isPPC = STI->getTargetTriple().isPPC();
- if (!isPPC && !STI->getTargetTriple().isX86())
+ const bool isX86 = STI->getTargetTriple().isX86();
+ const bool isBPF = STI->getTargetTriple().isBPF();
+ if (!isPPC && !isX86 && !isBPF)
return;
if (MIA)
|
The reason for the change is that with current clang master BPF selftests are disassembled w/o local labels at all:
Which is quite inconvenient. |
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).
40f7711
to
4ba4a00
Compare
## Verify generation of 'Lxx' labels for local jump targets, | ||
## when --symbolize-operands option is specified. | ||
|
||
# RUN: llvm-mc -triple=bpfel %s -filetype=obj -o - | \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer that the object file is written to the disk (e.g. %t
) to ease debugging.
The option conveys important context. How about The description can mention https://reviews.llvm.org/D84191 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but please give some time to @jh7370 who usually wants to be aware of these changes.
@@ -1486,7 +1486,9 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, MCInstrAnalysis *MIA, | |||
std::unordered_map<uint64_t, std::string> &Labels) { | |||
// So far only supports PowerPC and X86. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is now stale. I suggest that we replace it with // Supported by certain targets.
so that it will not become stale whenever we add a new target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my bad, will update.
Hi @MaskRay , thank you for the review, I agree with raised points. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from one minor nit, I've got no issues with this, and am happy with @MaskRay's review.
Will update and force push, if you don't mind force pushing.
You shouldn't need to force push, and I would actively discourage it, as it makes follow-up reviews harder (it's tricky to see what's changed since the previous review). Instead, you can use merge commits from main
, if rebasing is needed, and fixup commits on your branch with the changes requested (these will also collapse into a single regular commit when you squash and merge).
Also worth noting that the final commit title and description is taken from the PR's title and description, so there's no need to amend the commit message for the already-committed commit in this PR. Instead, make sure to update the PR itself for @MaskRay's suggestion.
## Verify generation of 'Lxx' labels for local jump targets, | ||
## when --symbolize-operands option is specified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor nit: if we follow the same coding standards for line length as in code files, the "when" should be on the previous line, I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch looks good to me. But it looks like we still need --symbolize-operands in order to emit labels. So with this patch, there are two ways to emit labels:
(1). llvm-objdump --symbolize-operands .... The variant of (1) will be to enable --symbolize-operands by default for BPF target.
(2). add '-Wa,-L' to compilation flags so labels in symbol table. The variant of (2) will be that enable labels in symbol table by BPF backend.
It would be great if user does not need to learn '--symbolize-operands' or '-Wa,-L' which is not needed before llvm19.
But in any case, this patch looks good.
Since we do not want L* labels to appear in symbol table (as they are private, generated by compiler), it would be great if we can enable --symbolize-operands by default for BPF target in llvm-objdump. |
I really hope that we avoid target-specific defaults, which haven't been used so far to the best of my knowledge.... |
- Use temporary file for llvm-mc results in the test; - Moved 'when' in the test comment one line up to correctly fill 80 chars per line; - Corrected a comment in the collectLocalBranchTargets
Hi @MaskRay , @jh7370 , thank you for the review, I've pushed requested changes. I will wait till Monday, if there would be no objections, I'll merge this change. @yonghong-song , @4ast , do we want to make |
@eddyz87 To fix the llvm-objdump regression for bpf target, I indeed would like to have --symbolize-operands default for bpf, which will roughly restore what we have for llvm18 and earlier. I guess @MaskRay can comment further on this. If we indeed agree to have --symbolize-operands for bpf target, the change should be in this commit. |
The patch can land as is. The default --symbolize-operands does not need to be combined. It would be a pretty significant policy change as we do not allow targets to customize the defaults. That would require more debates. |
No. User experience matters a lot more than some "policy". |
This feels like an excessively strong reaction to what @MaskRay has been saying, especially as there wasn't even room for discussion. This is an open source project, with a wide range of stakeholders. These "policies" are what are needed to keep the code in a maintainable state for all of these stakeholders. That being said, there is always an opportunity to discuss changing a policy or even working together to find an alternative solution that will satisfy everyone. I'm not familiar at all with the BPF target. Ignoring the prior situation of a bug that used the wrong name for temporary symbols (i.e. the "L"/".L" symbols), is BPF significantly different to other targets on the need for a different default for the --symbolize-operands option? |
a default state of a support flag being different for one architecture doesn't change anything from maintainability pov.
It clearly is. BPF users read assembly code pretty much daily and good readability is paramount. This particular diff #100550 is imo good to land. I misunderstood it first. |
Merging this change (w/o update to default behavior). |
Enable local labels computation for BPF disassembly when
--symbolize-operands
option is specified.This relies on
MCInstrAnalysis::evaluateBranch()
method, which is already defined inBPFMCInstrAnalysis::evaluateBranch
.After this change the assembly code below:
Would be printed as:
(when
--symbolize-operands
option is set).See https://reviews.llvm.org/D84191 for the main part of the
--symbolize-operands
implementation logic.