Author: Louis Dionne Date: 2026-11-16T13:45:42+01:00 New Revision: 15b7f2cfa1a8137d74d5226dd4c01ed0cbe071f4
URL: https://github.com/llvm/llvm-project/commit/15b7f2cfa1a8137d74d5226dd4c01ed0cbe071f4 DIFF: https://github.com/llvm/llvm-project/commit/15b7f2cfa1a8137d74d5226dd4c01ed0cbe071f4.diff LOG: [libc++] Use section-based overridden function detection on Mach-O (#240482) PR #208330 switched the non-ptrauth implementation of __is_function_overridden to a mechanism that defines a local alias at the same address as the weak function f. Recent Mach-O linkers (e.g. the one in Xcode 27.0) bind references to a weak definition directly when that definition has a local alias at the same address, instead of going through a weak-def-coalesced stub or GOT entry. Older linkers like the ones in Xcode 26.6 (which we use in the CI) don't do that, which is why this wasn't caught by the CI. This means that we always resolved `__is_function_overridden` to false with newer linkers, which breaks the detection mechanism. Assisted by Claude (cherry picked from commit de513b8f794ed75611475fea0f4ff2746a7c663f) Added: Modified: libcxx/src/include/overridable_function.h Removed: ################################################################################ diff --git a/libcxx/src/include/overridable_function.h b/libcxx/src/include/overridable_function.h index 307405812f9af7..ff69380d8fa8e9 100644 --- a/libcxx/src/include/overridable_function.h +++ b/libcxx/src/include/overridable_function.h @@ -43,10 +43,12 @@ // compares the address of `__impl_ref<f>::__impl_` with the address of `f` loaded from // GOT: if `f` was overridden by the user in another TU, the addresses will be diff erent. // -// When pointer authentication is used, the above mechanism doesn't work (yet) so we use -// a diff erent strategy placing `f`'s definition (in the libc++ built library) inside -// a special section, which we do using the `__section__` attribute via the -// OVERRIDABLE_FUNCTION macro. Then, when comes the time to check whether the function has +// When pointer authentication is used, the above mechanism doesn't work. It also doesn't work +// with recent Mach-O linkers, which bind references to a weak definition directly (instead of +// through a weak-def-coalesced GOT entry) when that definition has a local alias at the same +// address. In both cases, we use a diff erent strategy, placing `f`'s definition (in the libc++ +// built library) inside a special section, which we do using the `__section__` attribute via +// the OVERRIDABLE_FUNCTION macro. Then, when comes the time to check whether the function has // been overridden, we take the address of the function and we check whether it falls inside // the special section we created. This can be done by finding pointers to the start and // the end of the section, and then checking whether `f` falls within those bounds. @@ -63,7 +65,7 @@ # define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1 -# if !__has_feature(ptrauth_calls) +# if !__has_feature(ptrauth_calls) && !defined(_LIBCPP_OBJECT_FORMAT_MACHO) # define OVERRIDABLE_FUNCTION [[gnu::weak]] @@ -112,7 +114,7 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_function_overridden() noexcept { _LIBCPP_END_NAMESPACE_STD -# else // __has_feature(ptrauth_calls) +# else // __has_feature(ptrauth_calls) || defined(_LIBCPP_OBJECT_FORMAT_MACHO) # include <cstdint> # include <ptrauth.h> @@ -152,7 +154,7 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_function_overridden() noexcept { } _LIBCPP_END_NAMESPACE_STD -# endif // __has_feature(ptrauth_calls) +# endif // __has_feature(ptrauth_calls) || defined(_LIBCPP_OBJECT_FORMAT_MACHO) #else // defined(_LIBCPP_OBJECT_FORMAT_MACHO) || (defined(_LIBCPP_OBJECT_FORMAT_ELF) && !defined(__NVPTX__)) _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
