https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117683

--- Comment #7 from R. Diez <rdiez-2006 at rd10 dot de> ---
About using C++ exceptions without RTTI, I tried to build a toolchain for ARM
(arm-none-eabi) with -fno-rtti, and I got the following compilation errors
(they may be more):

File eh_arm.cc:

[...]/gcc-14.2.0/libstdc++-v3/libsupc++/eh_arm.cc: In function
'__cxxabiv1::__cxa_type_match_result __cxa_type_match(_Unwind_Control_Block*,
const std::type_info*, bool, void**)':
[...]/gcc-14.2.0/libstdc++-v3/libsupc++/eh_arm.cc:57:46: error: cannot use
'typeid' with '-fno-rtti'
   57 |     throw_type = &typeid(abi::__forced_unwind);

[...]/gcc-14.2.0/libstdc++-v3/libsupc++/eh_arm.cc:59:50: error: cannot use
'typeid' with '-fno-rtti'
   59 |     throw_type = &typeid(abi::__foreign_exception);

File eh_call.cc:

[...]/gcc-14.2.0/libstdc++-v3/libsupc++/eh_call.cc:130:64: error: cannot use
'typeid' with '-fno-rtti'
  130 |       const std::type_info& bad_exc = typeid(std::bad_exception);

So I gather that I need to enable RTTI when building the toolchain.

Questions are:

1) Is that the case only for ARM, but not for other architectures?

2) Is that only a requirement for libsupc++? Or are there other GCC components
which may need RTTI, like perhaps libstdc++?

Can I then specify something like "-frtti" to enable RTTI just for libsupc++,
and -fno-rtti for the rest? How do I do that with GCC's ./configure script or
make invocation? I am doing it with "make CXXFLAGS_FOR_TARGET=-fno-rtti" at the
moment.

3) If GCC is built with RTTI, is it really safe to disable RTTI in my firmware? 

I would then be mixing RTTI code from libsupc++, and maybe from other GCC
components, with non-RTTI code from my application.

Reply via email to