Skip to content

Commit be3aa41

Browse files
[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 <[email protected]>
1 parent 8fa4a10 commit be3aa41

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,27 @@ function (add_flangrt_library name)
231231
target_compile_options(${tgtname} PRIVATE
232232
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti -funwind-tables -fno-asynchronous-unwind-tables>
233233
)
234+
235+
# We define our own _GLIBCXX_THROW_OR_ABORT here because, as of
236+
# GCC 15.1, the libstdc++ header file <bits/c++config> uses
237+
# (void)_EXC in its definition of _GLIBCXX_THROW_OR_ABORT to
238+
# silence a warning.
239+
#
240+
# This is a problem for us because some compilers, specifically
241+
# clang, do not always optimize away that (void)_EXC even though
242+
# it is unreachable since it occurs after a call to
243+
# _builtin_abort(). Because _EXC is typically an object derived
244+
# from std::exception, (void)_EXC, when not optimized away,
245+
# calls std::exception methods defined in the libstdc++ shared
246+
# library. We shouldn't link against that library since our
247+
# build version may conflict with the version used by a hybrid
248+
# Fortran/C++ application.
249+
#
250+
# Redefining _GLIBCXX_THROW_OR_ABORT in this manner is not
251+
# supported by the maintainers of libstdc++, so future changes
252+
# to libstdc++ may require future changes to this build script
253+
# and/or future changes to the Fortran runtime source code.
254+
target_compile_options(${tgtname} PUBLIC "-D_GLIBCXX_THROW_OR_ABORT(_EXC)=(__builtin_abort())")
234255
elseif (MSVC)
235256
target_compile_options(${tgtname} PRIVATE
236257
$<$<COMPILE_LANGUAGE:CXX>:/EHs-c- /GR->

0 commit comments

Comments
 (0)