Skip to content

Commit 7681005

Browse files
petrhosekcopybara-github
authored andcommitted
[libcxx] Use alias for detecting overriden function (#120805)
This mechanism is preferable in environments like embedded since it doesn't require special handling of the custom section. This is a reland of llvm/llvm-project#114961 which addresses the issue reported by downstream users. Specifically, the two differences from the previous version are: * The internal `symbol##_impl__` symbol in the Mach-O implementation is annotated with `__attribute__((used))` to prevent LTO from deleting it which we've seen in the previous version. * `__is_function_overridden` is marked as `inline` so these symbols are placed in a COMDAT (or fully inlined) to avoid duplicate symbol errors which we've seen in the previous version. NOKEYCHECK=True GitOrigin-RevId: 841895543edcf98bd16027c6b85fe7c6419a4566
1 parent 83dfa1f commit 7681005

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/stdlib_new_delete.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void* operator_new_impl(std::size_t size) {
6363
return p;
6464
}
6565

66-
_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new(std::size_t size) _THROW_BAD_ALLOC {
66+
_LIBCPP_OVERRIDABLE_FUNCTION(_Znwm, void*, operator new, (std::size_t size)) _THROW_BAD_ALLOC {
6767
void* p = operator_new_impl(size);
6868
if (p == nullptr)
6969
__throw_bad_alloc_shim();
@@ -74,7 +74,7 @@ _LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
7474
#if !_LIBCPP_HAS_EXCEPTIONS
7575
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
7676
_LIBCPP_ASSERT_SHIM(
77-
!std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new)),
77+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t)>(&operator new)>(),
7878
"libc++ was configured with exceptions disabled and `operator new(size_t)` has been overridden, "
7979
"but `operator new(size_t, nothrow_t)` has not been overridden. This is problematic because "
8080
"`operator new(size_t, nothrow_t)` must call `operator new(size_t)`, which will terminate in case "
@@ -94,15 +94,15 @@ _LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
9494
#endif
9595
}
9696

97-
_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new[](size_t size) _THROW_BAD_ALLOC {
97+
_LIBCPP_OVERRIDABLE_FUNCTION(_Znam, void*, operator new[], (size_t size)) _THROW_BAD_ALLOC {
9898
return ::operator new(size);
9999
}
100100

101101
_LIBCPP_WEAK void* operator new[](size_t size, const std::nothrow_t&) noexcept {
102102
#if !_LIBCPP_HAS_EXCEPTIONS
103103
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
104104
_LIBCPP_ASSERT_SHIM(
105-
!std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new[])),
105+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t)>(&operator new[])>(),
106106
"libc++ was configured with exceptions disabled and `operator new[](size_t)` has been overridden, "
107107
"but `operator new[](size_t, nothrow_t)` has not been overridden. This is problematic because "
108108
"`operator new[](size_t, nothrow_t)` must call `operator new[](size_t)`, which will terminate in case "
@@ -156,8 +156,8 @@ static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignm
156156
return p;
157157
}
158158

159-
_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
160-
operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
159+
_LIBCPP_OVERRIDABLE_FUNCTION(_ZnwmSt11align_val_t, void*, operator new, (std::size_t size, std::align_val_t alignment))
160+
_THROW_BAD_ALLOC {
161161
void* p = operator_new_aligned_impl(size, alignment);
162162
if (p == nullptr)
163163
__throw_bad_alloc_shim();
@@ -168,7 +168,7 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
168168
# if !_LIBCPP_HAS_EXCEPTIONS
169169
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
170170
_LIBCPP_ASSERT_SHIM(
171-
!std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new)),
171+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new)>(),
172172
"libc++ was configured with exceptions disabled and `operator new(size_t, align_val_t)` has been overridden, "
173173
"but `operator new(size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
174174
"`operator new(size_t, align_val_t, nothrow_t)` must call `operator new(size_t, align_val_t)`, which will "
@@ -188,16 +188,14 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
188188
# endif
189189
}
190190

191-
_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
192-
operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
193-
return ::operator new(size, alignment);
194-
}
191+
_LIBCPP_OVERRIDABLE_FUNCTION(_ZnamSt11align_val_t, void*, operator new[], (size_t size, std::align_val_t alignment))
192+
_THROW_BAD_ALLOC { return ::operator new(size, alignment); }
195193

196194
_LIBCPP_WEAK void* operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept {
197195
# if !_LIBCPP_HAS_EXCEPTIONS
198196
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
199197
_LIBCPP_ASSERT_SHIM(
200-
!std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new[])),
198+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new[])>(),
201199
"libc++ was configured with exceptions disabled and `operator new[](size_t, align_val_t)` has been overridden, "
202200
"but `operator new[](size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
203201
"`operator new[](size_t, align_val_t, nothrow_t)` must call `operator new[](size_t, align_val_t)`, which will "

0 commit comments

Comments
 (0)