Error buidling LLVM for RISC-V

635 views
Skip to first unread message

zazad

unread,
Aug 30, 2021, 11:48:12 AM8/30/21
to RISC-V SW Dev
Hi all,

When building llvm for riscv64-unknown-linux-gnu target, I get this error:

Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-riscv64.dir/riscv/save.S.o FAILED: projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-riscv64.dir/riscv/save.S.o

/share/pkg.7/gcc/9.3.0/install/bin/gcc -DVISIBILITY_HIDDEN -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/builtins -I/riscv/riscv-llvm/compiler-rt/lib/builtins -Iinclude -I/riscv/riscv-llvm/llvm/include -fPIC -O3 -DNDEBUG  -fno-lto -std=c11 -MD -MT projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-riscv64.dir/riscv/save.S.o -MF projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-riscv64.dir/riscv/save.S.o.d -o projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-riscv64.dir/riscv/save.S.o -c /riscv/riscv-llvm/compiler-rt/lib/builtins/riscv/save.S

…riscv-llvm/compiler-rt/lib/builtins/riscv/save.S:183:3: error: #error "xlen must be 32 or 64 for save-restore implementation

  183 | # error "xlen must be 32 or 64 for save-restore implementation

      |   ^~~~~


Here is the config I'm using:

cmake -G Ninja
-DCMAKE_BUILD_TYPE="Release" \
-DBUILD_SHARED_LIBS=True -DLLVM_USE_SPLIT_DWARF=True \
-DCMAKE_INSTALL_PREFIX="../../_install" \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;ibcxx; libcxxabi;libunwind;lldb;compiler-rt;lld;polly" \
-DLLVM_OPTIMIZED_TABLEGEN=True -DLLVM_BUILD_TESTS=False \
-DDEFAULT_SYSROOT="../../_install/sysroot" \
-DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-linux-gnu" \
-DLLVM_TARGETS_TO_BUILD="RISCV" \
../llvm

Any idea what other config options I need to use to fix the issue?  

Thank you!

Alexey Baturo

unread,
Aug 30, 2021, 12:01:53 PM8/30/21
to zazad, RISC-V SW Dev
Hi,

>-DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-linux-gnu" \
Could you please confirm you have riscv64-unknown-linux-gnu available in yout PATH?

пн, 30 авг. 2021 г. в 18:48, zazad <za...@bu.edu>:
--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/ed01605a-77d7-4170-a5e4-870f169eb376n%40groups.riscv.org.

zazad

unread,
Aug 30, 2021, 2:52:02 PM8/30/21
to RISC-V SW Dev, baturo...@gmail.com, RISC-V SW Dev, zazad

Yes, I put the toolchain's bin directory on the PATH.
Building clang and lld projects are successful, but I think compiler-rt is failing.

Alexey Baturo

unread,
Aug 30, 2021, 3:02:31 PM8/30/21
to zazad, RISC-V SW Dev
Ok, I guess the issue here is that compiler-rt has to be built in native mode, while clang and lld are x86 binaries.
To solve your problem you could build compiler-rt as separate targets. I've done such thing while working on sanitizers, you could check my scripts for building llvm+compilerrt here: https://github.com/gattaca-lab/riscv_hwasan/tree/master/scripts

пн, 30 авг. 2021 г. в 21:52, zazad <za...@bu.edu>:
Message has been deleted

zazad

unread,
Aug 31, 2021, 1:21:23 AM8/31/21
to RISC-V SW Dev, baturo...@gmail.com, RISC-V SW Dev, zazad
Thank you! Building compiler-rt separately worked.

Now when I use clang+lld to build hello-world program, I get the following error although I pass the "-mno-relax" flag to clang.
Any idea what the problem could be?

 ./_install/bin/clang -fuse-ld=lld -mno-relax  -o hello hello.c

ld.lld: error: static-reloc.c:(.text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax                                                                     clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

" ./_install/bin/clang  -o hello hello.c"  works well, but it's using gnu linker instead. 
Reply all
Reply to author
Forward
0 new messages