83 Commits

Author SHA1 Message Date
Schrodinger ZHU Yifan
74c4243225
[libc][tsearch] add tsearch functions (#172625) 2026-03-30 17:51:36 -04:00
Jeff Bailey
9e6bd128f2
[libc][doc] Remove ToC incompatible with Furo (#188720)
Thanks to @Sukumarsawant for spotting this!
2026-03-26 13:42:03 +00:00
Jeff Bailey
4bfc9bd4cf
[libc][docs] Add guide for implementing a function (#188499)
Added implementing_a_function.rst providing a checklist for adding a new
function to LLVM-libc.

Updated dev/index.rst to include the new guide in the toctree.
2026-03-25 20:43:49 +00:00
Jeff Bailey
f0b58c16e1
[libc][docs][NFC] Expand entrypoints technical reference (#4) (#188255)
Expanded entrypoints.rst with details about definitions, registration
rules, and the lifecycle of an entrypoint.

Updated multiple documents to remove redundant technical details and
link to the centralized entrypoints reference:

- libc/docs/dev/cmake_build_rules.rst
- libc/docs/dev/implementation_standard.rst
- libc/docs/porting.rst
- libc/docs/dev/source_tree_layout.rst
2026-03-25 07:05:52 +00:00
Daniel Thornburgh
7efcd6198c
[libc] Modular printf option (float only) (#147426)
This adds LIBC_CONF_PRINTF_MODULAR, which causes floating point support
(later, others) to be weakly linked into the implementation.
__printf_modular becomes the main entry point of the implementaiton, an
printf itself wraps __printf_modular. printf it also contains a
BFD_RELOC_NONE relocation to bring in the float aspect.

See issue #146159 for context.
2026-03-19 14:22:03 -07:00
Jeff Bailey
89657f726f
[libc][docs][NFC] Documentation consolidation and de-duplication (#187385)
Summary:
Integrated a series of quick documentation cleanups for LLVM-libc. This
update focuses on de-duplicating core conventions (naming and
namespaces) across multiple developer and contribution guides, and
addresses empty platform stubs for UEFI.

Changes:

* libc/docs/contributing.rst: Removed duplicated code style rules and
provided a link to dev/code_style.rst.
* libc/docs/dev/clang_tidy_checks.rst: Removed redundant namespace
explanations and linked to dev/code_style.rst.
* libc/docs/dev/implementation_standard.rst: Removed repetitive notes
about LIBC_NAMESPACE_DECL and linked to the authoritative reference.
* libc/docs/uefi/support.rst & libc/docs/uefi/using.rst: Added
early-stage bring-up warnings and pointed to the config directory for
the source of truth.
2026-03-18 21:50:08 +00:00
Jeff Bailey
ebb3309975
[libc] Refactor core Linux syscalls to use syscall_wrappers (#185983)
This patch initiates the refactoring of Linux syscalls as described in
the RFC (https://discourse.llvm.org/t/rfc-linux-syscall-cleanup/87248/).

It introduces a new infrastructure in
`src/__support/OSUtil/linux/syscall_wrappers/` to house header-only
syscall wrappers. These wrappers utilize `ErrorOr` to provide a
consistent, type-safe interface for error handling across the library,
standardizing how syscall return values are converted into
errno-compatible Error objects.

Summary of changes:
- Created the `syscall_wrappers` directory and added `close.h`,
`read.h`, `write.h`, and `open.h`.
- Moved the existing `getrandom.h` into the new `syscall_wrappers`
directory and updated its callers (including HashTable/randomness.h).
- Refactored core entrypoints (`close`, `read`, `write`, `open`) to use
the new wrappers, removing direct `syscall_impl` logic and manual errno
setting.
- Updated `shm_open.cpp` to use the new `open` wrapper.
- Cleaned up `OSUtil/linux/fcntl.cpp` by removing redundant internal
implementations of `open` and `close`.
- Added a developer guide in `docs/dev/syscall_wrapper_refactor.rst`
outlining the established pattern for future migrations.

---------

Co-authored-by: Michael Jones <michaelrj@google.com>
2026-03-17 18:27:32 +00:00
Petter Berntsson
7887ac6e7f
[libc][docs] Update clang-tidy checks page (#185923)
Document layered .clang-tidy config, update llvmlibc-* check names, and
drop stale TODO
2026-03-17 09:07:38 +00:00
Jeff Bailey
7030a34403
[libc][docs] Furo theme, new landing page, cleanups (#184303)
Switch the libc documentation site from the alabaster theme to Furo,
which provides mobile-friendly layout, a collapsible sidebar with
caption-based section grouping, and built-in "Edit this page" links.

Changes by area:

conf.py
- Switch html_theme to "furo"
- Add myst_parser extension (already in llvm/docs/requirements.txt, used
by LLDB/Clang/LLVM docs) to allow Markdown alongside RST
- Accept both .rst and .md source suffixes
- Configure Furo source_repository/source_branch/source_directory for
"Edit this page" links pointing to GitHub
- Wire _static/copybutton.{js,css} for copy-to-clipboard buttons on code
blocks (no new pip dependency; can migrate to sphinx-copybutton later
once it's in requirements-hashed.txt)
- Exclude plan-docs.md and Helpers/ from Sphinx processing

index.rst
- Rewrite landing page: remove apologetic "not fully complete" note, add
"What Works Today" section with concrete supported use cases, honest
caveat that full C stdlib coverage is still in progress
- Restructure hidden toctrees into five captioned sidebar groups: "Using
LLVM-libc", "Platforms" (GPU/UEFI promoted to top-level),
"Implementation Status", "Development", "Links"

New files
- docs/_static/copybutton.{js,css}: lightweight copy button for code
blocks
- docs/_static/custom.css: add status badge styles (.badge-complete
etc.) for use with Helpers/Styles.rst substitutions in later phases

Prepare for future status badges:
- docs/Helpers/Styles.rst: RST substitution definitions for status
badges (|Complete|, |Partial|, |InProgress|, |NotStarted|, |GPUOnly|,
|LinuxOnly|) — excluded from toctree, available for Phase 5+ pages
- docs/dev/building_docs.rst: new page covering prerequisites (with
Debian apt-first instructions), CMake flags, ninja docs-libc-html, the
docgen auto-generation pipeline, and troubleshooting

Removed
- docs/README.txt: stale file claiming Sphinx 1.1.3, not in any toctree;
superseded by docs/dev/building_docs.rst

Cleanups
- Remove redundant ".. contents:: Table of Contents" directives from 16
RST files (Furo renders its own per-page TOC in the sidebar)
- Remove same directive from libc/Maintainers.rst (pulled into docs via
include)
2026-03-09 20:48:42 +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
petbernt
30533d0757
[libc][docs] Document printf NULL handling for %s/%n (#180067)
- Fix printf_behavior to describe NULL %s as printing "(null)" when
nullptr checks are enabled
- Point undefined_behavior NULL %s/%n entry at
LIBC_COPT_PRINTF_NO_NULLPTR_CHECKS
- Add Sphinx labels to link directly to the flag and Conversion sections
2026-02-06 15:40:50 +00: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
Roland McGrath
2e16cadd56
[libc] Split out src/__support/alloc-checker.h (#173104)
This moves the libc-internal AllocChecker API out of
src/__support/CPP/new.h and updates CPP/README.md to state the
intent to keep src/__support/CPP and the LIBC_NAMESPACE::cpp
namespace a "pure" subset of standard C++ API polyfills.
2025-12-22 11:04:33 -08:00
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
Connector Switch
5b3416caf9
[libc] implement inet_aton (#162651)
This patch adds the implementation for `inet_aton` function. Since this
function is not explicitly included in POSIX, I have marked it with
`llvm_libc_ext`. It is widely available and commonly used, and can also
be used to implement `inet_addr`, which is included in POSIX.
2025-10-21 23:47:38 +08:00
Shubh Pachchigar
98e8ef2273
[libc] Fix broken links in libc (#145199)
This PR fixes broken links in all files describing libc usage modes.
Please let me know if there are any other places that need updating.

---------

Co-authored-by: shubhp@perlmutter <shubhp@perlmutter.com>
2025-06-23 15:51:43 -07:00
lntue
d87eea35fa
[libc] Move libc_errno.h to libc/src/__support and make 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-11 16:25:27 -04:00
Kazu Hirata
c5229e92ce
[libc] Fix typos in documentation (#139852) 2025-05-14 07:14:43 -07:00
Michael Jones
64ae0a102f
[libc] implement l64a (#129099)
Adds l64a, which generates the base 64 string expected by a64l.
2025-02-27 12:48:39 -08:00
Alexey Samsonov
829e2a5526
[libc][hdrgen] Allow to treat hdrgen Python code as a Python module. (#128955)
Move the hdrgen code under a subdirectory to treat it as a Python
module.

This mimics the structure used by llvm/utils/lit and
llvm/utils/mlgo-utils and simplifies integration of hdrgen to the build
system which rely on Python modules. In addition to that, it clarifies
which imports are coming from the hdrgen-specific helpers (e.g. "from
type import ..." becomes "from hdrgen.type import ...".

Leave the entrypoints (top-level main.py and yaml_to_classes.py) as-is:
they can keep being referred by the CMake build system w/o any changes.
2025-02-26 15:41:30 -08:00
Michael Jones
398f865499
[libc] Implement strftime (#122556)
Implements the posix-specified strftime conversions for the default
locale, along with comprehensive unit tests. This reuses a lot of design
from printf, as well as the printf writer.

Roughly based on #111305, but with major rewrites.
2025-02-14 15:56:55 -08:00
Joseph Huber
db6b7a84e6
[libc][NFC] Strip all training whitespace and missing newlines (#124163) 2025-01-23 12:02:54 -06:00
Roland McGrath
62cd050b63
[libc] Move hdrgen yaml files into include/ (#121443)
The .yaml files should live next to the corresponding .h.def
files in libc/include/, rather than next to the implementation of
the tool in libc/utils/hdrgen/.  As with the .h.def files, there
is no need for a yaml/ subdirectory under include/.  This simpler
layout is more natural for maintenance and also simplifies build
integration outside the LLVM CMake build.
2025-01-01 17:03:35 -08:00
Roland McGrath
9abcca5e25
[libc] Move hdrgen into utils/ subdirectory (#121256) 2024-12-30 15:36:53 -08:00
Michael Jones
0a94ee694f
[libc] update host build docs (#120147)
Update the host build docs to better reflect the current recommended
process.
2024-12-19 13:13:55 -08:00
Guillaume Chatelet
4873968649
[libc] Remove automemcpy folder (#118781)
The build is currently broken and we don't have the resources to keep it
up to date :-/
2024-12-06 09:30:13 +01:00
Nick Desaulniers
06c831d7fb
[libc] rename newhdrgen to just hdrgen (#118545)
Link: #117208
Fixes: #117254
2024-12-04 08:48:12 -08:00
Nick Desaulniers
e0ae7793fc
[libc] delete hdrgen (#117220)
Thanks to the effort of @RoseZhang03 and @aaryanshukla under the
guidance of
@michaelrj-google and @amykhuang, we now have newhdrgen and no longer
have a
dependency on TableGen and thus LLVM in order to start bootstrapping a
full
build.

This PR removes:
- LIBC_HDRGEN_EXE; the in tree newhdrgen is the only hdrgen that can be
used.
- LIBC_USE_NEW_HEADER_GEN; newhdrgen is the default and only option.
- LIBC_HDRGEN_ONLY; there is no need to have a distinct build step for
old
  hdrgen.
- libc-api-test and libc-api-test-tidy build targets.
- Deletes all .td files.

It does not rename newhdrgen to just hdrgen. Will follow up with a
distinct PR
for that.

Link: #117209
Link: #117254
Fixes: #117208
2024-12-03 12:34:26 -08:00
Michael Jones
f009f72df5
[libc] Add printf strerror conversion (%m) (#105891)
This patch adds the %m conversion to printf, which prints the
strerror(errno). Explanation of why is below, this patch also updates
the docs, tests, and build system to accomodate this.

The standard for syslog in posix specifies it uses the same format as
printf, but adds %m which prints the error message string for the
current value of errno. For ease of implementation, it's standard
practice for libc implementers to just add %m to printf instead of
creating a separate parser for syslog.
2024-09-19 10:48:08 -07:00
Michael Jones
b89fef8f67
[libc][docs] Update docs to reflect new headergen (#102381)
Since new headergen is now the default for building LLVM-libc, the docs
need to be updated to reflect that. While I was editing those docs, I
took a quick pass at updating other out-of-date pages.
2024-08-21 10:50:39 -07:00
aaryanshukla
b6cbd014b9
[libc][newhdrgen]sorted function names in yaml (#102544) 2024-08-09 11:27:36 -07:00
Schrodinger ZHU Yifan
03841e7ab8
[libc] add spin lock family functions (#100509)
This PR:
- add entrypoints for `pthread_spin_*`
- additionally, the fixes a typo that has been disabling lock related
tests
2024-08-06 21:02:54 -07:00
Michael Jones
a21fc4c0a6
[libc] Fix printf handling of INT_MIN width (#101729)
Prevously, if INT_MIN was passed as a wildcard width to a printf
conversion the parser would attempt to negate it to get the positive
width (and set the left justify flag), but it would underflow and the
width would be treated as 0. This patch corrects the issue by instead
treating a width of INT_MIN as identical to -INT_MAX.

Also includes docs changes to explain this behavior and adding b to the
list of int conversions.
2024-08-02 13:45:54 -07:00
Eric977
44df89cc30
[libc] add pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock … (#100543) 2024-07-28 11:58:09 -07:00
Schrodinger ZHU Yifan
3db5c1eeb0
revert all tid changes (#100915) 2024-07-27 22:29:21 -07:00
RoseZhang03
134b4484d8
[libc] Updated GettingStarted.rst with PyYAML version (#100649)
New Headergen requires PyYAML version 5.1 or newer in order to generate
header files .
2024-07-26 18:31:00 +00:00
aaryanshukla
8b094c9df3
[libc][newheadergen]: PyYaml Version Update (#100463)
- a lot of builds had an issue using new headergen because they do not
have PyYaml installed.
2024-07-24 15:04:05 -07:00
RoseZhang03
8972979c37
[libc] Updated header_generation.rst (#99712)
Added new headergen documentation.
2024-07-22 20:15:26 +00:00
Schrodinger ZHU Yifan
29be889c2c
reland "[libc] implement cached process/thread identity (#98989)" (#99765) 2024-07-20 10:25:40 -07:00
Schrodinger ZHU Yifan
415ca24f8e
Revert "[libc] implement cached process/thread identity" (#99559)
Reverts llvm/llvm-project#98989
2024-07-18 13:31:04 -07:00
Schrodinger ZHU Yifan
5c9fc3cdd7
[libc] implement cached process/thread identity (#98989)
migrated from https://github.com/llvm/llvm-project/pull/95965 due to
corrupted git history
2024-07-18 13:27:50 -07:00
Petr Hosek
5ff3ff33ff
[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)
This is a part of #97655.
2024-07-12 09:28:41 -07:00
Mehdi Amini
ce9035f5bd
Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration" (#98593)
Reverts llvm/llvm-project#98075

bots are broken
2024-07-12 09:12:13 +02:00
Petr Hosek
3f30effe1b
[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)
This is a part of #97655.
2024-07-11 12:35:22 -07:00
Izaak Schroeder
b151c7e36a
[libc] Add dlfcn.h placeholder (#97501)
Adds `dlopen` and friends. This is needed as part of the effort to
compile `libunwind` + `libc` without baremetal mode. This is part of
https://github.com/llvm/llvm-project/issues/97191. This should still be
spec compliant, since `dlopen` always returns `NULL` and `dlerror`
always returns an error message.

> If dlopen() fails for any reason, it returns NULL.

> The function dlclose() returns 0 on success, and nonzero on error.

> Since the value of the symbol could actually be NULL (so that a NULL
return from dlsym() need not indicate an error), the correct way to test
for an error is to call dlerror() to clear any old error conditions,
then call dlsym(), and then call dlerror() again, saving its return
value into a variable, and check whether this saved value is not NULL.


See:
- https://linux.die.net/man/3/dlopen
2024-07-06 16:01:59 -07:00
PiJoules
665efe8967
[libc] Add LIBC_NAMESPACE_DECL macro (#97109)
This defines to LIBC_NAMESPACE with
`__attribute__((visibility("hidden")))` so all the symbols under it have
hidden visibility. This new macro should be used when declaring a new
namespace that will have internal functions/globals and LIBC_NAMESPACE
should be used as a means of accessing functions/globals declared within
LIBC_NAMESPACE_DECL.
2024-07-03 17:02:57 -07:00
Nick Desaulniers
0336116ed4
[libc][docs] codify Policy on Assembler Sources (#88185)
It would be helpful in future code reviews to document a policy with
regards to
where and when Assembler sources are appropriate. That way when
reviewers point
out infractions, they can point to this written policy, which may help
contributors understand that it's not solely the personal preferences of
individual reviewers but instead rather a previously agreed upon rule by
maintainers.

Link: https://github.com/llvm/llvm-project/pull/87837
Link: https://github.com/llvm/llvm-project/pull/88157
Link:
https://discourse.llvm.org/t/hand-written-in-assembly-in-libc-setjmp-longjmp/73249/12
2024-04-22 11:57:28 -07:00
Michael Flanders
2a2e21cd2b
[libc][docs] adds highlighting languages to docs/dev/config_options.rst (#89136)
Fixes #89135.
2024-04-18 12:26:14 -07:00