<div dir="ltr"><div>Compiling for RISC-V, clang makes appropriate use of mem*() functions for bulk operations such as initialisation:</div><div><br></div><div>********<br></div><div>// test.c<br></div><div></div><div>int main() {<br>        int a[16] = { 0 };<br>        return a[0];<br>}</div><div><br></div><div>$ clang test.c -c --target=riscv32 -march=rv32i -mabi=ilp32</div><div>$ llvm-objdump --syms test.o<br></div><div>test.o: file format elf32-littleriscv<br><br>SYMBOL TABLE:<br>00000000 l    df *ABS*  00000000 test.c<br>00000000 g     F .text  0000003c main<br>00000000         *UND*  00000000 memset<br></div><div>********<br></div><div><br></div><div>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:</div><div><br></div><div>(1) Is there a way to have the compiler provide substitutes, e.g. naive built-in implementations?</div><div><br></div><div><br></div><div>(2) I didn't successfully build llvm-libc for RISC-V, e.g. configuring as:<br></div><div><br></div><div>cmake -DLLVM_TARGETS_TO_BUILD='RISCV' -DLLVM_ENABLE_PROJECTS='clang;lld;compiler-rt;libc'  /* other options */</div><div><br></div><div>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?<br></div><div><br></div><div><br></div><div>(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.:</div><div>(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 (<a href="https://keithp.com/picolibc/">https://keithp.com/picolibc/</a>) looks like another possibility?</div><div>(c) or just provide (naive) implementations, e.g. textbook implementations in 'C'?</div><div><br></div><div><br></div><div><br></div><div><br></div></div>