[llvm-dev] Building compiler-rt for RISC-V?

Thomas Goodfellow via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 28 01:02:32 PDT 2021


Thank you for the hint - while it's certainly possible that with a better
choice of target the link would attempt other libraries, there is no RISC-V
compiler runtime library being built at all. Linking "testdiv.c" without
libraries fails as would be expected with an undefined reference to the
symbol "__divsi3"

Looking for this symbol across the release/12.0 installed binaries it's
only present in the x86 support:

lib/clang/12.0.0/lib/linux/libclang_rt.builtins-x86_64.a

perhaps suggesting that the list of LLVM_TARGETS_TO_BUILD isn't applied to
the compiler-rt build? However when building compiler-rt separately I
didn't yet find a working way to specify targets.



On Tue, 27 Jul 2021 at 18:21, Fāng-ruì Sòng <maskray at google.com> wrote:

> 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/20210728/53bfa565/attachment.html>


More information about the llvm-dev mailing list