Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtool cannot cross compile for Android #4519

Closed
Bjoe opened this issue Oct 29, 2021 · 6 comments
Closed

libtool cannot cross compile for Android #4519

Bjoe opened this issue Oct 29, 2021 · 6 comments
Assignees

Comments

@Bjoe
Copy link

Bjoe commented Oct 29, 2021

Hi

In short:

I try to compile WolfSSL 4.8.1 for android and use the android-ndk r19c toolchain.
I read the documentation https://www.wolfssl.com/docs/wolfssl-manual/ch2/ how to cross compile wolfssl.
I got a problem when they try to link, it uses the wrong linker. I figured out that libtool somehow striped out one required parameter.

In details:

If I execute libtool with following parameters from the command line:

/bin/sh ./libtool  --tag=CC   --mode=link /home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -DBUILDING_WOLFSSL -DWOLFSSL_TLS13 -DHAVE_TLS_EXTENSIONS -DHAVE_SUPPORTED_CURVES -DHAVE_FFDHE_2048 -DHAVE_EXT_CACHE -DWOLFSSL_VERIFY_CB_ALL_CERTS -DWOLFSSL_EXTRA_ALERTS -DOPENSSL_EXTRA -DWOLFSSL_ALWAYS_VERIFY_CB -D_POSIX_THREADS  -fvisibility=hidden -DHAVE_THREAD_LS -DNDEBUG -Xcompiler -Qunused-arguments -pthread -DTFM_TIMING_RESISTANT -DECC_TIMING_RESISTANT -DWC_RSA_BLINDING -DHAVE_PK_CALLBACKS -DHAVE_AESCCM -DHAVE_NULL_CIPHER -DWOLFSSL_SHA512 -DWOLFSSL_SHA384 -DWOLFSSL_KEY_GEN -DWOLFSSL_CERT_GEN -DWOLFSSL_CERT_REQ -DHAVE_HKDF -DNO_DSA -DHAVE_ECC -DTFM_ECC256 -DECC_SHAMIR -DNO_OLD_TLS -DWC_RSA_PSS -DNO_RC4 -DWOLFSSL_CMAC -DWOLFSSL_AES_DIRECT -DNO_HC128 -DNO_RABBIT -DWOLFSSL_SHA3 -DWOLFSSL_SHAKE256 -DHAVE_POLY1305 -DHAVE_ONE_TIME_AUTH -DHAVE_CHACHA -DHAVE_HASHDRBG -DHAVE_OCSP -DHAVE_OPENSSL_CMD -DHAVE_TLS_EXTENSIONS -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_TLS_EXTENSIONS -DHAVE_SNI -DHAVE_TLS_EXTENSIONS -DHAVE_ALPN -DHAVE_TLS_EXTENSIONS -DHAVE_SUPPORTED_CURVES -DHAVE_EXTENDED_MASTER -DHAVE_TLS_EXTENSIONS -DHAVE_SNI -DHAVE_MAX_FRAGMENT -DHAVE_TRUNCATED_HMAC -DHAVE_ALPN -DHAVE_TRUSTED_CA -DHAVE_SUPPORTED_CURVES -DNO_RC4 -DHAVE_ENCRYPT_THEN_MAC -DNO_MD4 -DWOLFSSL_ENCRYPTED_KEYS -DWC_NO_ASYNC_THREADING -DHAVE_DH_DEFAULT_PARAMS -DHAVE_PKCS7 -DHAVE_AES_KEYWRAP -DWOLFSSL_AES_DIRECT -DHAVE_X963_KDF -DGCM_TABLE_4BIT -DHAVE_AESGCM -Wall -Wno-unused -Os -DHAVE___UINT128_T=1 -DHAVE_WC_INTROSPECTION -fPIC --target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security  -DHAVE_SNI -DWOLFSSL_SHA3 -DHAVE_FFDHE -DHAVE_ONE_TIME_AUTH -DHAVE_POLY1305 -DHAVE_ALPN -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_ECC -DHAVE_PK_CALLBACKS -DOPENSSL_EXTRA -DWOLFSSL_STATIC_PSK -DHAVE_EX_DATA -DKEEP_PEER_CERT -DSESSION_CERTS -DSESSION_INDEX -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_SUPPORTED_CURVES -DHAVE_TLS_EXTENSIONS -DHAVE_OCSP -DOPENSSL_ALL -DHAVE_AESGCM -DWOLFSSL_AES_DIRECT -DHAVE_AES_ECB   -Wno-pragmas -Wall -Wno-strict-aliasing -Wextra -Wunknown-pragmas -Wthis-test-should-fail --param=ssp-buffer-size=1 -Waddress -Warray-bounds -Wbad-function-cast -Wchar-subscripts -Wcomment -Wfloat-equal -Wformat-security -Wformat=2 -Wmaybe-uninitialized -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wnormalized=id -Woverride-init -Wpointer-arith -Wpointer-sign -Wredundant-decls -Wshadow -Wshorten-64-to-32 -Wsign-compare -Wstrict-overflow=1 -Wstrict-prototypes -Wswitch-enum -Wundef -Wunused -Wunused-result -Wunused-variable -Wwrite-strings -fwrapv  -no-undefined -version-info 28:0:4 --target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now   -Wl,-lm -o src/libwolfssl.la -rpath /home/myuser/Development/wolfssl/vendor/lib                           wolfcrypt/src/src_libwolfssl_la-hmac.lo  wolfcrypt/src/src_libwolfssl_la-hash.lo wolfcrypt/src/src_libwolfssl_la-cpuid.lo wolfcrypt/src/src_libwolfssl_la-random.lo  wolfcrypt/src/src_libwolfssl_la-sha256.lo      wolfcrypt/src/src_libwolfssl_la-rsa.lo         wolfcrypt/src/src_libwolfssl_la-aes.lo   wolfcrypt/src/src_libwolfssl_la-cmac.lo wolfcrypt/src/src_libwolfssl_la-des3.lo wolfcrypt/src/src_libwolfssl_la-sha.lo  wolfcrypt/src/src_libwolfssl_la-sha512.lo  wolfcrypt/src/src_libwolfssl_la-sha3.lo wolfcrypt/src/src_libwolfssl_la-logging.lo wolfcrypt/src/src_libwolfssl_la-wc_port.lo wolfcrypt/src/src_libwolfssl_la-error.lo wolfcrypt/src/src_libwolfssl_la-wc_encrypt.lo wolfcrypt/src/src_libwolfssl_la-signature.lo wolfcrypt/src/src_libwolfssl_la-wolfmath.lo wolfcrypt/src/src_libwolfssl_la-memory.lo wolfcrypt/src/src_libwolfssl_la-dh.lo wolfcrypt/src/src_libwolfssl_la-asn.lo wolfcrypt/src/src_libwolfssl_la-coding.lo  wolfcrypt/src/src_libwolfssl_la-poly1305.lo    wolfcrypt/src/src_libwolfssl_la-md5.lo wolfcrypt/src/src_libwolfssl_la-pwdbased.lo wolfcrypt/src/src_libwolfssl_la-pkcs12.lo           wolfcrypt/src/src_libwolfssl_la-chacha.lo  wolfcrypt/src/src_libwolfssl_la-chacha20_poly1305.lo   wolfcrypt/src/src_libwolfssl_la-integer.lo wolfcrypt/src/src_libwolfssl_la-ecc.lo                  wolfcrypt/src/src_libwolfssl_la-pkcs7.lo    src/src_libwolfssl_la-internal.lo src/src_libwolfssl_la-wolfio.lo src/src_libwolfssl_la-keys.lo src/src_libwolfssl_la-ssl.lo src/src_libwolfssl_la-tls.lo src/src_libwolfssl_la-tls13.lo src/src_libwolfssl_la-ocsp.lo           -lm   

