Error: "xlen must be 32 or 64 for save-restore implementation

I have successfully built the clang compiler. The cmake parameter specifies “- DLLVM_TARGETS_TO_BUILD=” RISCV “- DLLVM_DEFAULT_TARGET_TRIPLE=riscv32 unknown elf”. Then I want to build compiler-rt, following the steps given on the official website:

cd llvm project;
mkdir build-compiler-rt;
cd build-compiler-rt;
cmake ../compiler-rt -DLLVM_ CONFIG_ PATH=/path/to/llvm-config;
make;

but it reports error:

[ 19%] Building ASM object lib/builtins/CMakeFiles/clang_rt.builtins-riscv32.dir/riscv/save.S.o
[ 20%] Building C object lib/profile/CMakeFiles/clang_rt.profile-riscv32.dir/InstrProfilingPlatformLinux.c.o
/home/suncheng/llvm-project-15.0.4.src/compiler-rt/lib/builtins/riscv/save.S:185:3: error: "xlen must be 32 or 64 for save-restore implementation
# error "xlen must be 32 or 64 for save-restore implementation
  ^
1 error generated.
make[2]: *** [lib/builtins/CMakeFiles/clang_rt.builtins-riscv32.dir/build.make:68: lib/builtins/CMakeFiles/clang_rt.builtins-riscv32.dir/riscv/save.S.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:622: lib/builtins/CMakeFiles/clang_rt.builtins-riscv32.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 20%] Building C object lib/profile/CMakeFiles/clang_rt.profile-riscv32.dir/InstrProfilingPlatformOther.c.o
[ 21%] Building C object lib/profile/CMakeFiles/clang_rt.profile-riscv32.dir/InstrProfilingPlatformWindows.c.o
[ 21%] Building CXX object lib/profile/CMakeFiles/clang_rt.profile-riscv32.dir/InstrProfilingRuntime.cpp.o
[ 22%] Building C object lib/profile/CMakeFiles/clang_rt.profile-riscv32.dir/InstrProfilingUtil.c.o
[ 22%] Linking CXX static library ../linux/libclang_rt.profile-riscv32.a
[ 22%] Built target clang_rt.profile-riscv32
make: *** [Makefile:130: all] Error 2

how to resolve this problem?

Is it the same issue as this one?

Yes, the problem is the same. But I don’t think there is a final solution to this issue.

Yes, you can leverage the gnu runtime libraries by clang/clang++ as workaround for now.

(post deleted by author)

Thank you very much. At present, I can successfully compile using gnu runtime libraries. Another problem is that I compared the size of the executable file compiled by clang with that compiled by riscv32-unknown-elf-gcc. It is found that the size of the file compiled by clang is several times larger than that compiled by gcc. Do you know why?

I think it may be case by case. You may need to check the below items.

  • Static/dynamic link.
  • Debug info, stripped or not.
  • C extension involved or not.
  • At last, compare the disassembly code, but may be tough here.