From 63f365ba5b4795a6225e9a70ccc2a026578afbe6 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Fri, 10 Jan 2025 16:11:28 -0800 Subject: [PATCH 1/2] [libcxx] Support providing symbol suffix through compiler define When -funique-internal-linkage-names option is enabled, Clang will append a unique suffix `.uniq.` to all internal symbols. Since we cannot detect when this option is enabled or compute the source file hash from within the source file itself, the unique suffix needs to be supplied by the build system. The `_LIBCPP_SYMBOL_SUFFIX` can be used for that purpose. --- libcxx/src/include/overridable_function.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libcxx/src/include/overridable_function.h b/libcxx/src/include/overridable_function.h index 7372e347831bb..7eee4ecd06a98 100644 --- a/libcxx/src/include/overridable_function.h +++ b/libcxx/src/include/overridable_function.h @@ -56,6 +56,15 @@ // with this macro must be defined at global scope. // +// When -funique-internal-linkage-names option is enabled, Clang will append a unique suffix +// `.uniq.` to all internal symbols. Since we cannot detect when +// this option is enabled or compute the source file hash from within the source file itself, +// the unique suffix needs to be supplied by the build system. The `_LIBCPP_SYMBOL_SUFFIX` can +// be used for that purpose. +#ifndef _LIBCPP_SYMBOL_SUFFIX +#define _LIBCPP_SYMBOL_SUFFIX +#endif + #if defined(_LIBCPP_OBJECT_FORMAT_MACHO) _LIBCPP_BEGIN_NAMESPACE_STD @@ -68,8 +77,8 @@ _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1 # define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \ static __attribute__((used)) type symbol##_impl__ arglist __asm__("_" _LIBCPP_TOSTRING(symbol)); \ - __asm__(".globl _" _LIBCPP_TOSTRING(symbol)); \ - __asm__(".weak_definition _" _LIBCPP_TOSTRING(symbol)); \ + __asm__(".globl _" _LIBCPP_TOSTRING(symbol) _LIBCPP_SYMBOL_SUFFIX); \ + __asm__(".weak_definition _" _LIBCPP_TOSTRING(symbol) _LIBCPP_SYMBOL_SUFFIX); \ extern __typeof(symbol##_impl__) name __attribute__((weak_import)); \ _LIBCPP_BEGIN_NAMESPACE_STD \ template <> \ @@ -91,7 +100,7 @@ _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1 # define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \ static type symbol##_impl__ arglist __asm__(_LIBCPP_TOSTRING(symbol##_impl__)); \ - [[gnu::weak, gnu::alias(_LIBCPP_TOSTRING(symbol##_impl__))]] type name arglist; \ + [[gnu::weak, gnu::alias(_LIBCPP_TOSTRING(symbol##_impl__) _LIBCPP_SYMBOL_SUFFIX)]] type name arglist; \ _LIBCPP_BEGIN_NAMESPACE_STD \ template <> \ inline bool __is_function_overridden(name)>() { \ From f1e0e27ba9db807ae9f1471323193852500be781 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Tue, 14 Jan 2025 16:02:33 -0800 Subject: [PATCH 2/2] Append the suffix to the declaration --- libcxx/src/include/overridable_function.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcxx/src/include/overridable_function.h b/libcxx/src/include/overridable_function.h index 7eee4ecd06a98..9071140516b99 100644 --- a/libcxx/src/include/overridable_function.h +++ b/libcxx/src/include/overridable_function.h @@ -99,7 +99,7 @@ _LIBCPP_END_NAMESPACE_STD # define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1 # define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \ - static type symbol##_impl__ arglist __asm__(_LIBCPP_TOSTRING(symbol##_impl__)); \ + static type symbol##_impl__ arglist __asm__(_LIBCPP_TOSTRING(symbol##_impl__) _LIBCPP_SYMBOL_SUFFIX); \ [[gnu::weak, gnu::alias(_LIBCPP_TOSTRING(symbol##_impl__) _LIBCPP_SYMBOL_SUFFIX)]] type name arglist; \ _LIBCPP_BEGIN_NAMESPACE_STD \ template <> \