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

            Bug ID: 85222
           Summary: [7/8 Regression] ABI breakage of __throw_ios_failure
                    by r244498
           Product: gcc
           Version: 7.3.1
            Status: UNCONFIRMED
          Keywords: ABI
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
                CC: redi at gcc dot gnu.org
            Blocks: 66145
  Target Milestone: ---

A program compiled with a GCC defaulting to the old ABI
(like GCC 4.8) now fails to run with a dual-ABI libstdc++:

#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
  std::ifstream pstats;
  pstats.exceptions(ifstream::failbit | ifstream::badbit | ifstream::eofbit);
  try {
      printf("\n Opening file : /proc/0/stat ");
      pstats.open("/proc/0/stat");
  }
  catch(ifstream::failure e)
    {
      printf("\n!!Caught ifstream exception!!\n");
      if(pstats.is_open()) {
          pstats.close();
      }
    }
  return 0;
}
tmp> g++-4.8 t.C
tmp> ./a.out 

terminate called after throwing an instance of
'std::ios_base::failure[abi:cxx11]'
  what():  basic_ios::clear: iostream error
Aborted (core dumped)
tmp> LD_LIBRARY_PATH=/space/rguenther/install/gcc-6.4/lib64 ./a.out 

 Opening file : /proc/0/stat 
!!Caught ifstream exception!!

This is because of the documented change of throwing the C++11 errors from
the libraries I/O routines in the attempt to fix PR66145.  This in turn
breaks any old programs trying to catch such exceptions thrown by the
library.

__throw_ios_failure, while being exported, isn't called by the testcase
above but just by libstdc++ but the program is rightfully expecting to
be able to catch ifstream::failure.

A workaround is to use a libstdc++ built with --disable-libstdcxx-dual-abi
but that of course makes it incompatible with any programs using the new ABI.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66145
[Bug 66145] [5/6/7 Regression] std::ios_base::failure objects thrown from
libstdc++.so use old ABI

Reply via email to