llvm-objdump cannot recognize mul&mulh RISC-V M Instructions

I am using llvm-project compiling risc-v programs.

llvm-project version:dd8a2013dc1804be1b7d9cffacad2e984300bd22

Instructons to build LLVM+clang:

cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/home/llvm/workspace/llvm/llvm-project/llvm_install -DCMAKE_BUILD_TYPE="Release" -DDEFAULT_SYSROOT="/home/llvm/workspace/riscv/riscv-tc-20200220/bin/riscv32-unknown-elf" -DGCC_INSTALL_PREFIX="/home/llvm/workspace/riscv/riscv-tc-20200220" -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" -DLLVM_ENABLE_PROJECTS="clang;lld;libc" -DLLVM_TARGETS_TO_BUILD="RISCV" ../llvm

Instructions to compile and dump:

RISCV_GCC_OPTS ?= -mcmodel=medany -static -O3 -std=gnu99 -fno-common -fno-builtin -march=rv32im -mabi=ilp32 -DMB_ADDR=0x80FFFFC --target=riscv64-unknown-elf --sysroot=/home/llvm/workspace/riscv/riscv-tc-20200220/bin/riscv64-unknown-elf --gcc-toolchain=/home/llvm/workspace/riscv/riscv-tc-20200220
RISCV_LINK_OPTS ?= -static -nostdlib -nostartfiles -lm -lgcc -T /home/llvm/workspace/HRV_IDE/common/test.ld
newlib_dir := /home/llvm/workspace/llvm/llvm-project/llvm_install/riscv64-unknown-elf/include
src_dir := $(WORK_DIR)/src/$(PROJ)
incs += -I$(WORK_DIR)/env -I$(WORK_DIR)/common -I$(src_dir) -I$(newlib_dir)
src := $(wildcard $(src_dir)/*.c) $(wildcard $(WORK_DIR)/common/*.c) $(wildcard $(WORK_DIR)/common/*.S)

$(RISCV_clang) $(incs) $(RISCV_GCC_OPTS) -o $(WORK_DIR)/build/$@/$@ $(src) $(RISCV_LINK_OPTS) --verbose
$(RISCV_OBJDUMP) -d $(WORK_DIR)/build/$@/$@ > $(WORK_DIR)/build/$@/$@.S

$(RISCV_LLVM_OBJDUMP) --arch=rv32imac -D $(WORK_DIR)/build/$@/$@ > $(WORK_DIR)/build/$@/$@.ASM

gcc objdump result:

4001168: 00052383 lw t2,0(a0)
400116c: 979a add a5,a5,t1
400116e: 439c lw a5,0(a5)
4001170: 0308a533 mulhsu a0,a7,a6

llvm-objdump result:

4001168: 83 23 05 00 lw t2, 0(a0)
400116c: 9a 97 add a5, a5, t1
400116e: 9c 43 lw a5, 0(a5)
4001170: 33 a5 08 03 <unknown>

Does anyone knows what is the problem and how to fix it?

Hi,

Unlike GNU objdump, llvm-objdump doesn't assume that for RISC-V all
standard extensions are available by default, and so need to be
provided on the command line. I'm not aware of a flag that you can
pass a RISC-V ISA string to (from your command it seems --arch doesn't
do this for you), but you can enable the disassembly of instructions
using the underlying attributes and the --mattr flag, so in your case
adding `--mattr=+m` to your llvm-objdump command (I think `--mattr=m`
should work as well).

Hope this helps.

Thanks,
Simon

Awesome, thanks!

‘ --mattr=m ’ works well, I can see mul & mulh instructions.

Seems like it’d make sense to change this? Is there any benefit to not disassemble the standard extensions unless requested?

I agree that disassembling all standard extensions’ instructions is a reasonable default, and that there is value in being compatible with the GNU objdump. I could see some arguments against that, but they are fairly minor. I’ll post a patch for that this week.

Thanks,
Luís