Compile compiler-rt for riscv with dedicated library name

Hello

I’m trying to compile llvm for the open-source GPGPU project vortex. I followed the instruction in "README.vortex " located in the https://github.com/vortexgpgpu/pocl.git to build llvm.

I build RiscV GNU Toolchain first as "README.vortex " say with the following command:

- git clone --depth=1 --recursive https://github.com/riscv-collab/riscv-gnu-toolchain.git
- mkdir build && cd build
- export CPATH=$TOOLDIR/GNU/include
- export LIBRARY_PATH=$TOOLDIR/GNU/lib
- ../configure --prefix=$TOOLDIR/riscv32-gnu-toolchain --with-cmodel=medany --with-arch=rv32imf --with-abi=ilp32f
#../configure --prefix=$TOOLDIR/riscv64-gnu-toolchain --with-cmodel=medany --with-arch=rv64imafd --with-abi=lp64d
- make -j32
- make -j32 build-qemu

And build LLVM for Vortex with following commands:

- git clone --recursive --branch vortex https://github.com/vortexgpgpu/llvm.git
- cd llvm
- mkdir build && cd build
- export LLVM_PREFIX=$TOOLDIR/llvm-vortex
- export RISCV_TOOLCHAIN_PATH=$TOOLDIR/riscv64-gnu-toolchain
- cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LLVM_PREFIX -DLLVM_ENABLE_PROJECTS="clang;lld" -DBUILD_SHARED_LIBS=True -DLLVM_TARGETS_TO_BUILD="RISCV" -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DDEFAULT_SYSROOT=$RISCV_TOOLCHAIN_PATH/riscv32-unknown-elf -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" ../llvm
- make -j32
- make install

But I encountered a problem in the step

## Sanity test your new RISC-V LLVM. 
- echo -e '#include <stdio.h>\n int main(void) { printf("Hello world!\\n"); return 0; }' > hello.c
- clang hello.c
- qemu-riscv32 hello

The error log showed as follows:


ld.lld: error: unable to find library -lclang_rt.builtins-riscv32

clang-16: error: ld.lld command failed with exit code 1 (use -v to see invocation)

It seems that lld cannot find a runtime library named clang_rt.builtins-riscv32. So I recompiled llvm with

 -DLLVM_ENABLE_RUNTIMES="compiler-rt"
 -DCOMPILER_RT_BAREMETAL_BUILD=ON

added. But it only generated a libclang_rt.builtins.a in llvm-vortex/lib/clang/16/lib/riscv32-unknown-elf only. But what I need is libclang_rt.builtins-riscv32.a in llvm-vortex/lib/clang/16/lib/baremetal since I run
clang -### hello.c and it returns