Libtool will execute the "linking" with:

libtool: link: /home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -shared  -fPIC -DPIC  wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o wolfcrypt/src/.libs/src_libwolfssl_la-hash.o wolfcrypt/src/.libs/src_libwolfssl_la-cpuid.o wolfcrypt/src/.libs/src_libwolfssl_la-random.o wolfcrypt/src/.libs/src_libwolfssl_la-sha256.o wolfcrypt/src/.libs/src_libwolfssl_la-rsa.o wolfcrypt/src/.libs/src_libwolfssl_la-aes.o wolfcrypt/src/.libs/src_libwolfssl_la-cmac.o wolfcrypt/src/.libs/src_libwolfssl_la-des3.o wolfcrypt/src/.libs/src_libwolfssl_la-sha.o wolfcrypt/src/.libs/src_libwolfssl_la-sha512.o wolfcrypt/src/.libs/src_libwolfssl_la-sha3.o wolfcrypt/src/.libs/src_libwolfssl_la-logging.o wolfcrypt/src/.libs/src_libwolfssl_la-wc_port.o wolfcrypt/src/.libs/src_libwolfssl_la-error.o wolfcrypt/src/.libs/src_libwolfssl_la-wc_encrypt.o wolfcrypt/src/.libs/src_libwolfssl_la-signature.o wolfcrypt/src/.libs/src_libwolfssl_la-wolfmath.o wolfcrypt/src/.libs/src_libwolfssl_la-memory.o wolfcrypt/src/.libs/src_libwolfssl_la-dh.o wolfcrypt/src/.libs/src_libwolfssl_la-asn.o wolfcrypt/src/.libs/src_libwolfssl_la-coding.o wolfcrypt/src/.libs/src_libwolfssl_la-poly1305.o wolfcrypt/src/.libs/src_libwolfssl_la-md5.o wolfcrypt/src/.libs/src_libwolfssl_la-pwdbased.o wolfcrypt/src/.libs/src_libwolfssl_la-pkcs12.o wolfcrypt/src/.libs/src_libwolfssl_la-chacha.o wolfcrypt/src/.libs/src_libwolfssl_la-chacha20_poly1305.o wolfcrypt/src/.libs/src_libwolfssl_la-integer.o wolfcrypt/src/.libs/src_libwolfssl_la-ecc.o wolfcrypt/src/.libs/src_libwolfssl_la-pkcs7.o src/.libs/src_libwolfssl_la-internal.o src/.libs/src_libwolfssl_la-wolfio.o src/.libs/src_libwolfssl_la-keys.o src/.libs/src_libwolfssl_la-ssl.o src/.libs/src_libwolfssl_la-tls.o src/.libs/src_libwolfssl_la-tls13.o src/.libs/src_libwolfssl_la-ocsp.o   -lm  -Qunused-arguments -pthread -Os --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -fstack-protector-strong --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot -Wl,--exclude-libs -Wl,libgcc.a -Wl,--exclude-libs -Wl,libatomic.a -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z -Wl,noexecstack -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,-lm   -pthread -Wl,-soname -Wl,libwolfssl.so -o src/.libs/libwolfssl.so

