diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h --- a/libc/src/__support/common.h +++ b/libc/src/__support/common.h @@ -22,7 +22,7 @@ #endif #ifndef LLVM_LIBC_FUNCTION_ATTR -#define LLVM_LIBC_FUNCTION_ATTR +#define LLVM_LIBC_FUNCTION_ATTR __attribute__((visibility("default"))) #endif // We use OpenMP to declare these functions on the device. diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -3,7 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # LLVM libc project. -load(":libc_build_rules.bzl", "libc_function", "libc_math_function") +load(":libc_build_rules.bzl", "libc_function", "libc_math_function", + "libc_support_library") load(":platforms.bzl", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_X86_64") load("@bazel_skylib//lib:selects.bzl", "selects") load("@bazel_skylib//rules:common_settings.bzl", "string_flag") @@ -55,7 +56,7 @@ ############################## Support libraries ############################# -cc_library( +libc_support_library( name = "__support_common", hdrs = [ "src/__support/architectures.h", @@ -65,25 +66,25 @@ ], ) -cc_library( +libc_support_library( name = "__support_cpp_array", hdrs = ["src/__support/CPP/array.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_bit", hdrs = ["src/__support/CPP/bit.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_bitset", hdrs = ["src/__support/CPP/bitset.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_cstddef", hdrs = ["src/__support/CPP/cstddef.h"], deps = [ @@ -92,25 +93,25 @@ ], ) -cc_library( +libc_support_library( name = "__support_cpp_functional", hdrs = ["src/__support/CPP/functional.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_limits", hdrs = ["src/__support/CPP/limits.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_optional", hdrs = ["src/__support/CPP/optional.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_span", hdrs = ["src/__support/CPP/span.h"], deps = [ @@ -120,19 +121,19 @@ ], ) -cc_library( +libc_support_library( name = "__support_cpp_string_view", hdrs = ["src/__support/CPP/string_view.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_type_traits", hdrs = ["src/__support/CPP/type_traits.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_utility", hdrs = ["src/__support/CPP/utility.h"], deps = [ @@ -141,13 +142,13 @@ ], ) -cc_library( +libc_support_library( name = "__support_cpp_vector", hdrs = ["src/__support/CPP/vector.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_cpp_atomic", hdrs = ["src/__support/CPP/atomic.h"], deps = [ @@ -156,7 +157,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_number_pair", hdrs = ["src/__support/number_pair.h"], deps = [ @@ -166,7 +167,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_integer_utils", hdrs = ["src/__support/integer_utils.h"], deps = [ @@ -177,7 +178,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_uint", hdrs = ["src/__support/UInt.h"], deps = [ @@ -192,7 +193,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_uint128", hdrs = ["src/__support/UInt128.h"], deps = [ @@ -201,18 +202,18 @@ ], ) -cc_library( +libc_support_library( name = "__support_integer_operations", hdrs = ["src/__support/integer_operations.h"], deps = [":__support_cpp_type_traits"], ) -cc_library( +libc_support_library( name = "__support_ctype_utils", hdrs = ["src/__support/ctype_utils.h"], ) -cc_library( +libc_support_library( name = "__support_str_to_integer", hdrs = ["src/__support/str_to_integer.h"], deps = [ @@ -221,7 +222,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_basic_operations", hdrs = ["src/__support/FPUtil/BasicOperations.h"], deps = [ @@ -231,13 +232,13 @@ ], ) -cc_library( +libc_support_library( name = "__support_named_pair", hdrs = ["src/__support/named_pair.h"], deps = [":libc_root"], ) -cc_library( +libc_support_library( name = "__support_builtin_wrappers", hdrs = ["src/__support/builtin_wrappers.h"], deps = [ @@ -247,7 +248,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_division_and_remainder_operations", hdrs = ["src/__support/FPUtil/DivisionAndRemainderOperations.h"], deps = [ @@ -259,7 +260,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_except_value_utils", hdrs = ["src/__support/FPUtil/except_value_utils.h"], deps = [ @@ -270,7 +271,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_fenv_impl", hdrs = ["src/__support/FPUtil/FEnvImpl.h"], textual_hdrs = [ @@ -285,7 +286,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_float_properties", hdrs = ["src/__support/FPUtil/FloatProperties.h"], deps = [ @@ -295,7 +296,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_fp_bits", hdrs = ["src/__support/FPUtil/FPBits.h"], textual_hdrs = ["src/__support/FPUtil/x86_64/LongDoubleBits.h"], @@ -311,7 +312,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_hypot", hdrs = ["src/__support/FPUtil/Hypot.h"], deps = [ @@ -326,7 +327,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_manipulation_functions", hdrs = ["src/__support/FPUtil/ManipulationFunctions.h"], textual_hdrs = ["src/__support/FPUtil/x86_64/NextAfterLongDouble.h"], @@ -343,7 +344,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_nearest_integer_operations", hdrs = ["src/__support/FPUtil/NearestIntegerOperations.h"], deps = [ @@ -354,7 +355,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_normal_float", hdrs = ["src/__support/FPUtil/NormalFloat.h"], deps = [ @@ -364,7 +365,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_platform_defs", hdrs = ["src/__support/FPUtil/PlatformDefs.h"], deps = [ @@ -389,7 +390,7 @@ ], }) -cc_library( +libc_support_library( name = "__support_fputil_sqrt", hdrs = sqrt_hdrs, deps = [ @@ -415,7 +416,7 @@ "src/__support/FPUtil/aarch64/FMA.h", ] -cc_library( +libc_support_library( name = "__support_fputil_fma", hdrs = fma_common_hdrs, # These are conditionally included and will #error out if the platform @@ -434,7 +435,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_multiply_add", hdrs = [ "src/__support/FPUtil/multiply_add.h", @@ -445,7 +446,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_fputil_polyeval", hdrs = [ "src/__support/FPUtil/PolyEval.h", @@ -464,7 +465,7 @@ "src/__support/FPUtil/aarch64/nearest_integer.h", ] -cc_library( +libc_support_library( name = "__support_fputil_nearest_integer", hdrs = nearest_integer_common_hdrs, # These are conditionally included and will #error out if the platform @@ -477,7 +478,7 @@ ], ) -cc_library( +libc_support_library( name = "__support_osutil", hdrs = ["src/__support/OSUtil/syscall.h"], textual_hdrs = [ @@ -635,7 +636,7 @@ ################################ math targets ################################ -cc_library( +libc_support_library( name = "math_utils", srcs = ["src/math/generic/math_utils.cpp"], hdrs = ["src/math/generic/math_utils.h"], @@ -647,7 +648,7 @@ ], ) -cc_library( +libc_support_library( name = "common_constants", srcs = ["src/math/generic/common_constants.cpp"], hdrs = ["src/math/generic/common_constants.h"], @@ -656,7 +657,7 @@ ], ) -cc_library( +libc_support_library( name = "range_reduction", hdrs = [ "src/math/generic/range_reduction.h", @@ -671,7 +672,7 @@ ], ) -cc_library( +libc_support_library( name = "sincosf_utils", hdrs = ["src/math/generic/sincosf_utils.h"], deps = [ @@ -1043,7 +1044,7 @@ "-ubsan", ] -cc_library( +libc_support_library( name = "string_memory_utils", hdrs = [ "src/string/memory_utils/op_aarch64.h", @@ -1070,7 +1071,7 @@ ], ) -cc_library( +libc_support_library( name = "string_utils", hdrs = ["src/string/string_utils.h"], deps = [ diff --git a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl --- a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl +++ b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl @@ -10,6 +10,31 @@ LIBC_ROOT_TARGET = ":libc_root" INTERNAL_SUFFIX = ".__internal__" +def _libc_library(name, copts = None, **kwargs): + """Internal macro to serve as a base for all other libc library rules. + + Args: + name: Target name. + copts: The special compiler options for the target. + **kwargs: All other attributes relevant for the cc_library rule. + """ + copts = copts or [] + # We want all libc sources to be compiled with "hidden" visibility. + # The public symbols will be given "default" visibility explicitly. + # See src/__support/common.h for more information. + copts.append("-fvisibility=hidden") + native.cc_library( + name = name, + copts = copts, + linkstatic = 1, + **kwargs + ) + +# A convenience var which should be used to list all libc support libraries. +# Any library which does not define a public function should be listed with +# libc_support_library. +libc_support_library = _libc_library + def libc_function(name, srcs, weak = False, deps = None, copts = None, **kwargs): """Add target for a libc function. @@ -23,7 +48,7 @@ name: Target name. It is normally the name of the function this target is for. srcs: The .cpp files which contain the function implementation. - weak: Whether the symbol is marked weak. + weak: Make the symbol corresponding to the libc function "weak". deps: The list of target dependencies if any. copts: The list of options to add to the C++ compilation command. **kwargs: Other attributes relevant for a cc_library. For example, deps. @@ -49,13 +74,16 @@ # This second target is the llvm libc C function. copts.append("-DLLVM_LIBC_PUBLIC_PACKAGING") if weak: - copts.append("-DLLVM_LIBC_FUNCTION_ATTR=__attribute__((weak))") - native.cc_library( + # We want weak libc functions to also have default visibility. So, + # we will add the weak as well as the default visibility attribute. + weak_attr = "__attribute__((weak))" + default_vis = "__attribute__((visibility(\"default\")))" + copts.append("-DLLVM_LIBC_FUNCTION_ATTR='%s %s'" % (weak_attr, default_vis)) + _libc_library( name = name, srcs = srcs, deps = deps, copts = copts, - linkstatic = 1, **kwargs )