Commit e80e45ba authored by David 'Digit' Turner's avatar David 'Digit' Turner
Browse files

Do not force exceptions and rtti when using GNU libstdc++

This patch changes the default exported flags for both
gnustl_static and gnustl_shared. Previously, they were always
set to -fexceptions and -frtti, but this resulted in a few
problems.

Now, the flags are empty by default, but you can use
APP_GNUSTL_FORCE_CPP_FEATURES in your Application.mk to
revert to the old behaviour, in case you need it.

+ Add four unit tests to check that the build system works
  correctly with regards to this new variable definition

+ Documentation updates.

+ Modify tests/run-tests.sh to recognize a 'BUILD_SHOULD_FAIL'
  tag in a unit test directory. If such a file is present,
  the build _should_ fail for the test to pass.

  This is required because there is no way to reliably detect
  at compile time that -frtti is _not_ used, so we actually
  require the opposite from our unit test sources.
  (see gnustl-force-none and gnustl-force-exceptions).

Change-Id: Ia6fd236284c942bc0cb8fc0b49d9344ab68fe7ee
parent 42e10796
......@@ -173,6 +173,35 @@ APP_STL
For more information on the subject, please read docs/CPLUSPLUS-SUPPORT.html
APP_GNUSTL_FORCE_CPP_FEATURES
In prior NDK versions, the simple fact of using the GNU libstdc++
runtime (i.e. by setting APP_STL to either 'gnustl_static' or
'gnustl_shared') enforced the support for exceptions and RTTI in all
generated machine code. This could be problematic in specific, but rare,
cases, and also generated un-necessarily bigger code for projects that
don't require these features.
This bug was fixed in NDK r7b, but this means that if your code requires
exceptions or RTTI, it should now explicitely say so, either in your
APP_CPPFLAGS, or your LOCAL_CPPFLAGS / LOCAL_CPP_FEATURES definitions.
To make it easier to port projects to NDK r7b and later, one can
optionally defined APP_GNUSTL_CPP_FEATURES to contain one or more of the
following values:
exceptions -> to enforce exceptions support for all modules.
rtti -> to enforce rtti support for all modules.
For example, to get the exact same behaviour than NDK r7:
APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti
IMPORTANT: This variable is provided here as a convenience to make it
easier to transition to a newer version of the NDK. It will
be removed in a future revision. We thus encourage all
developers to modify the module definitions properly instead
of relying on it here.
A trivial Application.mk file would be:
-------------- cut here -------------------------
......
......@@ -46,6 +46,18 @@ IMPORTANT BUG FIXES:
OTHER CHANGES:
- When your application uses the GNU libstdc++ runtime, the compiler will
no longer forcibly enable exceptions and RTTI. This will result in smaller
code.
If you need these features, you need to do either one of these:
1/ Enable exceptions and/or RTTI explicitely in your modules or
Application.mk (recommended)
2/ Define APP_GNUSTL_FORCE_CPP_FEATURES to 'exceptions', 'rtti' or both
in your Application.mk. See docs/APPLICATION-MK.html for more details.
- ndk-gdb now works properly when your application has private services
running in independent processes. More specifically it will debug the
main application process, instead of the first process listed by 'ps'
......
......@@ -86,7 +86,7 @@ If you insist on using it, read the "RTTI Support" and
I.3. STLport runtime:
- - - - - - - - - - -
- - - - - - - - - - -
This is a port of STLport (http://www.stlport.org) that can be used on
Android. It will provide you with a complete set of C++ standard library
......@@ -192,7 +192,7 @@ This is likely to result in code that doesn't work correctly, for example:
- exceptions raised in libfoo.so cannot be caught in libbar.so (and may
simply crash the program).
- the buffering of cout not working properly
- the buffering of std::cout not working properly
This problem also happens if you want to link an executable and a shared
library to the same static library.
......@@ -253,8 +253,7 @@ IV. Future Plans:
-----------------
- Add exceptions support to GAbi++
- Make STLport use GAbi++ to gain RTTI support (and potentially exceptions too)
- Shared GNU libstdc++ support
- Add exceptions support to STLport (once it is in GAbi++)
- uSTL support?
</pre></body></html>
LOCAL_PATH := $(call my-dir)
# Compute the compiler flags to export by the module.
# This is controlled by the APP_GNUSTL_FORCE_CPP_FEATURES variable.
# See docs/APPLICATION-MK.html for all details.
#
gnustl_exported_cppflags := $(strip \
$(if $(filter exceptions,$(APP_GNUSTL_FORCE_CPP_FEATURES)),-fexceptions)\
$(if $(filter rtti,$(APP_GNUSTL_FORCE_CPP_FEATURES)),-frtti))
# Include path to export
gnustl_exported_c_includes := $(LOCAL_PATH)/include $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/include
include $(CLEAR_VARS)
LOCAL_MODULE := gnustl_static
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libgnustl_static.a
LOCAL_EXPORT_CPPFLAGS := -fexceptions -frtti
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include \
$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/include
LOCAL_EXPORT_CPPFLAGS := $(gnustl_exported_cppflags)
LOCAL_EXPORT_C_INCLUDES := $(gnustl_exported_c_includes)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gnustl_shared
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libgnustl_shared.so
LOCAL_EXPORT_CPPFLAGS := -fexceptions -frtti
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include \
$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/include
LOCAL_EXPORT_CPPFLAGS := $(gnustl_exported_cppflags)
LOCAL_EXPORT_C_INCLUDES := $(gnustl_exported_c_includes)
LOCAL_EXPORT_LDLIBS := $(call host-path,$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libsupc++.a)
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test_gnustl_forced_all
LOCAL_SRC_FILES := forced_all.cpp
include $(BUILD_EXECUTABLE)
APP_STL := gnustl_static
APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti
/* This file should be compiled with exceptions and without RTTI */
#ifndef __EXCEPTIONS
#error This source file SHOULD be built with -fexceptions!
#endif
#include <typeinfo>
#include <stdio.h>
class Foo { int x; };
int main(void) {
printf("%p\n", typeid(Foo)); // will fail without -frtti
return 0;
}
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test_gnustl_forced_exceptions
LOCAL_SRC_FILES := forced_exceptions.cpp
include $(BUILD_EXECUTABLE)
APP_STL := gnustl_static
APP_GNUSTL_FORCE_CPP_FEATURES := exceptions
// This file should FAIL to build iff exceptions are enabled and RTTI is disabled
#ifndef __EXCEPTIONS
int main(void) { return 0; }
#else // !exceptions
#include <typeinfo>
#include <stdio.h>
class Foo { int x; };
int main(void) {
printf("%p\n", typeid(Foo)); // will fail without -frtti
return 0;
}
#endif
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test_gnustl_force_none
LOCAL_SRC_FILES := force_none.cpp
include $(BUILD_EXECUTABLE)
APP_STL := gnustl_static
APP_GNUSTL_FORCE_CPP_FEATURES := # empty
\ No newline at end of file
// This program should FAIL to build iff exceptions and RTTI are disabled.
#ifdef __EXCEPTIONS
// can't fail to build here
int main(void) { return 0; }
#else // !exceptions
#include <typeinfo>
#include <stdio.h>
class Foo { int x; };
int main(void) {
printf("%p\n", typeid(Foo)); // will fail with RTTI
return 0;
}
#endif
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test_gnustl_forced_rtti
LOCAL_SRC_FILES := forced_rtti.cpp
include $(BUILD_EXECUTABLE)
APP_STL := gnustl_static
APP_GNUSTL_FORCE_CPP_FEATURES := rtti
\ No newline at end of file
/* This file should be compiled without exceptions and with RTTI */
#ifdef __EXCEPTIONS
#error This source file SHOULD NOT be built with -fexceptions!
#endif
#include <typeinfo>
#include <stdio.h>
class Foo { int x; };
int main(void) {
printf("%p\n", typeid(Foo)); // will fail without -frtti
return 0;
}
APP_STL := gnustl_shared
APP_ABI := all
APP_CPPFLAGS := -fexceptions
......@@ -405,7 +405,16 @@ build_project ()
fi
rm -rf "$DIR" && cp -r "$1" "$DIR"
(cd "$DIR" && run_ndk_build $NDK_BUILD_FLAGS)
if [ $? != 0 ] ; then
RET=$?
if [ -f "$1/BUILD_SHOULD_FAIL" ]; then
if [ $RET = 0 ]; then
echo "!!! FAILURE: BUILD SHOULD HAVE FAILED [$1]"
exit 1
fi
log "!!! SUCCESS: BUILD FAILED AS EXPECTED [$(basename $1)]"
RET=0
fi
if [ $RET != 0 ] ; then
echo "!!! BUILD FAILURE [$1]!!! See $NDK_LOGFILE for details or use --verbose option!"
exit 1
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment