summaryrefslogtreecommitdiff
path: root/flang-rt
diff options
context:
space:
mode:
authorPatrick Simmons <psimmons@pensando.io>2025-10-16 11:24:06 -0500
committerGitHub <noreply@github.com>2025-10-16 18:24:06 +0200
commitbe3aa41ecc9b6cc68248e660a30829a16eda26b3 (patch)
treee455beadda4497aa1c384ef2c9c2b8225b1a54f7 /flang-rt
parent8fa4a1029cbad3c788a90152cf978f8233a6f87f (diff)
[Flang-RT] Fix GCC 15.1 Fortran Runtime libstdc++ Undefined Symbols (#157385)
Define the _GLIBCXX_THROW_OR_ABORT macro to not use its _EXC argument. _EXC may contain an expression constructing an std::exception object which is non-inline and therefore require a link dependency on the libstdc++ runtime. In -fno-exceptions builds it is typically optimized away when appearing in unreachable code, but is still present when compiling with -O0 when compiling with Clang. --------- Co-authored-by: Michael Kruse <github@meinersbur.de>
Diffstat (limited to 'flang-rt')
-rw-r--r--flang-rt/cmake/modules/AddFlangRT.cmake21
1 files changed, 21 insertions, 0 deletions
diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index ab383bcbe2cd..923507764d69 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -231,6 +231,27 @@ function (add_flangrt_library name)
target_compile_options(${tgtname} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti -funwind-tables -fno-asynchronous-unwind-tables>
)
+
+ # We define our own _GLIBCXX_THROW_OR_ABORT here because, as of
+ # GCC 15.1, the libstdc++ header file <bits/c++config> uses
+ # (void)_EXC in its definition of _GLIBCXX_THROW_OR_ABORT to
+ # silence a warning.
+ #
+ # This is a problem for us because some compilers, specifically
+ # clang, do not always optimize away that (void)_EXC even though
+ # it is unreachable since it occurs after a call to
+ # _builtin_abort(). Because _EXC is typically an object derived
+ # from std::exception, (void)_EXC, when not optimized away,
+ # calls std::exception methods defined in the libstdc++ shared
+ # library. We shouldn't link against that library since our
+ # build version may conflict with the version used by a hybrid
+ # Fortran/C++ application.
+ #
+ # Redefining _GLIBCXX_THROW_OR_ABORT in this manner is not
+ # supported by the maintainers of libstdc++, so future changes
+ # to libstdc++ may require future changes to this build script
+ # and/or future changes to the Fortran runtime source code.
+ target_compile_options(${tgtname} PUBLIC "-D_GLIBCXX_THROW_OR_ABORT(_EXC)=(__builtin_abort())")
elseif (MSVC)
target_compile_options(${tgtname} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:/EHs-c- /GR->