Get rid of patchelf requirement

OpenSSL has the configuration option shlib_variant, so we can use that instead.

This works for version 1.x and 3.x, so it would make the build script more similar between the two versions.

Also, this avoid issues that can come from patchelf, as this patch comes after a bug found in patchelf 0.18 that created wrongly aligned libraries. See https://github.com/NixOS/patchelf/issues/492.
This commit is contained in:
Assam Boudjelthia
2025-02-17 15:07:49 +02:00
committed by Assam Boudjelthia
parent 278fcd2602
commit 7ccc0bcede
2 changed files with 44 additions and 61 deletions
-1
View File
@@ -58,4 +58,3 @@ are correct for your environment.
### Build Prerequisites ### Build Prerequisites
The build script was tested against `bash` and `zsh` on Linux and macOS. The build script was tested against `bash` and `zsh` on Linux and macOS.
The `patchelf` command is required when building for OpenSSL 3.
+44 -60
View File
@@ -2,7 +2,6 @@
## Prerequisites ## Prerequisites
## The script supports builds from Linux and macOS. ## The script supports builds from Linux and macOS.
## The 'patchelf' command is required for OpenSSL 3.
## set BUILD_DIR and OUTPUT_ROOT variables to use custom build and output paths. ## set BUILD_DIR and OUTPUT_ROOT variables to use custom build and output paths.
## Set NDK_ROOT_PREFIX to use custom Android NDK root path that contains various ## Set NDK_ROOT_PREFIX to use custom Android NDK root path that contains various
## NDK versions. ## NDK versions.
@@ -97,8 +96,7 @@ configure_ssl() {
arch=$2 arch=$2
ndk=$3 ndk=$3
build_type=$4 build_type=$4
output_dir=$5 log_file=$5
log_file=$6
nkd_path="$NDK_ROOT_PREFIX/$ndk" nkd_path="$NDK_ROOT_PREFIX/$ndk"
@@ -119,12 +117,39 @@ configure_ssl() {
fi fi
done done
case $output_dir in case $ssl_version in
ssl_1.1) 1.1.*)
ANDROID_API=21 ANDROID_API=21
# use suffix _1_1.so with OpenSSL 1.1.x (up to Qt 6.4)
patch -p0 <<EOF
--- Configurations/15-android.conf
+++ Configurations/15-android.conf
@@ -190,6 +190,8 @@
bn_ops => sub { android_ndk()->{bn_ops} },
bin_cflags => "-pie",
enable => [ ],
+ shared_extension => ".so",
+ shlib_variant => "_1_1",
},
"android-arm" => {
################################################################
EOF
;; ;;
ssl_3) 3.*)
ANDROID_API=23 ANDROID_API=23
# use suffix _3.so with OpenSSL 3.1.x (Qt 6.5.0 and above)
patch -p0 <<EOF
--- Configurations/15-android.conf
+++ Configurations/15-android.conf
@@ -192,6 +192,7 @@
bin_lflags => "-pie",
enable => [ ],
shared_extension => ".so",
+ shlib_variant => "_3",
},
"android-arm" => {
################################################################
EOF
;; ;;
esac esac
@@ -137,55 +162,29 @@ configure_ssl() {
make depend make depend
} }
build_ssl_1_1() { build_ssl() {
# Qt up to 6.4 is using OpenSSL 1.1.x but the library is suffixed with _1_1.so log_file=$1
output_dir=$1
log_file=$2
echo "Building..."
make -j$(nproc) SHLIB_VERSION_NUMBER= SHLIB_EXT=_1_1.so build_libs 2>&1 1>>${log_file} \
| tee -a ${log_file} || exit 1
}
build_ssl_3() {
# Qt 6.5.0+ is using OpenSSL 3.1.x but the library is suffixed with _3.so
output_dir=$1
log_file=$2
echo "Building..." echo "Building..."
make -j$(nproc) SHLIB_VERSION_NUMBER= build_libs 2>&1 1>>${log_file} \ make -j$(nproc) SHLIB_VERSION_NUMBER= build_libs 2>&1 1>>${log_file} \
| tee -a ${log_file} || exit 1 | tee -a ${log_file} || exit 1
mv libcrypto.so libcrypto_3.so
mv libssl.so libssl_3.so
# SHLIB_EXT is no longer supported for OpenSSL, so we need to manually
# use patchelf to modify SONAME and NEEDED sections to set the correct
# suffix for the shared libraries.
# See https://github.com/openssl/openssl/issues/20854
patchelf --set-soname libcrypto_3.so libcrypto_3.so || exit 1
patchelf --set-soname libssl_3.so libssl_3.so || exit 1
patchelf --replace-needed libcrypto.so libcrypto_3.so libssl_3.so || exit 1
} }
strip_libs() { strip_libs() {
lib_suffix=$1 find . -name "libcrypto_*.so" -exec llvm-strip --strip-all {} \;
find . -name "libssl_*.so" -exec llvm-strip --strip-all {} \;
llvm-strip --strip-all libcrypto_$lib_suffix.so
llvm-strip --strip-all libssl_$lib_suffix.so
} }
copy_build_artefacts() { copy_build_artefacts() {
lib_suffix=$1 output_dir=$1
output_dir=$2
cp libcrypto_$lib_suffix.so "$output_dir/libcrypto_$lib_suffix.so" || exit 1 cp libcrypto_*.so "$output_dir/" || exit 1
cp libssl_$lib_suffix.so "$output_dir/libssl_$lib_suffix.so" || exit 1 cp libssl_*.so "$output_dir/" || exit 1
cp libcrypto.a libssl.a "$output_dir" || exit 1 cp libcrypto.a libssl.a "$output_dir" || exit 1
# Create relative non-versioned symlinks # Create relative non-versioned symlinks
ln -s "libcrypto_$lib_suffix.so" "$output_dir/libcrypto.so" ln -s $(find . -name "libcrypto_*.so" -exec basename {} \;) "${output_dir}/libcrypto.so"
ln -s "libssl_$lib_suffix.so" "$output_dir/libssl.so" ln -s $(find . -name "libssl_*.so" -exec basename {} \;) "${output_dir}/libssl.so"
ln -s "../include" "$output_dir/include" ln -s "../include" "$output_dir/include"
} }
@@ -214,8 +213,7 @@ for build_type in "${build_types[@]}"; do
pushd "openssl-$ssl_version-$arch" || exit 1 pushd "openssl-$ssl_version-$arch" || exit 1
log_file="build_${arch}_${ssl_version}.log" log_file="build_${arch}_${ssl_version}.log"
configure_ssl ${ssl_version} ${arch} "${ndk}" "${build_type}" \ configure_ssl ${ssl_version} ${arch} "${ndk}" "${build_type}" ${log_file}
${version_build_dir} ${log_file}
# Delete existing build artefacts # Delete existing build artefacts
output_dir="$OUTPUT_ROOT/$build_type/$version_build_dir/$qt_arch" output_dir="$OUTPUT_ROOT/$build_type/$version_build_dir/$qt_arch"
@@ -231,23 +229,9 @@ for build_type in "${build_types[@]}"; do
find "$output_dir/../" -name "*.def" -delete find "$output_dir/../" -name "*.def" -delete
fi fi
case $version_build_dir in build_ssl ${log_file}
ssl_1.1) strip_libs
build_ssl_1_1 ${output_dir} ${log_file} copy_build_artefacts ${output_dir}
suffix="1_1"
;;
ssl_3)
build_ssl_3 ${output_dir} ${log_file}
suffix="3"
;;
*)
echo "Unhandled OpenSSL version $version_build_dir"
exit 1
;;
esac
strip_libs "$suffix"
copy_build_artefacts "$suffix" ${output_dir}
popd popd