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?