aboutsummaryrefslogtreecommitdiff
path: root/libc/cmake/modules
AgeCommit message (Collapse)AuthorFilesLines
2026-02-10[libc] Add option to disable printf bit int (#180832)Michael Jones1-0/+4
Requested as a binary size optimization. Updates the parser, converter utils, config, tests, and docs.
2026-02-03[libc] Tweak the runtimes cross-build for GPU (#178548)Joseph Huber1-2/+2
Summary: We should likely use `-DLLVM_DEFAULT_TARGET_TRIPLE` as the general source of truth, make the handling work with that since we use it for the output directories. Fix the creation of startup files in this mode and make sure it can detect the GPU properly. Fixes: https://github.com/llvm/llvm-project/issues/179375
2026-01-30[libc] provide str to float build configs (#178780)Prabhu Rajasekaran1-0/+12
The str to float code path offers options which can reduce code bloat. Expose them as build config options. Disable Eisel Lemire for avoiding code bloat caused by DETAILED_POWERS_OF_TEN look up table.
2026-01-27[libc] fix LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR (#178136)Jakob Koschel1-4/+4
In order to apply the stack protector correctly to the compile options, we need to make sure to use the same config name everywhere. `LIBC_CONF_ENABLE_STACK_PROTECTOR` seems to be outdated and all other places specify `LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR` and it should therefore be updated here as well.
2026-01-20[libc] Reland %lc support in printf (#176110)Shubh Pachchigar1-0/+4
Add support for %lc in printf by calling internal wcrtomb function and relevant end-to-end sprintf test. Additionally, made the following changes: - Modified printf parser for recognizing length modifier - Added two internal error codes. - Added a flag to disable wchar support on windows platform. - To keep printf interface header only, converted wcrtomb and CharacterConverter to header only implementation and removed the cpp source. Resolves GPU libc issues in #169983 and original issue: #166598 --------- Co-authored-by: shubhe25p <shubhp@mbm3a24.local> Co-authored-by: Joseph Huber <huberjn@outlook.com>
2026-01-13Revert "[libc] Support %lc in printf (#169983)"Joseph Huber1-4/+0
This reverts commit 1327c50ef199b481f5326cf6ca3710fc111b70b1. The printf headers are intended to be header-only, this introduces external symbol dependencies.
2026-01-13[libc] Support %lc in printf (#169983)Shubh Pachchigar1-0/+4
Add support for %lc in printf by calling internal wcrtomb function and relevant end-to-end sprintf test. Additionally, modified printf parser for recognizing length modifier and added two internal error codes. Also added a flag to disable wchar support on windows platform. Resolves #166598 Co-authored-by: shubh@DOE <shubhp@mbm3a24.local>
2026-01-12[libc] Provide a minimal implementation of elf.h (#172766)Petr Hosek1-1/+1
Some of the baremetal users of libc use elf.h to generate coredumps and we would like to support this use case without needing Linux elf.h.
2026-01-09[libc] Support for generating proxy headers (#175279)Petr Hosek3-2/+10
This is a follow up to #174823 which adds build system integration.
2026-01-06[libc][wctype] Create generation script for classification lookup tables ↵Marcell Leleszi1-0/+4
(#172042) [#172040](https://github.com/llvm/llvm-project/issues/172040) This patch implements the scripts for generating the lookup tables and associated utils for wctype classification functions. Not all Unicode properties are covered as not all need a lookup table, the rest will be hardcoded. The size of the generated tables is 47,8KB.
2025-12-22[libc][math] Add LIBC_CONF_MATH_USE_SYSTEM_FENV / LIBC_MATH_USE_SYSTEM_FENV ↵lntue1-0/+8
(#172902) This is to allow math function implementations to use system libc's fenv.h instead of internal fenv implementations.
2025-12-16[libc] Add Darwin mutex support via os_sync primitives (#167722)Shreeyash Pandey1-0/+4
This patch implements the generic mutex and raw_mutex interfaces on macOS. A new Futex class is provided that relies on os_sync_wait and os_sync_wake to emulate futex‑like wait and wake semantics. The OS‑specific part is moved into futex_utils, which now contains the Darwin implementation.
2025-12-05[libc][fenv] Refactor x86 fenv implementations to make it work for various ↵lntue1-0/+4
fenv_t. (#165015)
2025-12-04Reland Refactor WIDE_READ to allow finer control over high-performance ↵Sterling-Augustine1-3/+2
function selection (#165613) (#170738) [Previous commit had an incorrect default case when FIND_FIRST_CHARACTER_WIDE_READ_IMPL was not specified in config.json. This PR is identical to that one with one line fixed.] As we implement more high-performance string-related functions, we have found a need for better control over their selection than the big-hammer LIBC_CONF_STRING_LENGTH_WIDE_READ. For example, I have a memchr implementation coming, and unless I implement it in every variant, a simple binary value doesn't work. This PR makes gives finer-grained control over high-performance functions than the generic LIBC_CONF_UNSAFE_WIDE_READ option. For any function they like, the user can now select one of four implementations at build time: 1. element, which reads byte-by-byte (or wchar by wchar) 2. wide, which reads by unsigned long 3. generic, which uses standard clang vector implemenations, if available 4. arch, which uses an architecture-specific implemenation (Reading the code carefully, you may note that a user can actually specify any namespace they want, so we aren't technically limited to those 4.) We may also want to switch from command-line #defines as it is currently done, to something more like llvm-project/llvm/include/llvm/Config/llvm-config.h.cmake, and complexity out of the command-line. But that's a future problem.
2025-12-04Revert "Refactor WIDE_READ to allow finer control over high-performance ↵Sterling-Augustine1-2/+3
function selection" (#170717) Reverts llvm/llvm-project#165613 Breaks build bot
2025-12-04Refactor WIDE_READ to allow finer control over high-performance function ↵Sterling-Augustine1-3/+2
selection (#165613) [This is more of a straw-proposal than a ready-for-merging PR. I got started thinking about what this might look like, and ended up just implementing something as a proof-of-concept. Totally open to other methods an ideas.] As we implement more high-performance string-related functions, we have found a need for better control over their selection than the big-hammer LIBC_CONF_STRING_LENGTH_WIDE_READ. For example, I have a memchr implementation coming, and unless I implement it in every variant, a simple binary value doesn't work. This PR makes gives finer-grained control over high-performance functions than the generic LIBC_CONF_UNSAFE_WIDE_READ option. For any function they like, the user can now select one of four implementations at build time: 1. element, which reads byte-by-byte (or wchar by wchar) 2. wide, which reads by unsigned long 3. generic, which uses standard clang vector implemenations, if available 4. arch, which uses an architecture-specific implemenation (Reading the code carefully, you may note that a user can actually specify any namespace they want, so we aren't technically limited to those 4.) We may also want to switch from command-line #defines as it is currently done, to something more like llvm-project/llvm/include/llvm/Config/llvm-config.h.cmake, and #including the resulting file, which would move quite a bit of complexity out of the command-line. But that's a future problem.
2025-11-27[libc][darwin] add syscall numbers from macos sdk (#166354)Shreeyash Pandey1-0/+31
This PR adds support to include syscall.h from MacOS sdk by explicitly including the path to the sdk via `xcrun`.
2025-11-19[Clang] Gut the libc wrapper headers and simplify (#168438)Joseph Huber1-15/+0
Summary: These were originally intended to represent the functions that are present on the GPU as to be provided by the LLVM libc implementation. The original plan was that LLVM libc would report which functions were supported and then the offload interface would mark those as supported. The problem is that these wrapper headers are very difficult to make work given the various libc extensions everyone does so they were extremely fragile. OpenMP already declares all functions used inside of a target region as implicitly host / device, while these headers weren't even used for CUDA / HIP yet anyway. The only things we need to define right now are the stdio FILE types. If we want to make this work for CUDA we'd need to define these manually, but we're a ways off and that's way easier because they do proper overloading.
2025-11-14Revert "[libc][test] split exit tests into two separate tests" (#168102)Schrodinger ZHU Yifan1-31/+0
Reverts llvm/llvm-project#166355
2025-11-14[libc][test] split exit tests into two separate tests (#166355)Shreeyash Pandey1-0/+31
_Exit(3) is a fairly simple syscall wrapper whereas exit(3) calls atexit-registered functions + whole lot of stuff that require support for sync primitives. Splitting the tests allows testing the former easily (especially for new port projects) --------- Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-11-12[libc] Handle the `unknown` default target in CMake (#115122)Petr Hosek1-34/+31
When the backend for the host target isn't enabled, Clang would report the default target as `unknown`. This currently breaks the libc CMake build, but shouldn't in the case where we're cross-compiling since we're given an explicit target and the default one isn't being used.
2025-11-07[libc] add cpu feature flags for SVE/SVE2/MOPS (#166884)Schrodinger ZHU Yifan4-1/+16
Add in SVE/SVE2/MOPS features for aarch64 cpus. These features may be interesting for future memory/math routines. SVE/SVE2 are now being accepted in more implementations: ``` ❯ echo | clang-21 -dM -E - -march=native | grep -i ARM_FEAT #define __ARM_FEATURE_ATOMICS 1 #define __ARM_FEATURE_BF16 1 #define __ARM_FEATURE_BF16_SCALAR_ARITHMETIC 1 #define __ARM_FEATURE_BF16_VECTOR_ARITHMETIC 1 #define __ARM_FEATURE_BTI 1 #define __ARM_FEATURE_CLZ 1 #define __ARM_FEATURE_COMPLEX 1 #define __ARM_FEATURE_CRC32 1 #define __ARM_FEATURE_DIRECTED_ROUNDING 1 #define __ARM_FEATURE_DIV 1 #define __ARM_FEATURE_DOTPROD 1 #define __ARM_FEATURE_FMA 1 #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1 #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1 #define __ARM_FEATURE_FRINT 1 #define __ARM_FEATURE_IDIV 1 #define __ARM_FEATURE_JCVT 1 #define __ARM_FEATURE_LDREX 0xF #define __ARM_FEATURE_MATMUL_INT8 1 #define __ARM_FEATURE_NUMERIC_MAXMIN 1 #define __ARM_FEATURE_PAUTH 1 #define __ARM_FEATURE_QRDMX 1 #define __ARM_FEATURE_RCPC 1 #define __ARM_FEATURE_SVE 1 #define __ARM_FEATURE_SVE2 1 #define __ARM_FEATURE_SVE_BF16 1 #define __ARM_FEATURE_SVE_MATMUL_INT8 1 #define __ARM_FEATURE_SVE_VECTOR_OPERATORS 2 #define __ARM_FEATURE_UNALIGNED 1 ``` MOPS is another set of extension for string operations, but may not be generally available for now: ``` ❯ echo | clang-21 -dM -E - -march=armv9.2a+mops | grep -i MOPS #define __ARM_FEATURE_MOPS 1 ```
2025-10-27Move LIBC_CONF_STRING_UNSAFE_WIDE_READ to top-level libc-configuration (#165046)Sterling-Augustine1-0/+8
This options sets a compile option when building sources inside the string directory, and this option affects string_utils.h. But string_utils.h is #included from more places than just the string directory (such as from __support/CPP/string.h), leading to both narrow-reads in those cases, but more seriously, ODR violations when the two different string_length implementations are included int he same program. Having this option at the top level avoids this problem.
2025-10-22Revert "[libc] Add -Werror for libc tests" (#164684)lntue1-1/+1
Reverts llvm/llvm-project#160413
2025-10-22[libc] Add -Werror for libc tests (#160413)Vinay Deshmukh1-1/+1
Relates to https://github.com/llvm/llvm-project/issues/119281 Note: 1) As this PR enables `-Werror` for `libc` tests, it's very likely some downstream CI's may fail / start failing, so it's very likely this PR may need to be reverted and re-applied. P.S. I do not have merge permissions, so I will need one of the reviews to merge it for me. Thank you!
2025-10-16[libc] Make LIBC_MATH_NO_ERRNO imply `-fno-math-errno` (#125794)Petr Hosek2-12/+3
This partially reverts #124200. Rather than using a CMake option to control whether to enable `-fno-math-errno`, use LIBC_MATH_NO_ERRNO configuration option. While there might be other cases when we want to set `-fno-math-errno`, having LIBC_MATH_NO_ERRNO imply it should be always safe and represents a reasonable starting point.
2025-09-23[libc] Add -Wall for libc tests (#160220)Vinay Deshmukh1-1/+1
Relates to #119281
2025-09-22[libc] Add -Wextra for libc tests (#153321)Vinay Deshmukh1-1/+1
RE apply https://github.com/llvm/llvm-project/pull/133643/commits#top
2025-09-19[LLVM] Simplify GPU runtimes flag handling (#159802)Joseph Huber1-6/+0
Summary: The AMDGPU hack can be removed, and we no longer need to skip 90% of the `HandleLLVMOptions` if we work around NVPTX earlier. Simplifies the interface by removing duplicated logic and keeps the GPU targets from being weirdly divergent on some flags.
2025-09-09[libc] Add check for support and a test for libc SIMD helpers (#157746)Joseph Huber2-0/+10
Summary: This adds a few basic tests for the SIMD helpers and adds a CMake variable we can use to detect support.
2025-09-09[libc][NFC] Add cmake facility to unify the way we parse arguments. (#156922)lntue1-0/+87
Also this will allow all arguments to have overlay-only and full-build-only options.
2025-09-04[libc] Expose the AMDGPU code object version (#152931)Joseph Huber1-6/+4
Summary: People might want to modify this to run on older machines. Expose this so it can be set with `-DRUNTIMES_amdgcn-amd-amdhsa_LIBC_GPU_CODE_OBJECT_VERSION`.
2025-09-02[libc][NFC] Remove unused add_redirector_object and add_redirector_library ↵lntue2-54/+0
in cmake. (#156485)
2025-08-21[libc] Add boot code for AArch64 (#154789)William Huynh1-1/+1
This is required in hermetic testing downstream. It is not complete, and will not work on hardware, however it runs on QEMU, and can report a pass/fail on our tests.
2025-08-12Revert "[libc] Add -Wextra for libc tests" (#153169)William Huynh1-1/+1
Reverts llvm/llvm-project#133643
2025-08-12[libc] Add -Wextra for libc tests (#133643)Vinay Deshmukh1-1/+1
* Relates to: https://github.com/llvm/llvm-project/issues/119281
2025-08-11[libc] Disable LlvmLibcTimespecGet.Monotonic for baremetal targets (#152290)William Huynh2-2/+24
This test was caught by our hermetic testing downstream. The baremetal implementation does not support monotonic, so we disable it.
2025-08-06[libc] warn when depending on public entrypoints (#146163)Michael Jones1-4/+54
Add a cmake warning when an entrypoint or object library depends on a public entrypoint.
2025-07-31[libc] Mutex implementation for single-threaded baremetal (#145358)William Huynh1-0/+4
Part of https://github.com/llvm/llvm-project/issues/145349. Required to allow `atexit` to work. As part of `HermeticTestUtils.cpp`, there is a reference to `atexit()`, which eventually instantiates an instance of a Mutex. Instead of copying the implementation from `libc/src/__support/threads/gpu/mutex.h`, we allow platforms to select an implementation based on configurations, allowing the GPU and single-threaded baremetal platforms to share an implementation. This can be configured or overridden. Later, when the threading API is more complete, we can add an option to support multithreading (or set it as the default), but having single-threading (in tandem) is in line with other libraries for embedded devices.
2025-07-21[libc][stdio] Separate temporary files for unit test and hermetic test in ↵lntue1-0/+2
stdio test suite. (#149740)
2025-07-19[libc] Simplify fma handling for riscv (#149673)Mikhail R. Gadelha3-4/+4
This PR simplifies how we enable the different fma configs for riscv: 1. Removes __LIBC_RISCV_USE_FMA define 2. Checks if __riscv_flen is defined to set LIBC_TARGET_CPU_HAS_FMA As a bonus, we enable *FMA_OPT tests for rv32, so any rv32 hardware that doesn't implement the f/d extensions is also covered by the tests.
2025-07-18[libc] Fix tests' linking flags accidentally modified by #147931. (#149453)lntue1-5/+12
https://github.com/llvm/llvm-project/pull/147931
2025-07-15[libc] Add hooks for extra options in running hermetic tests (#147931)William Huynh1-8/+50
Part of #145349. These hooks are required downstream in order to run hermetic tests. See https://github.com/arm/arm-toolchain/pull/420 for more context on how this PR will be used.
2025-07-12Change binary path in libc test cmake file from relative to absolute (#148315)Amy Huang1-1/+1
For some reason cmake usually turns this path into an absolute path, but sometimes it doesn't do it and stays as a relative path, which means the command will fail. Specify it as an absolute path always so this doesn't happen any more.
2025-06-19[libc] Fix bug in LIBC_CONF_ERRNO_MODE being undefined (#144896)William Huynh1-1/+1
A typo, set() instead of list() would cause the build to not define LIBC_CONF_ERRNO_MODE, which would cause the wrong configuration to be used.
2025-06-13[libc] Output all headers with LIBC_CONF_OUTPUT_ALL_HEADERS (#144114)William Huynh1-1/+6
Following discussion from https://discourse.llvm.org/t/missing-declarations-in-header-files/86678, we decided to add a flag to output all headers. Requires #144049. - Allows outputting all headers - Minor whitespace change for alignment --------- Co-authored-by: Michael Jones <michaelrj@google.com>
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue1-0/+4
LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187) This is the first step in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-06-06[libc] Cleanup unimplemented math functions (#143173)Joseph Huber3-21/+6
Summary: This patch cleans up the leftoever files that were either implemented or are still unimplemented stubs.
2025-05-30[libc] Pass config flags to unit tests. (#142085)lntue1-2/+14
2025-05-29[LibC] Refactor arm64 to aarch64 for darwin. (#141509)Aly ElAshram1-4/+2
Fixes [#141505](https://github.com/llvm/llvm-project/issues/141505) The main intention behind this PR is to update the LibCTargetArchitecture for arm64 to use the implementation of aarch64 architecture and not arm32. This is a historical issue , and is a blocker to issue #138407. The intended fix is to set the `LibCTargetArchitecture` to aarch64 when it matches arm64 , this in turn would help us run darwin/aarch64 specific code on our MacOs pipeline in the git actions. Methods used to search and find "darwin/arm" directories was 1. "find . -type d -path "*/libc/*/darwin/arm" in a linux terminal to check for arm specifically 2. "find . -type d -path "*/libc/*/darwin/*" to ensure there are no directories that are named "*arm*" where star is a wildcard for any character.