This ends in this error:

[build] /..//bin/ld: cannot find crti.o: No such file or directory
[build] /..//bin/ld: cannot find crtbeginS.o: No such file or directory
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: Relocations in generic ELF (EM: 183)
[build] /..//bin/ld: wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o: error adding symbols: file in wrong format
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[build] make[2]: *** [Makefile:3845: src/libwolfssl.la] Error 1
[build] make[2]: Leaving directory '/home/myuser/Development/wolfssl/build/src/project_wolfssl-build'
[build] make[1]: *** [Makefile:5577: all-recursive] Error 1
[build] make[1]: Leaving directory '/home/myuser/Development/wolfssl/build/src/project_wolfssl-build'

The problem is, that clang is using the the linker from the host machine and not from the toolchain. The reason why clang is using the wrong linker is because of the missing parameter --target=aarch64-none-linux-android28 !

If I execute clang with the pramater:

/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -shared --target=aarch64-none-linux-android28 -fPIC -DPIC  wolfcrypt/src/.libs/src_libwolfssl_la-hmac.o wolfcrypt/src/.libs/src_libwolfssl_la-hash.o wolfcrypt/src/.libs/src_libwolfssl_la-cpuid.o wolfcrypt/src/.libs/src_libwolfssl_la-random.o wolfcrypt/src/.libs/src_libwolfssl_la-sha256.o wolfcrypt/src/.libs/src_libwolfssl_la-rsa.o wolfcrypt/src/.libs/src_libwolfssl_la-aes.o wolfcrypt/src/.libs/src_libwolfssl_la-cmac.o wolfcrypt/src/.libs/src_libwolfssl_la-des3.o wolfcrypt/src/.libs/src_libwolfssl_la-sha.o wolfcrypt/src/.libs/src_libwolfssl_la-sha512.o wolfcrypt/src/.libs/src_libwolfssl_la-sha3.o wolfcrypt/src/.libs/src_libwolfssl_la-logging.o wolfcrypt/src/.libs/src_libwolfssl_la-wc_port.o wolfcrypt/src/.libs/src_libwolfssl_la-error.o wolfcrypt/src/.libs/src_libwolfssl_la-wc_encrypt.o wolfcrypt/src/.libs/src_libwolfssl_la-signature.o wolfcrypt/src/.libs/src_libwolfssl_la-wolfmath.o wolfcrypt/src/.libs/src_libwolfssl_la-memory.o wolfcrypt/src/.libs/src_libwolfssl_la-dh.o wolfcrypt/src/.libs/src_libwolfssl_la-asn.o wolfcrypt/src/.libs/src_libwolfssl_la-coding.o wolfcrypt/src/.libs/src_libwolfssl_la-poly1305.o wolfcrypt/src/.libs/src_libwolfssl_la-md5.o wolfcrypt/src/.libs/src_libwolfssl_la-pwdbased.o wolfcrypt/src/.libs/src_libwolfssl_la-pkcs12.o wolfcrypt/src/.libs/src_libwolfssl_la-chacha.o wolfcrypt/src/.libs/src_libwolfssl_la-chacha20_poly1305.o wolfcrypt/src/.libs/src_libwolfssl_la-integer.o wolfcrypt/src/.libs/src_libwolfssl_la-ecc.o wolfcrypt/src/.libs/src_libwolfssl_la-pkcs7.o src/.libs/src_libwolfssl_la-internal.o src/.libs/src_libwolfssl_la-wolfio.o src/.libs/src_libwolfssl_la-keys.o src/.libs/src_libwolfssl_la-ssl.o src/.libs/src_libwolfssl_la-tls.o src/.libs/src_libwolfssl_la-tls13.o src/.libs/src_libwolfssl_la-ocsp.o   -lm  -Qunused-arguments -pthread -Os --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -fstack-protector-strong --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot -Wl,--exclude-libs -Wl,libgcc.a -Wl,--exclude-libs -Wl,libatomic.a -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z -Wl,noexecstack -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,-lm   -pthread -Wl,-soname -Wl,libwolfssl.so -o src/.libs/libwolfssl.so

