Skip to content

Commit 9e8d9a8

Browse files
committed
fixup! [libc][math] Optimize nearest integer functions using builtins when available
Fix builtin detection succeeding even when calls to functions provided by the system libc are generated.
1 parent 80c9798 commit 9e8d9a8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

libc/cmake/modules/CheckCompilerFeatures.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,18 @@ set(AVAILABLE_COMPILER_FEATURES "")
5050
foreach(feature IN LISTS ALL_COMPILER_FEATURES)
5151
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
5252
set(compile_options ${LIBC_COMPILE_OPTIONS_NATIVE})
53+
set(link_options "")
5354
if(${feature} STREQUAL "fixed_point")
5455
list(APPEND compile_options "-ffixed-point")
5556
elseif(${feature} MATCHES "^builtin_")
5657
set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT})
58+
set(link_options -nostdlib)
5759
# The compiler might handle calls to rounding builtins by generating calls
5860
# to the respective libc math functions, in which case we cannot use these
5961
# builtins in our implementations of these functions. We check that this is
6062
# not the case by trying to link an executable, since linking would fail due
61-
# to unresolved references if calls to libc functions were generated.
63+
# to unresolved references with -nostdlib if calls to libc functions were
64+
# generated.
6265
set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
6366
endif()
6467

@@ -67,6 +70,7 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
6770
${CMAKE_CURRENT_BINARY_DIR}/compiler_features
6871
SOURCES ${LIBC_SOURCE_DIR}/cmake/modules/compiler_features/check_${feature}.cpp
6972
COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${compile_options}
73+
LINK_OPTIONS ${link_options}
7074
)
7175
if(has_feature)
7276
list(APPEND AVAILABLE_COMPILER_FEATURES ${feature})

0 commit comments

Comments
 (0)