[PATCH] libstdc++: ifdef rtti specific function __throw_ios_failure() by __cpp_rtti

2021-02-11 Thread Mirko Vogt

Hello,

ran into the following when building libstdc++ without rtti support:

libstdc++-v3/src/c++11/cxx11-ios_failure.cc:174:54: error: no matching 
function for call to 'std::ios_base::failure::failure(const char*&, int&)'


Attached patch does as follows:

ifdef rtti specific function __throw_ios_failure() by __cpp_rtti


Overloaded __throw_ios_failure(const char*, int) got introduced in

484e936e88e5, however __ios_failure() with respective signature is only

defined if __cpp_rtti is defined, hence should only be used within

contexts also guarded by __cpp_rtti.



This was done correctly for the c++98 part and probably just forgotten

for c++11.

Thanks

  mirko

PS: Shouldn't this have been covered by any tests?
>From 46aa7ca34b832695b3f13167034f6aa19f44d074 Mon Sep 17 00:00:00 2001
From: Mirko Vogt 
Date: Thu, 11 Feb 2021 23:18:28 +
Subject: [PATCH] ifdef rtti specific function __throw_ios_failure() by
 __cpp_rtti

Overloaded __throw_ios_failure(const char*, int) got introduced in
484e936e88e5, however __ios_failure() with respective signature is only
defined if __cpp_rtti is defined, hence should only be used within
contexts also guarded by __cpp_rtti.

This was done correctly for the c++98 part and probably just forgotten
for c++11.
---
 libstdc++-v3/src/c++11/cxx11-ios_failure.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libstdc++-v3/src/c++11/cxx11-ios_failure.cc b/libstdc++-v3/src/c++11/cxx11-ios_failure.cc
index e82c1aaf63b..7edde29f0e8 100644
--- a/libstdc++-v3/src/c++11/cxx11-ios_failure.cc
+++ b/libstdc++-v3/src/c++11/cxx11-ios_failure.cc
@@ -168,10 +168,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __throw_ios_failure(const char* __s __attribute__((unused)))
   { _GLIBCXX_THROW_OR_ABORT(__ios_failure(_(__s))); }
 
+#if __cpp_rtti
   void
   __throw_ios_failure(const char* str __attribute__((unused)),
 		  int err __attribute__((unused)))
   { _GLIBCXX_THROW_OR_ABORT(__ios_failure(_(str), err)); }
+#endif
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
-- 
2.20.1



Re: [PATCH] libstdc++: ifdef rtti specific function __throw_ios_failure() by __cpp_rtti

2021-02-12 Thread Mirko Vogt

On 2/12/21 11:30 AM, Jonathan Wakely wrote:

This patch is wrong.


Indeed, thanks for checking.


If you simply disable that function definition
for !__cpp_rtti then you'll get linker errors from fstream.tcc when
that function is called.

/usr/bin/ld: 
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so:
 undefined reference to `std::__throw_ios_failure(char const*, int)'


Funny enough that doesn't occur for my use case - builds fine. However 
building with a toolchain for bare metal, potentially resulting in 
disabling e.g. fstream.





This was done correctly for the c++98 part and probably just forgotten
for c++11.


This has nothing to do with C++98, it's relted to the gcc4-compatible
ABI versus the cxx11 ABI.


Urgs, yeah, that last chunk for cxx98 expands a different macro to 
include that definition - not the rtti ifdef. Misread and wrongly took over.




I added a better patch to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99077


Thanks!


PS: Shouldn't this have been covered by any tests?


Nobody tests building libstdc++ with -fno-rtti because almost nobody
does that.


Just as info: Espressif's crosstool-ng fork (not sure about vanilla) is 
building with no-rtti for targeting their Xtensa based ESP32 SoCs. 
That's how I stumbled over this.




But we have plenty of tests, and hundreds of them fail with your patch
:-)


Yeah, glass houses and stones.. sorry for that :)

  mirko