Skip to content

Commit c470197

Browse files
committed
[libcxx] Option to disable overridden function detection
The overriden function detection requires the use of a custom section which can break existing linker scripts that are commonly used in embedded systems. This change introduces an option to disable this feature.
1 parent 9fc789d commit c470197

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

libcxx/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
127127
to provide compile-time errors when using features unavailable on some version of
128128
the shared library they shipped should turn this on and see `include/__configuration/availability.h`
129129
for more details." OFF)
130+
option(LIBCXX_ENABLE_OVERRIDDEN_FUNCTION_DETECTION
131+
"Whether to support detecting if an overridable function (typically a weak symbol)
132+
has been overidden by a user or not." ON)
130133

131134
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
132135
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
@@ -763,6 +766,7 @@ config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
763766
config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
764767
config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
765768
config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
769+
config_define_if_not(LIBCXX_ENABLE_OVERRIDDEN_FUNCTION_DETECTION _LIBCPP_HAS_NO_OVERRIDDEN_FUNCTION_DETECTION)
766770

767771
if (LIBCXX_ENABLE_ASSERTIONS)
768772
message(DEPRECATION "LIBCXX_ENABLE_ASSERTIONS is deprecated and will be removed in LLVM 20. Please use LIBCXX_HARDENING_MODE instead.")

libcxx/include/__config_site.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32
2323
#cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
2424
#cmakedefine _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
25+
#cmakedefine _LIBCPP_HAS_NO_OVERRIDDEN_FUNCTION_DETECTION
2526
#cmakedefine _LIBCPP_NO_VCRUNTIME
2627
#cmakedefine _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION @_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION@
2728
#cmakedefine _LIBCPP_HAS_NO_FILESYSTEM

libcxx/src/include/overridable_function.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
// want to be defining special sections inside user's executables which use our headers.
6464
//
6565

66-
#if defined(_LIBCPP_OBJECT_FORMAT_MACHO)
66+
#if defined(_LIBCPP_OBJECT_FORMAT_MACHO) && !defined(_LIBCPP_HAS_NO_OVERRIDDEN_FUNCTION_DETECTION)
6767

6868
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
6969
# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE \
@@ -97,7 +97,7 @@ _LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) no
9797
_LIBCPP_END_NAMESPACE_STD
9898

9999
// The NVPTX linker cannot create '__start/__stop' sections.
100-
#elif defined(_LIBCPP_OBJECT_FORMAT_ELF) && !defined(__NVPTX__)
100+
#elif defined(_LIBCPP_OBJECT_FORMAT_ELF) && !defined(__NVPTX__) && !defined(_LIBCPP_HAS_NO_OVERRIDDEN_FUNCTION_DETECTION)
101101

102102
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
103103
# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE __attribute__((__section__("__lcxx_override")))

0 commit comments

Comments
 (0)