[flang-commits] [flang] ce6b9b3 - [flang][runtime] Avoid dependency on libc++ for `std::__libcpp_verbose_abort`

Markus Mützel via flang-commits flang-commits at lists.llvm.org
Thu Oct 26 05:30:25 PDT 2023


Author: Markus Mützel
Date: 2023-10-26T14:30:11+02:00
New Revision: ce6b9b3b58b6c9e51d87084c916fa7aef81401f1

URL: https://github.com/llvm/llvm-project/commit/ce6b9b3b58b6c9e51d87084c916fa7aef81401f1
DIFF: https://github.com/llvm/llvm-project/commit/ce6b9b3b58b6c9e51d87084c916fa7aef81401f1.diff

LOG: [flang][runtime] Avoid dependency on libc++ for `std::__libcpp_verbose_abort`

Changes in libc++ during the development cycle for LLVM 17 lead to the FortranRuntime library depending on libc++.

Trying to build with Flang 17 that was built with clang++ 17 and libc++ 17 (on MinGW) leads to the following linker error:

ld.lld: error: undefined symbol: std::__1::__libcpp_verbose_abort(char const*, ...)
>>> referenced by libFortranRuntime.a(io-api.cpp.obj):(std::__1::__throw_bad_variant_access[abi:v170000]())
>>> referenced by libFortranRuntime.a(io-stmt.cpp.obj)
>>> referenced by libFortranRuntime.a(unit.cpp.obj)
That might be caused by std::get being called on a std::variant in common::visit.

std::__libcpp_verbose_abort is a weak symbol in libc++ that can be optionally replaced by an alternative definition in user code (see: [1])

Do that to avoid a dependency of the FortranRuntime on libc++.

[1]: https://libcxx.llvm.org/UsingLibcxx.html#overriding-the-default-termination-handler

See also: https://github.com/msys2/MINGW-packages/pull/18002#issuecomment-1694412640

Differential Revision: https://reviews.llvm.org/D158957

Added: 
    

Modified: 
    flang/runtime/io-api.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index f9d60fecb149a52..2fc530c7431a50d 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -1517,3 +1517,17 @@ enum Iostat IONAME(CheckUnitNumberInRange128)(common::int128_t unit,
 #endif
 
 } // namespace Fortran::runtime::io
+
+#if defined(_LIBCPP_VERBOSE_ABORT)
+// Provide own definition for `std::__libcpp_verbose_abort` to avoid dependency
+// on the version provided by libc++.
+
+void std::__libcpp_verbose_abort(char const *format, ...) {
+  va_list list;
+  va_start(list, format);
+  std::vfprintf(stderr, format, list);
+  va_end(list);
+
+  std::abort();
+}
+#endif


        


More information about the flang-commits mailing list