clang version 16.0.6 (git@github.com:vortexgpgpu/llvm.git 5828d24a5b9270b7538854d28fa4cc14827da89c)
Target: riscv32-unknown-unknown-elf
Thread model: posix
InstalledDir: /home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/bin
 "/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/bin/clang-16" "-cc1" "-triple" "riscv32-unknown-unknown-elf" "-emit-obj" "-mrelax-all" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "hello.c" "-mrelocation-model" "static" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-fno-verbose-asm" "-mconstructor-aliases" "-nostdsysteminc" "-target-cpu" "generic-rv32" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+c" "-target-feature" "-e" "-target-feature" "-f" "-target-feature" "-d" "-target-feature" "-h" "-target-feature" "-zihintpause" "-target-feature" "-zfhmin" "-target-feature" "-zfh" "-target-feature" "-zfinx" "-target-feature" "-zdinx" "-target-feature" "-zhinxmin" "-target-feature" "-zhinx" "-target-feature" "-zba" "-target-feature" "-zbb" "-target-feature" "-zbc" "-target-feature" "-zbs" "-target-feature" "-zbkb" "-target-feature" "-zbkc" "-target-feature" "-zbkx" "-target-feature" "-zknd" "-target-feature" "-zkne" "-target-feature" "-zknh" "-target-feature" "-zksed" "-target-feature" "-zksh" "-target-feature" "-zkr" "-target-feature" "-zkn" "-target-feature" "-zks" "-target-feature" "-zkt" "-target-feature" "-zk" "-target-feature" "-zmmul" "-target-feature" "-v" "-target-feature" "-zvl32b" "-target-feature" "-zvl64b" "-target-feature" "-zvl128b" "-target-feature" "-zvl256b" "-target-feature" "-zvl512b" "-target-feature" "-zvl1024b" "-target-feature" "-zvl2048b" "-target-feature" "-zvl4096b" "-target-feature" "-zvl8192b" "-target-feature" "-zvl16384b" "-target-feature" "-zvl32768b" "-target-feature" "-zvl65536b" "-target-feature" "-zve32x" "-target-feature" "-zve32f" "-target-feature" "-zve64x" "-target-feature" "-zve64f" "-target-feature" "-zve64d" "-target-feature" "-zicbom" "-target-feature" "-zicboz" "-target-feature" "-zicbop" "-target-feature" "-svnapot" "-target-feature" "-svpbmt" "-target-feature" "-svinval" "-target-feature" "-xventanacondops" "-target-feature" "-xtheadvdot" "-target-feature" "-experimental-zihintntl" "-target-feature" "-experimental-zca" "-target-feature" "-experimental-zcd" "-target-feature" "-experimental-zcf" "-target-feature" "-experimental-zvfh" "-target-feature" "-experimental-zawrs" "-target-feature" "-experimental-ztso" "-target-feature" "+relax" "-target-feature" "-save-restore" "-target-abi" "ilp32" "-msmall-data-limit" "8" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/home/soc_szq/share/vortex/toolchain/out/tools/riscv-llvm-test" "-resource-dir" "/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/lib/clang/16" "-isysroot" "/home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf" "-internal-isystem" "/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/lib/clang/16/include" "-internal-isystem" "/home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf/include" "-fdebug-compilation-dir=/home/soc_szq/share/vortex/toolchain/out/tools/riscv-llvm-test" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-faddrsig" "-o" "/tmp/hello-f898cd.o" "-x" "c" "hello.c"
 "/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/bin/ld.lld" "/tmp/hello-f898cd.o" "-Bstatic" "-L/home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf/lib" "-L/home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf/lib" "-L/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/lib/clang/16/lib/baremetal" "-lc" "-lm" "-lclang_rt.builtins-riscv32" "-o" "a.out"

I wonder whether libclang_rt.builtins.a is the libclang_rt.builtins-riscv32.a I need with just a different name.
Besides, I may also need clang_rt.crtbegin-riscv32.o and clang_rt.crtend-riscv32.o since I found them in the prebuild toolchain repositories of vortex.

So how could I build compiler-rt for riscv32 with a dedicated library named libclang_rt.builtins-riscv32.a.

Thanks a lot.

1 Like

This is likely the config option LLVM_ENABLE_PER_TARGET_RUNTIME_DIR. When this is on you get lib/<target>/<library> and when it’s off you get lib/<library>-<target>.

See llvm-project/llvm/CMakeLists.txt at b86a9c5bf2fab0408a3d549995d6e2449f71a16d · llvm/llvm-project · GitHub. It’s default is ON for Linux and I suspect CMAKE_SYSTEM_NAME is set to Linux in your case since you haven’t told CMake that you’re compiling for bare metal (it’s in the target strings but CMake doesn’t know what those are).

https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html

-DCMAKE_SYSTEM_NAME=Generic may fix this, or you can just add -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF which is more direct.

Yes but as you suspected, you’d need to symlink all the required libraries so as a workaround, it’s more hassle.

I added -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF at first and rebuild llvm

