-fexceptions, -frtti, and C++ library support

2,390 views
Skip to first unread message

Jeffrey Walton

unread,
Jul 28, 2013, 1:19:19 AM7/28/13
to Android NDK List
Hi All,

According to CPLUSPLUS-SUPPORT.html:

By default, this 'system' runtime does not provide the following:

Standard C++ Library support (except a few trivial headers).
C++ exceptions support
RTTI support

When I check g++'s configuration, it appears they appear to be on by default:

$ arm-linux-androideabi-g++ -dumpspecs
...
*cc1plus:
%{mno-android|tno-android-cc:;:%{!fexceptions:%{!fno-exceptions:
-fexceptions}} %{!frtti:%{!fno-rtti: -frtti}}}
...

When I test my programs with and without -fexceptions -frtti, it
performs the same (it exercises both exceptions and RTTI).

Am I suffering from a disconnect? Or are the documents a bit stale?

Jeff

Piotr Morgwai Kotarbiński

unread,
Jul 29, 2013, 4:36:35 AM7/29/13
to andro...@googlegroups.com, nolo...@gmail.com
Standalone tools have rtti and exception support turn on by default and AFAIR they link against GNU STL by default.
The cited documentation refers to using ndk-build which by default links against minimalistic 'system' runtime and turns exception and rtti support off.

Cheers!

Jeffrey Walton

unread,
Jul 29, 2013, 4:54:57 AM7/29/13
to Piotr Morgwai Kotarbiński, andro...@googlegroups.com
Thanks Piotr,

So I'm clear: linking to libstlport or libgnustl does *not* require
-fexceptions, -frtti. Even if libstlport or libgnustl lacked
exception and rtti support, arm-linuxeabi-g++ is configured to use
them by default (modulo -fno-exceptions, -fno-rtti), so they would
still not be needed by an application building from the command line.

Related: does "system" and/or "gabi++" require the flags if I used
their minimal implementations. (I probably never will, but I'm trying
to sort out the rules).

Jeff

On Mon, Jul 29, 2013 at 4:36 AM, Piotr Morgwai Kotarbiński
<mor...@gmail.com> wrote:
> Standalone tools have rtti and exception support turn on by default and
> AFAIR they link against GNU STL by default.
> The cited documentation refers to using ndk-build which by default links
> against minimalistic 'system' runtime and turns exception and rtti support
> off.
>

Piotr Morgwai Kotarbiński

unread,
Jul 29, 2013, 5:11:39 AM7/29/13
to andro...@googlegroups.com, Piotr Morgwai Kotarbiński, nolo...@gmail.com
On Monday, July 29, 2013 3:54:57 PM UTC+7, Jeffrey Walton wrote:
Thanks Piotr,

So I'm clear: linking to libstlport or libgnustl does *not* require
-fexceptions, -frtti. Even if libstlport or libgnustl  lacked
exception and rtti support, arm-linuxeabi-g++ is configured to use
them by default (modulo -fno-exceptions, -fno-rtti), so they would
still not be needed by an application building from the command line.

yes, that's true for the r8e and probably r9 release, but I'm not sure if you can assume it will not change in the future.
btw: I'm not sure if it is possible at all to compile stl port or gnu stl without exception support: never tried.
 

Related: does "system" and/or "gabi++" require the flags if I used
their minimal implementations. (I probably never will, but I'm trying
to sort out the rules).

never tried it either: just do a quick test if you need to know :)

Cheers

  Morg





David Turner

unread,
Jul 29, 2013, 2:00:55 PM7/29/13
to andro...@googlegroups.com
Simply put it, there is a difference between what the compiler supports (i.e. what kind of code it generates), and what the runtime libraries do.

You can always generate code that supports -fexceptions and -frtti, but you won't be able to link it (or load it) properly if you use the system's runtime (i.e. /system/lib/libstdc++.so).

On the other hand, all the other C++ runtimes supported by the NDK support these features, which really means they provide low-level helper functions like __cxa_allocate_exception that you certainly don't want to hear about :-)

The compiler toolchains are built with -fexceptions -frtti by default because this doesn't affect generated code unless your sources explicitely uses these features (i.e. throw / catch / finally / dynamic_cast).

Note that at the moment, certain C++0x specific features are not supported with GAbi++ / STLport (i.e. exception propagation and nested_exception). We're working on it, but not ETA.

Hope this helps

- David



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages