From 4a6929f81144c735136660f9afc819b2f5eaac8c Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Thu, 16 Jun 2022 09:28:17 +0000 Subject: [PATCH] Revert "[libc] Apply no-builtin everywhere, remove unnecessary flags" This reverts commit b2a9ea4420127d10b18ae648b16757665f8bbd7c. --- libc/cmake/modules/LLVMLibCObjectRules.cmake | 2 +- libc/src/string/CMakeLists.txt | 14 ++++++++ utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 38 +++++++++++++++++----- .../llvm-project-overlay/libc/libc_build_rules.bzl | 1 - 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake index 496c8ba..80ca475 100644 --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -11,7 +11,7 @@ function(_get_common_compile_options output_var flags) set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN}) if(NOT ${LIBC_TARGET_OS} STREQUAL "windows") - set(compile_options ${compile_options} -fpie -ffreestanding -fno-builtin) + set(compile_options ${compile_options} -fpie -ffreestanding) endif() if(LLVM_COMPILER_IS_GCC_COMPATIBLE) list(APPEND compile_options "-fno-exceptions") diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index 68962e2..c4f45e6 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -279,6 +279,7 @@ function(add_implementation name impl_name) ${ARGN}) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + list(APPEND ADD_IMPL_MLLVM_COMPILE_OPTIONS "-combiner-global-alias-analysis") # Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication. foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS) list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}") @@ -308,6 +309,9 @@ function(add_bcmp bcmp_name) DEPENDS .memory_utils.memory_utils libc.include.string + COMPILE_OPTIONS + -fno-builtin-memcmp + -fno-builtin-bcmp ${ARGN} ) endfunction() @@ -335,6 +339,8 @@ function(add_bzero bzero_name) DEPENDS .memory_utils.memset_implementation libc.include.string + COMPILE_OPTIONS + -fno-builtin-bzero ${ARGN} ) endfunction() @@ -362,6 +368,8 @@ function(add_memcmp memcmp_name) DEPENDS .memory_utils.memcmp_implementation libc.include.string + COMPILE_OPTIONS + -fno-builtin-memcmp ${ARGN} ) endfunction() @@ -392,6 +400,8 @@ function(add_memcpy memcpy_name) DEPENDS .memory_utils.memcpy_implementation libc.include.string + COMPILE_OPTIONS + -fno-builtin-memcpy ${ARGN} ) endfunction() @@ -424,6 +434,8 @@ function(add_memmove memmove_name) DEPENDS .memory_utils.memory_utils libc.include.string + COMPILE_OPTIONS + -fno-builtin ${ARGN} ) endfunction() @@ -456,6 +468,8 @@ function(add_memset memset_name) DEPENDS .memory_utils.memset_implementation libc.include.string + COMPILE_OPTIONS + -fno-builtin-memset ${ARGN} ) endfunction() diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 48bf68a..0dde561 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -9,7 +9,6 @@ load("@bazel_skylib//lib:selects.bzl", "selects") package( default_visibility = ["//visibility:public"], - features = ["-use_header_modules"], licenses = ["notice"], ) @@ -86,10 +85,7 @@ cc_library( hdrs = [ "src/__support/CPP/UInt.h", ], - deps = [ - "__support_cpp_array", - ":libc_root", - ], + deps = [":libc_root","__support_cpp_array"], ) cc_library( @@ -97,10 +93,7 @@ cc_library( hdrs = [ "src/__support/CPP/TypeTraits.h", ], - deps = [ - "__support_cpp_uint", - ":libc_root", - ], + deps = [":libc_root","__support_cpp_uint"], ) cc_library( @@ -833,6 +826,12 @@ libc_function( name = "memcpy", srcs = ["src/string/memcpy.cpp"], hdrs = ["src/string/memcpy.h"], + copts = [ + "-fno-builtin-memcpy", + "-fno-builtin-memmove", + "-mllvm -combiner-global-alias-analysis", + "-mllvm --tail-merge-threshold=0", + ], features = no_sanitize_features, deps = [ ":__support_common", @@ -844,6 +843,10 @@ libc_function( name = "memset", srcs = ["src/string/memset.cpp"], hdrs = ["src/string/memset.h"], + copts = [ + "-fno-builtin-memset", + "-mllvm -combiner-global-alias-analysis", + ], features = no_sanitize_features, deps = [ ":__support_common", @@ -855,6 +858,10 @@ libc_function( name = "memmove", srcs = ["src/string/memmove.cpp"], hdrs = ["src/string/memmove.h"], + copts = [ + "-fno-builtin-memmove", + "-mllvm -combiner-global-alias-analysis", + ], features = no_sanitize_features, deps = [ ":__support_common", @@ -868,6 +875,10 @@ libc_function( name = "memcmp", srcs = ["src/string/memcmp.cpp"], hdrs = ["src/string/memcmp.h"], + copts = [ + "-fno-builtin-memcmp", + "-mllvm -combiner-global-alias-analysis", + ], features = no_sanitize_features, deps = [ ":__support_common", @@ -880,6 +891,10 @@ libc_function( name = "bcmp", srcs = ["src/string/bcmp.cpp"], hdrs = ["src/string/bcmp.h"], + copts = [ + "-fno-builtin-bcmp", + "-fno-builtin-memcmp", + ], features = no_sanitize_features, deps = [ ":__support_common", @@ -891,6 +906,11 @@ libc_function( name = "bzero", srcs = ["src/string/bzero.cpp"], hdrs = ["src/string/bzero.h"], + copts = [ + "-fno-builtin-bzero", + "-fno-builtin-memset", + "-mllvm -combiner-global-alias-analysis", + ], features = no_sanitize_features, deps = [ ":__support_common", diff --git a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl index 2e1732e..85eb35c 100644 --- a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl +++ b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl @@ -31,7 +31,6 @@ def libc_function(name, srcs, deps = None, copts = None, **kwargs): deps.append(LIBC_ROOT_TARGET) copts = copts or [] copts.append("-O3") - copts.append("-fno-builtin") # We compile the code twice, the first target is suffixed with ".__internal__" and contains the # C++ functions in the "__llvm_libc" namespace. This allows us to test the function in the -- 2.7.4