From 8a611a8b595bba59ce47b5f9841457bc30c2d65e Mon Sep 17 00:00:00 2001 From: hmelder Date: Mon, 25 Aug 2025 15:32:20 +0200 Subject: [PATCH 1/4] Build OpenSSL from upstream and drop v1 The current binary distribution of OpenSSL is outdated and ships both version 3 and version 1. The later is EOL and not used by Qt anymore. --- patches/openssl-android-16k.patch | 31 ++++++++++++++++++ phases/18-openssl.sh | 52 ++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 patches/openssl-android-16k.patch diff --git a/patches/openssl-android-16k.patch b/patches/openssl-android-16k.patch new file mode 100644 index 0000000..5cc3a3f --- /dev/null +++ b/patches/openssl-android-16k.patch @@ -0,0 +1,31 @@ +From 66ed6db2ac83430e5bb768a44308df04ad685847 Mon Sep 17 00:00:00 2001 +From: vkryl <6242627+vkryl@users.noreply.github.com> +Date: Fri, 15 Aug 2025 15:01:51 +0300 +Subject: [PATCH] Android: Enable 16 KB ELF alignment for `arm64-v8a` and + `x86_64` platforms + +CLA: trivial +--- + Configurations/15-android.conf | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf +index 1de6b7a91571d..26d9d6508f582 100644 +--- a/Configurations/15-android.conf ++++ b/Configurations/15-android.conf +@@ -232,6 +232,7 @@ my %targets = ( + bn_ops => add("RC4_CHAR"), + asm_arch => 'aarch64', + perlasm_scheme => "linux64", ++ shared_ldflag => add("-Wl,-z,max-page-size=16384"), + }, + + "android-mips" => { +@@ -269,6 +270,7 @@ my %targets = ( + bn_ops => add("RC4_INT"), + asm_arch => 'x86_64', + perlasm_scheme => "elf", ++ shared_ldflag => add("-Wl,-z,max-page-size=16384"), + }, + + "android-riscv64" => { diff --git a/phases/18-openssl.sh b/phases/18-openssl.sh index 51873b8..77b9375 100755 --- a/phases/18-openssl.sh +++ b/phases/18-openssl.sh @@ -5,30 +5,54 @@ set -e # make any subsequent failing command exit the script . `dirname $0`/../scripts/common.sh PROJECT=openssl -GITHUB_REPO=KDAB/android_openssl +GITHUB_REPO=openssl/openssl +TAG=$(get_latest_github_release_tag $GITHUB_REPO) # load environment and prepare project if ! prepare_project $PROJECT $GITHUB_REPO; then exit 0 fi -echo -e "\n### Installing headers" +BUILD_TARGET= +case $ABI_NAME in + armeabi-v7a) + BUILD_TARGET=android-arm + ;; + arm64-v8a) + BUILD_TARGET=android-arm64 + ;; + x86) + BUILD_TARGET=android-x86 + ;; + x86_64) + BUILD_TARGET=android-x86_64 + ;; + *) +esac + +SSL_BUILD_TYPE=release +if [ "${BUILD_TYPE}" = "Debug" ]; then + SSL_BUILD_TYPE=debug +fi -cp -Rf ssl_3/include/ ${INSTALL_PREFIX}/include -echo -e "\n### Installing libraries" +echo -e "\n### Running configure" +PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH +./Configure \ + shared \ + no-docs \ + no-apps \ + ${BUILD_TARGET} \ + --prefix="${INSTALL_PREFIX}" \ + --${SSL_BUILD_TYPE} \ + -U__ANDROID_API__ \ + -D__ANDROID_API__="${ANDROID_API_LEVEL}" \ -cp -f ssl_3/$ABI_NAME/*.so ${INSTALL_PREFIX}/lib +echo -e "\n### Building" +make -j${MAKE_JOBS} -# create version-less symlinks for libcrypto/libssl.so to versioned libraries -libraries=`ls ssl_3/$ABI_NAME/*.so` -cd ${INSTALL_PREFIX}/lib -for lib in $libraries; do - libname=`basename $lib` - if [[ $libname =~ ([a-z]+)[0-9\_]+.so ]]; then - ln -sf $libname ${BASH_REMATCH[1]}.so - fi -done +echo -e "\n### Installing" +make install echo -e "\n### Downloading CA bundle (must be installed into Android app bundle)" mkdir -p "$CACHE_ROOT" From f2025b305ea231886093501c701fe4ae10bd146f Mon Sep 17 00:00:00 2001 From: hmelder Date: Mon, 25 Aug 2025 15:33:50 +0200 Subject: [PATCH 2/4] Add linker directives to align to 16 KiB pages --- scripts/toolchain.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/toolchain.sh b/scripts/toolchain.sh index 78bf9cd..5835ddd 100755 --- a/scripts/toolchain.sh +++ b/scripts/toolchain.sh @@ -40,6 +40,7 @@ export CFLAGS="$OPTFLAG -fstack-protector-strong -D_FORTIFY_SOURCE=2 -fPIC" # --gc-sections is recommended to decrease binary size export LDFLAGS="-L${INSTALL_PREFIX}/lib -fuse-ld=lld -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--gc-sections" +ADDITIONAL_CMAKE_FLAGS= case $ABI_NAME in armeabi-v7a) # use Thumb instruction set for smaller code @@ -47,6 +48,10 @@ case $ABI_NAME in # don't export symbols from libunwind export LDFLAGS="$LDFLAGS -Wl,--exclude-libs,libunwind.a" ;; + arm64-v8a) + export LDFLAGS="$LDFLAGS -Wl,-z,max-page-size=16384" + ADDITIONAL_CMAKE_FLAGS="-Wl,-z,max-page-size=16384" + ;; x86) # properly align stacks for global constructors when targeting API < 24 if [ "$ANDROID_API_LEVEL" -lt "24" ]; then @@ -72,4 +77,5 @@ CMAKE_OPTIONS=" \ -DANDROID_NDK=${ANDROID_NDK_ROOT} \ -DANDROID_PLATFORM=android-${ANDROID_API_LEVEL} \ -DANDROID_STL=c++_shared \ + -DCMAKE_SHARED_LINKER_FLAGS=$ADDITIONAL_CMAKE_FLAGS \ " From f69da5a03adbc766a9be57a067c0906da028c917 Mon Sep 17 00:00:00 2001 From: hmelder Date: Wed, 27 Aug 2025 11:13:56 +0200 Subject: [PATCH 3/4] Make PATH platform-agnostic --- phases/18-openssl.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phases/18-openssl.sh b/phases/18-openssl.sh index 77b9375..6d2a89c 100755 --- a/phases/18-openssl.sh +++ b/phases/18-openssl.sh @@ -35,13 +35,21 @@ if [ "${BUILD_TYPE}" = "Debug" ]; then SSL_BUILD_TYPE=debug fi +ANDROID_NDK_MAJOR=`basename $ANDROID_NDK_ROOT | cut -d. -f1` +ASM= +# Seems like there is a bug in the r26 ndk which prevents us from compiling some assembly +if [ "$ANDROID_NDK_MAJOR" = "26" ]; then + ASM=no-asm +fi + echo -e "\n### Running configure" -PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH +PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/${HOST_TAG}/bin:$PATH ./Configure \ shared \ no-docs \ no-apps \ + ${ASM} \ ${BUILD_TARGET} \ --prefix="${INSTALL_PREFIX}" \ --${SSL_BUILD_TYPE} \ From 063bc2ee3ce4667c7a50fabc9359ce25722f24c9 Mon Sep 17 00:00:00 2001 From: hmelder Date: Thu, 28 Aug 2025 11:37:23 +0200 Subject: [PATCH 4/4] Add alignment on x86_64 --- scripts/toolchain.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/toolchain.sh b/scripts/toolchain.sh index 5835ddd..e8ca62e 100755 --- a/scripts/toolchain.sh +++ b/scripts/toolchain.sh @@ -58,6 +58,10 @@ case $ABI_NAME in export CFLAGS="$CFLAGS -mstackrealign" fi ;; + x86_64) + export LDFLAGS="$LDFLAGS -Wl,-z,max-page-size=16384" + ADDITIONAL_CMAKE_FLAGS="-Wl,-z,max-page-size=16384" + ;; esac export CXXFLAGS=$CFLAGS