1 (edited by tuankiet 2023-10-17 01:54:45)

Topic: Cross compile for bare-metal RISC-V [Undefined reference problem]

Hello everyone,

My objective is to use the feature "openssl compatibility" of woflssl on rv32-imac. I built a static library and linked it to some test programs.

Here is my configuration options used to create the static library:

./configure --host=riscv32 \
--prefix=/home/tuankiet/Documents/tools/wolfssl-build-riscv32/ \
CC=riscv32-unknown-elf-gcc \
AR=riscv32-unknown-elf-ar RANLIB=riscv32-unknown-elf-ranlib \
CPPFLAGS="-I./" \
CFLAGS="-DHAVE_ECC_KOBLITZ -DNO_WOLFSSL_DIR -mabi=ilp32 -march=rv32imac -I$RISCV/sysroot/usr/include -I$RISCV/riscv32-unknown-elf/include" \
LDFLAGS="-L$RISCV/riscv32-unknown-elf/lib" \
--with-sysroot="$RISCV/sysroot/" \
--disable-filesystem --enable-singlethreaded \
--enable-static --disable-shared --disable-examples --disable-crypttests --disable-asm --disable-rsa \
--disable-dh --disable-oldtls --disable-tlsv12 \
--enable-opensslextra --enable-opensslall \
--enable-ecc --enable-ecccustcurves

The static library was built successfully, and I was able to run a test program with SHA256 on the platform.
However, when I tried to run a program with ECC using openssl compatible function (I have coded a more complicated program on linux before migrating everything to RISCV platform):

#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
#include <wolfssl/openssl/ssl.h>
#include <wolfssl/openssl/ec.h>

int main(){
   WOLFSSL_EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
   return 0;
}

After this, I think I have a linker problem, I tried to rebuild the library several times (with different configuration) but have not yet solved the problem. I am not sure the reason why.

Here is the "make":

