aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2011-09-29 20:07:30 +0200
committerDavid 'Digit' Turner <digit@google.com>2011-09-30 02:37:26 +0200
commitc8f9439673c9d115c94fb4f6d1f1954ef02f0e11 (patch)
tree605f802fe61d282eb5f4f1fe3e722e671c40685b
parentbb499f5b912cd9d0c8e028a7c6bc67a384b77907 (diff)
downloadndk-c8f9439673c9d115c94fb4f6d1f1954ef02f0e11.tar.gz
Make STLPort support RTTI through GAbi++
This patch modifies our build of stlport to include the GAbi++ runtime in order to support RTTI. Change-Id: I8ff1853ad886e217f3d0d8a9366fc5075c63cc34
-rwxr-xr-xbuild/tools/build-stlport.sh25
-rw-r--r--build/tools/builder-funcs.sh15
-rw-r--r--sources/cxx-stl/gabi++/Android.mk22
-rw-r--r--sources/cxx-stl/gabi++/sources.mk18
-rw-r--r--sources/cxx-stl/stlport/Android.mk32
-rw-r--r--sources/cxx-stl/stlport/stlport/stl/config/_android.h8
-rw-r--r--tests/build/prebuild-stlport/jni/Application.mk2
-rw-r--r--tests/device/test-stlport-rtti/README2
-rw-r--r--tests/device/test-stlport-rtti/jni/Android.mk6
-rw-r--r--tests/device/test-stlport-rtti/jni/Application.mk8
-rw-r--r--tests/device/test-stlport-rtti/jni/test_stlport_rtti.cpp105
11 files changed, 200 insertions, 43 deletions
diff --git a/build/tools/build-stlport.sh b/build/tools/build-stlport.sh
index 48f564867..37544fe29 100755
--- a/build/tools/build-stlport.sh
+++ b/build/tools/build-stlport.sh
@@ -89,15 +89,17 @@ fi
mkdir -p "$BUILD_DIR"
fail_panic "Could not create build directory: $BUILD_DIR"
+GABIXX_SRCDIR=$ANDROID_NDK_ROOT/$GABIXX_SUBDIR
+GABIXX_CFLAGS="-O2 -DANDROID -D__ANDROID__ -I$GABIXX_SRCDIR/include"
+GABIXX_CXXFLAGS="-fno-exceptions -frtti"
+GABIXX_SOURCES=$(cd $ANDROID_NDK_ROOT/$GABIXX_SUBDIR && ls src/*.cc)
+GABIXX_LDFLAGS="-lstdc++"
+
# Location of the STLPort source tree
STLPORT_SRCDIR=$ANDROID_NDK_ROOT/$STLPORT_SUBDIR
-
-# Compiler flags we want to use
STLPORT_CFLAGS="-DGNU_SOURCE -fPIC -O2 -I$STLPORT_SRCDIR/stlport -DANDROID -D__ANDROID__"
-STLPORT_CFLAGS=$STLPORT_CFLAGS" -I$ANDROID_NDK_ROOT/sources/cxx-stl/system/include"
-STLPORT_CXXFLAGS="-fuse-cxa-atexit -fno-exceptions -fno-rtti"
-
-# List of sources to compile
+STLPORT_CFLAGS=$STLPORT_CFLAGS" -I$ANDROID_NDK_ROOT/$GABIXX_SUBDIR/include"
+STLPORT_CXXFLAGS="-fuse-cxa-atexit -fno-exceptions -frtti"
STLPORT_SOURCES=\
"src/dll_main.cpp \
src/fstream.cpp \
@@ -160,10 +162,19 @@ build_stlport_libs_for_abi ()
mkdir -p "$DSTDIR"
builder_begin_android $ABI "$BUILDDIR" "$MAKEFILE"
- builder_set_srcdir "$STLPORT_SRCDIR"
+
builder_set_dstdir "$DSTDIR"
+ builder_set_srcdir "$GABIXX_SRCDIR"
+ builder_cflags "$GABIXX_CFLAGS"
+ builder_cxxflags "$GABIXX_CXXFLAGS"
+ builder_ldflags "$GABIXX_LDFLAGS"
+ builder_sources $GABIXX_SOURCES
+
+ builder_set_srcdir "$STLPORT_SRCDIR"
+ builder_reset_cflags
builder_cflags "$STLPORT_CFLAGS"
+ builder_reset_cxxflags
builder_cxxflags "$STLPORT_CXXFLAGS"
builder_sources $STLPORT_SOURCES
diff --git a/build/tools/builder-funcs.sh b/build/tools/builder-funcs.sh
index 702099d5b..c9544a390 100644
--- a/build/tools/builder-funcs.sh
+++ b/build/tools/builder-funcs.sh
@@ -165,6 +165,21 @@ builder_c_includes ()
_builder_varadd _BUILD_C_INCLUDES $@
}
+builder_reset_cflags ()
+{
+ _BUILD_CFLAGS=
+}
+
+builder_reset_cxxflags ()
+{
+ _BUILD_CXXFLAGS=
+}
+
+builder_reset_c_includes ()
+{
+ _BUILD_C_INCLUDES=
+}
+
builder_link_with ()
{
local LIB
diff --git a/sources/cxx-stl/gabi++/Android.mk b/sources/cxx-stl/gabi++/Android.mk
index c88569b52..56c8bd318 100644
--- a/sources/cxx-stl/gabi++/Android.mk
+++ b/sources/cxx-stl/gabi++/Android.mk
@@ -1,21 +1,6 @@
LOCAL_PATH:= $(call my-dir)
-libgabi++_common_src_files := \
- src/array_type_info.cc \
- src/class_type_info.cc \
- src/delete.cc \
- src/dynamic_cast.cc \
- src/enum_type_info.cc \
- src/function_type_info.cc \
- src/new.cc \
- src/pbase_type_info.cc \
- src/pointer_type_info.cc \
- src/pointer_to_member_type_info.cc \
- src/si_class_type_info.cc \
- src/type_info.cc \
- src/vmi_class_type_info.cc
-
-libgabi++_c_includes := $(LOCAL_PATH)/include
+include $(LOCAL_PATH)/sources.mk
ifneq (,$(GABIXX_FORCE_REBUILD))
@@ -44,7 +29,7 @@ else # ! GABIXX_FORCE_REBUILD
include $(CLEAR_VARS)
LOCAL_MODULE:= libgabi++_shared
LOCAL_CPP_EXTENSION := .cc
- LOCAL_SRC_FILES:= $(libgabi++_common_src_files)
+ LOCAL_SRC_FILES:= $(libgabi++_src_files)
LOCAL_EXPORT_C_INCLUDES := $(libgabi++_c_includes)
LOCAL_EXPORT_LDLIBS := -lstdc++
LOCAL_C_INCLUDES := $(libgabi++_c_includes)
@@ -55,7 +40,7 @@ else # ! GABIXX_FORCE_REBUILD
#
include $(CLEAR_VARS)
LOCAL_MODULE:= libgabi++_static
- LOCAL_SRC_FILES:= $(libgabi++_common_src_files)
+ LOCAL_SRC_FILES:= $(libgabi++_src_files)
LOCAL_CPP_EXTENSION := .cc
LOCAL_EXPORT_C_INCLUDES := $(libgabi++_c_includes)
LOCAL_EXPORT_LDLIBS := -lstdc++
@@ -64,4 +49,3 @@ else # ! GABIXX_FORCE_REBUILD
include $(BUILD_STATIC_LIBRARY)
endif # ! GABIXX_FORCE_REBUILD
-
diff --git a/sources/cxx-stl/gabi++/sources.mk b/sources/cxx-stl/gabi++/sources.mk
new file mode 100644
index 000000000..bc419f2d8
--- /dev/null
+++ b/sources/cxx-stl/gabi++/sources.mk
@@ -0,0 +1,18 @@
+libgabi++_path := $(call my-dir)
+
+libgabi++_src_files := \
+ src/array_type_info.cc \
+ src/class_type_info.cc \
+ src/delete.cc \
+ src/dynamic_cast.cc \
+ src/enum_type_info.cc \
+ src/function_type_info.cc \
+ src/new.cc \
+ src/pbase_type_info.cc \
+ src/pointer_type_info.cc \
+ src/pointer_to_member_type_info.cc \
+ src/si_class_type_info.cc \
+ src/type_info.cc \
+ src/vmi_class_type_info.cc
+
+libgabi++_c_includes := $(libgabi++_path)/include
diff --git a/sources/cxx-stl/stlport/Android.mk b/sources/cxx-stl/stlport/Android.mk
index b0a67691f..ffae0d8a5 100644
--- a/sources/cxx-stl/stlport/Android.mk
+++ b/sources/cxx-stl/stlport/Android.mk
@@ -14,7 +14,7 @@ ifndef STLPORT_FORCE_REBUILD
endif
endif
-libstlport_path := $(call my-dir)
+libstlport_path := $(LOCAL_PATH)
libstlport_src_files := \
src/dll_main.cpp \
@@ -54,10 +54,17 @@ libstlport_cflags := -D_GNU_SOURCE
libstlport_cppflags := -fuse-cxa-atexit
libstlport_c_includes := $(libstlport_path)/stlport
-# Note: For now, this implementation depends on the system libstdc++
-# We may want to avoid that in the future, i.e. in order to
-# properly support exceptions and RTTI.
-libstlport_static_libs := libstdc++
+#It is much more practical to include the sources of GAbi++ in our builds
+# of STLport. This is similar to what the GNU libstdc++ does (it includes
+# its own copy of libsupc++)
+#
+# This simplifies usage, since you only have to list a single library
+# as a dependency, instead of two, especially when using the standalone
+# toolchain.
+#
+include $(dir $(LOCAL_PATH))/gabi++/sources.mk
+
+libstlport_c_includes += $(libgabi++_c_includes)
ifneq ($(STLPORT_FORCE_REBUILD),true)
@@ -66,15 +73,15 @@ $(call ndk_log,Using prebuilt STLport libraries)
include $(CLEAR_VARS)
LOCAL_MODULE := stlport_static
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).a
-LOCAL_STATIC_LIBRARIES := $(libstlport_static_libs)
LOCAL_EXPORT_C_INCLUDES := $(libstlport_c_includes)
+LOCAL_CPP_FEATURES := rtti
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := stlport_shared
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE).so
-LOCAL_STATIC_LIBRARIES := $(libstlport_static_libs)
LOCAL_EXPORT_C_INCLUDES := $(libstlport_c_includes)
+LOCAL_CPP_FEATURES := rtti
include $(PREBUILT_SHARED_LIBRARY)
else # STLPORT_FORCE_REBUILD == true
@@ -83,25 +90,26 @@ $(call ndk_log,Rebuilding STLport libraries from sources)
include $(CLEAR_VARS)
LOCAL_MODULE := stlport_static
+LOCAL_CPP_EXTENSION := .cpp .cc
LOCAL_SRC_FILES := $(libstlport_src_files)
+LOCAL_SRC_FILES += $(libgabi++_src_files:%=../gabi++/%)
LOCAL_CFLAGS := $(libstlport_cflags)
LOCAL_CPPFLAGS := $(libstlport_cppflags)
LOCAL_C_INCLUDES := $(libstlport_c_includes)
-LOCAL_STATIC_LIBRARIES := $(libstlport_static_libs)
LOCAL_EXPORT_C_INCLUDES := $(libstlport_c_includes)
+LOCAL_CPP_FEATURES := rtti
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := stlport_shared
+LOCAL_CPP_EXTENSION := .cpp .cc
LOCAL_SRC_FILES := $(libstlport_src_files)
+LOCAL_SRC_FILES += $(libgabi++_src_files:%=../gabi++/%)
LOCAL_CFLAGS := $(libstlport_cflags)
LOCAL_CPPFLAGS := $(libstlport_cppflags)
LOCAL_C_INCLUDES := $(libstlport_c_includes)
-LOCAL_STATIC_LIBRARIES := $(libstlport_static_libs)
LOCAL_EXPORT_C_INCLUDES := $(libstlport_c_includes)
+LOCAL_CPP_FEATURES := rtti
include $(BUILD_SHARED_LIBRARY)
endif # STLPORT_FORCE_REBUILD == true
-
-# See above not above libstdc++ dependency.
-$(call import-module,cxx-stl/system)
diff --git a/sources/cxx-stl/stlport/stlport/stl/config/_android.h b/sources/cxx-stl/stlport/stlport/stl/config/_android.h
index a9f1cd88f..6cf08f224 100644
--- a/sources/cxx-stl/stlport/stlport/stl/config/_android.h
+++ b/sources/cxx-stl/stlport/stlport/stl/config/_android.h
@@ -15,8 +15,8 @@
// Use unix for streams
#define _STLP_USE_UNIX_IO 1
-// No rtti support
-#define _STLP_NO_RTTI 1
+// We do have rtti support now through GAbi++
+#undef _STLP_NO_RTTI
// C library is in the global namespace.
#define _STLP_VENDOR_GLOBAL_CSTD 1
@@ -56,8 +56,8 @@
// Define how to include our native headers.
#define _STLP_NATIVE_HEADER(header) <usr/include/header>
#define _STLP_NATIVE_C_HEADER(header) <../include/header>
-#define _STLP_NATIVE_CPP_C_HEADER(header) <../../system/include/header>
-#define _STLP_NATIVE_CPP_RUNTIME_HEADER(header) <../../system/include/header>
+#define _STLP_NATIVE_CPP_C_HEADER(header) <../../gabi++/include/header>
+#define _STLP_NATIVE_CPP_RUNTIME_HEADER(header) <../../gabi++/include/header>
#define _STLP_NATIVE_OLD_STREAMS_HEADER(header) <usr/include/header>
// Include most of the gcc settings.
diff --git a/tests/build/prebuild-stlport/jni/Application.mk b/tests/build/prebuild-stlport/jni/Application.mk
index 3f203d45c..84f146f88 100644
--- a/tests/build/prebuild-stlport/jni/Application.mk
+++ b/tests/build/prebuild-stlport/jni/Application.mk
@@ -1,4 +1,4 @@
# We want to build support for all ARM ABIs
# This can be overriden by build/tools/rebuild-stlport.sh though
-APP_ABI := armeabi armeabi-v7a
+APP_ABI := all
STLPORT_FORCE_REBUILD := true \ No newline at end of file
diff --git a/tests/device/test-stlport-rtti/README b/tests/device/test-stlport-rtti/README
new file mode 100644
index 000000000..14dfe0c2e
--- /dev/null
+++ b/tests/device/test-stlport-rtti/README
@@ -0,0 +1,2 @@
+This test is meant to test the RTTI support when linking to STLport
+
diff --git a/tests/device/test-stlport-rtti/jni/Android.mk b/tests/device/test-stlport-rtti/jni/Android.mk
new file mode 100644
index 000000000..9744b7af4
--- /dev/null
+++ b/tests/device/test-stlport-rtti/jni/Android.mk
@@ -0,0 +1,6 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := test_stlport_rtti
+LOCAL_SRC_FILES := test_stlport_rtti.cpp
+include $(BUILD_EXECUTABLE)
diff --git a/tests/device/test-stlport-rtti/jni/Application.mk b/tests/device/test-stlport-rtti/jni/Application.mk
new file mode 100644
index 000000000..1032bbd1b
--- /dev/null
+++ b/tests/device/test-stlport-rtti/jni/Application.mk
@@ -0,0 +1,8 @@
+# Note: by default, build for all supported ABIs
+# build.sh in the project tree will check
+# all generated files to ensure that none
+# was forgotten.
+#
+APP_ABI := all
+
+APP_STL := stlport_shared
diff --git a/tests/device/test-stlport-rtti/jni/test_stlport_rtti.cpp b/tests/device/test-stlport-rtti/jni/test_stlport_rtti.cpp
new file mode 100644
index 000000000..3ca3371d4
--- /dev/null
+++ b/tests/device/test-stlport-rtti/jni/test_stlport_rtti.cpp
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <typeinfo>
+#include <cstdio>
+
+using namespace std;
+
+class Foo
+{
+public:
+ virtual ~Foo() { }
+ virtual void print()
+ {
+ std::printf("in Foo!\n");
+ }
+};
+
+class Bar: public Foo
+{
+ public:
+ void print()
+ {
+ std::printf("in Bar!\n");
+ }
+};
+
+struct Base {};
+struct Derived : Base {};
+struct Poly_Base {virtual void Member(){}};
+struct Poly_Derived: Poly_Base {};
+
+#define CHECK(cond) \
+ do { \
+ if (!(cond)) { \
+ fprintf(stderr, "KO: Assertion failure: %s\n", #cond); \
+ fail++;\
+ }\
+ } while (0)
+
+int main()
+{
+ int fail = 0;
+ Foo* foo = new Bar();
+ Bar* bar;
+
+ // built-in types:
+ int i;
+ int * pi;
+
+ CHECK(typeid(int) == typeid(i));
+ CHECK(typeid(int*) == typeid(pi));
+ CHECK(typeid(int) == typeid(*pi));
+
+ printf("int is: %s\n", typeid(int).name());
+ printf(" i is: %s\n", typeid(i).name());
+ printf(" pi is: %s\n", typeid(pi).name());
+ printf("*pi is: %s\n", typeid(*pi).name());
+
+ // non-polymorphic types:
+ Derived derived;
+ Base* pbase = &derived;
+
+ CHECK(typeid(derived) == typeid(Derived));
+ CHECK(typeid(pbase) == typeid(Base*));
+ CHECK(typeid(&derived) == typeid(Derived*));
+
+ printf("derived is: %s\n", typeid(derived).name());
+ printf(" *pbase is: %s\n", typeid(*pbase).name());
+
+ // polymorphic types:
+ Poly_Derived polyderived;
+ Poly_Base* ppolybase = &polyderived;
+
+ CHECK(typeid(polyderived) == typeid(Poly_Derived));
+ CHECK(typeid(ppolybase) == typeid(Poly_Base*));
+ CHECK(typeid(polyderived) == typeid(*ppolybase));
+
+ printf("polyderived is: %s\n", typeid(polyderived).name());
+ printf(" *ppolybase is: %s\n", typeid(*ppolybase).name());
+
+ bar = dynamic_cast<Bar*>(foo);
+ if (bar != NULL) {
+ printf("OK: 'foo' is pointing to a Bar class instance.\n");
+ } else {
+ fprintf(stderr, "KO: Could not dynamically cast 'foo' to a 'Bar*'\n");
+ fail++;
+ }
+
+ delete foo;
+
+ return (fail > 0);
+}