[llvm-dev] RISC-V runtime support functions

Thomas Goodfellow via llvm-dev llvm-dev at lists.llvm.org
Wed Jan 26 00:35:23 PST 2022


Compiling for RISC-V, clang makes appropriate use of mem*() functions for
bulk operations such as initialisation:

********
// test.c
int main() {
        int a[16] = { 0 };
        return a[0];
}

$ clang test.c -c --target=riscv32 -march=rv32i -mabi=ilp32
$ llvm-objdump --syms test.o
test.o: file format elf32-littleriscv

SYMBOL TABLE:
00000000 l    df *ABS*  00000000 test.c
00000000 g     F .text  0000003c main
00000000         *UND*  00000000 memset
********

Unlike integer helper routines such as __divsi3, the mem* functions are not
supplied by compiler-rt. I would naively expect them to come from libc.
Some questions:

(1) Is there a way to have the compiler provide substitutes, e.g. naive
built-in implementations?


(2) I didn't successfully build llvm-libc for RISC-V, e.g. configuring as:

cmake -DLLVM_TARGETS_TO_BUILD='RISCV'
-DLLVM_ENABLE_PROJECTS='clang;lld;compiler-rt;libc'  /* other options */

built lib/libllvmlibc.a as elf64-x86-64, and specifying as
-DLLVM_ENABLE_RUNTIMES="libc" triggered asserts in the 'X86 FP Stackifier'
pass while building LLVM. Is there a way to build llvm/libc for RISC-V?


(3) If llvm/libc isn't buildable for a RISC-V baremetal target, what is the
best way to supply the missing mem* functions? E.g.:
(a) are there problems with using the Newlib-based library in
riscv-gnu-toolchain for this? (the OS-dependent functions that use ecall
instructions won't be supported but hopefully mem*, str*, math.h, etc, all
work.) (b) Picolibc (https://keithp.com/picolibc/) looks like another
possibility?
(c) or just provide (naive) implementations, e.g. textbook implementations
in 'C'?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20220126/2c8cc827/attachment.html>


More information about the llvm-dev mailing list