Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android cross compile autoconf header check #222

Closed
polmr opened this issue Jul 11, 2016 · 11 comments
Closed

android cross compile autoconf header check #222

polmr opened this issue Jul 11, 2016 · 11 comments
Labels

Comments

@polmr
Copy link

polmr commented Jul 11, 2016

Trying to check for crytopp headers, I have this on configure.ac: AC_CHECK_HEADERS(cryptopp/cryptlib.h,, AC_MSG_ERROR([cryptopp/cryptlib.h header not found or not usable]) )
Configure reports error:

checking for libcryptopp... checking cryptopp/cryptlib.h usability... no
checking cryptopp/cryptlib.h presence... yes
configure: WARNING: cryptopp/cryptlib.h: present but cannot be compiled
configure: WARNING: cryptopp/cryptlib.h:     check for missing prerequisite headers?
configure: WARNING: cryptopp/cryptlib.h: see the Autoconf documentation
configure: WARNING: cryptopp/cryptlib.h:     section "Present But Cannot Be Compiled"
configure: WARNING: cryptopp/cryptlib.h: proceeding with the compiler's result
configure: WARNING:     ## -------------------------------------------- ##
configure: WARNING:     ## Report this to ...........................   ##
configure: WARNING:     ## -------------------------------------------- ##
checking for cryptopp/cryptlib.h... no
configure: error: cryptopp/cryptlib.h header not found or not usable

Checking the log, it leads to config.h:

// OK to comment the following out, but please report it so we can fix it.
#if (defined(__cplusplus) && (__cplusplus >= 199711L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE)
# error "std::uncaught_exception is not available. This is likely a configuration error."
#endif

Here are some related environment variables:
ARCH=arm
CXX=.../bin/arm-linux-androideabi-g++

@noloader
Copy link
Collaborator

noloader commented Jul 11, 2016

Thanks @polmr. Please bear with me due to my Autotools ignorance.

I'm guessing the pain point is !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE). Working up config.h to around line 400:

#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__MWERKS__) || (defined(_STLPORT_VERSION) && ((_STLPORT_VERSION < 0x450) || defined(_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT)))
#define CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION
#endif

#ifndef CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION
#define CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE
#endif

I'm guessing the culprit is STLport, and _STLPORT_VERSION. Would you happen to know:

  • Are you using STLport or GNU STL library?
  • What value of _STLPORT_VERSION?
  • Does STLport defines _STLP_NO_UNCAUGHT_EXCEPT_SUPPORT

If the defines are completely missing, then I would venture a guess:

  1. No STL library is specified
  2. The file is being tested as C file, and not a C++ file
  3. The STL library is not included during the header check

For item (1) and Crypto++ procedures, our setenv-android.sh script uses STLport by default, but allows selection of GNU. I don't know how to convert it to Autotools.

For item (2), I'm guessing a C++ compiler is all that's needed. Or maybe add -x c++ to force the treatment to C++. Be careful of -x c++ because it sometimes causes deprecated warnings, IIRC.

For item (3), you might be able to "force include" a header like <ios_fwd> with GCC using option -include. That will ensure STL library defines are present.

@noloader
Copy link
Collaborator

noloader commented Jul 11, 2016

Thanks again @polmr. Here's what a typical compile looks like using our Android procedures and our setenv-android.sh script. It may help guide you when back fitting Autotools. Notice we always need a AOSP_STL_INC and AOSP_STL_LIB for every configuration we get into. IF its GNU STL, then we also need AOSP_BITS_INC. AOSP_BITS_INC is the path to <bitops> or <bitops.h>, and its not on path by default (IIRC).

You should also have a look at our wiki page with the procedures at Android (Command_Line). The page provides the CXXFLAGS used by Android's build system. It may save you some time from looking them up yourself.

cryptopp$ . ./setenv-android.sh 
ANDROID_NDK_ROOT: /opt/android-ndk
AOSP_TOOLCHAIN_PATH: /opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin
AOSP_ABI: armeabi
AOSP_API: android-21
AOSP_SYSROOT: /opt/android-ndk/platforms/android-21/arch-arm
AOSP_FLAGS: -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti
AOSP_STL_INC: /opt/android-ndk/sources/cxx-stl/stlport/stlport/
AOSP_STL_LIB: /opt/android-ndk/sources/cxx-stl/stlport/libs/armeabi/libstlport_shared.so

*******************************************************************************
It looks the the environment is set correctly. Your next step is
build the library with 'make -f GNUmakefile-cross'
*******************************************************************************