make clean
cd .. && rm -r build
mkdir build && cd build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LLVM_PREFIX -DLLVM_ENABLE_PROJECTS="clang;lld" -DBUILD_SHARED_LIBS=True -DLLVM_TARGETS_TO_BUILD="RISCV" -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DDEFAULT_SYSROOT=$RISCV_TOOLCHAIN_PATH/riscv32-unknown-elf -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" -DLLVM_ENABLE_RUNTIMES="compiler-rt" -DCOMPILER_RT_BAREMETAL_BUILD=ON  -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF ../llvm
makr -j32
make install

But nothing changed. There is still only llvm-vortex/lib/clang/16/lib/riscv32-unknown-elf/libclang_rt.builtins.a.

Then I used

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LLVM_PREFIX -DLLVM_ENABLE_PROJECTS="clang;lld" -DBUILD_SHARED_LIBS=False -DLLVM_TARGETS_TO_BUILD="RISCV" -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DDEFAULT_SYSROOT=$RISCV_TOOLCHAIN_PATH/riscv32-unknown-elf -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" -DLLVM_ENABLE_RUNTIMES="compiler-rt" -DCOMPILER_RT_BAREMETAL_BUILD=ON -DCMAKE_SYSTEM_NAME=Generic ../llvm

But the configuration return error:

CMake Error at cmake/modules/HandleLLVMOptions.cmake:151 (MESSAGE):
  Unable to determine platform
Call Stack (most recent call first):
  CMakeLists.txt:883 (include)

Besides there is some other warnings:

CMake Warning (dev) at cmake/modules/AddLLVM.cmake:583 (add_library):
  ADD_LIBRARY called with MODULE option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.
Call Stack (most recent call first):
  cmake/modules/AddLLVM.cmake:844 (llvm_add_library)
  tools/bugpoint-passes/CMakeLists.txt:17 (add_llvm_library)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake/modules/AddLLVM.cmake:586 (add_library):
  ADD_LIBRARY called with SHARED option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.
Call Stack (most recent call first):
  cmake/modules/AddLLVM.cmake:846 (llvm_add_library)
  tools/remarks-shlib/CMakeLists.txt:16 (add_llvm_library)
This warning is for project developers.  Use -Wno-dev to suppress it.

Anyhow -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF may not working.

Weird, llvm-project/llvm/cmake/modules/HandleLLVMOptions.cmake at de32a3df354f1d01c0a5c81285ac786cea9d8bdf · llvm/llvm-project · GitHub should find the value.

You might need to set CMAKE_SYSTEM_PROCESSOR as well. If it’s not set, CMake might be overriding both variables itself. I guess it should be RISC-V?

(judging by Building - 🐛 LLDB)

But that’s beside the point, LLVM_ENABLE_PER_TARGET_RUNTIME_DIR isn’t acting as expected either way.

Perhaps you can add some prints (message(STATUS "...")) to llvm-project/compiler-rt/cmake/Modules/AddCompilerRT.cmake at de32a3df354f1d01c0a5c81285ac786cea9d8bdf · llvm/llvm-project · GitHub and see if the value makes it there.

I added a message in AddCompilerRT.cmake as follows:

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index 045221312a82..f266f0bd4f3b 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -153,6 +153,7 @@ macro(set_output_name output name arch)
       # target.
       if (COMPILER_RT_BAREMETAL_BUILD)
         set(${output} "${name}-${arch}${COMPILER_RT_OS_SUFFIX}")
+       message(STATUS "sunzq: ${name}-${arch}${COMPILER_RT_OS_SUFFIX}")
       elseif ("${arch}" MATCHES "hf$" OR "${triple}" MATCHES "hf$")
         set(${output} "${name}-armhf${COMPILER_RT_OS_SUFFIX}")
       else()

and re-generated the build folder:

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LLVM_PREFIX -DLLVM_ENABLE_PROJECTS="clang;lld" -DBUILD_SHARED_LIBS=True -DLLVM_TARGETS_TO_BUILD="RISCV" -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DDEFAULT_SYSROOT=$RISCV_TOOLCHAIN_PATH/riscv32-unknown-elf -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" -DLLVM_ENABLE_RUNTIMES="compiler-rt" -DCOMPILER_RT_BAREMETAL_BUILD=ON  -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF ../llvm

