Skip to content

[libc] Only add '-fno-builtin-*' on the entrypoints that use them #100481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,7 @@ function(_get_common_compile_options output_var flags)
list(APPEND compile_options "-ffixed-point")
endif()

# Builtin recognition causes issues when trying to implement the builtin
# functions themselves. The GPU backends do not use libcalls so we disable
# the known problematic ones. This allows inlining during LTO linking.
if(LIBC_TARGET_OS_IS_GPU)
set(libc_builtins bcmp strlen memmem bzero memcmp memcpy memmem memmove
memset strcmp strstr)
foreach(builtin ${libc_builtins})
list(APPEND compile_options "-fno-builtin-${builtin}")
endforeach()
else()
if(NOT LIBC_TARGET_OS_IS_GPU)
list(APPEND compile_options "-fno-builtin")
endif()

Expand Down
11 changes: 11 additions & 0 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ function(create_entrypoint_object fq_target_name)
add_dependencies(${fq_target_name} ${full_deps_list})
target_link_libraries(${fq_target_name} ${full_deps_list})

# Builtin recognition causes issues when trying to implement the builtin
# functions themselves. The GPU backends do not use libcalls so we disable the
# known problematic ones on the entrypoints that implement them.
if(LIBC_TARGET_OS_IS_GPU)
set(libc_builtins bcmp strlen memmem bzero memcmp memcpy memmem memmove
memset strcmp strstr)
if(${ADD_ENTRYPOINT_OBJ_NAME} IN_LIST libc_builtins)
target_compile_options(${fq_target_name} PRIVATE -fno-builtin-${ADD_ENTRYPOINT_OBJ_NAME})
endif()
endif()

set_target_properties(
${fq_target_name}
PROPERTIES
Expand Down
Loading