[libcxx][libcxxabi] Remove OVERRIDABLE_FUNCTION macro (#209323)

This is no longer needed, we can just use [[gnu::weak]] attribute.
This commit is contained in:
Petr Hosek 2026-07-14 00:15:30 -07:00 committed by GitHub
parent aae0191917
commit 6c6ecb376a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 21 deletions

View file

@ -21,17 +21,12 @@
// whether an overridable function (typically a weak symbol) like `operator new`
// has been overridden by a user or not.
//
// This is a low-level utility which does not work on all platforms, since it needs
// to make assumptions about the object file format in use. Furthermore, it requires
// the "base definition" of the function (the one we want to check whether it has been
// overridden) to be defined using the OVERRIDABLE_FUNCTION macro.
//
// This currently works with Mach-O files (used on Darwin) and with ELF files (used on Linux
// and others). On platforms where we know how to implement this detection, the macro
// _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION is defined to 1, and it is defined to 0 on
// other platforms. The OVERRIDABLE_FUNCTION macro is defined to perform a normal
// function definition on unsupported platforms so that it can be used to define functions
// regardless of whether detection is actually supported.
// This is a low-level utility which does not work on all platforms, since it needs to
// make assumptions about the object file format in use. This currently works with Mach-O
// files (used on Darwin) and with ELF files (used on Linux and others). On platforms
// where we know how to implement this detection, the macro
// _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION is defined to 1, and it is defined to 0 on
// other platforms.
//
// How does this work?
// -------------------
@ -54,7 +49,6 @@
#if defined(_LIBCPP_OBJECT_FORMAT_MACHO) || (defined(_LIBCPP_OBJECT_FORMAT_ELF) && !defined(__NVPTX__))
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
# define OVERRIDABLE_FUNCTION [[gnu::weak]]
_LIBCPP_BEGIN_NAMESPACE_STD
@ -104,7 +98,6 @@ _LIBCPP_END_NAMESPACE_STD
#else
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 0
# define OVERRIDABLE_FUNCTION [[gnu::weak]]
#endif

View file

@ -43,7 +43,7 @@ static void* operator_new_impl(std::size_t size) {
return p;
}
OVERRIDABLE_FUNCTION void* operator new(std::size_t size) _THROW_BAD_ALLOC {
[[gnu::weak]] void* operator new(std::size_t size) _THROW_BAD_ALLOC {
void* p = operator_new_impl(size);
if (p == nullptr)
__throw_bad_alloc_shim();
@ -74,7 +74,7 @@ OVERRIDABLE_FUNCTION void* operator new(std::size_t size) _THROW_BAD_ALLOC {
# endif
}
OVERRIDABLE_FUNCTION void* operator new[](size_t size) _THROW_BAD_ALLOC { return ::operator new(size); }
[[gnu::weak]] void* operator new[](size_t size) _THROW_BAD_ALLOC { return ::operator new(size); }
[[gnu::weak]] void* operator new[](size_t size, const std::nothrow_t&) noexcept {
# if !_LIBCPP_HAS_EXCEPTIONS
@ -134,7 +134,7 @@ static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignm
return p;
}
OVERRIDABLE_FUNCTION void* operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
[[gnu::weak]] void* operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
void* p = operator_new_aligned_impl(size, alignment);
if (p == nullptr)
__throw_bad_alloc_shim();
@ -165,7 +165,7 @@ OVERRIDABLE_FUNCTION void* operator new(std::size_t size, std::align_val_t align
# endif
}
OVERRIDABLE_FUNCTION void* operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
[[gnu::weak]] void* operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
return ::operator new(size, alignment);
}

View file

@ -59,7 +59,7 @@ static void* operator_new_impl(std::size_t size) {
return p;
}
OVERRIDABLE_FUNCTION void* operator new(std::size_t size) _THROW_BAD_ALLOC {
[[gnu::weak]] void* operator new(std::size_t size) _THROW_BAD_ALLOC {
void* p = operator_new_impl(size);
if (p == nullptr)
__throw_bad_alloc_shim();
@ -90,7 +90,7 @@ OVERRIDABLE_FUNCTION void* operator new(std::size_t size) _THROW_BAD_ALLOC {
#endif
}
OVERRIDABLE_FUNCTION void* operator new[](size_t size) _THROW_BAD_ALLOC { return ::operator new(size); }
[[gnu::weak]] void* operator new[](size_t size) _THROW_BAD_ALLOC { return ::operator new(size); }
[[gnu::weak]] void* operator new[](size_t size, const std::nothrow_t&) noexcept {
#if !_LIBCPP_HAS_EXCEPTIONS
@ -150,7 +150,7 @@ static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignm
return p;
}
OVERRIDABLE_FUNCTION void* operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
[[gnu::weak]] void* operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
void* p = operator_new_aligned_impl(size, alignment);
if (p == nullptr)
__throw_bad_alloc_shim();
@ -181,7 +181,7 @@ OVERRIDABLE_FUNCTION void* operator new(std::size_t size, std::align_val_t align
# endif
}
OVERRIDABLE_FUNCTION void* operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
[[gnu::weak]] void* operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
return ::operator new(size, alignment);
}