diff options
author | David 'Digit' Turner <digit@google.com> | 2011-10-10 18:01:38 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2011-10-10 18:05:34 +0200 |
commit | 0059fb2aa9c710cfe7dfd3d67a1cdc7b5e3e284a (patch) | |
tree | f5124e13a5cbcfbe65b0e7e0b8c774482294be97 | |
parent | 13b5f454053aa62ea4cda3c5aa0fb80cfca82dad (diff) | |
download | ndk-0059fb2aa9c710cfe7dfd3d67a1cdc7b5e3e284a.tar.gz |
gnustl_shared: New C++ runtime
This patch fixes build-gnu-libstdc++.sh to work properly
and generate libgnustl_shared.so from the GNU libstdc++ sources.
This is done by a custom patch to the gcc toolchain source tree
to force the generation of libgnustl_shared.so from the same objects
than libstdc++.so. This is required because there is no way to change
the internal DT_SONAME of a given shared library, so a simple rename
will not work.
We also ensure that libgnustl_static.a is properly generated and
used by the make-standalone-toolchain.sh script (which uses
copy-libstdcxx.sh)
+ Update definitions.mk to make "gnustl_shared" available in APP_STL
+ Update documentation to reflect that STLport now supports RTTI
+ Update documentation to reflect the new gnustl_shared runtime
Change-Id: Ie3ffaf825ba2d65eca027ec0be5e320d0ee39cbc
-rw-r--r-- | build/core/definitions.mk | 7 | ||||
-rwxr-xr-x | build/tools/build-gnu-libstdc++.sh | 26 | ||||
-rwxr-xr-x | build/tools/copy-libstdcxx.sh | 23 | ||||
-rw-r--r-- | build/tools/toolchain-patches/gcc/0006-Disable-libstdc++-versioning.patch | 27 | ||||
-rw-r--r-- | docs/CHANGES.html | 12 | ||||
-rw-r--r-- | docs/CPLUSPLUS-SUPPORT.html | 47 | ||||
-rw-r--r-- | sources/cxx-stl/gnu-libstdc++/Android.mk | 8 |
7 files changed, 120 insertions, 30 deletions
diff --git a/build/core/definitions.mk b/build/core/definitions.mk index 2bd268594..ecf1a23f4 100644 --- a/build/core/definitions.mk +++ b/build/core/definitions.mk @@ -1511,6 +1511,13 @@ $(call ndk-stl-register,\ \ ) +$(call ndk-stl-register,\ + gnustl_shared,\ + cxx-stl/gnu-libstdc++,\ + ,\ + gnustl_shared\ + ) + # Register the static version of the GAbi++ C++ runtime # $(call ndk-stl-register,\ diff --git a/build/tools/build-gnu-libstdc++.sh b/build/tools/build-gnu-libstdc++.sh index 38b4f9ba8..ed4a2b22b 100755 --- a/build/tools/build-gnu-libstdc++.sh +++ b/build/tools/build-gnu-libstdc++.sh @@ -127,7 +127,8 @@ build_gnustl_for_abi () mkdir -p $DSTDIR ARCH=$(convert_abi_to_arch $ABI) - BINPREFIX=${TOOLCHAIN_PREFIX%%-}- + BINPREFIX=$NDK_DIR/$(get_default_toolchain_binprefix_for_arch $ARCH) + SYSROOT=$NDK_DIR/$(get_default_platform_sysroot_for_arch $ARCH) # Sanity check if [ ! -f "$SYSROOT/usr/lib/libc.a" ]; then @@ -149,7 +150,19 @@ build_gnustl_for_abi () ;; esac - export CXXFLAGS="-fexceptions -frtti -D__BIONIC__ -O2" + export CXXFLAGS="$CXXFLAGS --sysroot=$SYSROOT -fexceptions -frtti -D__BIONIC__ -O2 -fvisibility=hidden -fvisibility-inlines-hidden" + + export CC=${BINPREFIX}gcc + export CXX=${BINPREFIX}g++ + export AS=${BINPREFIX}as + export LD=${BINPREFIX}ld + export AR=${BINPREFIX}ar + export RANLIB=${BINPREFIX}ranlib + export STRIP=${BINPREFIX}strip + + setup_ccache + + export LDFLAGS="-nostdinc -L$SYSROOT/usr/lib -lc" PROJECT="GNU libstdc++ $ABI" echo "$PROJECT: configuring" @@ -205,7 +218,12 @@ copy_gnustl_libs () copy_directory "$SDIR/include/c++/$VERSION/$PREFIX" "$DDIR/libs/$ABI/include" # Copy the ABI-specific libraries - copy_file_list "$SDIR/lib" "$DDIR/libs/$ABI" libsupc++.a libstdc++.a libstdc++.so + # Note: the shared library name is libgnustl_shared.so due our custom toolchain patch + # We need to copy libstdc++.so which is identical to libgnustl_shared.so except for the DT_LIBRARY entry + # within the ELF file, since it will be needed by the standalone toolchain installation later. + copy_file_list "$SDIR/lib" "$DDIR/libs/$ABI" libsupc++.a libstdc++.so libgnustl_shared.so + # Note: we need to rename libgnustl_shared.a to libgnustl_static.a + cp "$SDIR/lib/libgnustl_shared.a" "$DDIR/libs/$ABI/libgnustl_static.a" } @@ -225,7 +243,7 @@ if [ -n "$PACKAGE_DIR" ] ; then # Then, one package per ABI for libraries for ABI in $ABIS; do FILES="" - for LIB in libsupc++.a libstdc++.a libstdc++.so; do + for LIB in libsupc++.a libgnustl_static.a libstdc++.so libgnustl_shared.so; do FILES="$FILES $GNUSTL_SUBDIR/libs/$ABI/$LIB" done PACKAGE="$PACKAGE_DIR/gnu-libstdc++-libs-$ABI.tar.bz2" diff --git a/build/tools/copy-libstdcxx.sh b/build/tools/copy-libstdcxx.sh index 41d1a1d5e..156974d78 100755 --- a/build/tools/copy-libstdcxx.sh +++ b/build/tools/copy-libstdcxx.sh @@ -139,14 +139,17 @@ if [ "$REVERSE" = "no" ] ; then arm) # We use the thumb version by default. copy_directory "$OUT_INCLUDE_ABI/thumb/bits" "$OUT_LIBS/armeabi/include/bits" - copy_file_list "$ABI_STL/lib/thumb" "$OUT_LIBS/armeabi" "libstdc++.*" + copy_file_list "$ABI_STL/lib/thumb" "$OUT_LIBS/armeabi" "libstdc++.so libgnustl_shared.so" + cp "$ABI_STL/lib/thumb/libstdc++.a" "$OUT_LIBS/armeabi-v7a/libgnustl_static.a" copy_directory "$OUT_INCLUDE_ABI/armv7-a/bits" "$OUT_LIBS/armeabi-v7a/include/bits" - copy_file_list "$ABI_STL/lib/armv7-a" "$OUT_LIBS/armeabi-v7a" "libstdc++.*" + copy_file_list "$ABI_STL/lib/armv7-a" "$OUT_LIBS/armeabi-v7a" "libstdc++.so libgnustl_shared.so" + cp "$ABI_STL/lib/armv7-a/libstdc++.a" "$OUT_LIBS/armeabi/libgnustl_static.a" ;; x86) copy_directory "$OUT_INCLUDE_ABI/bits" "$OUT_LIBS/x86/include/bits" - copy_file_list "$ABI_STL/lib" "$OUT_LIBS/x86" "libstdc++.*" + copy_file_list "$ABI_STL/lib" "$OUT_LIBS/x86" "libstdc++.so" + cp "$ABI_STL/lib/libstdc++.a" "$OUT_LIBS/x86/libgnustl_static.a" ;; *) dump "ERROR: Unsupported NDK architecture!" @@ -165,15 +168,21 @@ else # REVERSE = yes case "$ARCH" in arm) copy_directory "$OUT_LIBS/armeabi/include/bits" "$ABI_STL_INCLUDE_TARGET/bits" - copy_file_list "$OUT_LIBS/armeabi" "$ABI_STL/lib" "libstdc++.*" + copy_file_list "$OUT_LIBS/armeabi" "$ABI_STL/lib" "libstdc++.so" + cp "$OUT_LIBS/armeabi/libgnustl_static.a" "$ABI_STL/lib/libstdc++.a" + copy_directory "$OUT_LIBS/armeabi/include/bits" "$ABI_STL_INCLUDE_TARGET/thumb/bits" - copy_file_list "$OUT_LIBS/armeabi" "$ABI_STL/lib/thumb" "libstdc++.*" + copy_file_list "$OUT_LIBS/armeabi" "$ABI_STL/lib/thumb" "libstdc++.so" + cp "$OUT_LIBS/armeabi/libgnustl_static.a" "$ABI_STL/lib/thumb/libstdc++.a" + copy_directory "$OUT_LIBS/armeabi-v7a/include/bits" "$ABI_STL_INCLUDE_TARGET/armv7-a/bits" - copy_file_list "$OUT_LIBS/armeabi-v7a" "$ABI_STL/lib/armv7-a" "libstdc++.*" + copy_file_list "$OUT_LIBS/armeabi-v7a" "$ABI_STL/lib/armv7-a" "libstdc++.so" + cp "$OUT_LIBS/armeabi-v7a/libgnustl_static.a" "$ABI_STL/lib/armv7-a/libstdc++.a" ;; x86) copy_directory "$OUT_LIBS/x86/include/bits" "$ABI_STL_INCLUDE_TARGET/bits" - copy_file_list "$OUT_LIBS/x86" "$ABI_STL/lib" "libstdc++.*" + copy_file_list "$OUT_LIBS/x86" "$ABI_STL/lib" "libstdc++.so" + cp "$OUT_LIBS/x86/libgnustl_static.a" "$ABI_STL/lib/libstdc++.a" ;; *) dump "ERROR: Unsupported NDK architecture!" diff --git a/build/tools/toolchain-patches/gcc/0006-Disable-libstdc++-versioning.patch b/build/tools/toolchain-patches/gcc/0006-Disable-libstdc++-versioning.patch index 5bd8b38a1..acb23eae9 100644 --- a/build/tools/toolchain-patches/gcc/0006-Disable-libstdc++-versioning.patch +++ b/build/tools/toolchain-patches/gcc/0006-Disable-libstdc++-versioning.patch @@ -1,6 +1,6 @@ diff -burN gcc-a/gcc-4.4.3/libstdc++-v3/src/Makefile.am gcc-b/gcc-4.4.3/libstdc++-v3/src/Makefile.am ---- gcc-a/gcc-4.4.3/libstdc++-v3/src/Makefile.am 2011-10-02 22:00:20.352164415 +0200 -+++ gcc-b/gcc-4.4.3/libstdc++-v3/src/Makefile.am 2011-10-02 22:00:37.311501551 +0200 +--- gcc-a/gcc-4.4.3/libstdc++-v3/src/Makefile.am 2011-10-10 17:32:21.983349054 +0200 ++++ gcc-b/gcc-4.4.3/libstdc++-v3/src/Makefile.am 2011-10-10 17:10:06.474674579 +0200 @@ -206,7 +206,7 @@ $(top_builddir)/libsupc++/libsupc++convenience.la @@ -11,8 +11,17 @@ diff -burN gcc-a/gcc-4.4.3/libstdc++-v3/src/Makefile.am gcc-b/gcc-4.4.3/libstdc+ # Use special rules for the deprecated source files so that they find # deprecated include files. diff -burN gcc-a/gcc-4.4.3/libstdc++-v3/src/Makefile.in gcc-b/gcc-4.4.3/libstdc++-v3/src/Makefile.in ---- gcc-a/gcc-4.4.3/libstdc++-v3/src/Makefile.in 2011-10-02 22:00:20.352164415 +0200 -+++ gcc-b/gcc-4.4.3/libstdc++-v3/src/Makefile.in 2011-10-02 22:00:37.311501551 +0200 +--- gcc-a/gcc-4.4.3/libstdc++-v3/src/Makefile.in 2011-10-10 17:32:21.983349054 +0200 ++++ gcc-b/gcc-4.4.3/libstdc++-v3/src/Makefile.in 2011-10-10 17:10:06.514673034 +0200 +@@ -350,7 +350,7 @@ + AM_CPPFLAGS = $(GLIBCXX_INCLUDES) + + # Cross compiler support. +-toolexeclib_LTLIBRARIES = libstdc++.la ++toolexeclib_LTLIBRARIES = libstdc++.la libgnustl_shared.la + @ENABLE_SYMVERS_DARWIN_TRUE@@ENABLE_SYMVERS_TRUE@version_arg = -Wl,-exported_symbols_list,libstdc++-symbols.explist + @ENABLE_SYMVERS_FALSE@version_arg = + @ENABLE_SYMVERS_GNU_NAMESPACE_TRUE@@ENABLE_SYMVERS_TRUE@version_arg = -Wl,--version-script=libstdc++-symbols.ver @@ -454,7 +454,7 @@ $(top_builddir)/libsupc++/libsupc++convenience.la @@ -22,3 +31,13 @@ diff -burN gcc-a/gcc-4.4.3/libstdc++-v3/src/Makefile.in gcc-b/gcc-4.4.3/libstdc+ # Use special rules for the deprecated source files so that they find +@@ -576,6 +576,9 @@ + libstdc++.la: $(libstdc___la_OBJECTS) $(libstdc___la_DEPENDENCIES) + $(CXXLINK) -rpath $(toolexeclibdir) $(libstdc___la_LDFLAGS) $(libstdc___la_OBJECTS) $(libstdc___la_LIBADD) $(LIBS) + ++libgnustl_shared.la: $(libstdc___la_OBJECTS) $(libstdc___la_DEPENDENCIES) ++ $(CXXLINK) -rpath $(toolexeclibdir) $(libstdc___la_LDFLAGS) $(libstdc___la_OBJECTS) $(libstdc___la_LIBADD) $(LIBS) ++ + mostlyclean-compile: + -rm -f *.$(OBJEXT) + diff --git a/docs/CHANGES.html b/docs/CHANGES.html index 3d8b5edc7..6ea976202 100644 --- a/docs/CHANGES.html +++ b/docs/CHANGES.html @@ -73,7 +73,17 @@ OTHER CHANGES: - Add a new C++ support runtime named "gabi++". More details about it are available in the updated docs/CPLUSPLUS-SUPPORT.html. -- You can now list several file extensions in LOCAL_CPP_EXTENSION. +- The STLport C++ runtimes now support RTTI (no exceptions yet though). + +- Add a new C++ support runtime named "gnustl_shared" corresponding to the + shared library version of GNU libstdc++ v3 (GPLv3 license). See more + info at docs/CPLUSPLUS-SUPPORT.html + +- You can now list several file extensions in LOCAL_CPP_EXTENSION. As in: + + LOCAL_CPP_EXTENSION := .cpp .cxx + + To compile both foo.cpp and bar.cxx as C++ sources. ------------------------------------------------------------------------------- android-ndk-r6b diff --git a/docs/CPLUSPLUS-SUPPORT.html b/docs/CPLUSPLUS-SUPPORT.html index 45bf322bc..4b63d8108 100644 --- a/docs/CPLUSPLUS-SUPPORT.html +++ b/docs/CPLUSPLUS-SUPPORT.html @@ -24,11 +24,10 @@ Application.mk to one of the following values: stlport_static -> Use the STLport runtime as a static library. stlport_shared -> Use the STLport runtime as a shared library. gnustl_static -> Use the GNU STL as a static library. - -Note that there is no 'gnustl_shared' runtime available for now. + gnustl_shared -> Use the GNU STL as a shared library. The 'system' runtime is the default if there is no APP_STL definition in -your Application.mk. As an example, to use the GNU STL, add a line like: +your Application.mk. As an example, to use the static GNU STL, add a line like: APP_STL := gnustl_static @@ -48,7 +47,7 @@ The capabilities of the various runtimes vary. See this table: system no no no gabi++ no yes no - stlport no no yes + stlport no yes yes gnustl yes yes yes @@ -91,7 +90,9 @@ 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 -headers, however it CURRENTLY DOES NOT SUPPORT EXCEPTIONS OR RTTI! +headers, however it ONLY SUPPORTS RTTI, AND NO EXCEPTIONS! + +That's because the library embeds its own copy of GAbi++. Available as both both static and shared libraries. To use it, use either one of these two lines in your Application.mk: @@ -107,7 +108,8 @@ I.4. GNU STL runtime: - - - - - - - - - - - This is the GNU Standard C++ Library (a.k.a. libstdc++-v3), providing the -more features. Note that it is currently only available as a static library. +more features. Note that the shared library file is named "libgnustl_shared.so" +instead of "libstdc++.so" as on other platforms. If you want to use it, please read the "C++ Exceptions support", "RTTI Support" and "Static runtime considerations" sections below. @@ -125,8 +127,15 @@ The NDK toolchain supports C++ exceptions, since NDK r5, however all C++ sources are compiled with -fno-exceptions support by default, for compatibility reasons with previous releases. -To enable it, use the '-fexceptions' C++ compiler flag. This can be done -by adding the following to every module definition in your Android.mk: +To enable it, use the new LOCAL_CPP_FEATURES variable in your Android.mk, +as in: + + LOCAL_CPP_FEATURES += exceptions + +See docs/ANDROID-MK.html for more details about this varibale. + +Another way to do the same is to define it in your LOCAL_CPPFLAGS definition +(but using LOCAL_CPP_FEATURES is preferred), as in: LOCAL_CPPFLAGS += -fexceptions @@ -137,7 +146,7 @@ automatically apply to all your project's NDK modules: IMPORTANT: You *will* have to select a C++ runtime that supports exceptions to be able to link / run your code. At this point - this means only 'gnustl_static'! + this means only 'gnustl_static' or "gnustl_shared'! II.2. RTTI support: @@ -148,17 +157,16 @@ since NDK r5, but all C++ sources are built with -fno-rtti by default for compatibility reasons. To enable it, add the following to your module declarations: + LOCAL_CPP_FEATURES += rtti + +This will be equivalent to: + LOCAL_CPPFLAGS += -frtti Or more simply to your Application.mk: APP_CPPFLAGS += -frtti -IMPORTANT: You *will* have to select an C++ runtime that supports - RTTI to be able to link / run your code. At this point - this means only 'gabi++_static/shared' or 'gnustl_static' - - II.3. Static runtimes: - - - - - - - - - - - - @@ -230,6 +238,17 @@ STLport is licensed under a BSD-style open-source license. See sources/cxx-stl/stlport/README for more details about the library. +III.2. GNU libstdc++ license is GPLv3 + linking exception! +---------------------------------------------------------- + +Be aware that the GNU libstdc++ is covered by the GPLv3 license (and *not* +the LGPLv2 or LGPLv3 as some assume), full details available here: + + http://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html + +Be sure that you comply with all clauses of this license. + + IV. Future Plans: ----------------- diff --git a/sources/cxx-stl/gnu-libstdc++/Android.mk b/sources/cxx-stl/gnu-libstdc++/Android.mk index 89ae858e7..7c82567fa 100644 --- a/sources/cxx-stl/gnu-libstdc++/Android.mk +++ b/sources/cxx-stl/gnu-libstdc++/Android.mk @@ -7,3 +7,11 @@ LOCAL_EXPORT_CPPFLAGS := -fexceptions -frtti LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include \ $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/include 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 +include $(PREBUILT_SHARED_LIBRARY) |