From f840b45ae175a9fc410a224f1039c158485190ff Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Thu, 4 Mar 2021 13:16:39 +0700 Subject: [PATCH] Add hack for kotlinx-datetime:0.1.1 linkage Provide a `std::system_category` wrapper with the same mangling as in GCC 4.8.5 (cherry picked from commit ec5828a1f375a74a09aa49182571201e1f67b4fa) --- .../runtime/src/main/cpp/StdCppStubs.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kotlin-native/runtime/src/main/cpp/StdCppStubs.cpp b/kotlin-native/runtime/src/main/cpp/StdCppStubs.cpp index a0f9ac2ae0f..cc9967cbb4a 100644 --- a/kotlin-native/runtime/src/main/cpp/StdCppStubs.cpp +++ b/kotlin-native/runtime/src/main/cpp/StdCppStubs.cpp @@ -38,3 +38,20 @@ RUNTIME_WEAK void __throw_length_error(const char* __s __attribute__((unused))) } // namespace std #endif // KONAN_LINUX || KONAN_WINDOWS + +#if KONAN_LINUX + +#include + +// Since GCC 4.8.5 mangling for std::system_category has changed from _ZNSt3_V215system_categoryEv to _ZSt15system_categoryv. +// It causes linkage problems in case of kotlinx-datetime:0.1.1 usage, because its C++ dependency is compiled with old GCC 4.8.5. +// So to avoid nasty linkage problems when users migrate their projects with kotlinx-datetime:0.1.1 dependency from 1.4.x to 1.5.x +// we provide this compatibility layer. +RUNTIME_WEAK +const std::error_category& std_system_category_backward_compatibility_with_gcc_4_8_5() noexcept __asm("_ZSt15system_categoryv"); + +const std::error_category& std_system_category_backward_compatibility_with_gcc_4_8_5() noexcept { + return std::system_category(); +} + +#endif // KONAN_LINUX