Skip to content

Commit c8f87e4

Browse files
committed
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 NixOS/patchelf#492.
1 parent e2a1884 commit c8f87e4

File tree

2 files changed

+44
-61
lines changed

2 files changed

+44
-61
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,3 @@ are correct for your environment.
5858
### Build Prerequisites
5959

6060
The build script was tested against `bash` and `zsh` on Linux and macOS.
61-
The `patchelf` command is required when building for OpenSSL 3.

build_ssl.sh

Lines changed: 44 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
## Prerequisites
44
## The script supports builds from Linux and macOS.
5-
## The 'patchelf' command is required for OpenSSL 3.
65
## set BUILD_DIR and OUTPUT_ROOT variables to use custom build and output paths.
76
## Set NDK_ROOT_PREFIX to use custom Android NDK root path that contains various
87
## NDK versions.
@@ -94,8 +93,7 @@ configure_ssl() {
9493
arch=$2
9594
ndk=$3
9695
build_type=$4
97-
output_dir=$5
98-
log_file=$6
96+
log_file=$5
9997

10098
nkd_path="$NDK_ROOT_PREFIX/$ndk"
10199

@@ -116,12 +114,39 @@ configure_ssl() {
116114
fi
117115
done
118116

119-
case $output_dir in
120-
ssl_1.1)
117+
case $ssl_version in
118+
1.1*)
121119
ANDROID_API=21
120+
# use suffix _1_1.so with OpenSSL 1.1.x (up to Qt 6.4)
121+
patch <<EOF
122+
--- Configurations/15-android.conf
123+
+++ Configurations/15-android.conf
124+
@@ -190,6 +190,8 @@
125+
bn_ops => sub { android_ndk()->{bn_ops} },
126+
bin_cflags => "-pie",
127+
enable => [ ],
128+
+ shared_extension => ".so",
129+
+ shlib_variant => "_1_1",
130+
},
131+
"android-arm" => {
132+
################################################################
133+
EOF
122134
;;
123-
ssl_3)
135+
3*)
124136
ANDROID_API=23
137+
# use suffix _3.so with OpenSSL 3.1.x (Qt 6.5.0 and above)
138+
patch <<EOF
139+
--- Configurations/15-android.conf
140+
+++ Configurations/15-android.conf
141+
@@ -192,6 +192,7 @@
142+
bin_lflags => "-pie",
143+
enable => [ ],
144+
shared_extension => ".so",
145+
+ shlib_variant => "_3",
146+
},
147+
"android-arm" => {
148+
################################################################
149+
EOF
125150
;;
126151
esac
127152

@@ -134,55 +159,29 @@ configure_ssl() {
134159
make depend
135160
}
136161

137-
build_ssl_1_1() {
138-
# Qt up to 6.4 is using OpenSSL 1.1.x but the library is suffixed with _1_1.so
139-
output_dir=$1
140-
log_file=$2
141-
142-
echo "Building..."
143-
make -j$(nproc) SHLIB_VERSION_NUMBER= SHLIB_EXT=_1_1.so build_libs 2>&1 1>>${log_file} \
144-
| tee -a ${log_file} || exit 1
145-
}
146-
147-
build_ssl_3() {
148-
# Qt 6.5.0+ is using OpenSSL 3.1.x but the library is suffixed with _3.so
149-
output_dir=$1
150-
log_file=$2
162+
build_ssl() {
163+
log_file=$1
151164

152165
echo "Building..."
153166
make -j$(nproc) SHLIB_VERSION_NUMBER= build_libs 2>&1 1>>${log_file} \
154167
| tee -a ${log_file} || exit 1
155-
156-
mv libcrypto.so libcrypto_3.so
157-
mv libssl.so libssl_3.so
158-
159-
# SHLIB_EXT is no longer supported for OpenSSL, so we need to manually
160-
# use patchelf to modify SONAME and NEEDED sections to set the correct
161-
# suffix for the shared libraries.
162-
# See https://github.com/openssl/openssl/issues/20854
163-
patchelf --set-soname libcrypto_3.so libcrypto_3.so || exit 1
164-
patchelf --set-soname libssl_3.so libssl_3.so || exit 1
165-
patchelf --replace-needed libcrypto.so libcrypto_3.so libssl_3.so || exit 1
166168
}
167169

168170
strip_libs() {
169-
lib_suffix=$1
170-
171-
llvm-strip --strip-all libcrypto_$lib_suffix.so
172-
llvm-strip --strip-all libssl_$lib_suffix.so
171+
find . -name "libcrypto_*.so" -exec llvm-strip --strip-all {} \;
172+
find . -name "libssl_*.so" -exec llvm-strip --strip-all {} \;
173173
}
174174

175175
copy_build_artefacts() {
176-
lib_suffix=$1
177-
output_dir=$2
176+
output_dir=$1
178177

179-
cp libcrypto_$lib_suffix.so "$output_dir/libcrypto_$lib_suffix.so" || exit 1
180-
cp libssl_$lib_suffix.so "$output_dir/libssl_$lib_suffix.so" || exit 1
178+
cp libcrypto_*.so "$output_dir/" || exit 1
179+
cp libssl_*.so "$output_dir/" || exit 1
181180
cp libcrypto.a libssl.a "$output_dir" || exit 1
182181

183182
# Create relative non-versioned symlinks
184-
ln -s "libcrypto_$lib_suffix.so" "$output_dir/libcrypto.so"
185-
ln -s "libssl_$lib_suffix.so" "$output_dir/libssl.so"
183+
find . -name "libcrypto_*.so" -exec ln -s {} "$output_dir/libcrypto.so" \;
184+
find . -name "libssl_*.so" -exec ln -s {} "$output_dir/libssl.so" \;
186185
ln -s "../include" "$output_dir/include"
187186
}
188187

@@ -211,8 +210,7 @@ for build_type in "${build_types[@]}"; do
211210
pushd "openssl-$ssl_version-$arch" || exit 1
212211

213212
log_file="build_${arch}_${ssl_version}.log"
214-
configure_ssl ${ssl_version} ${arch} "${ndk}" "${build_type}" \
215-
${version_build_dir} ${log_file}
213+
configure_ssl ${ssl_version} ${arch} "${ndk}" "${build_type}" ${log_file}
216214

217215
# Delete existing build artefacts
218216
output_dir="$OUTPUT_ROOT/$build_type/$version_build_dir/$qt_arch"
@@ -228,23 +226,9 @@ for build_type in "${build_types[@]}"; do
228226
find "$output_dir/../" -name "*.def" -delete
229227
fi
230228

231-
case $version_build_dir in
232-
ssl_1.1)
233-
build_ssl_1_1 ${output_dir} ${log_file}
234-
suffix="1_1"
235-
;;
236-
ssl_3)
237-
build_ssl_3 ${output_dir} ${log_file}
238-
suffix="3"
239-
;;
240-
*)
241-
echo "Unhandled OpenSSL version $version_build_dir"
242-
exit 1
243-
;;
244-
esac
245-
246-
strip_libs "$suffix"
247-
copy_build_artefacts "$suffix" ${output_dir}
229+
build_ssl ${log_file}
230+
strip_libs
231+
copy_build_artefacts ${output_dir}
248232

249233

250234
popd

0 commit comments

Comments
 (0)