https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88159
Bug ID: 88159 Summary: LTO seems to mishandle exceptions that're thrown from c-linkage functions Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: wanyingloo at gmail dot com CC: marxin at gcc dot gnu.org Target Milestone: --- This looks to be a bug in LTO. Can someone please confirm? $ cat main.cpp #include <string> extern "C" void run(); extern "C" void throw_ex(const char *err_text) { throw std::string(err_text); } void call() { try { run(); } catch (std::string &msg) {} } int main(int argc, char *argv[]) { call(); } $ cat util.c void throw_ex(const char*); void run() { throw_ex("foobar"); } $ g++ -v Using built-in specs. COLLECT_GCC=/opt/pkg/gcc-7.3.0/bin/g++ COLLECT_LTO_WRAPPER=/opt/pkg/gcc-7.3.0/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../configure --prefix=/opt/pkg/gcc-7.3.0 --program-suffix=-7.3.0 --enable-languages=c,c++ --disable-multilib Thread model: posix gcc version 7.3.0 (GCC) $ g++ -xc util.c -xc++ main.cpp -O2 $ ./a.out $ g++ -xc util.c -xc++ main.cpp -O2 -flto $ ./a.out terminate called after throwing an instance of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >' Aborted