and found that my appending doesn’t appear in the build folder. So I checked the cmake log and foud this : -- compiler-rt project is disabled

The complete log of cmake is as follows

CMake Deprecation Warning at /home/soc_szq/share/vortex/toolchain/src/llvm/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
  The OLD behavior for policy CMP0114 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  CMakeLists.txt:13 (include)


CMake Deprecation Warning at /home/soc_szq/share/vortex/toolchain/src/llvm/cmake/Modules/CMakePolicy.cmake:11 (cmake_policy):
  The OLD behavior for policy CMP0116 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  CMakeLists.txt:13 (include)


-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- bolt project is disabled
-- clang project is enabled
-- clang-tools-extra project is disabled
-- compiler-rt project is disabled
-- cross-project-tests project is disabled
-- libc project is disabled
-- libclc project is disabled
-- lld project is enabled
-- lldb project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- polly project is disabled
-- pstl project is disabled
-- flang project is disabled
-- Found Python3: /usr/bin/python3 (found suitable version "3.12.3", minimum required is "3.0") found components: Interpreter 
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for errno.h
-- Looking for errno.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for link.h
-- Looking for link.h - found
-- Looking for malloc/malloc.h
-- Looking for malloc/malloc.h - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for signal.h
-- Looking for signal.h - found
-- Looking for sys/ioctl.h
-- Looking for sys/ioctl.h - found
-- Looking for sys/mman.h
-- Looking for sys/mman.h - found
-- Looking for sys/param.h
-- Looking for sys/param.h - found
-- Looking for sys/resource.h
-- Looking for sys/resource.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for sys/time.h
-- Looking for sys/time.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for sysexits.h
-- Looking for sysexits.h - found
-- Looking for termios.h
-- Looking for termios.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for valgrind/valgrind.h
-- Looking for valgrind/valgrind.h - not found
-- Looking for fenv.h
-- Looking for fenv.h - found
-- Looking for FE_ALL_EXCEPT
-- Looking for FE_ALL_EXCEPT - found
-- Looking for FE_INEXACT
-- Looking for FE_INEXACT - found
-- Looking for mach/mach.h
-- Looking for mach/mach.h - not found
-- Looking for CrashReporterClient.h
-- Looking for CrashReporterClient.h - not found
-- Looking for linux/magic.h
-- Looking for linux/magic.h - found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Looking for pthread_rwlock_init in pthread
-- Looking for pthread_rwlock_init in pthread - found
-- Looking for pthread_mutex_lock in pthread
-- Looking for pthread_mutex_lock in pthread - found
-- Looking for dlopen in dl
-- Looking for dlopen in dl - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for pfm_initialize in pfm
-- Looking for pfm_initialize in pfm - not found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.3")  
-- Looking for compress2
-- Looking for compress2 - found
-- Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) 
-- Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) 
-- Could NOT find Terminfo (missing: Terminfo_LIBRARIES Terminfo_LINKABLE) 
-- Looking for xar_open in xar
-- Looking for xar_open in xar - not found
-- Looking for arc4random
-- Looking for arc4random - found
-- Looking for backtrace
-- Looking for backtrace - found
-- backtrace facility detected in default set of libraries
-- Found Backtrace: /usr/include  
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
-- Looking for __register_frame
-- Looking for __register_frame - found
-- Looking for __deregister_frame
-- Looking for __deregister_frame - found
-- Looking for __unw_add_dynamic_fde
-- Looking for __unw_add_dynamic_fde - not found
-- Looking for _Unwind_Backtrace
-- Looking for _Unwind_Backtrace - found
-- Looking for getpagesize
-- Looking for getpagesize - found
-- Looking for sysconf
-- Looking for sysconf - found
-- Looking for getrusage
-- Looking for getrusage - found
-- Looking for setrlimit
-- Looking for setrlimit - found
-- Looking for isatty
-- Looking for isatty - found
-- Looking for futimens
-- Looking for futimens - found
-- Looking for futimes
-- Looking for futimes - found
-- Looking for sigaltstack
-- Looking for sigaltstack - found
-- Looking for mallctl
-- Looking for mallctl - not found
-- Looking for mallinfo
-- Looking for mallinfo - found
-- Looking for mallinfo2
-- Looking for mallinfo2 - found
-- Looking for malloc_zone_statistics
-- Looking for malloc_zone_statistics - not found
-- Looking for getrlimit
-- Looking for getrlimit - found
-- Looking for posix_spawn
-- Looking for posix_spawn - found
-- Looking for pread
-- Looking for pread - found
-- Looking for sbrk
-- Looking for sbrk - found
-- Looking for strerror
-- Looking for strerror - found
-- Looking for strerror_r
-- Looking for strerror_r - found
-- Looking for strerror_s
-- Looking for strerror_s - not found
-- Looking for setenv
-- Looking for setenv - found
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - Failed
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - Success
-- Looking for __GLIBC__
-- Looking for __GLIBC__ - found
-- Looking for pthread_getname_np
-- Looking for pthread_getname_np - found
-- Looking for pthread_setname_np
-- Looking for pthread_setname_np - found
-- Looking for dlopen
-- Looking for dlopen - found
-- Looking for dladdr
-- Looking for dladdr - found
-- Looking for proc_pid_rusage
-- Looking for proc_pid_rusage - not found
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Success
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Success
-- Performing Test LLVM_HAS_ATOMICS
-- Performing Test LLVM_HAS_ATOMICS - Success
-- Performing Test SUPPORTS_VARIADIC_MACROS_FLAG
-- Performing Test SUPPORTS_VARIADIC_MACROS_FLAG - Success
-- Performing Test SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG
-- Performing Test SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG - Failed
-- Performing Test HAS_MAYBE_UNINITIALIZED
-- Performing Test HAS_MAYBE_UNINITIALIZED - Success
-- Native target X86 is not selected; lli will not JIT code
-- Threads enabled.
-- Doxygen disabled.
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) 
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) 
-- OCaml bindings disabled.
-- Found Python module pygments
-- Found Python module pygments.lexers.c_cpp
-- Found Python module yaml
-- LLVM host triple: x86_64-unknown-linux-gnu
-- LLVM default target triple: riscv32-unknown-elf
-- sunzq: platform is 1
-- Performing Test C_SUPPORTS_FPIC
-- Performing Test C_SUPPORTS_FPIC - Success
-- Performing Test CXX_SUPPORTS_FPIC
-- Performing Test CXX_SUPPORTS_FPIC - Success
-- Building with -fPIC
-- Performing Test C_SUPPORTS_FNO_SEMANTIC_INTERPOSITION
-- Performing Test C_SUPPORTS_FNO_SEMANTIC_INTERPOSITION - Success
-- Performing Test CXX_SUPPORTS_FNO_SEMANTIC_INTERPOSITION
-- Performing Test CXX_SUPPORTS_FNO_SEMANTIC_INTERPOSITION - Success
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Failed
-- Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG
-- Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG - Success
-- Performing Test C_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG
-- Performing Test C_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG - Failed
-- Performing Test CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG
-- Performing Test CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG - Failed
-- Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
-- Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG
-- Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
-- Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Failed
-- Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG
-- Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Failed
-- Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG
-- Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG - Success
-- Performing Test CXX_SUPPORTS_REDUNDANT_MOVE_FLAG
-- Performing Test CXX_SUPPORTS_REDUNDANT_MOVE_FLAG - Success
-- Performing Test CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG
-- Performing Test CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG - Success
-- Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG
-- Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG - Success
-- Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR
-- Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR - Failed
-- Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG
-- Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG - Success
-- Performing Test CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL
-- Performing Test CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL - Success
-- Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP
-- Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP - Failed
-- Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG
-- Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG - Failed
-- Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG
-- Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG - Failed
-- Performing Test CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG
-- Performing Test CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG - Success
-- Performing Test C_SUPPORTS_CTAD_MAYBE_UNSPPORTED_FLAG
-- Performing Test C_SUPPORTS_CTAD_MAYBE_UNSPPORTED_FLAG - Failed
-- Performing Test CXX_SUPPORTS_CTAD_MAYBE_UNSPPORTED_FLAG
-- Performing Test CXX_SUPPORTS_CTAD_MAYBE_UNSPPORTED_FLAG - Success
-- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS
-- Performing Test C_SUPPORTS_FNO_FUNCTION_SECTIONS - Success
-- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS
-- Performing Test C_SUPPORTS_FFUNCTION_SECTIONS - Success
-- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS
-- Performing Test CXX_SUPPORTS_FFUNCTION_SECTIONS - Success
-- Performing Test C_SUPPORTS_FDATA_SECTIONS
-- Performing Test C_SUPPORTS_FDATA_SECTIONS - Success
-- Performing Test CXX_SUPPORTS_FDATA_SECTIONS
-- Performing Test CXX_SUPPORTS_FDATA_SECTIONS - Success
-- Looking for os_signpost_interval_begin
-- Looking for os_signpost_interval_begin - not found
-- Linker detection: GNU ld
-- Performing Test HAS_WERROR_GLOBAL_CTORS
-- Performing Test HAS_WERROR_GLOBAL_CTORS - Failed
-- Looking for __x86_64__
-- Looking for __x86_64__ - found
-- Found Git: /usr/bin/git (found version "2.43.0") 
-- Targeting RISCV
CMake Deprecation Warning at /home/soc_szq/share/vortex/toolchain/src/llvm/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
  The OLD behavior for policy CMP0114 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  /home/soc_szq/share/vortex/toolchain/src/llvm/clang/CMakeLists.txt:6 (include)