tuankiet@ubuntu:wolfssl-riscv$ make demo
riscv32-unknown-elf-gcc -Wall -static -std=c11 -g -march=rv32imac -mabi=ilp32 -I/home/tuankiet/Documents/tools/wolfssl-build-riscv32/include -I/home/tuankiet/Documents/tools/riscv-32imac/sysroot/usr/include -I/home/tuankiet/Documents/tools/riscv-32imac/riscv32-unknown-elf/include -c demo.c -o demo.o
demo.c: In function 'main':
demo.c:28:23: warning: unused variable 'group' [-Wunused-variable]
28 | WOLFSSL_EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
| ^~~~~
riscv32-unknown-elf-gcc -Wall -static -std=c11 -g -march=rv32imac -mabi=ilp32 -I/home/tuankiet/Documents/tools/wolfssl-build-riscv32/include -I/home/tuankiet/Documents/tools/riscv-32imac/sysroot/usr/include -I/home/tuankiet/Documents/tools/riscv-32imac/riscv32-unknown-elf/include -o demo demo.o -L/home/tuankiet/Documents/tools/riscv-32imac/lib -L/home/tuankiet/Documents/tools/riscv-32imac/riscv32-unknown-elf/lib -L/home/tuankiet/Documents/tools/riscv-32imac/sysroot/lib -L/home/tuankiet/Documents/tools/riscv-32imac/sysroot/usr/lib /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a -lm
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L199':
ssl.c:(.text+0x870): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L1247':
ssl.c:(.text+0x2a72): undefined reference to `__ctype_toupper_loc'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L1872':
ssl.c:(.text+0x3ebe): undefined reference to `__ctype_toupper_loc'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `wolfSSL_ASN1_OBJECT_dup':
ssl.c:(.text+0x5ef4): undefined reference to `__ctype_b_loc'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: ssl.c:(.text+0x5f80): undefined reference to `__ctype_tolower_loc'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L4938':
ssl.c:(.text+0x9690): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L4942':
ssl.c:(.text+0x9724): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L6047':
ssl.c:(.text+0xb6ca): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L8195':
ssl.c:(.text+0x102f0): undefined reference to `inet_pton'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L14187':
ssl.c:(.text+0x1c516): undefined reference to `socket'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L14011':
ssl.c:(.text+0x1c544): undefined reference to `connect'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L14026':
ssl.c:(.text+0x1c592): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-ssl.o): in function `.L14077':
ssl.c:(.text+0x1c664): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-tls13.o): in function `.L1026':
tls13.c:(.text+0x420c): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-tls13.o): in function `.L1274':
tls13.c:(.text+0x49fe): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(src_libwolfssl_la-asn.o): in function `.L26':
asn.c:(.text+0x10e): undefined reference to `__ctype_tolower_loc'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-internal.o): in function `GetSesionFromCacheOrExt':
internal.c:(.text+0x2fa): undefined reference to `TlsSessionCacheGetAndRdLock'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-internal.o): in function `.L68':
internal.c:(.text+0x3ae): undefined reference to `__ctype_tolower_loc'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-internal.o): in function `.L146':
internal.c:(.text+0x8e2): undefined reference to `TlsSessionCacheUnlockRow'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-internal.o): in function `.L3090':
internal.c:(.text+0x7a1c): undefined reference to `TlsSessionCacheUnlockRow'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-internal.o): in function `.L3125':
internal.c:(.text+0x7b00): undefined reference to `TlsSessionCacheUnlockRow'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L106':
wolfio.c:(.text+0x25e): undefined reference to `recv'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L115':
wolfio.c:(.text+0x31a): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L154':
wolfio.c:(.text+0x3d2): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L155':
wolfio.c:(.text+0x41e): undefined reference to `recv'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0x432): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L167':
wolfio.c:(.text+0x486): undefined reference to `send'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0x498): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L176':
wolfio.c:(.text+0x4e0): undefined reference to `recv'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0x4e8): undefined reference to `send'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `wolfIO_Recv':
wolfio.c:(.text+0x512): undefined reference to `gethostbyname'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `wolfIO_TcpConnect':
wolfio.c:(.text+0x540): undefined reference to `socket'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0x552): undefined reference to `connect'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0x5b8): undefined reference to `socket'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `wolfIO_TcpBind':
wolfio.c:(.text+0x5d2): undefined reference to `setsockopt'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0x5f8): undefined reference to `bind'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0x606): undefined reference to `listen'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0x622): undefined reference to `accept'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L239':
wolfio.c:(.text+0x78a): undefined reference to `recv'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L251':
wolfio.c:(.text+0x848): undefined reference to `recv'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `.L274':
wolfio.c:(.text+0x854): undefined reference to `__errno_location'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a(libwolfssl_la-wolfio.o): in function `wolfIO_HttpBuildRequestOcsp':
wolfio.c:(.text+0xe2e): undefined reference to `send'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: wolfio.c:(.text+0xe42): undefined reference to `send'
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: demo: hidden symbol `TlsSessionCacheGetAndRdLock' isn't defined
/home/tuankiet/Documents/tools/riscv-32imac/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:34: demo] Error 1

Share

Re: Cross compile for bare-metal RISC-V [Undefined reference problem]

Hello tuankiet,

Welcome to the wolfSSL Forums. The linker is complaining about system calls ("inet_pton", "__errno_location", etc)

Could this be related to order the libraries are included?

-L/home/tuankiet/Documents/tools/riscv-32imac/lib -L/home/tuankiet/Documents/tools/riscv-32imac/riscv32-unknown-elf/lib -L/home/tuankiet/Documents/tools/riscv-32imac/sysroot/lib -L/home/tuankiet/Documents/tools/riscv-32imac/sysroot/usr/lib /home/tuankiet/Documents/tools/wolfssl-build-riscv32/lib/libwolfssl.a -lm

Kind regards,
Eric - wolfSSL Support