[llvm] [llvm-objdump] Support --mcpu=help/--mattr=help without -d (PR #165661)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 01:34:19 PST 2025
jh7370 wrote:
Taking the conversation out-of-line, due to the lengthy comment. It turns out we're both right, but mostly because the behaviour is inconsistent!
Take the following two simple assembly files for ARM and x86_64:
```
# arm.s
.text
.global foo
.type foo#function
foo:
add r0, r0
```
```
.text
.global foo
.type foo,function
foo:
nop
```
Then compile them as follows:
```
D:\Work> D:\llvm\build\Debug\bin\clang -c --target=arm-pc-linux arm.s
D:\Work> D:\llvm\build\Debug\bin\clang -c --target=x86_64-pc-linux x86_64.s
```
Then do disassembly and --mcpu=help, with and without --triple=<other-target>, i.e.:
```
D:\Work> D:\llvm\build\Debug\bin\llvm-objdump.exe -d --mcpu=help arm.o
D:\Work> D:\llvm\build\Debug\bin\llvm-objdump.exe -d --mcpu=help x86_64.o
D:\Work> D:\llvm\build\Debug\bin\llvm-objdump.exe -d --mcpu=help arm.o --triple=x86_64
D:\Work> D:\llvm\build\Debug\bin\llvm-objdump.exe -d --mcpu=help x86_64.o --triple=arm
```
For things to be consistent, you'd either expect the help to always match the target of the input file, or to always match that specified by the input file. However, what I actually see is:
| Command | Arm object | x86_64 object |
|---------|----------|----------|
| -d --mcpu=help | Arm disassembly, Arm mcpu help | x86_64 disassembly, x86_64 mcpu help |
| -d --mcpu=help --triple=arm | Arm disassembly, Arm mcpu help | Arm disassembly, Arm mcpu help |
| -d --mcpu=help --triple=x86_64 | ❗ Arm disassembly, Arm mcpu help | x86_64 disassembly, x86_64 mcpu help |
I experimented briefly with RISC-V inputs and triples too and that follows the same as x86_64. I've not dug into the code yet, but my suspicion is that this has to do with ARM's primary/secondary target functionality, because of how it handles Thumb code. I think it could probably be described as a bug, but one we don't really care about (it would be weird in practice to disassemble ARM code as x86_64 etc). Given this, I think we should use two targets that aren't ARM, e.g. RISCV and x86_64, and avoid ARM targets completely. The behaviour we mirror for --triple + --mcpu=help (without other dump options) should be the x86_64 behaviour. (This does mean that this specific case will behave differently for ARM with and without an input file, but I don't think that matters). Does that make sense?
https://github.com/llvm/llvm-project/pull/165661
More information about the llvm-commits
mailing list