Thomas Goodfellow via llvm-dev
2021-Jul-27 10:51 UTC
[llvm-dev] Building compiler-rt for RISC-V?
My overall goal is locally building [1] an LLVM toolchain which compiles a mixture of C and supporting assembler for bare RISC-V development environments (no OS). Library support is required for some language features on some RISC-V targets, e.g. integer division when the "M" extension isn't present.>From the details on https://compiler-rt.llvm.org/ I expected that somethinglike this on release/12.x would build the support library for RISC-V: cmake -G Ninja ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS='clang;lld;compiler-rt' -DCMAKE_INSTALL_PREFIX=~/bin/s4e -DLLVM_TARGETS_TO_BUILD='RISCV' ninja ninja install however although that yields the RISCV compiler target libraries (libLLVMRISCV*.a) it doesn't install any obvious RISCV runtime libraries (only x86 ones) and linking a test program with integer division fails: clang testdiv.c --target=riscv32 -march=rv32i ld.lld: error: unable to find library -lc ld.lld: error: unable to find library -lm ld.lld: error: unable to find library -lclang_rt.builtins-riscv32 (using LLVM release/12.x on x86_64 release/12.x; also tried building all targets and also copying the cmake line from a build triggered by Phabricator for a RISC-V-related change to compiler-rt with the hope that some of the additional defines would prove the solution) Thanks in advance for whatever advice you can provide for building the support libraries for RISC-V. Tom Goodfellow [1] in the very short-term obtaining working ones from another build would suffice, however I'll be needing to modify them soon anyway. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210727/05c25b49/attachment.html>
Fāng-ruì Sòng via llvm-dev
2021-Jul-27 16:21 UTC
[llvm-dev] Building compiler-rt for RISC-V?
On Tue, Jul 27, 2021 at 3:51 AM Thomas Goodfellow via llvm-dev < llvm-dev at lists.llvm.org> wrote:> My overall goal is locally building [1] an LLVM toolchain which compiles a > mixture of C and supporting assembler for bare RISC-V development > environments (no OS). Library support is required for some language > features on some RISC-V targets, e.g. integer division when the "M" > extension isn't present. > > From the details on https://compiler-rt.llvm.org/ I expected that > something like this on release/12.x would build the support library for > RISC-V: > > cmake -G Ninja ../llvm -DCMAKE_BUILD_TYPE=Release > -DLLVM_ENABLE_PROJECTS='clang;lld;compiler-rt' > -DCMAKE_INSTALL_PREFIX=~/bin/s4e -DLLVM_TARGETS_TO_BUILD='RISCV' > ninja > ninja install > > however although that yields the RISCV compiler target libraries > (libLLVMRISCV*.a) it doesn't install any obvious RISCV runtime libraries > (only x86 ones) and linking a test program with integer division fails: > > clang testdiv.c --target=riscv32 -march=rv32i > ld.lld: error: unable to find library -lc > ld.lld: error: unable to find library -lm > ld.lld: error: unable to find library -lclang_rt.builtins-riscv32 > > (using LLVM release/12.x on x86_64 release/12.x; also tried building all > targets and also copying the cmake line from a build triggered by > Phabricator for a RISC-V-related change to compiler-rt with the hope that > some of the additional defines would prove the solution) > > Thanks in advance for whatever advice you can provide for building the > support libraries for RISC-V. > > Tom Goodfellow >Your --target= is not correct. Normally, if you use --target=aarch64-linux-gnu, the clang driver will pick up crt1.o crti.o crtn.o libc libm from libc, crtbegin.o/crtend.o from aarch64-linux-gnu-gcc. The libc and gcc paths are detected by locating aarch64-linux-gnu-gcc. riscv may be more strange on some systems due to the complex multiarch/multilib scheme. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210727/27add423/attachment.html>
Luís Marques via llvm-dev
2021-Jul-28 11:24 UTC
[llvm-dev] Building compiler-rt for RISC-V?
On Tue, Jul 27, 2021 at 11:51 AM Thomas Goodfellow via llvm-dev <llvm-dev at lists.llvm.org> wrote:> however although that yields the RISCV compiler target libraries (libLLVMRISCV*.a) it doesn't install any obvious RISCV runtime libraries (only x86 ones) and linking a test program with integer division failsWhen compiling compiler-rt standalone (instead of as part of the overall LLVM build) I have in the past used the following for the rv32i build: FLAGS="--target=riscv32-unknown-elf -march=rv32i -mabi=ilp32 --gcc-toolchain=$GCC_TOOLCHAIN --sysroot=$SYSROOT" TEST_FLAGS="$FLAGS" cmake $LLVM/compiler-rt \ -G "Ninja" \ -DCOMPILER_RT_BUILD_BUILTINS=ON \ -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ -DCOMPILER_RT_BUILD_XRAY=OFF \ -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ -DCOMPILER_RT_BUILD_PROFILE=OFF \ -DCMAKE_C_COMPILER=$LLVM_BUILD/bin/clang \ -DCMAKE_AR=$LLVM_BUILD/bin/llvm-ar \ -DCMAKE_NM=$LLVM_BUILD/bin/llvm-nm \ -DCMAKE_RANLIB=$LLVM_BUILD/bin/llvm-ranlib \ -DCMAKE_C_COMPILER_TARGET="riscv32-unknown-elf" \ -DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf" \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \ -DCMAKE_C_FLAGS="$FLAGS" \ -DCMAKE_ASM_FLAGS="$FLAGS" \ -DCOMPILER_RT_OS_DIR="baremetal" \ -DCOMPILER_RT_BAREMETAL_BUILD=ON \ -DCOMPILER_RT_INCLUDE_TESTS=ON \ -DCOMPILER_RT_EMULATOR="qemu-riscv32 -L $SYSROOT" \ -DCOMPILER_RT_TEST_COMPILER="$LLVM_BUILD/bin/clang" \ -DCOMPILER_RT_TEST_COMPILER_CFLAGS="$TEST_FLAGS" \ -DLLVM_CONFIG_PATH=$LLVM_CONFIG For compiling Compiler-RT as part of an integrated LLVM build, IIRC you want to add it to the runtimes list (LLVM_ENABLE_RUNTIMES) and not as a subproject. You can use cmake cache files to configure the runtimes, and LLVM/compiler-rt has a weird setup for parsing cmake settings of the form RUNTIMES_${target}_*. Check the existing cmake cache files. I hope that helps. Best, Luís