如何将OpenSSL构建为Android的未版本共享库?

问题描述:

我正在按照编译最新的Android OpenSSL 来构建最新的Android OpenSSL.我设法建立了静态库.

I am trying to build the latest OpenSSL for Android following Compiling the latest OpenSSL for Android. I manage to build the static libs.

但是,我尝试编译共享库.为此,我运行:

However I try to compile the shared libs. To do so I run:

./Configure android-armv7 shared

这会编译.问题是这会创建一个版本化的lib,如libssl.so.1.0.0,Android不支持.因为SONAME仍指向版本化的文件名,所以只是重命名不起作用.

This compiles. Problem is that this creates a versioned lib like libssl.so.1.0.0, which is not supported by Android. Just rename does not do because of SONAME is still pointing to the versioned filename.

我遇到的其他问题是尝试为旧的armeabi平台创建库时.当我跑步时:

Different problem I have is when trying to the create the libs for old armeabi platform. When I run:

./Configure android shared

它为旧的armeabi平台创建静态库,但是共享库是arm-v7体系结构.

it creates the static libs for the old armeabi plattform, the shared libs however are arm-v7 architecture.

要构建无版本的libcrypto,覆盖CALC_VERSIONS可以解决问题(至少适用于1.0.2d):

As to build a version-less libcrypto, overwriting CALC_VERSIONS does the trick (at least for 1.0.2d):

make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" all

然后,必须禁用目标install_sw的子目标link-shared(否则,损坏的符号链接将覆盖库),这可以通过在适当的位置创建同名的虚拟文件来完成(此外,还必须为要复制的无版本文件设置SHLIB_EXT.

Then, the sub-target link-shared of the target install_sw must be disabled (otherwise broken symlinks overwrite the libraries), which can be done by creating a dummy file of the same name at the suitable place (furthermore, SHLIB_EXT must also be set for the version-less files to be copied).

我使用的完整bash脚本:

The complete bash-script I used:

ORIG_PATH=$PATH
SCRIPT_PATH=$(dirname $(readlink -f $0))

tar -zxf $SCRIPT_PATH/openssl-fips-2.0.10.tar.gz
tar -zxf $SCRIPT_PATH/openssl-1.0.2d.tar.gz

ANDROID_NDK_PATH=<system-specific-path>/android-ndk-r10e-linux
ANDROID_API=android-14
ANDROID_SYSROOT=$ANDROID_NDK_PATH/platforms/$ANDROID_API/arch-arm
export OPENSSLDIR=$SCRIPT_PATH/ssl/android/arm
export FIPSDIR=$OPENSSLDIR/fips-2.0
export HOSTCC=gcc
export FIPS_SIG=$SCRIPT_PATH/openssl-fips-2.0.10/util/incore
export ANDROID_DEV=$ANDROID_SYSROOT/usr
export PATH=$ANDROID_NDK_PATH/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$ORIG_PATH
export MACHINE=armv7
export RELEASE=2.6.37
export SYSTEM=android
export ARCH=arm
export CROSS_COMPILE=arm-linux-androideabi-

cd $SCRIPT_PATH/openssl-fips-2.0.10
./config shared
make clean
make
make install_sw

cd $SCRIPT_PATH/openssl-1.0.2d
./config fips shared -no-sslv2 -no-sslv3 -no-comp -no-hw -no-engines --openssldir=$OPENSSLDIR --with-fipsdir=$FIPSDIR --with-fipslibdir=$FIPSDIR/lib/
make clean
make depend
make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" MAKE="make -e" all
mkdir -p $OPENSSLDIR/lib
echo "place-holder make target for avoiding symlinks" >> $OPENSSLDIR/lib/link-shared
make SHLIB_EXT=.so install_sw
rm $OPENSSLDIR/lib/link-shared

然后,任何生成的目标文件都不应具有或引用版本化的so-name:

Then no generated object file should have or reference a versioned so-name:

$ readelf -d ssl/android/arm/lib/libcrypto.so | grep 'SONAME\|NEEDED'
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
 0x0000000e (SONAME)                     Library soname: [libcrypto.so]
$ readelf -d ssl/android/arm/lib/libssl.so | grep 'SONAME\|NEEDED'
 0x00000001 (NEEDED)                     Shared library: [libcrypto.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
 0x0000000e (SONAME)                     Library soname: [libssl.so]
$ readelf -d ssl/android/arm/bin/openssl | grep 'SONAME\|NEEDED'
 0x00000001 (NEEDED)                     Shared library: [libssl.so]
 0x00000001 (NEEDED)                     Shared library: [libcrypto.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]