CMake Deprecation Warning at /home/soc_szq/share/vortex/toolchain/src/llvm/cmake/Modules/CMakePolicy.cmake:11 (cmake_policy):
  The OLD behavior for policy CMP0116 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  /home/soc_szq/share/vortex/toolchain/src/llvm/clang/CMakeLists.txt:6 (include)


-- Looking for sys/resource.h
-- Looking for sys/resource.h - found
-- Clang version: 16.0.6
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Failed
-- Looking for include file sys/inotify.h
-- Looking for include file sys/inotify.h - found
CMake Warning (dev) at /home/soc_szq/share/vortex/toolchain/src/llvm/clang/tools/nvptx-arch/CMakeLists.txt:13 (find_package):
  Policy CMP0146 is not set: The FindCUDA module is removed.  Run "cmake
  --help-policy CMP0146" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at /home/soc_szq/share/vortex/toolchain/src/llvm/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
  The OLD behavior for policy CMP0114 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  /home/soc_szq/share/vortex/toolchain/src/llvm/lld/CMakeLists.txt:6 (include)


CMake Deprecation Warning at /home/soc_szq/share/vortex/toolchain/src/llvm/cmake/Modules/CMakePolicy.cmake:11 (cmake_policy):
  The OLD behavior for policy CMP0116 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  /home/soc_szq/share/vortex/toolchain/src/llvm/lld/CMakeLists.txt:6 (include)