cryptopp$ make -f GNUmakefile-cross 
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti -DANDROID --sysroot=/opt/android-ndk/platforms/android-21/arch-arm -Wa,--noexecstack -I/opt/android-ndk/sources/cxx-stl/stlport/stlport/ -c cryptlib.cpp
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti -DANDROID --sysroot=/opt/android-ndk/platforms/android-21/arch-arm -Wa,--noexecstack -I/opt/android-ndk/sources/cxx-stl/stlport/stlport/ -c cpu.cpp
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti -DANDROID --sysroot=/opt/android-ndk/platforms/android-21/arch-arm -Wa,--noexecstack -I/opt/android-ndk/sources/cxx-stl/stlport/stlport/ -c shacal2.cpp
...

If you want ARMv7a and GNU STL, then something like the following will probably do:

$ . ./setenv-android.sh armv7a gnu
ANDROID_NDK_ROOT: /opt/android-ndk
AOSP_TOOLCHAIN_PATH: /opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin
AOSP_ABI: armeabi-v7a
AOSP_API: android-21
AOSP_SYSROOT: /opt/android-ndk/platforms/android-21/arch-arm
AOSP_FLAGS: -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti
AOSP_STL_INC: /opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include
AOSP_STL_LIB: /opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_shared.so
AOSP_BITS_INC: /opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include

*******************************************************************************
It looks the the environment is set correctly. Your next step is
build the library with 'make -f GNUmakefile-cross'
*******************************************************************************

@noloader
Copy link
Collaborator

noloader commented Jul 11, 2016

I should probably comment on this:

ARCH=arm
CXX=.../bin/arm-linux-androideabi-g++

Crypto++'s GNUmakefile-cross does not use ARCH. Crypto++'s GNUmakefile-cross does honor CXX. ARM is discovered from preprocessor macro definitions.

When cross compiling with Autotools (always a treat), the user typically specifies the triplet that includes host and target:

./configure --host=x86_64-darwin --build=arm --with-sysroot=$SYSROOT

Keep in mind you still must get the STL header inserted into CXXFLAGS, and the STL lib inserted into LDLIBS. Maybe something like:

export CXXFLAGS="-DNDEBUG -g2 -O2 -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti -I/opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include"
export LDLIBS="/opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_shared.so"
export SYSROOT: /opt/android-ndk/platforms/android-21/arch-arm
./configure --host=x86_64-darwin --build=arm --with-sysroot=$SYSROOT

Autotools is not for the feint of heart when cross-compiling for Android. Also see Convey C++ STL library for Android?, How To Configure for Android? and How To Configure for Android? (Redux for x86_64) on the Autoconf mailing list. I know about them because I already suffered them :)

@noloader
Copy link
Collaborator

noloader commented Jul 12, 2016

@polmr, Is there anything else we can do for you here?

Also, the user group is located at Crypto++ Users Group.

@polmr
Copy link
Author

polmr commented Jul 12, 2016

Hi @noloader, thank you for your support!
I'm using STLport, If I'm not mistake it is version 5.2.0

STLport defines _STLP_NO_UNCAUGHT_EXCEPT_SUPPORT at host.h but it might be undef later on.

The thing is that... I don't have any problem compiling is just the header check in configure.

Adding -x c++ to CXXFLAGS makes no difference.

@polmr
Copy link
Author

polmr commented Jul 12, 2016

I've found out that the problem is not !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE) but the value of __cplusplus.

Changing
#if (defined(__cplusplus) && (__cplusplus >= 199711L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE)
for
#if (defined(__cplusplus) && (__cplusplus < 199711L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE)
Solves the issue.

