I am trying to cross-compile a program for RISC-V using Clang (LLVM) with the -flto (Link Time Optimization) flag, but I encounter a linking error. The error message suggests that LLVM bit-code files cannot be passed to the linker. Here is the command I used:
/data/tools/riscv64-llvm-baremetal/bin/clang -O3 -flto -std=gnu99 -I./common -mcmodel=medany -static -std=gnu99 -ffast-math -fno-common -fno-builtin-printf -nostdlib -nostartfiles -march=rv64gc -mabi=lp64d -Wno-implicit-int -Wno-implicit-function-declaration ./common/syscalls.c ./common/crt.S dhrystone/*.c -o ../bin/bmi_dhrystone.llvm.bare.riscv -lm -lgcc -T ./common/test.ld
The errors returned are:
clang: error: 'riscv64-unknown-unknown-elf': unable to pass LLVM bit-code files to linker
This issue only occurs when I include the -flto flag. Without it, the compilation proceeds without any errors, but I would like to benefit from the optimizations that LTO provides.
Has anyone encountered this issue, or does anyone know why Clang is unable to pass LLVM bit-code files to the linker in this configuration? How can I resolve this error to successfully use LTO in my build process?
I’ve tried recompiling the LLVM to get LLVMgold.so
plugin and use it for compilation alongside gold
linker to get LTO to work, but it didn’t solve the issue.