It works!

So why is libtool stripped out --target=aarch64-none-linux-android28 ?

Here some settings from libtool:

       host-triplet:   arm-unknown-linux-androideabi
       shell:          /bin/sh
       compiler:       /home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
       compiler flags: -fPIC --target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security  -DHAVE_SNI -DWOLFSSL_SHA3 -DHAVE_FFDHE -DHAVE_ONE_TIME_AUTH -DHAVE_POLY1305 -DHAVE_ALPN -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_ECC -DHAVE_PK_CALLBACKS -DOPENSSL_EXTRA -DWOLFSSL_STATIC_PSK -DHAVE_EX_DATA -DKEEP_PEER_CERT -DSESSION_CERTS -DSESSION_INDEX -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_SUPPORTED_CURVES -DHAVE_TLS_EXTENSIONS -DHAVE_OCSP -DOPENSSL_ALL -DHAVE_AESGCM -DWOLFSSL_AES_DIRECT -DHAVE_AES_ECB   -Wno-pragmas -Wall -Wno-strict-aliasing -Wextra -Wunknown-pragmas -Wthis-test-should-fail --param=ssp-buffer-size=1 -Waddress -Warray-bounds -Wbad-function-cast -Wchar-subscripts -Wcomment -Wfloat-equal -Wformat-security -Wformat=2 -Wmaybe-uninitialized -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wnormalized=id -Woverride-init -Wpointer-arith -Wpointer-sign -Wredundant-decls -Wshadow -Wshorten-64-to-32 -Wsign-compare -Wstrict-overflow=1 -Wstrict-prototypes -Wswitch-enum -Wundef -Wunused -Wunused-result -Wunused-variable -Wwrite-strings -fwrapv
       linker:         /home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld (gnu? yes)
       version:        libtool (GNU libtool) 2.4.6
       automake:       automake (GNU automake) 1.16.1
       autoconf:       autoconf (GNU Autoconf) 2.69

