479 Commits

Author SHA1 Message Date
Joseph Huber
1484e0f16a
[libc] Use CMAKE_CROSSCOMPILING_EMULATOR instead searching for `llvm-gpu-loader' (#189417)
Summary:
We already handle this with other targets, we should be able to unify
the handling here.
2026-04-03 09:58:04 -05:00
lntue
096f9d0aa8
[libc] Initial support so that libc-shared-tests can be built with pp64le (#188882) 2026-04-01 20:55:44 -04:00
lntue
e87ea848b7
Reapply "[libc] Finetune libc.src.__support.OSUtil.osutil dependency." (#190033) (#190065)
This reverts commit 84f23eb3113f2e75d1a2e45db1b5c570a5d2f4c5 and fix GPU
builds.
2026-04-01 18:38:32 -04:00
Jan Patrick Lehr
84f23eb311
Revert "[libc] Finetune libc.src.__support.OSUtil.osutil dependency." (#190033)
Reverts llvm/llvm-project#189501

Buildbot failure on libc for GPU buildbots
2026-04-01 22:02:27 +02:00
lntue
35ceec6a78
[libc] Finetune libc.src.__support.OSUtil.osutil dependency. (#189501)
Several key targets unconditionally depend on `OSUtil.osutil` target,
causing errors when it is unnecessarily linked, or not available. This
PR fine-tuning the dependency on `OSUtil.osutil` to cleanly decouple
those targets, and gracefully skip targets that need `osutil`. Main
changes include:

* Make `LIBC_COPT_USE_C_ASSERT` to a cmake config, allowing
`LIBC_ASSERT` to use system's `assert` and not depending on `osutil`.
* Adjust cmake dependency for the following targets:
  - libc.src.__support.libc_assert
  - libc.src.__support.time.*
  - libc.src.time.linux.*
  - libc.src.unistd.*
  - LibcTest
* Give an option for `TestLogger` to use system's `fprintf` instead of
`osutil`.
2026-04-01 14:59:02 -04:00
lntue
ec45f95799
[libc] Add libc_set_definition and libc_add_definition to properly pass definitions to MSVC. (#189664) 2026-03-31 13:15:13 -04:00
Jeff Bailey
ecfcdd6e2a
[libc] Fix check-libc-lit running tests during build (#188081)
Updated check-libc-lit to depend only on build-only targets. Added
libc-integration-tests-build to track integration test executables and
updated LLVMLibCTestRules.cmake to populate it.

Removed incorrect dependencies on execution suites in include and
integration tests that were introduced in #184366.
2026-03-26 21:00:28 +00:00
Joseph Huber
cc4727ae3b
[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#188303)
Summary:
This PR primarily changes using `LLVM_RUNTIMES_TARGET` to
`LLVM_DEFAULT_TARGET_TRIPLE`. The reason is that the default target
triple is the true cross-compiling architecture we are using, while the
runtimes_target can contain multilib strings like `+debug` or similar.

Additionally add the proper path handling to the OpenMP / Offload
libraries.
2026-03-26 08:52:32 -05:00
Ilya Tokar
267b0ea6e8
[libc][x86] add MEMCPY_X86_USE_NTA_STORES to config (#188321)
Add LIBC_CONF_COPT_MEMCPY_X86_USE_NTA_STORES to cmake/bazel/json config.
2026-03-25 15:14:27 -04:00
Jeff Bailey
253616de7e
[libc][docs] Generate configure.rst in the build directory (#187266)
generate_config_doc() was writing configure.rst directly into the source
tree, which fails when building from a read-only source directory (e.g.
when the source is on a read-only filesystem or in a packaging
environment).

The Sphinx build in libc/docs/CMakeLists.txt already copies static .rst
files from the source tree into the build tree so that generated docs
don't pollute the source directory. Move configure.rst generation to
follow this same pattern by writing to LIBC_BUILD_DIR/docs/ instead of
LIBC_SOURCE_DIR/docs/.

This also removes configure.rst from the checked-in source tree, since
it was fully generated content that was being regenerated on every CMake
configure anyway.
2026-03-18 16:51:13 +00:00
Michael Jones
838b1ccdd9
[libc] Add a smaller b36_char_to_int (#180841)
For ASCII systems, b36_char_to_int gets compiled into a jump table. That
jump table ends up being pretty large because it covers the range from
'0' (48) to 'z' (122). On size-constrained systems that can assume
ASCII, this patch provides a new flag: LIBC_CONF_CTYPE_SMALLER_ASCII
that forces a smaller implementation that doesn't compile into a jump
table.
2026-03-17 15:36:41 -07:00
Joseph Huber
9a81d7130f
[libc] Use the proper name for the 'llvm-gpu-loader' (#186101)
Summary:
This used to be two separate executables but was merged awhile back. The
LLVM libc code was never updated to use the new tool name and a recent
refactoring unintentionally removed the symlinks. Just look for
`llvm-gpu-loader`.
2026-03-12 07:17:12 -05:00
Jeff Bailey
31f69d333e
[libc] Fix integration test args/env in LibcTest lit format (#184438)
Integration tests with ARGS or ENV in their add_integration_test() call
were being run with no arguments or environment variables by the
LibcTest lit format, causing failures in startup_args_test,
sprintf_size_test, getenv_test, execv_test, execve_test, and
getcwd_test.

Fix this by having add_integration_test() emit a sidecar
<executable>.params JSON file (via file(GENERATE)) whenever ARGS or ENV
are specified. LibcTest.execute() reads this file at test time and
passes the args and environment to the test executable.

Also always set PWD=exec_dir in the test environment so that
getenv("PWD") matches getcwd() for tests that compare them.
2026-03-04 09:47:40 +00:00
Petr Hosek
c5339b7025
[libc] Use response files for hdrgen entry points (#183267)
This avoids the build failure when the command line ends up being too
long which can be especially problematic on Windows.

Fixes #182374
2026-02-26 00:42:17 -08:00
Joseph Huber
049cfda67c
[LLVM] Port 'llvm-gpu-loader' to use LLVMOffload (#162739)
Summary:
This patch rewrites the `llvm-gpu-loader` utility to use the LLVMOffload
interface. This heavily simplifies it while re-using the already
existing support. Another benefit is that I can now easily do this
dynamically so we can always build this utility without needing to find
non-standard packages.

One issue is mentioned in
https://github.com/llvm/llvm-project/issues/159636 where this will now
take extra time if you have both installed on the same machine. This is
just slightly annoying since most people don't have both CUDA and ROCm
at the same time so I don't consider it a blocker. I will work later to
address it.

Slightly unfortunate environment variable usage, I will also expose that
better in the future.

Fixes: https://github.com/llvm/llvm-project/issues/132890
2026-02-24 08:44:29 -06:00
Joseph Huber
581eb22265
[libc] Fix OS when using -llvm OS in the triple (#181908)
Summary:
We spoof the OS name for the GPU targets and used to get it form the
'end' of the triple list. Adding `-llvm` makes that now point to `-llvm`
which is not recognized so it fails. Just use the direct index, we
already guard that the triple is the correct size
2026-02-17 15:22:51 -06:00
fineg74
ab3d742f6f
[libc] Add basic support for building SPIR-V libraries (#181049)
This is to add support to build libc for building with spirv backend,
for use with OpenMP kernels
2026-02-16 20:27:39 -06:00
Jeff Bailey
c776a52fa2
[libc] Implement lit-based test execution for Libc (#178746)
This provides optional lit-based test execution for the LLVM Libc tests,
alongside the existing CMake-based test execution.

Usage:
  ninja -C build check-libc-lit
  cd build && bin/llvm-lit libc/test/src/

Partially addresses
[#118694](https://github.com/llvm/llvm-project/issues/118694). A future
PR once this lands will flip the default (per suggestion in the RFC)
2026-02-13 18:39:54 +00:00
Michael Jones
ac1220f860
[libc] Add option to disable printf bit int (#180832)
Requested as a binary size optimization. Updates the parser, converter
utils, config, tests, and docs.
2026-02-10 15:41:38 -08:00
Joseph Huber
e07a1182fd
[libc] Tweak the runtimes cross-build for GPU (#178548)
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-02-03 10:35:17 -06:00
Prabhu Rajasekaran
66424a02de
[libc] provide str to float build configs (#178780)
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-30 00:32:38 +00:00
Jakob Koschel
a451344aba
[libc] fix LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR (#178136)
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-27 09:38:13 -08:00
Shubh Pachchigar
41cfe83ab1
[libc] Reland %lc support in printf (#176110)
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-20 16:18:50 -06:00
Joseph Huber
95da1354d0 Revert "[libc] Support %lc in printf (#169983)"
This reverts commit 1327c50ef199b481f5326cf6ca3710fc111b70b1.

The printf headers are intended to be header-only, this introduces
external symbol dependencies.
2026-01-13 20:01:29 -06:00
Shubh Pachchigar
1327c50ef1
[libc] Support %lc in printf (#169983)
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-13 14:05:48 -08:00
Petr Hosek
5db5782da1
[libc] Provide a minimal implementation of elf.h (#172766)
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-12 10:56:49 -08:00
Petr Hosek
9a02a3c7f4
[libc] Support for generating proxy headers (#175279)
This is a follow up to #174823 which adds build system integration.
2026-01-09 23:21:16 -08:00
Marcell Leleszi
9373dbdc00
[libc][wctype] Create generation script for classification lookup tables (#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.
2026-01-06 12:13:28 +01:00
lntue
e2956fefd9
[libc][math] Add LIBC_CONF_MATH_USE_SYSTEM_FENV / LIBC_MATH_USE_SYSTEM_FENV (#172902)
This is to allow math function implementations to use system libc's
fenv.h instead of internal fenv implementations.
2025-12-22 13:19:56 -05:00
Shreeyash Pandey
3c97829d97
[libc] Add Darwin mutex support via os_sync primitives (#167722)
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-16 23:22:19 +05:30
lntue
4c59219fc9
[libc][fenv] Refactor x86 fenv implementations to make it work for various fenv_t. (#165015) 2025-12-05 16:00:10 -05:00
Sterling-Augustine
ed7e66a41d
Reland Refactor WIDE_READ to allow finer control over high-performance 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-04 15:58:14 -08:00
Sterling-Augustine
4e5b114ce2
Revert "Refactor WIDE_READ to allow finer control over high-performance function selection" (#170717)
Reverts llvm/llvm-project#165613

Breaks build bot
2025-12-04 10:34:46 -08:00
Sterling-Augustine
8701c2a910
Refactor WIDE_READ to allow finer control over high-performance function 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-12-04 10:21:53 -08:00
Shreeyash Pandey
fb94261d88
[libc][darwin] add syscall numbers from macos sdk (#166354)
This PR adds support to include syscall.h from MacOS sdk by explicitly including the path to the sdk via `xcrun`.
2025-11-27 21:26:42 +05:30
Joseph Huber
7fe3564167
[Clang] Gut the libc wrapper headers and simplify (#168438)
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-19 07:18:13 -06:00
Schrodinger ZHU Yifan
5b798df8c4
Revert "[libc][test] split exit tests into two separate tests" (#168102)
Reverts llvm/llvm-project#166355
2025-11-14 13:36:05 -05:00
Shreeyash Pandey
e7db040b79
[libc][test] split exit tests into two separate tests (#166355)
_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-14 13:27:32 -05:00
Petr Hosek
242a6cbc5f
[libc] Handle the unknown default target in CMake (#115122)
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-12 11:36:54 -08:00
Schrodinger ZHU Yifan
2dd77050d4
[libc] add cpu feature flags for SVE/SVE2/MOPS (#166884)
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-11-07 13:58:54 -05:00
Sterling-Augustine
7d1538cd3d
Move LIBC_CONF_STRING_UNSAFE_WIDE_READ to top-level libc-configuration (#165046)
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-27 14:39:46 -07:00
lntue
c597a4f476
Revert "[libc] Add -Werror for libc tests" (#164684)
Reverts llvm/llvm-project#160413
2025-10-22 19:05:10 +00:00
Vinay Deshmukh
5d6c00cd0f
[libc] Add -Werror for libc tests (#160413)
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-22 14:32:21 -04:00
Petr Hosek
543932f034
[libc] Make LIBC_MATH_NO_ERRNO imply -fno-math-errno (#125794)
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-10-16 10:00:45 -07:00
Vinay Deshmukh
88bcb58186
[libc] Add -Wall for libc tests (#160220)
Relates to #119281
2025-09-23 10:18:46 -04:00
Vinay Deshmukh
beb743b982
[libc] Add -Wextra for libc tests (#153321)
RE apply https://github.com/llvm/llvm-project/pull/133643/commits#top
2025-09-22 12:56:38 -04:00
Joseph Huber
2d503b924c
[LLVM] Simplify GPU runtimes flag handling (#159802)
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-19 13:09:52 -05:00
Joseph Huber
44d14049c7
[libc] Add check for support and a test for libc SIMD helpers (#157746)
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 19:11:54 -05:00
lntue
0bd3ef4cf2
[libc][NFC] Add cmake facility to unify the way we parse arguments. (#156922)
Also this will allow all arguments to have overlay-only and
full-build-only options.
2025-09-09 16:29:38 -04:00
Joseph Huber
128e7ed788
[libc] Expose the AMDGPU code object version (#152931)
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-04 20:26:32 -05:00