Skip to content

Commit 7b6b05c

Browse files
committed
Update the Mach-O implementation
This roughly matches the ELF version and addresses the issue #123224.
1 parent f76dd14 commit 7b6b05c

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

libcxx/src/include/overridable_function.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@
4242
// -------------------
4343
//
4444
// Let's say we want to check whether a weak function `f` has been overridden by the user.
45-
// The general mechanism works by defining an internal symbol `.L.f` and a weak alias `f`
46-
// via the _LIBCPP_OVERRIDABLE_FUNCTION macro.
47-
//
48-
// Then, when comes the time to check whether the function has been overridden, we take
49-
// the address of the function `f` and we check whether it is different from `.L.f`.
50-
// If so it means the function was overriden by the user.
45+
// The general mechanism works by defining an internal symbol and a weak alias `f` via the
46+
// _LIBCPP_OVERRIDABLE_FUNCTION macro. Then, when comes the time to check whether the
47+
// function has been overridden, we take the address of the internal symbol and the weak
48+
// alias `f` and check whether they're different. If so it means the function was overriden
49+
// by the user.
5150
//
5251
// Important note
5352
// --------------
@@ -67,17 +66,14 @@ _LIBCPP_END_NAMESPACE_STD
6766

6867
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
6968
# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \
70-
[[gnu::used]] static type symbol arglist __asm__("_" _LIBCPP_TOSTRING(symbol)); \
71-
__asm__(".globl _" _LIBCPP_TOSTRING(symbol)); \
72-
__asm__(".weak_definition _" _LIBCPP_TOSTRING(symbol)); \
73-
[[clang::weak_import]] extern type name arglist; \
69+
[[clang::weak_import]] extern type symbol arglist __asm__("_" _LIBCPP_TOSTRING(symbol)); \
7470
_LIBCPP_BEGIN_NAMESPACE_STD \
7571
template <> \
7672
inline bool __is_function_overridden<static_cast<type(*) arglist>(name)>() { \
7773
return static_cast<type(*) arglist>(name) != symbol; \
7874
} \
7975
_LIBCPP_END_NAMESPACE_STD \
80-
static type symbol arglist
76+
type name arglist
8177

8278
#elif defined(_LIBCPP_OBJECT_FORMAT_ELF)
8379

0 commit comments

Comments
 (0)