-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm-objdump] Support --symbolize-operand on AArch64 #145009
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] Support --symbolize-operand on AArch64 #145009
Conversation
Created using spr 1.3.5-bogner [skip ci]
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-llvm-binary-utilities Author: Alexis Engelke (aengelke) ChangesSimilar to the existing implementations for X86 and PPC, support Full diff: https://github.com/llvm/llvm-project/pull/145009.diff 3 Files Affected:
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
index bbe83821eca8e..fa7610db82bfb 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp
@@ -1784,6 +1784,10 @@ void AArch64InstPrinter::printAlignedLabel(const MCInst *MI, uint64_t Address,
unsigned OpNum,
const MCSubtargetInfo &STI,
raw_ostream &O) {
+ // Do not print the numberic target address when symbolizing.
+ if (SymbolizeOperands)
+ return;
+
const MCOperand &Op = MI->getOperand(OpNum);
// If the label has already been resolved to an immediate offset (say, when
@@ -1813,6 +1817,12 @@ void AArch64InstPrinter::printAdrAdrpLabel(const MCInst *MI, uint64_t Address,
unsigned OpNum,
const MCSubtargetInfo &STI,
raw_ostream &O) {
+ // Do not print the numberic target address when symbolizing.
+ // However, do print for ADRP, as this is typically used together with an ADD
+ // or an immediate-offset ldr/str and the label is likely at the wrong point.
+ if (SymbolizeOperands && MI->getOpcode() != AArch64::ADRP)
+ return;
+
const MCOperand &Op = MI->getOperand(OpNum);
// If the label has already been resolved to an immediate offset (say, when
diff --git a/llvm/test/tools/llvm-objdump/AArch64/elf-disassemble-symbololize-operands.yaml b/llvm/test/tools/llvm-objdump/AArch64/elf-disassemble-symbololize-operands.yaml
new file mode 100644
index 0000000000000..3f3c6f33e620f
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/AArch64/elf-disassemble-symbololize-operands.yaml
@@ -0,0 +1,42 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objdump %t -d --symbolize-operands --no-show-raw-insn --no-leading-addr | \
+# RUN: FileCheck %s --match-full-lines
+# RUN: llvm-objdump %t -d --symbolize-operands --no-show-raw-insn --no-leading-addr --adjust-vma=0x2000 | \
+# RUN: FileCheck %s --match-full-lines
+
+## Expect to find the branch labels and global variable name.
+# CHECK: <_start>:
+# CHECK-NEXT: ldr x0, <symbol>
+# CHECK-NEXT: <L0>:
+# CHECK-NEXT: adrp x1, 0x{{[68]}}000 <symbol+0xff4>
+# CHECK-NEXT: adr x2, <symbol>
+# CHECK-NEXT: cmp x1, x2
+# CHECK-NEXT: b.eq <L1>
+# CHECK-NEXT: b <L0>
+# CHECK-NEXT: <L1>:
+# CHECK-NEXT: cbz x2, <L0>
+# CHECK-NEXT: ret
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_AARCH64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Address: 0x4000
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ Content: '60800058010000d0228000103f0002eb40000054fcffff1762ffffb4c0035fd6'
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_WRITE]
+ Address: 0x5000
+Symbols:
+ - Name: _start
+ Section: .text
+ Value: 0x4000
+ - Name: symbol
+ Section: .data
+ Value: 0x500c
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 5ecb33375943f..c5967cd090eec 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1495,8 +1495,9 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, MCInstrAnalysis *MIA,
// Supported by certain targets.
const bool isPPC = STI->getTargetTriple().isPPC();
const bool isX86 = STI->getTargetTriple().isX86();
+ const bool isAArch64 = STI->getTargetTriple().isAArch64();
const bool isBPF = STI->getTargetTriple().isBPF();
- if (!isPPC && !isX86 && !isBPF)
+ if (!isPPC && !isX86 && !isAArch64 && !isBPF)
return;
if (MIA)
|
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.
Looks good, but I'd check whether @jh7370 has opinions on the test.
(We need an executable for testing. llvm/test cannot use lld, so we have to resort to hexadecimal bytes...)
llvm/test/tools/llvm-objdump/AArch64/elf-disassemble-symbololize-operands.yaml
Outdated
Show resolved
Hide resolved
llvm/test/tools/llvm-objdump/AArch64/elf-disassemble-symbololize-operands.yaml
Outdated
Show resolved
Hide resolved
llvm/test/tools/llvm-objdump/AArch64/elf-disassemble-symbololize-operands.yaml
Outdated
Show resolved
Hide resolved
Created using spr 1.3.5-bogner
Created using spr 1.3.5-bogner
Created using spr 1.3.5-bogner
Created using spr 1.3.5-bogner
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.
Basically looks good. Just some typos and other nits. Also, the documentation for the option says it works only for PPC and X86. Please could you update this and double-check whether the command-line help has the same note.
llvm/test/tools/llvm-objdump/ELF/AArch64/symbolize-operands-relocatable.s
Outdated
Show resolved
Hide resolved
llvm/test/tools/llvm-objdump/ELF/AArch64/symbolize-operands-relocatable.s
Outdated
Show resolved
Hide resolved
llvm/test/tools/llvm-objdump/ELF/AArch64/symbolize-operands-relocatable.s
Outdated
Show resolved
Hide resolved
llvm/test/tools/llvm-objdump/ELF/AArch64/symbolize-operands-relocatable.s
Outdated
Show resolved
Hide resolved
Created using spr 1.3.5-bogner
Done. The command line help doesn't give any indication on supported architectures. |
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, thanks. Probably want to wait for @MaskRay for final sign-off, but if he's too busy, land it in a couple of days anyway.
# CHECK-NEXT: cbz x2, <L0> | ||
# CHECK-NEXT: ret | ||
|
||
## Machine code generated with: |
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.
Consider adopting llvm/utils/update_test_body.py to make this easier to re-create https://llvm.org/docs/TestingGuide.html#elaborated-tests
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.
obj2yaml produces loads of unnecessary content (program headers, dynamic sections (dynsym/dynstr/hash/dynamic), its output is twice as long as this test currently is. I can do that, but I don't think it's worth the effort.
Created using spr 1.3.5-bogner
sigh sorry for the noise, rebase for merging gone wrong :( |
Similar to the existing implementations for X86 and PPC, support symbolizing branch targets for AArch64. Do not omit the address for ADRP as the target is typically not at an intended location. Pull Request: llvm/llvm-project#145009
(weird, I only unselected |
Similar to the existing implementations for X86 and PPC, support
symbolizing branch targets for AArch64. Do not omit the address for ADRP
as the target is typically not at an intended location.