1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 load(":libc_build_rules.bzl", "libc_function", "libc_math_function")
7 load(":platforms.bzl", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_X86_64")
8 load("@bazel_skylib//lib:selects.bzl", "selects")
11 default_visibility = ["//visibility:public"],
12 licenses = ["notice"],
15 # This empty root library helps us add an include path to this directory
16 # using the 'includes' attribute. The strings listed in the includes attribute
17 # are relative paths wrt this library but are inherited by the dependents
18 # appropriately. Hence, using this as a root dependency avoids adding include
19 # paths of the kind "../../" to other libc targets.
25 ############################## Support libraries #############################
28 name = "__support_common",
30 "src/__support/architectures.h",
31 "src/__support/common.h",
32 "src/__support/endian.h",
33 "src/__support/sanitizer.h",
38 name = "__support_standalone_cpp",
40 "src/__support/CPP/Array.h",
41 "src/__support/CPP/ArrayRef.h",
42 "src/__support/CPP/Bitset.h",
43 "src/__support/CPP/Functional.h",
44 "src/__support/CPP/Limits.h",
45 "src/__support/CPP/StringView.h",
46 "src/__support/CPP/TypeTraits.h",
48 deps = [":libc_root"],
52 name = "__support_integer_operations",
53 hdrs = ["src/__support/integer_operations.h"],
54 deps = [":__support_standalone_cpp"],
58 name = "__support_ctype_utils",
59 hdrs = ["src/__support/ctype_utils.h"],
63 name = "__support_str_to_integer",
64 hdrs = ["src/__support/str_to_integer.h"],
66 ":__support_ctype_utils",
67 ":__support_standalone_cpp",
71 fputil_common_hdrs = [
72 "src/__support/FPUtil/BasicOperations.h",
73 "src/__support/FPUtil/DivisionAndRemainderOperations.h",
74 "src/__support/FPUtil/FEnvImpl.h",
75 "src/__support/FPUtil/FEnvUtils.h",
76 "src/__support/FPUtil/FPBits.h",
77 "src/__support/FPUtil/FloatProperties.h",
78 "src/__support/FPUtil/Hypot.h",
79 "src/__support/FPUtil/ManipulationFunctions.h",
80 "src/__support/FPUtil/NearestIntegerOperations.h",
81 "src/__support/FPUtil/NormalFloat.h",
82 "src/__support/FPUtil/PlatformDefs.h",
83 "src/__support/FPUtil/Sqrt.h",
86 fputil_hdrs = selects.with_or({
87 "//conditions:default": fputil_common_hdrs,
88 PLATFORM_CPU_X86_64: fputil_common_hdrs + [
89 "src/__support/FPUtil/x86_64/LongDoubleBits.h",
90 "src/__support/FPUtil/x86_64/NextAfterLongDouble.h",
91 "src/__support/FPUtil/x86_64/SqrtLongDouble.h",
92 "src/__support/FPUtil/x86_64/FEnvImpl.h",
94 PLATFORM_CPU_ARM64: fputil_common_hdrs + [
95 "src/__support/FPUtil/aarch64/FEnvImpl.h",
100 name = "__support_fputil",
104 ":__support_standalone_cpp",
109 ################################ fenv targets ################################
112 name = "fetestexcept",
113 srcs = ["src/fenv/fetestexcept.cpp"],
114 hdrs = ["src/fenv/fetestexcept.h"],
122 name = "feclearexcept",
123 srcs = ["src/fenv/feclearexcept.cpp"],
124 hdrs = ["src/fenv/feclearexcept.h"],
132 name = "feraiseexcept",
133 srcs = ["src/fenv/feraiseexcept.cpp"],
134 hdrs = ["src/fenv/feraiseexcept.h"],
143 srcs = ["src/fenv/fegetround.cpp"],
144 hdrs = ["src/fenv/fegetround.h"],
153 srcs = ["src/fenv/fesetround.cpp"],
154 hdrs = ["src/fenv/fesetround.h"],
162 name = "fedisableexcept",
163 srcs = ["src/fenv/fedisableexcept.cpp"],
164 hdrs = ["src/fenv/fedisableexcept.h"],
172 name = "feenableexcept",
173 srcs = ["src/fenv/feenableexcept.cpp"],
174 hdrs = ["src/fenv/feenableexcept.h"],
182 name = "fegetexcept",
183 srcs = ["src/fenv/fegetexcept.cpp"],
184 hdrs = ["src/fenv/fegetexcept.h"],
193 srcs = ["src/fenv/fegetenv.cpp"],
194 hdrs = ["src/fenv/fegetenv.h"],
203 srcs = ["src/fenv/fesetenv.cpp"],
204 hdrs = ["src/fenv/fesetenv.h"],
212 name = "feupdateenv",
213 srcs = ["src/fenv/feupdateenv.cpp"],
214 hdrs = ["src/fenv/feupdateenv.h"],
222 name = "fegetexceptflag",
223 srcs = ["src/fenv/fegetexceptflag.cpp"],
224 hdrs = ["src/fenv/fegetexceptflag.h"],
232 name = "fesetexceptflag",
233 srcs = ["src/fenv/fesetexceptflag.cpp"],
234 hdrs = ["src/fenv/fesetexceptflag.h"],
242 name = "feholdexcept",
243 srcs = ["src/fenv/feholdexcept.cpp"],
244 hdrs = ["src/fenv/feholdexcept.h"],
251 ################################ math targets ################################
255 srcs = ["src/math/generic/math_utils.cpp"],
256 hdrs = ["src/math/generic/math_utils.h"],
259 ":__support_standalone_cpp",
265 name = "sincosf_utils",
266 srcs = ["src/math/generic/sincosf_data.cpp"],
267 hdrs = ["src/math/generic/sincosf_utils.h"],
274 libc_math_function(name = "fabs")
276 libc_math_function(name = "fabsf")
278 libc_math_function(name = "fabsl")
280 libc_math_function(name = "fdim")
282 libc_math_function(name = "fdimf")
284 libc_math_function(name = "fdiml")
325 libc_math_function(name = "floorl")
327 libc_math_function(name = "ldexp")
329 libc_math_function(name = "ldexpf")
331 libc_math_function(name = "ldexpl")
349 libc_math_function(name = "truncl")
367 libc_math_function(name = "roundl")
369 libc_math_function(name = "frexp")
371 libc_math_function(name = "frexpf")
373 libc_math_function(name = "frexpl")
375 libc_math_function(name = "hypot")
377 libc_math_function(name = "hypotf")
379 libc_math_function(name = "logb")
381 libc_math_function(name = "logbf")
383 libc_math_function(name = "logbl")
385 libc_math_function(name = "modf")
387 libc_math_function(name = "modff")
389 libc_math_function(name = "modfl")
391 libc_math_function(name = "remquo")
393 libc_math_function(name = "remquof")
395 libc_math_function(name = "remquol")
397 libc_math_function(name = "remainder")
399 libc_math_function(name = "remainderf")
401 libc_math_function(name = "remainderl")
403 libc_math_function(name = "fmin")
405 libc_math_function(name = "fminf")
407 libc_math_function(name = "fminl")
409 libc_math_function(name = "fmax")
411 libc_math_function(name = "fmaxf")
413 libc_math_function(name = "fmaxl")
465 libc_math_function(name = "copysign")
467 libc_math_function(name = "copysignf")
469 libc_math_function(name = "copysignl")
471 libc_math_function(name = "ilogb")
473 libc_math_function(name = "ilogbf")
475 libc_math_function(name = "ilogbl")
477 libc_math_function(name = "rint")
479 libc_math_function(name = "rintf")
481 libc_math_function(name = "rintl")
483 libc_math_function(name = "lrint")
485 libc_math_function(name = "lrintf")
487 libc_math_function(name = "lrintl")
489 libc_math_function(name = "llrint")
491 libc_math_function(name = "llrintf")
493 libc_math_function(name = "llrintl")
495 libc_math_function(name = "lround")
497 libc_math_function(name = "lroundf")
499 libc_math_function(name = "lroundl")
501 libc_math_function(name = "llround")
503 libc_math_function(name = "llroundf")
505 libc_math_function(name = "llroundl")
507 libc_math_function(name = "nearbyint")
509 libc_math_function(name = "nearbyintf")
511 libc_math_function(name = "nearbyintl")
513 libc_math_function(name = "nextafter")
515 libc_math_function(name = "nextafterf")
517 libc_math_function(name = "nextafterl")
519 ############################### stdlib targets ###############################
523 srcs = ["src/stdlib/atoi.cpp"],
524 hdrs = ["src/stdlib/atoi.h"],
527 ":__support_str_to_integer",
533 srcs = ["src/stdlib/atol.cpp"],
534 hdrs = ["src/stdlib/atol.h"],
537 ":__support_str_to_integer",
543 srcs = ["src/stdlib/atoll.cpp"],
544 hdrs = ["src/stdlib/atoll.h"],
547 ":__support_str_to_integer",
553 srcs = ["src/stdlib/bsearch.cpp"],
554 hdrs = ["src/stdlib/bsearch.h"],
562 srcs = ["src/stdlib/qsort.cpp"],
563 hdrs = ["src/stdlib/qsort.h"],
571 srcs = ["src/stdlib/strtol.cpp"],
572 hdrs = ["src/stdlib/strtol.h"],
575 ":__support_str_to_integer",
581 srcs = ["src/stdlib/strtoll.cpp"],
582 hdrs = ["src/stdlib/strtoll.h"],
585 ":__support_str_to_integer",
591 srcs = ["src/stdlib/strtoul.cpp"],
592 hdrs = ["src/stdlib/strtoul.h"],
595 ":__support_str_to_integer",
601 srcs = ["src/stdlib/strtoull.cpp"],
602 hdrs = ["src/stdlib/strtoull.h"],
605 ":__support_str_to_integer",
609 ############################### string targets ###############################
611 no_sanitize_features = [
619 name = "string_utils",
620 hdrs = ["src/string/string_utils.h"],
623 ":__support_standalone_cpp",
629 name = "string_memory_utils",
631 "src/string/memory_utils/elements.h",
632 "src/string/memory_utils/elements_aarch64.h",
633 "src/string/memory_utils/elements_x86.h",
634 "src/string/memory_utils/utils.h",
637 "src/string/memory_utils/bcmp_implementations.h",
638 "src/string/memory_utils/memcmp_implementations.h",
639 "src/string/memory_utils/memcpy_implementations.h",
640 "src/string/memory_utils/memset_implementations.h",
650 srcs = ["src/string/memchr.cpp"],
651 hdrs = ["src/string/memchr.h"],
660 srcs = ["src/string/memcpy.cpp"],
661 hdrs = ["src/string/memcpy.h"],
663 "-fno-builtin-memcpy",
664 "-fno-builtin-memmove",
665 "-mllvm -combiner-global-alias-analysis",
666 "-mllvm --tail-merge-threshold=0",
668 features = no_sanitize_features,
671 ":string_memory_utils",
677 srcs = ["src/string/memset.cpp"],
678 hdrs = ["src/string/memset.h"],
680 "-fno-builtin-memset",
681 "-mllvm -combiner-global-alias-analysis",
683 features = no_sanitize_features,
686 ":string_memory_utils",
692 srcs = ["src/string/memmove.cpp"],
693 hdrs = ["src/string/memmove.h"],
695 "-fno-builtin-memmove",
696 "-mllvm -combiner-global-alias-analysis",
698 features = no_sanitize_features,
701 ":__support_integer_operations",
703 ":string_memory_utils",
709 srcs = ["src/string/memcmp.cpp"],
710 hdrs = ["src/string/memcmp.h"],
712 "-fno-builtin-memcmp",
713 "-mllvm -combiner-global-alias-analysis",
715 features = no_sanitize_features,
718 ":__support_integer_operations",
719 ":string_memory_utils",
725 srcs = ["src/string/bcmp.cpp"],
726 hdrs = ["src/string/bcmp.h"],
729 "-fno-builtin-memcmp",
731 features = no_sanitize_features,
734 ":string_memory_utils",
740 srcs = ["src/string/bzero.cpp"],
741 hdrs = ["src/string/bzero.h"],
743 "-fno-builtin-bzero",
744 "-fno-builtin-memset",
745 "-mllvm -combiner-global-alias-analysis",
747 features = no_sanitize_features,
750 ":string_memory_utils",
756 srcs = ["src/string/memrchr.cpp"],
757 hdrs = ["src/string/memrchr.h"],
766 srcs = ["src/string/strlen.cpp"],
767 hdrs = ["src/string/strlen.h"],
768 features = no_sanitize_features,
777 srcs = ["src/string/strcpy.cpp"],
778 hdrs = ["src/string/strcpy.h"],
779 features = no_sanitize_features,
783 ":string_memory_utils",
788 # A sanitizer instrumented flavor of strcpy to be used with unittests.
790 name = "strcpy_sanitized",
792 srcs = ["src/string/strcpy.cpp"],
793 hdrs = ["src/string/strcpy.h"],
797 ":string_memory_utils",
804 srcs = ["src/string/strcmp.cpp"],
805 hdrs = ["src/string/strcmp.h"],
814 srcs = ["src/string/strchr.cpp"],
815 hdrs = ["src/string/strchr.h"],
824 srcs = ["src/string/strrchr.cpp"],
825 hdrs = ["src/string/strrchr.h"],
834 srcs = ["src/string/strstr.cpp"],
835 hdrs = ["src/string/strstr.h"],
844 srcs = ["src/string/strnlen.cpp"],
845 hdrs = ["src/string/strnlen.h"],
854 srcs = ["src/string/strcspn.cpp"],
855 hdrs = ["src/string/strcspn.h"],
864 srcs = ["src/string/strspn.cpp"],
865 hdrs = ["src/string/strspn.h"],
868 ":__support_standalone_cpp",
875 srcs = ["src/string/strpbrk.cpp"],
876 hdrs = ["src/string/strpbrk.h"],
885 srcs = ["src/string/strtok.cpp"],
886 hdrs = ["src/string/strtok.h"],