Linking errors when using Sleef_expfx_u10rvvm2 (original) (raw)

Hi all,

I want to use SLEEF to support some math operations(e.g. expf) for RVV, and I tried the following code:

#include <stdio.h>
#include <math.h>

#define ARRAY_SIZE 256

float input_data[ARRAY_SIZE];
float output_data[ARRAY_SIZE];

void initialize_data() {
    for (int i = 0; i < ARRAY_SIZE; ++i) {
        input_data[i] = (float)i / 10.0f;
    }
}

int main() {
    initialize_data();

    for (int i = 0; i < ARRAY_SIZE; ++i) {
        output_data[i] = expf(input_data[i]);
    }
    float sum = 0.0f;
    for (int i = 0; i < ARRAY_SIZE; ++i) {
        sum += output_data[i];
    }

    printf("Calculation complete. Sum of results: %f\n", sum);

    return 0;
}

To enable auto-vectorization, I used:

$ clang++ test/exp.cpp \
         --target=riscv64-unknown-linux-gnu 
         --sysroot=/llvm_rvv/rvv/riscv/sysroot \
         --gcc-toolchain=/llvm_rvv/rvv/riscv \
         -march=rv64gcv_zvl256b -mabi=lp64d \
         -O2 -g -static -v -fveclib=SLEEF \
         -o exp.elf

But I got the linking error:

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
Found candidate GCC installation: /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0
Selected GCC installation: /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0
 "/llvm_rvv/llvm/llvm-project/build/bin/clang-20" -cc1 -triple riscv64-unknown-linux-gnu -emit-obj -dumpdir exp.elf- -disable-free -clear-ast-before-backend -main-file-name exp.cpp -static-define -mrelocation-model pic -pic-level 2 -pic-is-pie -fveclib=SLEEF -mframe-pointer=none -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 +v -target-feature +zicsr -target-feature +zifencei -target-feature +zmmul -target-feature +zaamo -target-feature +zalrsc -target-feature +zca -target-feature +zcd -target-feature +zve32f -target-feature +zve32x -target-feature +zve64d -target-feature +zve64f -target-feature +zve64x -target-feature +zvl128b -target-feature +zvl256b -target-feature +zvl32b -target-feature +zvl64b -target-feature -b -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 -zba -target-feature -zbb -target-feature -zbc -target-feature -zbkb -target-feature -zbkc -target-feature -zbkx -target-feature -zbs -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 -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 -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/home/yuhao/T_RVV -v -fcoverage-compilation-dir=/home/yuhao/T_RVV -resource-dir /llvm_rvv/llvm/llvm-project/build/lib/clang/21 -isysroot /llvm_rvv/rvv/riscv/sysroot -internal-isystem /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/include/c++/14.2.0 -internal-isystem /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/include/c++/14.2.0/riscv64-unknown-linux-gnu -internal-isystem /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/include/c++/14.2.0/backward -internal-isystem /llvm_rvv/llvm/llvm-project/build/lib/clang/21/include -internal-isystem /llvm_rvv/rvv/riscv/sysroot/usr/local/include -internal-isystem /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/include -internal-externc-isystem /llvm_rvv/rvv/riscv/sysroot/include -internal-externc-isystem /llvm_rvv/rvv/riscv/sysroot/usr/include -O2 -fdeprecated-macro -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/exp-3da438.o -x c++ test/exp.cpp
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/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/include/c++/14.2.0
 /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/include/c++/14.2.0/riscv64-unknown-linux-gnu
 /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/include/c++/14.2.0/backward
 /llvm_rvv/llvm/llvm-project/build/lib/clang/21/include
 /llvm_rvv/rvv/riscv/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/include
 /llvm_rvv/rvv/riscv/sysroot/usr/include
End of search list.
 "/llvm_rvv/rvv/riscv/bin/riscv64-unknown-linux-gnu-ld" --sysroot=/llvm_rvv/rvv/riscv/sysroot -z relro --hash-style=gnu --eh-frame-hdr -m elf64lriscv -X -static -o exp.elf /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/lib/gcc/riscv64-unknown-linux-gnu/14.2.0/../../../../riscv64-unknown-linux-gnu/lib -L/llvm_rvv/rvv/riscv/sysroot/lib -L/llvm_rvv/rvv/riscv/sysroot/usr/lib /tmp/exp-3da438.o -lstdc++ -lm --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
/llvm_rvv/rvv/riscv/bin/riscv64-unknown-linux-gnu-ld: /tmp/exp-3da438.o: in function `main':
/home/yuhao/T_RVV/test/exp.cpp:21:(.text+0x184): undefined reference to `Sleef_expfx_u10rvvm2'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

I know there is SLEEF support in LLVM, but I don’t know how to use it correctly.

Thank you in advance.

topperc June 9, 2025, 3:13pm 2

I think you need to tell the linker where to find the SLEEF library and that wish to link with it. -fveclib only tells the compiler to generate the calls.

Thanks for your reply.

So should I cross-compile SLEEF for RISC-V? I haven’t tried that because I assumed it is done during building LLVM/Clang.

topperc June 9, 2025, 4:01pm 4

The SLEEF source code is not part of the LLVM/clang repository. It is a separate project. I’ve never built it myself.