After some hours I found a dirty workaround. When I change in the libtool script the following line:
From:
pic_flag=" -fPIC -DPIC"
To:
pic_flag=" -fPIC -DPIC --target=aarch64-none-linux-android28"

It works.

Here my Question:

  • Can you fixe the m4/libtoo.m4 script?
  • Or add an option to configure to disable libtool, because I know that libtool makes a lot of problem in cross environment.
  • Or finish the work on the CMakeLists.txt. This would be the best option.
  • Or did I sometihng wrong? Is there a required parameter in the configure ?
  • Some other hints ?
@embhorn
Copy link
Member

embhorn commented Oct 29, 2021

Hi @Bjoe

Could you please show the full configure command that sets up the cross-compilation?

@embhorn embhorn self-assigned this Oct 29, 2021
@Bjoe
Copy link
Author

Bjoe commented Oct 31, 2021

@embhorn Yep, true. Sorry I forgot.

Here my full configure command execution:

CC=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/clang CXX=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ AR=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar RANLIB=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ranlib LD=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld "C_EXTRA_FLAGS=-DHAVE_SNI -DWOLFSSL_SHA3 -DHAVE_FFDHE -DHAVE_ONE_TIME_AUTH -DHAVE_POLY1305 -DHAVE_ALPN -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_ECC -DHAVE_PK_CALLBACKS -DOPENSSL_EXTRA -DWOLFSSL_STATIC_PSK -DHAVE_EX_DATA -DKEEP_PEER_CERT -DSESSION_CERTS -DSESSION_INDEX -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_SUPPORTED_CURVES -DHAVE_TLS_EXTENSIONS -DHAVE_OCSP -DOPENSSL_ALL -DHAVE_AESGCM -DWOLFSSL_AES_DIRECT -DHAVE_AES_ECB " /home/myuser/Development/wolfssl/build/src/project_wolfssl/configure --disable-oldtls --enable-alpn --enable-supportedcurves --enable-harden --enable-tlsx --enable-psk --enable-aesgcm --enable-cmac --enable-aesccm --enable-ocsp --enable-ocspstapling --enable-sni --enable-pkcallbacks --enable-opensslextra --enable-nullcipher --enable-static --enable-sha3 --disable-examples --enable-des3 --enable-keygen --enable-certreq --enable-certgen --enable-pkcs7 --prefix=/home/myuser/Development/wolfssl/vendor --host=arm-linux-androideabi "CPPFLAGS=--target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ " "CFLAGS=-fPIC --target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security " "LDFLAGS=--target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now   -Wl,-lm"

