Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions libcxx/src/include/overridable_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like a generally missing feature that Clang doesn't provide any way to access that. I would prefer if we instead introduced either a macro that contains this suffix, or even better some kind of __builtin_symbol_name(name) that returns a string representing the symbol name for that entity while taking into account -funique-internal-linkage-names if needed.

That's something we could also use when defining operator new itself, i.e. we would not have to hardcode the mangled name in the macro. Similarly, we could refactor horrors like https://github.com/llvm/llvm-project/blob/main/libcxx/src/iostream.cpp#L22 where we hardcode mangled names, something @philnik777 was looking to do recently.

WDYT?

// `.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.
#ifndef _LIBCPP_SYMBOL_SUFFIX
#define _LIBCPP_SYMBOL_SUFFIX
#endif

#if defined(_LIBCPP_OBJECT_FORMAT_MACHO)

_LIBCPP_BEGIN_NAMESPACE_STD
Expand All @@ -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 <> \
Expand All @@ -90,8 +99,8 @@ _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; \
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 <> \
inline bool __is_function_overridden<static_cast<type(*) arglist>(name)>() { \
Expand Down
Loading