openssl: Building for Android with clang fails: "-mandroid" unknown argument

OpenSSL sets -mandroid flag when compiling for Android, which breaks building with clang, as clang does not recognize this argument.

Starting with clang 3.4 unknown compiler flags were treated as an error. This caused problems on OS X (-> Xcode 5.1) with packages failing to compile. For some time the behavior could be disabled with -Wno-error=unused-command-line-argument-hard-error-in-future, but this option has been removed (don’t know the exact version).

Problematic OpenSSL source code: file: Configurations/10-main.conf lines: 876 and 916

OpenSSL 1.1.0
Android NDK r12b
Android clang version 3.8.256229  (based on LLVM 3.8.256229)
Compilation target: armv7-a

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 28 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Well, so far gcc was supported and I can confirm that targets are operational as long as you follow instructions in Configurations/10-main.cf. If clang support is desired, then one should formulate problem like that, i.e. clang support is desired.

Yes, there are no problems using GCC.

Why I am concerned about clang support (and have opened this issue) is that GCC is going to be deprecated in Android NDK in the future. See https://android.googlesource.com/platform/ndk.git/+/master/CHANGELOG.md

GCC is no longer supported. It will not be removed from the NDK just yet, but is no longer receiving backports. It cannot be removed until after libc++ has become stable enough to be the default, as some parts of gnustl are still incompatible with Clang. It will likely be removed after that point.

Sacha wrote:

Can we have this issue re-opened or should I make it again? It was never resolved. The only workaround for now is to use linux-generic32/64 target instead of android.

This issue is closed but problem not rejected - see #2229 “Build for Android with Clang”

Actually, I just discovered, using NDK r20, its easy to build with clang:

$ export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
$ ./Configure android-arm -D__ANDROID_API__=16
$ make

@yan12125, is there any way to backport the fix to the LTS versions (and perhaps an official patch file workaround until then)? We have a dependency on the LTS versions of OpenSSL for our software, and talking to the team that actually makes the software, bumping up to the non-LTS versions AND a beta version carries a lot of risk and work. We cross-compile our software with multiple other platforms (iOS, Windows, Linux, Mac), and your suggested fix makes our Android build the odd man out with what the lead quotes is a “whacko” version of OpenSSL.

I’m currently trying to compile 1.0.2o with clang btw.