Here the Configuration summary:

  * Installation prefix:        /home/myuser/Development/wolfssl/vendor
  * System type:                unknown-linux-androideabi
  * Host CPU:                   arm
  * C Compiler:                 /home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  * C Flags:                    -fPIC --target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security  -DHAVE_SNI -DWOLFSSL_SHA3 -DHAVE_FFDHE -DHAVE_ONE_TIME_AUTH -DHAVE_POLY1305 -DHAVE_ALPN -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_ECC -DHAVE_PK_CALLBACKS -DOPENSSL_EXTRA -DWOLFSSL_STATIC_PSK -DHAVE_EX_DATA -DKEEP_PEER_CERT -DSESSION_CERTS -DSESSION_INDEX -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_SUPPORTED_CURVES -DHAVE_TLS_EXTENSIONS -DHAVE_OCSP -DOPENSSL_ALL -DHAVE_AESGCM -DWOLFSSL_AES_DIRECT -DHAVE_AES_ECB   -Wno-pragmas -Wall -Wno-strict-aliasing -Wextra -Wunknown-pragmas -Wthis-test-should-fail --param=ssp-buffer-size=1 -Waddress -Warray-bounds -Wbad-function-cast -Wchar-subscripts -Wcomment -Wfloat-equal -Wformat-security -Wformat=2 -Wmaybe-uninitialized -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wnormalized=id -Woverride-init -Wpointer-arith -Wpointer-sign -Wredundant-decls -Wshadow -Wshorten-64-to-32 -Wsign-compare -Wstrict-overflow=1 -Wstrict-prototypes -Wswitch-enum -Wundef -Wunused -Wunused-result -Wunused-variable -Wwrite-strings -fwrapv
  * C++ Compiler:               /home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
  * C++ Flags:                  
  * CPP Flags:                  --target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ 
  * CCAS Flags:                 -fPIC --target=aarch64-none-linux-android28 --sysroot=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64/sysroot --gcc-toolchain=/home/myuser/SDKs/android-ndk/r19c/linux-x86_64/toolchains/llvm/prebuilt/linux-x86_64 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security  -DHAVE_SNI -DWOLFSSL_SHA3 -DHAVE_FFDHE -DHAVE_ONE_TIME_AUTH -DHAVE_POLY1305 -DHAVE_ALPN -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_ECC -DHAVE_PK_CALLBACKS -DOPENSSL_EXTRA -DWOLFSSL_STATIC_PSK -DHAVE_EX_DATA -DKEEP_PEER_CERT -DSESSION_CERTS -DSESSION_INDEX -DHAVE_CERTIFICATE_STATUS_REQUEST -DHAVE_SUPPORTED_CURVES -DHAVE_TLS_EXTENSIONS -DHAVE_OCSP -DOPENSSL_ALL -DHAVE_AESGCM -DWOLFSSL_AES_DIRECT -DHAVE_AES_ECB  
  * LIB Flags:                   -pie -z relro -z now 
  * Debug enabled:              no
  * Coverage enabled:           
  * Warnings as failure:        no
  * make -j:                    5
  * VCS checkout:               no
