Cannot find crtbeginS.o and -lgcc during cross compilation to RISC-V
Hi,
I am trying to cross compile SLEEF for RVV on my Ubuntu 22.04.5 LTS, and my clang version is 21.0.0, SLEEF git commit d28232a309e06bcb75e9fb0f6262d9251739fd1e. I have built RISC-V toolchain with vector extension, and I can build it successfully with native configuration:
root@b729f9dd73a4:~/sleef# cmake -S . -B build-native -DCMAKE_TOOLCHAIN_FILE=$(pwd)/toolchains/native-llvm.cmake -DCMAKE_INSTALL_PREFIX=./install-native
-- Configuring SLEEF 4.0.0
-- The C compiler identification is Clang 18.1.8
-- The CXX compiler identification is Clang 18.1.8
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang-18 - 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/clang++-18 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.2")
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Checking for one of the modules 'tlfloat'
-- Found Git: /usr/bin/git (found version "2.34.1")
-- Setting build type to 'Release' (required for full support).
-- Performing Test COMPILER_SUPPORTS_FLOAT128
-- Performing Test COMPILER_SUPPORTS_FLOAT128 - Success
-- Performing Test COMPILER_SUPPORTS_QUADMATH
-- Performing Test COMPILER_SUPPORTS_QUADMATH - Failed
-- Performing Test SLEEF_FLOAT128_IS_IEEEQP
-- Performing Test SLEEF_FLOAT128_IS_IEEEQP - Success
-- Performing Test SLEEF_LONGDOUBLE_IS_IEEEQP
-- Performing Test SLEEF_LONGDOUBLE_IS_IEEEQP - Failed
-- Performing Test COMPILER_SUPPORTS_AVX2
-- Performing Test COMPILER_SUPPORTS_AVX2 - Success
-- Performing Test COMPILER_SUPPORTS_AVX512F
-- Performing Test COMPILER_SUPPORTS_AVX512F - Success
-- Found OpenMP_C: -fopenmp=libomp (found version "5.1")
-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.1")
-- Found OpenMP: TRUE (found version "5.1")
-- Performing Test COMPILER_SUPPORTS_OPENMP
-- Performing Test COMPILER_SUPPORTS_OPENMP - Success
-- Performing Test COMPILER_SUPPORTS_OMP_SIMD
-- Performing Test COMPILER_SUPPORTS_OMP_SIMD - Success
-- Performing Test COMPILER_SUPPORTS_BUILTIN_MATH
-- Performing Test COMPILER_SUPPORTS_BUILTIN_MATH - Failed
-- Performing Test COMPILER_SUPPORTS_SYS_GETRANDOM
-- Performing Test COMPILER_SUPPORTS_SYS_GETRANDOM - Success
-- Configuring build for SLEEF-v4.0.0
Target system: Linux-6.11.0-26-generic
Target processor: x86_64
Host system: Linux-6.11.0-26-generic
Host processor: x86_64
Detected C compiler: Clang @ /usr/bin/clang-18
CMake: 3.31.4
Make program: /usr/bin/gmake
CMake build type: Release
-- Using option `-Wall -Wno-unused-function -Wno-attributes -Wno-unused-result -ffp-contract=off -fvisibility=hidden` to compile libsleef
-- Building shared libs : OFF
-- Building static test bins: OFF
-- MPFR : /usr/lib/x86_64-linux-gnu/libmpfr.so
-- MPFR header file in /usr/include
-- GMP : /usr/lib/x86_64-linux-gnu/libgmp.so
-- RT : /usr/lib/x86_64-linux-gnu/librt.a
-- FFTW3 : LIBFFTW3-NOTFOUND
-- FFTW3F : LIBFFTW3F-NOTFOUND
-- OPENSSL : 3.0.2
-- SDE : SDE_COMMAND-NOTFOUND
-- COMPILER_SUPPORTS_OPENMP : 1
-- Configuring done (9.6s)
-- Generating done (0.1s)
-- Build files have been written to: /root/sleef/build-native
Then I tried configure for RISC-V, but got errors:
root@b729f9dd73a4:~/sleef# cmake -S . -B build-riscv64 -DCMAKE_TOOLCHAIN_FILE=$(pwd)/toolchains/riscv64-llvm.cmake -DCMAKE_SYSROOT=/llvm_rvv/rvv/riscv/sysroot -DNATIVE_BUILD_DIR="$(pwd)/build-native" -DSLEEF_SHOW_CONFIG=1 -DSLEEF_BUILD_GNUABI_LIBS=ON -DSLEEF_BUILD_INLINE_HEADERS=ON -DSLEEF_BUILD_DFT=ON -DSLEEF_BUILD_QUAD=ON -DSLEEF_BUILD_SCALAR_LIB=ON -DSLEEF_BUILD_STATIC_TEST_BINS=ON -DSLEEF_ENFORCE_RVVM1=ON -DSLEEF_ENFORCE_RVVM2=ON
-- Configuring SLEEF 4.0.0
-- The C compiler identification is Clang 21.0.0
-- The CXX compiler identification is Clang 21.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /llvm_rvv/llvm/llvm-project/build/bin/clang
-- Check for working C compiler: /llvm_rvv/llvm/llvm-project/build/bin/clang - broken
CMake Error at /usr/local/lib/python3.10/dist-packages/cmake/data/share/cmake-3.31/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"/llvm_rvv/llvm/llvm-project/build/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: '/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-bp7mnt'
Run Build Command(s): /usr/local/lib/python3.10/dist-packages/cmake/data/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_70a5a/fast
/usr/bin/gmake -f CMakeFiles/cmTC_70a5a.dir/build.make CMakeFiles/cmTC_70a5a.dir/build
gmake[1]: Entering directory '/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-bp7mnt'
Building C object CMakeFiles/cmTC_70a5a.dir/testCCompiler.c.o
/llvm_rvv/llvm/llvm-project/build/bin/clang --target=riscv64-linux-gnu --sysroot=/llvm_rvv/rvv/riscv/sysroot -MD -MT CMakeFiles/cmTC_70a5a.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_70a5a.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_70a5a.dir/testCCompiler.c.o -c /root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-bp7mnt/testCCompiler.c
Linking C executable cmTC_70a5a
/usr/local/lib/python3.10/dist-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/cmTC_70a5a.dir/link.txt --verbose=1
/usr/bin/riscv64-linux-gnu-ld: cannot find crtbeginS.o: No such file or directory
/usr/bin/riscv64-linux-gnu-ld: cannot find -lgcc: No such file or directory
/usr/bin/riscv64-linux-gnu-ld: cannot find -lgcc: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/llvm_rvv/llvm/llvm-project/build/bin/clang --target=riscv64-linux-gnu --sysroot=/llvm_rvv/rvv/riscv/sysroot CMakeFiles/cmTC_70a5a.dir/testCCompiler.c.o -o cmTC_70a5a
gmake[1]: *** [CMakeFiles/cmTC_70a5a.dir/build.make:103: cmTC_70a5a] Error 1
gmake[1]: Leaving directory '/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-bp7mnt'
gmake: *** [Makefile:134: cmTC_70a5a/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
I can locate crtbeginS.o on my device:
root@b729f9dd73a4:~/sleef# locate crtbeginS.o
/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/build_linux/build-gcc-linux-stage1/gcc/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/build_linux/build-gcc-linux-stage1/riscv64-unknown-linux-gnu/libgcc/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/build_linux/build-gcc-linux-stage2/gcc/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/build_linux/build-gcc-linux-stage2/riscv64-unknown-linux-gnu/libgcc/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_android_tree/lib/gcc/aarch64-linux-android/4.8/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_android_tree/lib/gcc/arm-linux-androideabi/4.4.3/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_android_tree/lib/gcc/mipsel-linux-android/4.4.3/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_android_tree/lib/gcc/mipsel-linux-android/4.4.3/mips-r2/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_hurd_tree/usr/lib/gcc/i686-gnu/10/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_hurd_tree/usr/lib/gcc/x86_64-gnu/10/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/x86_64-unknown-linux/10.2.0/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/basic_netbsd_tree/usr/lib/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/crtbeginS.o
/llvm_rvv/rvv/source/riscv-gnu-toolchain/llvm/clang/test/Driver/Inputs/solaris_sparc_tree/usr/gcc/4.8/lib/gcc/sparc-sun-solaris2.11/4.8.2/sparcv9/crtbeginS.o
but I don't how to fix it.
Thanks in advance.
I think your clang installation is broken. Maybe if you set the library paths properly, it should work.
Thanks for your reply. And I modified toolchains/riscv64-llvm.cmake to set library path:
find_program(CMAKE_C_COMPILER NAMES clang clang)
set(CMAKE_C_COMPILER_TARGET riscv64-linux-gnu)
find_program(CMAKE_CXX_COMPILER NAMES clang++ clang++) ##
set(CMAKE_CXX_COMPILER_TARGET riscv64-linux-gnu) ##
set(GCC_LIB_PATH "/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0")
set(CMAKE_LIBRARY_PATH ${GCC_LIB_PATH} /usr/riscv64-linux-gnu/lib /usr/lib/riscv64-linux-gnu /lib/riscv64-linux-gnu)
set(CMAKE_EXE_LINKER_FLAGS "-L${GCC_LIB_PATH} -B${GCC_LIB_PATH}")
set(CMAKE_C_FLAGS "-v -L${GCC_LIB_PATH} -B${GCC_LIB_PATH}")
set(CMAKE_CXX_FLAGS "-L${GCC_LIB_PATH} -B${GCC_LIB_PATH}")
Then I tried:
# cmake -S . -B build-riscv64 -DCMAKE_TOOLCHAIN_FILE=$(pwd)/toolchains/riscv64-llvm.cmake -DCMAKE_SYSROOT=/llvm_rvv/rvv/riscv/sysroot -DNATIVE_BUILD_DIR="$(pwd)/build-native" -DSLEEF_SHOW_CONFIG=1 -DSLEEF
_BUILD_GNUABI_LIBS=ON -DSLEEF_BUILD_INLINE_HEADERS=ON -DSLEEF_BUILD_DFT=ON -DSLEEF_BUILD_QUAD=ON -DSLEEF_BUILD_S
CALAR_LIB=ON -DSLEEF_BUILD_STATIC_TEST_BINS=ON -DSLEEF_ENFORCE_RVVM1=ON -DSLEEF_ENFORCE_RVVM2=ON -DCMAKE_INSTALL
_PREFIX=./install-riscv
-- Configuring SLEEF 4.0.0
-- The C compiler identification is Clang 21.0.0
-- The CXX compiler identification is Clang 21.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /llvm_rvv/llvm/llvm-project/build/bin/clang - 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: /llvm_rvv/llvm/llvm-project/build/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at CMakeLists.txt:161 (message):
You enabled RVVM1 support, which is an experimental feature. Experimental
features may be removed without notice.
CMake Warning at CMakeLists.txt:169 (message):
You enabled RVVM2 support, which is an experimental feature. Experimental
features may be removed without notice.
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Checking for one of the modules 'tlfloat'
-- Found installed TLFloat 1.16.0
-- Setting build type to 'Release' (required for full support).
-- Performing Test COMPILER_SUPPORTS_FLOAT128
-- Performing Test COMPILER_SUPPORTS_FLOAT128 - Failed
-- Performing Test SLEEF_LONGDOUBLE_IS_IEEEQP
-- Performing Test SLEEF_LONGDOUBLE_IS_IEEEQP - Failed
-- Performing Test COMPILER_SUPPORTS_RVVM1
-- Performing Test COMPILER_SUPPORTS_RVVM1 - Failed
CMake Error at Configure.cmake:609 (message):
SLEEF_ENFORCE_RVVM1 is specified and that feature is disabled or not
supported by the compiler
Call Stack (most recent call first):
CMakeLists.txt:338 (include)
-- Configuring incomplete, errors occurred!
And I got error malloc(): corrupted top size shown in the following CMakeConfigureLog.yaml:
kind: "try_compile-v1"
backtrace:
- "/usr/local/lib/python3.10/dist-packages/cmake/data/share/cmake-3.31/Modules/Internal/CheckSourceCompiles.cmake:108 (try_compile)"
- "/usr/local/lib/python3.10/dist-packages/cmake/data/share/cmake-3.31/Modules/CheckCSourceCompiles.cmake:58 (cmake_check_source_compiles)"
- "Configure.cmake:587 (CHECK_C_SOURCE_COMPILES)"
- "CMakeLists.txt:338 (include)"
checks:
- "Performing Test COMPILER_SUPPORTS_RVVM1"
directories:
source: "/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH"
binary: "/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH"
cmakeVariables:
CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS: "/llvm_rvv/llvm/llvm-project/build/bin/clang-scan-deps"
CMAKE_CXX_COMPILER_TARGET: "riscv64-linux-gnu"
CMAKE_C_COMPILER_TARGET: "riscv64-linux-gnu"
CMAKE_C_FLAGS: "-v -L/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0 -B/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0"
CMAKE_C_FLAGS_DEBUG: "-g"
CMAKE_EXE_LINKER_FLAGS: "-static"
CMAKE_MODULE_PATH: "/root/sleef/cmake/Modules"
CMAKE_SYSROOT: "/llvm_rvv/rvv/riscv/sysroot"
buildResult:
variable: "COMPILER_SUPPORTS_RVVM1"
cached: true
stdout: |
Change Dir: '/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH'
Run Build Command(s): /usr/local/lib/python3.10/dist-packages/cmake/data/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_81bc8/fast
/usr/bin/gmake -f CMakeFiles/cmTC_81bc8.dir/build.make CMakeFiles/cmTC_81bc8.dir/build
gmake[1]: Entering directory '/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH'
Building C object CMakeFiles/cmTC_81bc8.dir/src.c.o
/llvm_rvv/llvm/llvm-project/build/bin/clang --target=riscv64-linux-gnu --sysroot=/llvm_rvv/rvv/riscv/sysroot -DCOMPILER_SUPPORTS_RVVM1 -v -L/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0 -B/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0 -march=rv64gcv_zba_zbb_zbs -MD -MT CMakeFiles/cmTC_81bc8.dir/src.c.o -MF CMakeFiles/cmTC_81bc8.dir/src.c.o.d -o CMakeFiles/cmTC_81bc8.dir/src.c.o -c /root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH/src.c
clang version 21.0.0git (https://github.com/llvm/llvm-project.git adba14acea99cc6a17d837763a3248c9d4a2fadf)
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /llvm_rvv/llvm/llvm-project/build/bin
Build config: +assertions
clang: warning: argument unused during compilation: '-L/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0' [-Wunused-command-line-argument]
(in-process)
"/llvm_rvv/llvm/llvm-project/build/bin/clang-20" -cc1 -triple riscv64-unknown-linux-gnu -emit-obj -disable-free -clear-ast-before-backend -main-file-name src.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic-rv64 -target-feature +m -target-feature +a -target-feature +f -target-feature +d -target-feature +c -target-feature +b -target-feature +v -target-feature +zicsr -target-feature +zifencei -target-feature +zmmul -target-feature +zaamo -target-feature +zalrsc -target-feature +zca -target-feature +zcd -target-feature +zba -target-feature +zbb -target-feature +zbs -target-feature +zve32f -target-feature +zve32x -target-feature +zve64d -target-feature +zve64f -target-feature +zve64x -target-feature +zvl128b -target-feature +zvl32b -target-feature +zvl64b -target-feature -e -target-feature -h -target-feature -sdext -target-feature -sdtrig -target-feature -sha -target-feature -shcounterenw -target-feature -shgatpa -target-feature -shtvala -target-feature -shvsatpa -target-feature -shvstvala -target-feature -shvstvecd -target-feature -smaia -target-feature -smcdeleg -target-feature -smcsrind -target-feature -smdbltrp -target-feature -smepmp -target-feature -smmpm -target-feature -smnpm -target-feature -smrnmi -target-feature -smstateen -target-feature -ssaia -target-feature -ssccfg -target-feature -ssccptr -target-feature -sscofpmf -target-feature -sscounterenw -target-feature -sscsrind -target-feature -ssdbltrp -target-feature -ssnpm -target-feature -sspm -target-feature -ssqosid -target-feature -ssstateen -target-feature -ssstrict -target-feature -sstc -target-feature -sstvala -target-feature -sstvecd -target-feature -ssu64xl -target-feature -supm -target-feature -svade -target-feature -svadu -target-feature -svbare -target-feature -svinval -target-feature -svnapot -target-feature -svpbmt -target-feature -svvptc -target-feature -xcvalu -target-feature -xcvbi -target-feature -xcvbitmanip -target-feature -xcvelw -target-feature -xcvmac -target-feature -xcvmem -target-feature -xcvsimd -target-feature -xmipscmove -target-feature -xmipslsp -target-feature -xsfcease -target-feature -xsfvcp -target-feature -xsfvfnrclipxfqf -target-feature -xsfvfwmaccqqq -target-feature -xsfvqmaccdod -target-feature -xsfvqmaccqoq -target-feature -xsifivecdiscarddlone -target-feature -xsifivecflushdlone -target-feature -xtheadba -target-feature -xtheadbb -target-feature -xtheadbs -target-feature -xtheadcmo -target-feature -xtheadcondmov -target-feature -xtheadfmemidx -target-feature -xtheadmac -target-feature -xtheadmemidx -target-feature -xtheadmempair -target-feature -xtheadsync -target-feature -xtheadvdot -target-feature -xventanacondops -target-feature -xwchc -target-feature -za128rs -target-feature -za64rs -target-feature -zabha -target-feature -zacas -target-feature -zama16b -target-feature -zawrs -target-feature -zbc -target-feature -zbkb -target-feature -zbkc -target-feature -zbkx -target-feature -zcb -target-feature -zce -target-feature -zcf -target-feature -zclsd -target-feature -zcmop -target-feature -zcmp -target-feature -zcmt -target-feature -zdinx -target-feature -zfa -target-feature -zfbfmin -target-feature -zfh -target-feature -zfhmin -target-feature -zfinx -target-feature -zhinx -target-feature -zhinxmin -target-feature -zic64b -target-feature -zicbom -target-feature -zicbop -target-feature -zicboz -target-feature -ziccamoa -target-feature -ziccif -target-feature -zicclsm -target-feature -ziccrse -target-feature -zicntr -target-feature -zicond -target-feature -zihintntl -target-feature -zihintpause -target-feature -zihpm -target-feature -zilsd -target-feature -zimop -target-feature -zk -target-feature -zkn -target-feature -zknd -target-feature -zkne -target-feature -zknh -target-feature -zkr -target-feature -zks -target-feature -zksed -target-feature -zksh -target-feature -zkt -target-feature -ztso -target-feature -zvbb -target-feature -zvbc -target-feature -zvfbfmin -target-feature -zvfbfwma -target-feature -zvfh -target-feature -zvfhmin -target-feature -zvkb -target-feature -zvkg -target-feature -zvkn -target-feature -zvknc -target-feature -zvkned -target-feature -zvkng -target-feature -zvknha -target-feature -zvknhb -target-feature -zvks -target-feature -zvksc -target-feature -zvksed -target-feature -zvksg -target-feature -zvksh -target-feature -zvkt -target-feature -zvl1024b -target-feature -zvl16384b -target-feature -zvl2048b -target-feature -zvl256b -target-feature -zvl32768b -target-feature -zvl4096b -target-feature -zvl512b -target-feature -zvl65536b -target-feature -zvl8192b -target-feature -experimental-p -target-feature -experimental-smctr -target-feature -experimental-ssctr -target-feature -experimental-svukte -target-feature -experimental-xqccmp -target-feature -experimental-xqcia -target-feature -experimental-xqciac -target-feature -experimental-xqcibi -target-feature -experimental-xqcibm -target-feature -experimental-xqcicli -target-feature -experimental-xqcicm -target-feature -experimental-xqcics -target-feature -experimental-xqcicsr -target-feature -experimental-xqciint -target-feature -experimental-xqciio -target-feature -experimental-xqcilb -target-feature -experimental-xqcili -target-feature -experimental-xqcilia -target-feature -experimental-xqcilo -target-feature -experimental-xqcilsm -target-feature -experimental-xqcisim -target-feature -experimental-xqcisls -target-feature -experimental-xqcisync -target-feature -experimental-xrivosvisni -target-feature -experimental-xrivosvizip -target-feature -experimental-zalasr -target-feature -experimental-zicfilp -target-feature -experimental-zicfiss -target-feature -experimental-zvbc32e -target-feature -experimental-zvkgs -target-feature -experimental-zvqdotq -target-feature +relax -target-abi lp64d -debugger-tuning=gdb -fdebug-compilation-dir=/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH -v -fcoverage-compilation-dir=/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH -resource-dir /llvm_rvv/llvm/llvm-project/build/lib/clang/21 -dependency-file CMakeFiles/cmTC_81bc8.dir/src.c.o.d -MT CMakeFiles/cmTC_81bc8.dir/src.c.o -sys-header-deps -D COMPILER_SUPPORTS_RVVM1 -isysroot /llvm_rvv/rvv/riscv/sysroot -internal-isystem /llvm_rvv/llvm/llvm-project/build/lib/clang/21/include -internal-isystem /llvm_rvv/rvv/riscv/sysroot/usr/local/include -internal-externc-isystem /llvm_rvv/rvv/riscv/sysroot/include -internal-externc-isystem /llvm_rvv/rvv/riscv/sysroot/usr/include -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o CMakeFiles/cmTC_81bc8.dir/src.c.o -x c /root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH/src.c
clang -cc1 version 21.0.0git based upon LLVM 21.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/llvm_rvv/rvv/riscv/sysroot/usr/local/include"
ignoring nonexistent directory "/llvm_rvv/rvv/riscv/sysroot/include"
#include "..." search starts here:
#include <...> search starts here:
/llvm_rvv/llvm/llvm-project/build/lib/clang/21/include
/llvm_rvv/rvv/riscv/sysroot/usr/include
End of search list.
Linking C executable cmTC_81bc8
/usr/local/lib/python3.10/dist-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/cmTC_81bc8.dir/link.txt --verbose=1
clang version 21.0.0git (https://github.com/llvm/llvm-project.git adba14acea99cc6a17d837763a3248c9d4a2fadf)
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /llvm_rvv/llvm/llvm-project/build/bin
Build config: +assertions
"/usr/bin/riscv64-linux-gnu-ld" --sysroot=/llvm_rvv/rvv/riscv/sysroot -z relro --hash-style=gnu --eh-frame-hdr -m elf64lriscv -X -static -o cmTC_81bc8 /llvm_rvv/rvv/riscv/sysroot/usr/lib/crt1.o /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/crti.o /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/crtbeginT.o -L/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0 -L/llvm_rvv/rvv/riscv/sysroot/lib -L/llvm_rvv/rvv/riscv/sysroot/usr/lib CMakeFiles/cmTC_81bc8.dir/src.c.o --start-group -lgcc -lgcc_eh -lc --end-group /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/crtend.o /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/crtn.o
malloc(): corrupted top size
clang: error: unable to execute command: Aborted (core dumped)
clang: error: linker command failed due to signal (use -v to see invocation)
/llvm_rvv/llvm/llvm-project/build/bin/clang --target=riscv64-linux-gnu --sysroot=/llvm_rvv/rvv/riscv/sysroot -v -L/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0 -B/llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0 -march=rv64gcv_zba_zbb_zbs -static CMakeFiles/cmTC_81bc8.dir/src.c.o -o cmTC_81bc8
gmake[1]: *** [CMakeFiles/cmTC_81bc8.dir/build.make:103: cmTC_81bc8] Error 1
gmake[1]: Leaving directory '/root/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-uKdCYH'
gmake: *** [Makefile:134: cmTC_81bc8/fast] Error 2
exitCode: 2
What's the possible reason?
Did you build clang yourself? If so, try using lld instead of gnu-ld. Also, build a release version of clang.
Did you build clang yourself? If so, try using lld instead of gnu-ld. Also, build a release version of clang.
Thank you for your prompt response, and I would try that.
Can I ask a silly question? If I get the sleef library which is built with clang-17, would there be some problems or potential issues if I use it with clang-21? I guess I have to use clang-21 to compile other applications.
There should not be any problem unless you use LTO.
Truly grateful!
Well, I have built a release version clang and the only modification is to add SET(CMAKE_C_FLAGS "-fuse-ld=lld") in riscv64-llvm.cmake, and build it:
$ cmake -S . -B build-riscv64 \
-DCMAKE_TOOLCHAIN_FILE=$(pwd)/toolchains/riscv64-llvm.cmake \
-DCMAKE_SYSROOT="/llvm_rvv/rvv/riscv/sysroot" \
-DNATIVE_BUILD_DIR="$(pwd)/build-native" \
-DCMAKE_INSTALL_PREFIX=./install-cross \
-DSLEEF_SHOW_CONFIG=1 \
-DSLEEF_BUILD_GNUABI_LIBS=ON \
-DSLEEF_BUILD_INLINE_HEADERS=ON \
-DSLEEF_BUILD_DFT=ON \
-DSLEEF_BUILD_QUAD=ON \
-DSLEEF_BUILD_SCALAR_LIB=ON \
-DSLEEF_BUILD_STATIC_TEST_BINS=ON \
-DSLEEF_ENFORCE_RVVM1=ON \
-DSLEEF_ENFORCE_RVVM2=ON
-- Configuring SLEEF 3.9.0
-- The C compiler identification is Clang 17.0.6
-- The CXX compiler identification is Clang 17.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /llvm_rvv/rvv/riscv/bin/clang-17 - 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: /llvm_rvv/rvv/riscv/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Checking for one of the modules 'tlfloat'
-- Found installed TLFloat 1.16.0
-- Setting build type to 'Release' (required for full support).
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of long double
-- Check size of long double - done
-- Performing Test COMPILER_SUPPORTS_LONG_DOUBLE
-- Performing Test COMPILER_SUPPORTS_LONG_DOUBLE - Success
-- Performing Test COMPILER_SUPPORTS_FLOAT128
-- Performing Test COMPILER_SUPPORTS_FLOAT128 - Failed
-- Performing Test SLEEF_LONGDOUBLE_IS_IEEEQP
-- Performing Test SLEEF_LONGDOUBLE_IS_IEEEQP - Success
-- Performing Test COMPILER_SUPPORTS_RVVM1
-- Performing Test COMPILER_SUPPORTS_RVVM1 - Success
-- Performing Test COMPILER_SUPPORTS_RVVM2
-- Performing Test COMPILER_SUPPORTS_RVVM2 - Success
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
-- Performing Test COMPILER_SUPPORTS_WEAK_ALIASES
-- Performing Test COMPILER_SUPPORTS_WEAK_ALIASES - Success
-- Performing Test COMPILER_SUPPORTS_BUILTIN_MATH
-- Performing Test COMPILER_SUPPORTS_BUILTIN_MATH - Failed
-- Performing Test COMPILER_SUPPORTS_SYS_GETRANDOM
-- Performing Test COMPILER_SUPPORTS_SYS_GETRANDOM - Success
CMake Warning (dev) at src/libm/CMakeLists.txt:1001 (install):
Target sleefscalar has PUBLIC_HEADER files but no PUBLIC_HEADER
DESTINATION.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring build for SLEEF-v3.9.0
Target system: Linux
Target processor: riscv64
Host system: Linux-6.11.0-26-generic
Host processor: x86_64
Detected C compiler: Clang @ /llvm_rvv/rvv/riscv/bin/clang-17
CMake: 3.31.4
Make program: /usr/bin/gmakex
CMake build type: Release
Crosscompiling SLEEF.
Native build dir: /home/yuhao/sleef/build-native
-- Using option `-Wall -Wno-unused-function -Wno-attributes -Wno-unused-result -ffp-contract=off -fno-math-errno -fno-trapping-math` to compile libsleef
-- Building shared libs : OFF
-- Building static test bins: ON
-- MPFR : LIB_MPFR-NOTFOUND
-- GMP : LIBGMP-NOTFOUND
-- RT : /usr/riscv64-linux-gnu/lib/librt.a
-- FFTW3 : LIBFFTW3-NOTFOUND
-- FFTW3F : LIBFFTW3F-NOTFOUND
-- OPENSSL :
-- SDE : SDE_COMMAND-NOTFOUND
-- SED : /usr/bin/sed
-- COMPILER_SUPPORTS_OPENMP :
-- A version of SLEEF compatible with libm and libmvec in GNU libc will be produced (sleefgnuabi.so)
-- Configuring done (10.3s)
-- Generating done (0.8s)
-- Build files have been written to: /home/yuhao/sleef/build-riscv64
Although it looks alright, I find the errors about missing omp.h and undefined sqrt symbol in the log:
kind: "try_compile-v1"
backtrace:
- "/usr/local/lib/python3.10/dist-packages/cmake/data/share/cmake-3.31/Modules/FindOpenMP.cmake:252 (try_compile)"
- "/usr/local/lib/python3.10/dist-packages/cmake/data/share/cmake-3.31/Modules/FindOpenMP.cmake:522 (_OPENMP_GET_FLAGS)"
- "Configure.cmake:811 (find_package)"
- "CMakeLists.txt:268 (include)"
description: "Detecting CXX OpenMP compiler info"
directories:
source: "/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-lV752S"
binary: "/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-lV752S"
cmakeVariables:
CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS: "/llvm_rvv/rvv/riscv/bin/clang-scan-deps"
CMAKE_CXX_FLAGS: ""
CMAKE_CXX_FLAGS_DEBUG: "-g"
CMAKE_C_COMPILER_TARGET: "riscv64-linux-gnu"
CMAKE_EXE_LINKER_FLAGS: "-static"
CMAKE_MODULE_PATH: "/home/yuhao/sleef/cmake/Modules"
CMAKE_SYSROOT: "/llvm_rvv/rvv/riscv/sysroot"
buildResult:
variable: "OpenMP_COMPILE_RESULT_CXX_Xclang fopenmp"
cached: true
stdout: |
Change Dir: '/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-lV752S'
Run Build Command(s): /usr/local/lib/python3.10/dist-packages/cmake/data/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_ba2d0/fast
/usr/bin/gmake -f CMakeFiles/cmTC_ba2d0.dir/build.make CMakeFiles/cmTC_ba2d0.dir/build
gmake[1]: Entering directory '/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-lV752S'
Building CXX object CMakeFiles/cmTC_ba2d0.dir/OpenMPTryFlag.cpp.o
/llvm_rvv/rvv/riscv/bin/clang++ --sysroot=/llvm_rvv/rvv/riscv/sysroot -Xclang -fopenmp -std=gnu++20 -MD -MT CMakeFiles/cmTC_ba2d0.dir/OpenMPTryFlag.cpp.o -MF CMakeFiles/cmTC_ba2d0.dir/OpenMPTryFlag.cpp.o.d -o CMakeFiles/cmTC_ba2d0.dir/OpenMPTryFlag.cpp.o -c /home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-lV752S/OpenMPTryFlag.cpp
/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-lV752S/OpenMPTryFlag.cpp:2:10: fatal error: 'omp.h' file not found
2 | #include <omp.h>
| ^~~~~~~
1 error generated.
gmake[1]: *** [CMakeFiles/cmTC_ba2d0.dir/build.make:82: CMakeFiles/cmTC_ba2d0.dir/OpenMPTryFlag.cpp.o] Error 1
gmake[1]: Leaving directory '/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-lV752S'
gmake: *** [Makefile:134: cmTC_ba2d0/fast] Error 2
exitCode: 2
kind: "try_compile-v1"
backtrace:
- "/usr/local/lib/python3.10/dist-packages/cmake/data/share/cmake-3.31/Modules/Internal/CheckSourceCompiles.cmake:108 (try_compile)"
- "/usr/local/lib/python3.10/dist-packages/cmake/data/share/cmake-3.31/Modules/CheckCSourceCompiles.cmake:58 (cmake_check_source_compiles)"
- "Configure.cmake:870 (CHECK_C_SOURCE_COMPILES)"
- "CMakeLists.txt:268 (include)"
checks:
- "Performing Test COMPILER_SUPPORTS_BUILTIN_MATH"
directories:
source: "/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-ZK3wwO"
binary: "/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-ZK3wwO"
cmakeVariables:
CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS: "/llvm_rvv/rvv/riscv/bin/clang-scan-deps"
CMAKE_C_COMPILER_TARGET: "riscv64-linux-gnu"
CMAKE_C_FLAGS: "-fuse-ld=lld"
CMAKE_C_FLAGS_DEBUG: "-g"
CMAKE_EXE_LINKER_FLAGS: "-static"
CMAKE_MODULE_PATH: "/home/yuhao/sleef/cmake/Modules"
CMAKE_SYSROOT: "/llvm_rvv/rvv/riscv/sysroot"
buildResult:
variable: "COMPILER_SUPPORTS_BUILTIN_MATH"
cached: true
stdout: |
Change Dir: '/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-ZK3wwO'
Run Build Command(s): /usr/local/lib/python3.10/dist-packages/cmake/data/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_e57b6/fast
/usr/bin/gmake -f CMakeFiles/cmTC_e57b6.dir/build.make CMakeFiles/cmTC_e57b6.dir/build
gmake[1]: Entering directory '/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-ZK3wwO'
Building C object CMakeFiles/cmTC_e57b6.dir/src.c.o
/llvm_rvv/rvv/riscv/bin/clang-17 --target=riscv64-linux-gnu --sysroot=/llvm_rvv/rvv/riscv/sysroot -DCOMPILER_SUPPORTS_BUILTIN_MATH -fuse-ld=lld -MD -MT CMakeFiles/cmTC_e57b6.dir/src.c.o -MF CMakeFiles/cmTC_e57b6.dir/src.c.o.d -o CMakeFiles/cmTC_e57b6.dir/src.c.o -c /home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-ZK3wwO/src.c
clang-17: warning: argument unused during compilation: '-fuse-ld=lld' [-Wunused-command-line-argument]
Linking C executable cmTC_e57b6
/usr/local/lib/python3.10/dist-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e57b6.dir/link.txt --verbose=1
ld.lld: error: undefined symbol: sqrt
>>> referenced by src.c
>>> CMakeFiles/cmTC_e57b6.dir/src.c.o:(main)
ld.lld: error: undefined symbol: sqrtf
>>> referenced by src.c
>>> CMakeFiles/cmTC_e57b6.dir/src.c.o:(main)
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)
/llvm_rvv/rvv/riscv/bin/clang-17 --target=riscv64-linux-gnu --sysroot=/llvm_rvv/rvv/riscv/sysroot -fuse-ld=lld -static CMakeFiles/cmTC_e57b6.dir/src.c.o -o cmTC_e57b6
gmake[1]: *** [CMakeFiles/cmTC_e57b6.dir/build.make:103: cmTC_e57b6] Error 1
gmake[1]: Leaving directory '/home/yuhao/sleef/build-riscv64/CMakeFiles/CMakeScratch/TryCompile-ZK3wwO'
gmake: *** [Makefile:134: cmTC_e57b6/fast] Error 2
exitCode: 2
I don't know whether I should build it with omp path.
In addition, according to the output I can find Failed COMPILER_SUPPORTS_FLOAT128 and COMPILER_SUPPORTS_BUILTIN_MATH, and under my build directory, build-riscv64/bin/ and build-riscv64/lib are empty. I guess it hasn't succeeded. Is it because Failed COMPILER_SUPPORTS_FLOAT128 and COMPILER_SUPPORTS_BUILTIN_MATH ?
Generally speaking, it is not so easy to build the entire toolchain yourself. I guess you built the entire toolchain from the ground up, and you seem to be having a problem with your libc and openmp. It is difficult for me to assess exactly what problem you are having.
Thanks for your patient response.
Yes, I built riscv-toochain from scratch again. Could you please tell me what the reasonable outcomes(e.g. COMPILER_SUPPORTS_FLOAT128 - Failed or success) would be if I can build it successfully? Any word would be appreciated.
Rather, what do you want to use SLEEF for? If you're not interested in Quad and DFT, then FLOAT128 and OpenMP are not really relevant.
Currently I want to use some basic mathematical operations(like exp, sin, log) for float32.