FYI: This is fixed since version 1.1.1-pre3 (#5613, #5589)

Can we have this issue re-opened? It was never resolved. The only workaround for now is to use linux-generic32/64 target instead of android or to follow the accepted solution of adding a new target.

The accepted solution looks like it was to create a new android-*-clang target but this was never put in to git and as such the issue still exists. I understand work is underway in #2229

So, this is still broken (tested 1.0.2k and 1.1.0e). Any ideas of a workaround or fix on the horizon?

All android* configure options will give gcc:-mandroid

https://github.com/openssl/openssl/blob/edd689efbfa26a657a5d8310f43a4f11d29a460e/Configurations/10-main.conf#L947

Finally I can run tests on Android for my clang build. I guess this indicates everything is fine?

$ PERL=$(which perl) make test
make depend && make _tests
make[1]: Entering directory '/data/data/com.termux/files/home/openssl'
make[1]: Leaving directory '/data/data/com.termux/files/home/openssl'
make[1]: Entering directory '/data/data/com.termux/files/home/openssl'
( cd test; \
  SRCTOP=../. \
  BLDTOP=../. \
  PERL="/data/data/com.termux/files/usr/bin/perl" \
  EXE_EXT= \
  OPENSSL_ENGINES=.././engines \
    /data/data/com.termux/files/usr/bin/perl .././test/run_tests.pl  )
../test/recipes/01-test_abort.t ............ ok   
../test/recipes/01-test_sanity.t ........... ok   
../test/recipes/01-test_symbol_presence.t .. ok   
../test/recipes/02-test_ordinals.t ......... ok   
../test/recipes/05-test_bf.t ............... ok   
../test/recipes/05-test_cast.t ............. ok   
../test/recipes/05-test_des.t .............. ok   
../test/recipes/05-test_hmac.t ............. ok   
../test/recipes/05-test_idea.t ............. ok   
../test/recipes/05-test_md2.t .............. skipped: md2 is not supported by this OpenSSL build
../test/recipes/05-test_md4.t .............. ok   
../test/recipes/05-test_md5.t .............. ok   
../test/recipes/05-test_mdc2.t ............. ok   
../test/recipes/05-test_rand.t ............. ok   
../test/recipes/05-test_rc2.t .............. ok   
../test/recipes/05-test_rc4.t .............. ok   
../test/recipes/05-test_rc5.t .............. skipped: rc5 is not supported by this OpenSSL build
../test/recipes/05-test_rmd.t .............. ok   
../test/recipes/05-test_sha1.t ............. ok   
../test/recipes/05-test_sha256.t ........... ok   
../test/recipes/05-test_sha512.t ........... ok   
../test/recipes/05-test_wp.t ............... ok   
../test/recipes/10-test_bn.t ............... ok   
../test/recipes/10-test_exp.t .............. ok   
../test/recipes/15-test_dh.t ............... ok   
../test/recipes/15-test_dsa.t .............. ok   
../test/recipes/15-test_ec.t ............... ok   
../test/recipes/15-test_ecdh.t ............. ok   
../test/recipes/15-test_ecdsa.t ............ ok   
../test/recipes/15-test_rsa.t .............. ok   
../test/recipes/20-test_enc.t .............. ok       
../test/recipes/20-test_passwd.t ........... ok     
../test/recipes/25-test_crl.t .............. ok   
../test/recipes/25-test_d2i.t .............. ok     
../test/recipes/25-test_pkcs7.t ............ ok   
../test/recipes/25-test_req.t .............. ok   
../test/recipes/25-test_sid.t .............. ok   
../test/recipes/25-test_verify.t ........... ok       
../test/recipes/25-test_x509.t ............. ok   
../test/recipes/30-test_afalg.t ............ skipped: test_afalg not supported for this build
../test/recipes/30-test_engine.t ........... ok   
../test/recipes/30-test_evp.t .............. ok   
../test/recipes/30-test_evp_extra.t ........ ok   
../test/recipes/30-test_pbelu.t ............ ok   
../test/recipes/40-test_rehash.t ........... ok   
../test/recipes/70-test_asyncio.t .......... ok   
../test/recipes/70-test_bad_dtls.t ......... ok   
../test/recipes/70-test_clienthello.t ...... ok   
../test/recipes/70-test_packet.t ........... ok   
../test/recipes/70-test_sslcbcpadding.t .... ok   
../test/recipes/70-test_sslcertstatus.t .... ok   
../test/recipes/70-test_sslextension.t ..... ok   
../test/recipes/70-test_sslrecords.t ....... ok   
../test/recipes/70-test_sslsessiontick.t ... ok    
../test/recipes/70-test_sslskewith0p.t ..... ok   
../test/recipes/70-test_sslvertol.t ........ ok   
../test/recipes/70-test_tlsextms.t ......... ok   
../test/recipes/70-test_verify_extra.t ..... ok   
../test/recipes/70-test_wpacket.t .......... skipped: Only supported in no-shared builds
../test/recipes/80-test_ca.t ............... Use of uninitialized value in -x at /data/data/com.termux/files/usr/lib/perl5/5.24.0/aarch64-linux/Cwd.pm line 197.
../test/recipes/80-test_ca.t ............... ok   
../test/recipes/80-test_cipherlist.t ....... ok   
../test/recipes/80-test_cms.t .............. ok   
../test/recipes/80-test_ct.t ............... ok   
../test/recipes/80-test_dane.t ............. ok   
../test/recipes/80-test_dtls.t ............. ok   
../test/recipes/80-test_dtlsv1listen.t ..... ok   
../test/recipes/80-test_ocsp.t ............. ok     
../test/recipes/80-test_pkcs12.t ........... Can't exec "locale": No such file or directory at ../test/recipes/80-test_pkcs12.t line 48.
../test/recipes/80-test_pkcs12.t ........... ok   
../test/recipes/80-test_ssl_new.t .......... ok     
../test/recipes/80-test_ssl_old.t .......... ok   
../test/recipes/80-test_ssl_test_ctx.t ..... ok   
../test/recipes/80-test_tsa.t .............. ok     
../test/recipes/80-test_x509aux.t .......... ok   
../test/recipes/90-test_async.t ............ ok   
../test/recipes/90-test_bio_enc.t .......... ok   
../test/recipes/90-test_bioprint.t ......... ok   
../test/recipes/90-test_constant_time.t .... ok   
../test/recipes/90-test_fuzz.t ............. ok     
../test/recipes/90-test_gmdiff.t ........... ok   
../test/recipes/90-test_heartbeat.t ........ skipped: heartbeats is not supported by this OpenSSL build
../test/recipes/90-test_ige.t .............. ok   
../test/recipes/90-test_memleak.t .......... ok   
../test/recipes/90-test_p5_crpt2.t ......... ok   
../test/recipes/90-test_secmem.t ........... ok   
../test/recipes/90-test_srp.t .............. ok   
../test/recipes/90-test_sslapi.t ........... ok   
../test/recipes/90-test_threads.t .......... ok   
../test/recipes/90-test_v3name.t ........... ok   
All tests successful.
Files=88, Tests=488, 763 wallclock secs ( 5.53 usr  0.43 sys + 470.11 cusr 57.18 csys = 533.25 CPU)
Result: PASS
make[1]: Leaving directory '/data/data/com.termux/files/home/openssl'