[build] 
  Features 
  * FIPS:                       no
  * Single threaded:            no
  * Filesystem:                 yes
  * OpenSSH Build:              no
  * OpenSSL Extra API:          yes
  * OpenSSL Coexist:            no
  * Old Names:                  yes
  * Max Strength Build:         no
  * Distro Build:               no
  * Reproducible Build:         no
  * fastmath:                   no
  * Assembly Allowed:           yes
  * sniffer:                    no
  * snifftest:                  no
  * ARC4:                       no
  * AES:                        yes
  * AES-NI:                     no
  * AES-CBC:                    yes
  * AES-GCM:                    yes
  * AES-CCM:                    yes
  * AES-CTR:                    no
  * AES-CFB:                    no
  * AES-OFB:                    no
  * DES3:                       yes
  * IDEA:                       no
  * Camellia:                   no
  * NULL Cipher:                yes
  * MD2:                        no
  * MD4:                        no
  * MD5:                        yes
  * RIPEMD:                     no
  * SHA:                        yes
  * SHA-224:                    no
  * SHA-384:                    yes
  * SHA-512:                    yes
  * SHA3:                       yes
  * SHAKE256:                   yes
  * BLAKE2:                     no
  * BLAKE2S:                    no
  * CMAC:                       yes
  * keygen:                     yes
  * certgen:                    yes
  * certreq:                    yes
  * certext:                    no
  * certgencache:               no
  * HC-128:                     no
  * RABBIT:                     no
  * CHACHA:                     yes
  * XCHACHA:                    no
  * Hash DRBG:                  yes
  * PWDBASED:                   yes
  * scrypt:                     no
  * wolfCrypt Only:             no
  * HKDF:                       yes
  * X9.63 KDF:                  yes
  * MD4:                        no
  * PSK:                        yes
  * Poly1305:                   yes
  * LEANPSK:                    no
  * LEANTLS:                    no
  * RSA:                        yes
  * RSA-PSS:                    yes
  * DSA:                        no
  * DH:                         yes
  * DH Default Parameters:      yes
  * ECC:                        yes
  * ECC Custom Curves           no
  * ECC Minimum Bits            224
  * CURVE25519:                 no
  * ED25519:                    no
  * CURVE448:                   no
  * ED448:                      no
  * FPECC:                      no
  * ECC_ENCRYPT:                no
  * ASN:                        yes
  * Anonymous cipher:           no
  * CODING:                     yes
  * MEMORY:                     yes
  * I/O POOL:                   no
  * LIGHTY:                     no
  * HAPROXY:                    no
  * STUNNEL:                    no
  * Apache httpd:               no
  * NGINX:                      no
  * ASIO:                       no
  * LIBWEBSOCKETS:              no
  * Qt                          no
  * Qt Unit Testing             no
  * SIGNAL:                     no
  * ERROR_STRINGS:              yes
  * DTLS:                       no
  * SCTP:                       no
  * Indefinite Length:          no
  * Multicast:                  no
  * SSL v3.0 (Old):             no
  * TLS v1.0 (Old):             no
  * TLS v1.1 (Old):             no
  * TLS v1.2:                   yes
  * TLS v1.3:                   yes
  * Post-handshake Auth:        no
  * Early Data:                 no
  * Send State in HRR Cookie:   no
  * OCSP:                       yes
  * OCSP Stapling:              yes
  * OCSP Stapling v2:           no
  * CRL:                        no
  * CRL-MONITOR:                no
  * Persistent session cache:   no
  * Persistent cert    cache:   no
  * Atomic User Record Layer:   no
  * Public Key Callbacks:       yes
  * NTRU:                       no
  * QSH:                        no
  * Whitewood netRandom:        no
  * Server Name Indication:     yes
  * ALPN:                       yes
  * Maximum Fragment Length:    yes
  * Trusted CA Indication:      yes
  * Truncated HMAC:             yes
  * Supported Elliptic Curves:  yes
  * FFDHE only in client:       no
  * Session Ticket:             no
  * Extended Master Secret:     yes
  * Renegotiation Indication:   no
  * Secure Renegotiation:       no
  * Fallback SCSV:              no
  * Keying Material Exporter:   no
  * All TLS Extensions:         yes
  * PKCS#7                      yes
  * S/MIME                      no
  * wolfSSH                     no
  * wolfTPM                     no
  * wolfSCEP                    no
  * Secure Remote Password      no
  * Small Stack:                no
  * Linux Kernel Module:        no
  * valgrind unit tests:        no
  * LIBZ:                       no
  * Examples:                   no
  * Crypt tests:                yes
  * Stack sizes in tests:       no
  * Heap stats in tests:        no
  * User Crypto:                no
  * Fast RSA:                   no
  * Single Precision:           no
  * SP math implementation:     no
  * Async Crypto:               no
  * PKCS#11:                    no
  * PKCS#12:                    yes
  * Cavium Nitrox:              no
  * Cavium Octeon (Sync):       no
  * Intel Quick Assist:         no
  * ARM ASM:                    no
  * AES Key Wrap:               yes
  * Write duplicate:            no
  * Xilinx Hardware Acc.:       no
  * Inline Code:                yes
  * Linux AF_ALG:               no
  * Linux devcrypto:            no
  * Crypto callbacks:           no

