Skip to content

[RISCV] LLVM produces binaries where GNU objdump is unable to use the mapping symbols for proper disassembly #127657

@asb

Description

@asb

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.

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 (i.e. max a0, a1, a0 is printed)
  • 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions