Skip to content

Commit 63f365b

Browse files
committed
[libcxx] Support providing symbol suffix through compiler define
When -funique-internal-linkage-names option is enabled, Clang will append a unique suffix `.uniq.<MD5 hash of the source file>` 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.
1 parent 833a174 commit 63f365b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

libcxx/src/include/overridable_function.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@
5656
// with this macro must be defined at global scope.
5757
//
5858

59+
// When -funique-internal-linkage-names option is enabled, Clang will append a unique suffix
60+
// `.uniq.<MD5 hash of the source file>` to all internal symbols. Since we cannot detect when
61+
// this option is enabled or compute the source file hash from within the source file itself,
62+
// the unique suffix needs to be supplied by the build system. The `_LIBCPP_SYMBOL_SUFFIX` can
63+
// be used for that purpose.
64+
#ifndef _LIBCPP_SYMBOL_SUFFIX
65+
#define _LIBCPP_SYMBOL_SUFFIX
66+
#endif
67+
5968
#if defined(_LIBCPP_OBJECT_FORMAT_MACHO)
6069

6170
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -68,8 +77,8 @@ _LIBCPP_END_NAMESPACE_STD
6877
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
6978
# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \
7079
static __attribute__((used)) type symbol##_impl__ arglist __asm__("_" _LIBCPP_TOSTRING(symbol)); \
71-
__asm__(".globl _" _LIBCPP_TOSTRING(symbol)); \
72-
__asm__(".weak_definition _" _LIBCPP_TOSTRING(symbol)); \
80+
__asm__(".globl _" _LIBCPP_TOSTRING(symbol) _LIBCPP_SYMBOL_SUFFIX); \
81+
__asm__(".weak_definition _" _LIBCPP_TOSTRING(symbol) _LIBCPP_SYMBOL_SUFFIX); \
7382
extern __typeof(symbol##_impl__) name __attribute__((weak_import)); \
7483
_LIBCPP_BEGIN_NAMESPACE_STD \
7584
template <> \
@@ -91,7 +100,7 @@ _LIBCPP_END_NAMESPACE_STD
91100
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
92101
# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \
93102
static type symbol##_impl__ arglist __asm__(_LIBCPP_TOSTRING(symbol##_impl__)); \
94-
[[gnu::weak, gnu::alias(_LIBCPP_TOSTRING(symbol##_impl__))]] type name arglist; \
103+
[[gnu::weak, gnu::alias(_LIBCPP_TOSTRING(symbol##_impl__) _LIBCPP_SYMBOL_SUFFIX)]] type name arglist; \
95104
_LIBCPP_BEGIN_NAMESPACE_STD \
96105
template <> \
97106
inline bool __is_function_overridden<static_cast<type(*) arglist>(name)>() { \

0 commit comments

Comments
 (0)