@embhorn
Copy link
Member

embhorn commented Nov 2, 2021

Hi @Bjoe

Cross compilation with the autotools is often difficult. We do have an example project for building in Android Studio
https://github.com/wolfSSL/wolfssl/tree/master/IDE/Android

If you still want to try the configure path, try setting the target, like:
./configure --target=arm-oe-linux-gnueabi --host=arm-oe-linux-gnueabi --build=x86_64

@dgarske dgarske assigned dgarske and unassigned embhorn Nov 3, 2021
@dgarske
Copy link
Contributor

dgarske commented Nov 3, 2021

Hi @Bjoe ,

I am encountering a similar issue cross-compiling wolfSSL for Android using configure.

This worked for me:

TOOLCHAIN_BIN_PATH=/Users/davidgarske/NDK_21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/
./configure --host=aarch64 \
    CC="${TOOLCHAIN_BIN_PATH}aarch64-linux-android21-clang -mcpu=cortex-a53+crypto -march=armv8-a -mstrict-align" \
    AR="${TOOLCHAIN_BIN_PATH}aarch64-linux-android-ar" \
    RANLIB="${TOOLCHAIN_BIN_PATH}aarch64-linux-android-ranlib"
make

If you want a static library add --disable-shared --enable-static. You might also consider --disable-examples if getting any errors in the test applications.

Thanks,
David Garske, wolfSSL

@Bjoe
Copy link
Author

Bjoe commented Nov 5, 2021

Cross compilation with the autotools is often difficult. We do have an example project for building in Android Studio https://github.com/wolfSSL/wolfssl/tree/master/IDE/Android

I already seen this. I also see that in WolfSSL is a CMakeLists.txt. But in both build solution, how can I enable/disable the "feature" that I need?

If you still want to try the configure path, try setting the target, like: ./configure --target=arm-oe-linux-gnueabi --host=arm-oe-linux-gnueabi --build=x86_64

Sorry, still same issue.

@Bjoe
Copy link
Author

Bjoe commented Nov 5, 2021

I am encountering a similar issue cross-compiling wolfSSL for Android using configure.

This worked for me:

TOOLCHAIN_BIN_PATH=/Users/davidgarske/NDK_21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/
./configure --host=aarch64 \
    CC="${TOOLCHAIN_BIN_PATH}aarch64-linux-android21-clang -mcpu=cortex-a53+crypto -march=armv8-a -mstrict-align" \
    AR="${TOOLCHAIN_BIN_PATH}aarch64-linux-android-ar" \
    RANLIB="${TOOLCHAIN_BIN_PATH}aarch64-linux-android-ranlib"
make

Ah! This ${TOOLCHAIN_BIN_PATH}aarch64-linux-android21-clang is a shell script and set the --target=aarch64-linux-android21 parameter for the clang compiler. For libtool is not possible to remove this parameter, nice :-)

Thanks for the hint, @dgarske !

Maybe you should add this also as hint on https://www.wolfssl.com/docs/wolfssl-manual/ch2/ -> 2.6.1 Example cross compile configure options for toolchain builds

I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants