<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59228>59228</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            recipe for target 'CMakeFiles/clang_rt.builtins-riscv64.dir/emutls.c.o' failed, build llvm for riscv failed
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dshm
      </td>
    </tr>
</table>

<pre>
    llvm code is tag llvmorg-15.0.4, build for RISCV target. 

cmake -G "Unix Makefiles" -DGCC_INSTALL_PREFIX=/data/dushaomin/task20221114/insta
lltest20221128 -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;libc;compiler-rt"  -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On -DDEFAULT_SYSROOT="/data/dushaomin/task20221109/test2/install/riscv64-unknown-elf" -DGCC_INSTALL_PREFIX="/data/dushaomin/task20221109/test2/install" -DLLVM_TARGETS_TO_BUILD="RISCV" -DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-elf" ../llvm

/data/dushaomin/task20221109/test2/install/ is where I install riscv-gnu-toolchain 

make -j

and I get the following error:
[ 93%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/floatunditf.c.o
[ 94%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/floatunsitf.c.o
[ 94%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/floatuntitf.c.o
[ 95%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/multc3.c.o
[ 95%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/powitf2.c.o
[ 96%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/multf3.c.o
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/enable_execute_stack.c:12:10: fatal error: 'sys/mman.h' file not found
#include <sys/mman.h>
         ^~~~~~~~~~~~
[ 97%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/subtf3.c.o
[ 98%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/trunctfdf2.c.o
1 error generated.
[ 98%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/trunctfhf2.c.o
[ 99%] Building C object CMakeFiles/clang_rt.builtins-riscv64.dir/trunctfsf2.c.o
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:52:8: error: unknown type name 'pthread_mutex_t'
static pthread_mutex_t emutls_mutex = PTHREAD_MUTEX_INITIALIZER;
       ^
CMakeFiles/clang_rt.builtins-riscv64.dir/build.make:1780: recipe for target 'CMakeFiles/clang_rt.builtins-riscv64.dir/enable_execute_stack.c.o' failed
make[5]: *** [CMakeFiles/clang_rt.builtins-riscv64.dir/enable_execute_stack.c.o] Error 1
make[5]: *** Waiting for unfinished jobs....
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:52:39: error: use of undeclared identifier 'PTHREAD_MUTEX_INITIALIZER'
static pthread_mutex_t emutls_mutex = PTHREAD_MUTEX_INITIALIZER;
                                      ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:53:8: error: unknown type name 'pthread_key_t'
static pthread_key_t emutls_pthread_key;
       ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:93:3: warning: call to undeclared function 'pthread_setspecific'; ISO C99 and
 later do not support implicit function declarations [-Wimplicit-function-declaration]  pthread_setspecific(emutls_pthread_key, (void *)value);
  ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:97:34: warning: call to undeclared function 'pthread_getspecific'; ISO C99 an
d later do not support implicit function declarations [-Wimplicit-function-declaration]  return (emutls_address_array *)pthread_getspecific(emutls_pthread_key);
                                 ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:118:7: warning: call to undeclared function 'pthread_key_create'; ISO C99 and
 later do not support implicit function declarations [-Wimplicit-function-declaration]  if (pthread_key_create(&emutls_pthread_key, emutls_key_destructor) != 0)
      ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:124:10: error: unknown type name 'pthread_once_t'
  static pthread_once_t once = PTHREAD_ONCE_INIT;
         ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:124:32: error: use of undeclared identifier 'PTHREAD_ONCE_INIT'
  static pthread_once_t once = PTHREAD_ONCE_INIT;
                               ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:125:3: warning: call to undeclared function 'pthread_once'; ISO C99 and later
 do not support implicit function declarations [-Wimplicit-function-declaration]  pthread_once(&once, emutls_init);
  ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:128:42: warning: call to undeclared function 'pthread_mutex_lock'; ISO C99 an
d later do not support implicit function declarations [-Wimplicit-function-declaration]static __inline void emutls_lock(void) { pthread_mutex_lock(&emutls_mutex); }
                                         ^
/data/dushaomin/task20221114/llvm-project/compiler-rt/lib/builtins/emutls.c:130:44: warning: call to undeclared function 'pthread_mutex_unlock'; ISO C99 
and later do not support implicit function declarations [-Wimplicit-function-declaration]static __inline void emutls_unlock(void) { pthread_mutex_unlock(&emutls_mutex); }
                                           ^
6 warnings and 5 errors generated.
CMakeFiles/clang_rt.builtins-riscv64.dir/build.make:1766: recipe for target 'CMakeFiles/clang_rt.builtins-riscv64.dir/emutls.c.o' failed
make[5]: *** [CMakeFiles/clang_rt.builtins-riscv64.dir/emutls.c.o] Error 1
CMakeFiles/Makefile2:303: recipe for target 'CMakeFiles/clang_rt.builtins-riscv64.dir/all' failed
make[4]: *** [CMakeFiles/clang_rt.builtins-riscv64.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make[3]: *** [all] Error 2
runtimes/CMakeFiles/builtins.dir/build.make:85: recipe for target 'runtimes/builtins-stamps/builtins-build' failed
make[2]: *** [runtimes/builtins-stamps/builtins-build] Error 2
CMakeFiles/Makefile2:100027: recipe for target 'runtimes/CMakeFiles/builtins.dir/all' failed
make[1]: *** [runtimes/CMakeFiles/builtins.dir/all] Error 2
Makefile:155: recipe for target 'all' failed
make: *** [all] Error 2

these days I have been trying to using llvm as the compiler to generate code that can be run on RISCV, and the test platform is spike[https://github.com/riscv-software-src/riscv-isa-sim.git]. I have meet some trouble in build llvm for RISCV and I also raise issues but it is not solved. In this issue, I wiil state the error in detail I met and ask some questions, which I google much time and find many people asked , but there are not a complete answer. 

the main question is Does LLVM libc, compiler-rt and etc support RISCV? as seen in issue https://github.com/llvm/llvm-project/issues/59026 , it said 
"With respect to libc, it does not work on RISC-V so the libc failures are expected. With respect to compiler-rt, I am not sure if we can list it under LLVM_ENABLE_RUNTIMES. Adding @petrhosek who can confirm/help."
 at the bottom of the webpage. and shown in comipler-rt offical page https://compiler-rt.llvm.org/ platform support section, it said 
"builtins is known to work on the following platforms:
Machine Architectures: i386, X86-64, SPARC64, ARM, PowerPC, PowerPC 64.
OS: DragonFlyBSD, FreeBSD, NetBSD, OpenBSD, Linux, Darwin."
RISCV is not in the list. 
But as the answer in https://github.com/llvm/llvm-project/issues/59026 said by BertalanD, 
"I think your issue is that the command you ran does not build the compiler-rt library, just the compiler. Check out [the documentation](https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html) for how to cross-compile the builtins library."
it seems that compiler-rt support RISCV? I tried as he said "-DLLVM_BUILTIN_TARGETS=riscv64-unknown-elf -DBUILTINS_riscv64-unknown-elf_CMAKE_SYSROOT=<path to sysroot>" but failed, and I also tried write compiler-rt libc and etc in -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;libc;compiler-rt" when cmake, but the build process failed. As seen in officail page https://llvm.org/docs/CMake.html , the target in DLLVM_ENABLE_RUNTIMES is compilerd using just built compiler , thus just built clang target RISCV. 
The answer by different people is contradictory and I am not sure which is right and which wrong.

Could someone please answer me directly? Does llvm support RISCV target completely? Does llvm libc, compiler-rt and etc. supported RISCV? I know using clang with --gcc-toolchain and --sysroot params can generate code for RISCV target, gcc-toolchain and sysroot points to riscv-gnu toolchain install path. But can I use clang without --gcc-toolchain and --sysroot?  Thus using llvm completely without  riscv-gnu toolchain riscv64-unknown-elf-gcc ? As error asked in issue [https://github.com/llvm/llvm-project/issues/59026], there are friendly people answer me that it was the problem of compiler-rt , but I can't build compiler-rt for RISCV successful. Does llvm libc, compiler-rt and etc. supported RISCV?  I have tried much to build it and google it but not make sence. If it support RISCV, Could someone please give a complete proccess how to make it successful, If it not support RISCV, I may not waste time on it.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFWllz4rgW_jXkRWUXmP0hD2yZ4d5sBfQy94UStozVsS2uJIfw7-ccyTYmIWuHdFcajCWf9TuLLK1EsDuP4_uE-CJghCui6ZrgDSHXTqPt1t1WzRuRVcbjgIRCktl0PvoOs-SaaZfU6uNafWA__YTeMeL8RWqe9y3lD-QKfoc8ZgpuEGf812i0nF7PF4PLy-XtbHIx_VlrjmveRUA1xa9MRVQkPIVrTdWdV_e8RqMB7C94qmCKYRLHmiltx7weUL28_H61nFwPhpcToHrzn8loMTd0PT-m6brWHJpvRwsRK4c9aEnhXhwH8GnlqlKYfbteTK8mOYWYr_yHB5xuLuiK2-ss3fI0yO8jB5FsQE_pSI0kgeboavDfyXL4bXo5Xi7-uZ0AvRmLGVXsEcPBfD6ZLaY318jyJoXR8eRi8O1ysZz_M5_d3CysJK-Zqd7Hn2iZwlxxDFeSK_--03Ky9C4V29RhcfiiLz7Ip7TiYjD7a7KYLxc3VndL1ECmMqvQ0M5eLmbT28uJnfqMwK4L7BCVVbx90CYI8m3EJCNTkt8lhq2zTjMDEz-iPD2AtkX2r-otmgZAAIKA6IhBZMSxAFCsCZNSyFqzkLE9JP1mzWvX2mMyxCDCOSMiVr-Yr8kIQ-TChsiFwelSaheDTYNo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