-- LLD version: 16.0.6
-- Configuring done (13.4s)
-- Generating done (1.3s)
-- Build files have been written to: /home/soc_szq/share/vortex/toolchain/src/llvm/build

I will check the Cmake files further more to position the problem.

-- compiler-rt project is disabled

This may be being printed just because it’s not in LLVM_ENABLE_PROJECTS. Confusing, I agree.

For example this buildbot puts compiler-rt in LLVM_ENABLE_RUNTIMES and has the same message in its log.

You can still build compiler-rt as a project, but building is as a runtime is the preferred method.

If the problem is some CMake options not being passed to the runtimes build, then building compiler-rt as a project instead may fix things.

I built compiler-rt standalone referring to this script build-riscv32-clang-baremetal.sh:

mkdir build_rt && cd build_rt
export COMPILER_RT_PREFIX=$TOOLDIR/libcrt32
export LLVM_PREFIX=$TOOLDIR/llvm-vortex
cmake -G"Unix Makefiles"                                                     \
      -DCMAKE_SYSTEM_NAME=Linux                                                \
      -DCMAKE_INSTALL_PREFIX=$COMPILER_RT_PREFIX \
      -DCMAKE_C_COMPILER=${LLVM_PREFIX}/bin/clang                     \
      -DCMAKE_CXX_COMPILER=${LLVM_PREFIX}/bin/clang                    \
      -DCMAKE_LINKER=${LLVM_PREFIX}/bin/ld.lld                      \
      -DCMAKE_AR=${LLVM_PREFIX}/bin/llvm-ar                            \
      -DCMAKE_NM=${LLVM_PREFIX}/bin/llvm-nm                           \
      -DCMAKE_RANLIB=${LLVM_PREFIX}/bin/llvm-ranlib                  \
      -DCMAKE_C_COMPILER_TARGET="riscv32-unknown-elf"                          \
      -DCMAKE_CXX_COMPILER_TARGET="riscv32-unknown-elf"                        \
      -DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf"                        \
      -DCMAKE_EXE_LINKER_FLAGS="-nostartfiles -nostdlib"                       \
      -DCOMPILER_RT_BAREMETAL_BUILD=ON                                         \
      -DCOMPILER_RT_BUILD_BUILTINS=ON                                          \
      -DCOMPILER_RT_BUILD_MEMPROF=OFF                                          \
      -DCOMPILER_RT_BUILD_LIBFUZZER=OFF                                        \
      -DCOMPILER_RT_BUILD_PROFILE=OFF                                          \
      -DCOMPILER_RT_BUILD_SANITIZERS=OFF                                       \
      -DCOMPILER_RT_BUILD_XRAY=OFF                                             \
      -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON                                     \
      -DCOMPILER_RT_OS_DIR=""                                                  \
      -DLLVM_CONFIG_PATH=${LLVM_PREFIX}/bin/llvm-config                   \
      ../compiler-rt

