简体   繁体   中英

Building OpenSSL 1.0.2n for 64-bit Android with NDK r16b undefined reference to bsd_signal

I'm trying to get OpenSSL 1.0.2n to build using the latest Android NDK r16b. Building for 32-bit archs (armv7, x86) works just fine, but when I try building for 64-bit archs (arm64, x86_64) I get a linker error stating that bsd_signal is undefined:

shlib_target=; if [ -n "libcrypto.so.1.0.0 libssl.so.1.0.0" ]; then \
        shlib_target="linux-shared"; \
    elif [ -n "" ]; then \
      FIPSLD_CC="aarch64-linux-android-gcc"; CC=/usr/local/ssl/fips-2.0/bin/fipsld; export CC FIPSLD_CC; \
    fi; \
    LIBRARIES="-L.. -lssl  -L.. -lcrypto" ; \
    /Applications/Xcode.app/Contents/Developer/usr/bin/make -f ../Makefile.shared -e \
        APPNAME=openssl OBJECTS="openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o ec.o ecparam.o x509.o genrsa.o gendsa.o genpkey.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o pkey.o pkeyparam.o pkeyutl.o spkac.o smime.o cms.o rand.o engine.o ocsp.o prime.o ts.o srp.o" \
        LIBDEPS=" $LIBRARIES -ldl" \
        link_app.${shlib_target}
req.o: In function `req_main':
req.c:(.text+0x368): undefined reference to `bsd_signal'
ca.o: In function `ca_main':
ca.c:(.text+0xe90): undefined reference to `bsd_signal'
ecparam.o: In function `ecparam_main':
ecparam.c:(.text+0x30): undefined reference to `bsd_signal'
s_server.o: In function `s_server_main':
s_server.c:(.text+0x32c0): undefined reference to `bsd_signal'
pkcs12.o: In function `pkcs12_main':
pkcs12.c:(.text+0x1134): undefined reference to `bsd_signal'
cms.o:cms.c:(.text+0x98): more undefined references to `bsd_signal' follow
collect2: error: ld returned 1 exit status

I saw that bsd_signal had been omitted from NDK at one point, but it was added back in NDK 13 ( https://github.com/android-ndk/ndk/issues/160 ). Besides, if it were missing entirely I would expect the 32-bit builds to fail as well.

Here are the configurations I'm attempting to use for the arm64 build (this is actually done with a script, which is quite long. To avoid pasting the whole nonsense here, these are the values that wind up being used when it is executed):

export MACHINE=armv7
export ARCH=arm64
export CROSS_COMPILE="aarch64-linux-android-"
export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/android-21/arch-arm64"
export SYSROOT="$ANDROID_SYSROOT"
export NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_API=android-21

export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/android-21/arch-arm64/usr"
export HOSTCC=gcc
export ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin"
export PATH="$ANDROID_TOOLCHAIN":"$PATH"

./Configure shared no-ssl2 no-ssl3 no-comp no-hw no-engine linux-generic64 --openssldir=/usr/local/ssl/android-21 -fPIE -D__ANDROID_API__=android-21 -I$ANDROID_NDK_ROOT/sysroot/usr/include -I$ANDROID_NDK_ROOT/sysroot/usr/include/aarch64-linux-android -B$ANDROID_NDK_ROOT/platforms/android-21/arch-arm64/usr/lib

make clean
make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" depend
make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" all

I've tried so many different things at this point I couldn't even begin to list them.

Anyone see what I'm missing here?

  1. I would recommend to use the make that is shipped with Android NDK to build with NDK toolchain. If it's not on your PATH, you'll find it at

     $ANDROID_NDK_ROOT/prebuilt/darwin-x86_64/bin/make 

    I don't think this is a real cause of your problem here.

  2. bsd_signal is exported from platforms/android-21/arch-arm/usr/lib/libc.so , and also the corresponding libc.a , but not from platforms/android-21/arch-arm64/usr/lib/libc.so .

  3. It is marked as __REMOVED_IN(21) in the unified headers, so I would expect the compiler to issue a warning about using an undefined function.

  4. A possible workaround is to provide a dummy bsd_signal , as Felipe Cavalcanti proposed on GitHub .

  5. The issue with bsd_signal seems to have been resolved in openssl 1.1 series.

  6. You have a mistake on command line: use -D__ANDROID_API__=21 instead.

This definitely looks like a case of building against one API level and linking against another (or perhaps a mismatch of the header ABI vs the library ABI?). To rule out any configuration issues (and to simply your build even if it doesn't solve the issue), I'd recommend using a standalone toolchain .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM