<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/127657>127657</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISCV] LLVM produces binaries where GNU objdump is unable to use the mapping symbols for proper disassembly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:RISC-V
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
asb
</td>
</tr>
</table>
<pre>
It's possible there's a GNU bug here, but it's the case that `clang` produces binaries where GNU objdump can't use the mapping symbols to properly print some instructions, while `llvm-objdump` manages fine. But binaries produced by `gcc` are disassembled properly with either objdump implementation.
Consider the following example, where `max` is a trivial function that will result in the selection of `max` from the Zbb extension.
```sh
cat - <<EOF > max.c
int max(int x, int y) {
return x > y ? x : y;
}
int main(void) {
return 0;
}
EOF
riscv64-linux-gnu-gcc -c -O3 -march=rv64gc_zbb max.c -o max.gcc.o
$HOME/llvm-project/build/default/bin/clang --target=riscv64-linux-gnu -c -O3 -march=rv64gc_zbb max.c -o max.clang.o
riscv64-linux-gnu-gcc -O3 -march=rv64gc_zbb max.c -o max.gcc
$HOME/llvm-project/build/default/bin/clang --target=riscv64-linux-gnu -O3 -march=rv64gc_zbb --sysroot=$HOME/rvsysroot -fuse-ld=lld max.c -o max.clang
riscv64-linux-gnu-gcc -O3 -fuse-ld=lld -march=rv64gc_zbb max.c -o max.gcc.lld
```
The result is:
* max.gcc.o: Disassembles fine for LLVM and GNU objdump
* max.clang.o: Disassembles fine for LLVM and GNU objdump
* max.gcc: Disassembles fine for LLVM and GNU objdump
* max.gcc.lld: Disassembles fine for LLVM and GNU objdump
* max.clang: Disassembles fine for LLVM objdump, but for GNU objdump we get `.insn` printed for the `max` instruction
* `169a: 0ab56533 .insn 4, 0x0ab56533`
I see this across basically all LLVM/Clang produced binaries.
CC @kito-cheng in case you've seen this as well or have any insight?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm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