And that is what installed :

out/tools/libcrt32$ tree
.
├── include
│   └── orc
│       └── c_api.h
└── lib
    ├── clang_rt.crtbegin-riscv32.o
    ├── clang_rt.crtend-riscv32.o
    └── libclang_rt.builtins-riscv32.a

4 directories, 4 files

And I copied the lib file to llvm-vortex/lib/clang/16/lib/baremetal
Then I run clang hello.c but it returned with another error:

ld.lld: error: /home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf/lib/libc.a(libc_a-printf.o): cannot link object files with different floating-point ABI from /tmp/hello-8fb0a1.o
ld.lld: error: /home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf/lib/libc.a(libc_a-vfprintf.o): cannot link object files with different floating-point ABI from /tmp/hello-8fb0a1.o
...

I compiled hello.c to generate hello.o standalone following what clang -### hello.c say. And that’s the readelf output of hello.c:

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           RISC-V
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          576 (bytes into file)
  Flags:                             0x3, RVC, single-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         10
  Section header string table index: 1

Besides,that’s the readelf output of libc.a:

File: libc.a(libm_a-sf_copysign.o)
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           RISC-V
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          504 (bytes into file)
  Flags:                             0x2, single-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         11
  Section header string table index: 10

Seems that the clang I build use the wrong default options when compile source codes.

1 Like

Besides, I checked the clang hello.c with the prebuilt toolchains released by the author of Vortex and it returned with the same error :thinking: . Maybe some compile options need to be added manually somehow.