In the end std:uncaught_exception exists in c++98. Maybe it should also check that c++ < c++17 since uncaught_exception is supposed to be deprecated for the upcoming c++17 (http://en.cppreference.com/w/cpp/error/uncaught_exception)

@noloader
Copy link
Collaborator

noloader commented Jul 12, 2016

@polmr, I might be missing something, but I think there's something not quite right about the Autotools test. Below, android-23 is Marshmallow from NDK r11c, and it does not have any problems.

$ . ./setenv-android.sh 
ANDROID_NDK_ROOT: /opt/android-ndk
AOSP_TOOLCHAIN_PATH: /opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin
AOSP_ABI: armeabi
AOSP_API: android-23
AOSP_SYSROOT: /opt/android-ndk/platforms/android-23/arch-arm
AOSP_FLAGS: -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti
AOSP_STL_INC: /opt/android-ndk/sources/cxx-stl/stlport/stlport/
AOSP_STL_LIB: /opt/android-ndk/sources/cxx-stl/stlport/libs/armeabi/libstlport_shared.so

*******************************************************************************
It looks the the environment is set correctly. Your next step is
build the library with 'make -f GNUmakefile-cross'
*******************************************************************************

$ make -f GNUmakefile-cross 
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti -DANDROID --sysroot=/opt/android-ndk/platforms/android-23/arch-arm -Wa,--noexecstack -I/opt/android-ndk/sources/cxx-stl/stlport/stlport/ -c cryptlib.cpp
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti -DANDROID --sysroot=/opt/android-ndk/platforms/android-23/arch-arm -Wa,--noexecstack -I/opt/android-ndk/sources/cxx-stl/stlport/stlport/ -c cpu.cpp
...

Changing
#if (defined(__cplusplus) && (__cplusplus >= 199711L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE)
for
#if (defined(__cplusplus) && (__cplusplus < 199711L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE)
Solves the issue.

If I am parsing things correctly, that only inverts the test. It make failures appear to succeed, and successes appear to fail.

I think the real issue is Autotools does not have an STL library available when it performs its tests. The Autotools folks need to say how to specify a C++ STL library with the header check.

If I knew how to do it, then I would tell you. Unfortunately, I don't know how to do it, so I depend on the Autotools folks like you.


std:uncaught_exception exists in c++98. Maybe it should also check that c++ < c++17 since uncaught_exception is supposed to be deprecated for the upcoming c++17

Thank you very much. We need to account for that.

it looks like that value is in flux at the moment (If I am parsing LLVM's patch correctly):

+    // FIXME: Use correct value for C++17.
+    if (LangOpts.CPlusPlus1z)
+      Builder.defineMacro("__cplusplus", "201406L");

@noloader
Copy link
Collaborator

noloader commented Jul 12, 2016

@polmr,

std:uncaught_exception exists in c++98. Maybe it should also check that c++ < c++17 since uncaught_exception is supposed to be deprecated for the upcoming c++17

Thank you very much. We need to account for that.

We added the C++17 guard on the #error at Commit ebef1f418b312590. I think more needs to be done, but I need to see the interactions to ensure the actions are correct.

We are actively testing C++17 with both -std=c++17 and -std=gnu17 in cryptest.sh. We have not seen any problems, which does not mean there are none. It may indicate the compilers are still providing std::uncaught_exception.

@noloader
Copy link
Collaborator

noloader commented Jul 13, 2016

@polmr, I tested with android-ndk-r12b, but I cannot reproduce the issue.

$ ANDROID_NDK_ROOT=/opt/android-ndk-r12b AOSP_API=android-23 . ./setenv-android.sh 
ANDROID_NDK_ROOT: /opt/android-ndk-r12b
AOSP_TOOLCHAIN_PATH: /opt/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin
AOSP_ABI: armeabi
AOSP_API: android-23
AOSP_SYSROOT: /opt/android-ndk-r12b/platforms/android-23/arch-arm
AOSP_FLAGS: -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti
AOSP_STL_INC: /opt/android-ndk-r12b/sources/cxx-stl/stlport/stlport/
AOSP_STL_LIB: /opt/android-ndk-r12b/sources/cxx-stl/stlport/libs/armeabi/libstlport_shared.so

*******************************************************************************
It looks the the environment is set correctly. Your next step is
build the library with 'make -f GNUmakefile-cross'
*******************************************************************************

$ make -f GNUmakefile-cross
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti -DANDROID --sysroot=/opt/android-ndk-r12b/platforms/android-23/arch-arm -Wa,--noexecstack -I/opt/android-ndk-r12b/sources/cxx-stl/stlport/stlport/ -c cryptlib.cpp
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe -march=armv5te -mtune=xscale -mthumb -msoft-float -funwind-tables -fexceptions -frtti -DANDROID --sysroot=/opt/android-ndk-r12b/platforms/android-23/arch-arm -Wa,--noexecstack -I/opt/android-ndk-r12b/sources/cxx-stl/stlport/stlport/ -c cpu.cpp
...

I think your best bet is to liaise with the Autotools folks to determine how to specify the STL library under Android.

Is there anything else we can try to assist with?

@noloader
Copy link
Collaborator

noloader commented Jul 15, 2016

@polmr, despite my sincerest efforts to work with the Autoconf folks to find a solution, I can't come up with one. The Autoconf folks seem a bit unwilling to help us with the issue.

Please work directly with the Autoconf folks on this issue.

If you develop a patch that addresses the failure without degrading the existing tests for existing clients, then please supply a pull request. I'd be happy to incorporate it. I'll even write a wiki page for you pointing to your work for folks who want to use Autoconf rather than GNUmakefile.

@polmr
Copy link
Author

polmr commented Jul 20, 2016

In the end it was the _STLPORT_VERSION value: in my case when cross-compiling is defined and valuated as:
#define _STLPORT_VERSION 0x521.

Therefore the check at config.h ( using latest release cryptopp563 or cryptopp562) evaluates as true:
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(MWERKS) || defined(_STLPORT_VERSION)
#define CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION
#endif

I've seen it is "solved" in 1e17620,
The check is now:
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(MWERKS) || (defined(_STLPORT_VERSION) && ((_STLPORT_VERSION < 0x450) || defined(_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT)))
(in my case it wouldn't enter the if)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants