Commit Graph

4675 Commits

Author SHA1 Message Date
Schrodinger ZHU Yifan
2505df0a4f Revert "[libc] add basic lifetime annotations for support data structures" (#164012)
Reverts llvm/llvm-project#145933 due to broken aarch64 buildbots.
2025-10-17 16:35:14 -04:00
Schrodinger ZHU Yifan
c0e0a33f48 [libc] add basic lifetime annotations for support data structures (#145933)
fix #145932

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-17 16:10:44 -04:00
Connector Switch
404099dcf2 [libc][NFC] Remove cpp20 requirement for arpa/inet test (#163983)
Address
https://github.com/llvm/llvm-project/pull/162651#discussion_r2417151569.
2025-10-17 15:56:11 +00:00
Connector Switch
c4ceb8d7e5 [libc] add IPV6 related macros (#162219) 2025-10-17 23:41:52 +08:00
Muhammad Bassiouni
a55c4c812e [libc][math] Refactor exp2m1f implementation to header-only in src/__support/math folder. (#162017)
Part of #147386

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-10-17 18:27:51 +03:00
Petr Hosek
08c115d1f8 [libc] Enable intermediate computation in float for baremetal (#163829)
This can improve performance on 32-bit baremetal targets.
2025-10-16 11:57:00 -07: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
lntue
e6afe2a854 [libc] Fix temporary types for fputil::split template. (#163813)
Fix #163711.
2025-10-16 12:56:09 -04:00
Petr Hosek
d50423e182 Revert "[libc] Enable intermediate computation in float for baremetal" (#163712)
Reverts llvm/llvm-project#163622, see #163711 for details.
2025-10-15 23:46:53 -07:00
Alexey Samsonov
36f7f3442c [libc] Update generated libc header to include missing functions/files. (#163658)
* Add a missing dependency to install struct_itimerval.h
* Add fseeko/ftello declarations to stdio.h
2025-10-15 18:06:13 -07:00
Petr Hosek
49f03eed05 [libc] Enable intermediate computation in float for baremetal (#163622)
This can improve performance on 32-bit baremetal targets.
2025-10-15 16:33:55 -07:00
Peter Collingbourne
72c6e4b230 libc: Introduce calls to sysconf to get page size.
sysconf(_SC_PAGESIZE) is implemented now.

Reviewers: michaelrj-google, aaronmondal, rupprecht, keith

Reviewed By: michaelrj-google

Pull Request: https://github.com/llvm/llvm-project/pull/163462
2025-10-15 12:31:26 -07:00
Petr Hosek
24a4ad8941 [libc] Disable null checks on baremetal platforms (#163515)
On baremetal platforms, 0 is often a valid address and the null checks
can break otherwise correct code.
2025-10-15 10:06:24 -07:00
Guillaume Chatelet
57726bdca2 Revert "[libc] Implement branchless head-tail comparison for bcmp" (#162859)
Reverts llvm/llvm-project#107540

This PR demonstrated improvements on micro-benchmarks but the gains did
not seem to materialize in production. We are reverting this change for
now to get more data. This PR might be reintegrated later once we're
more confident in its effects.
2025-10-13 23:25:42 +02:00
Peter Collingbourne
7905ec387e [libc] Use UMAXV.4S to reduce bcmp result.
We can use UMAXV.4S to reduce the comparison result in a single
instruction. This improves performance by roughly 4% on Apple M1:

Summary
  bin/libc.src.string.bcmp_benchmark3 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10 ran
    1.01 ± 0.02 times faster than bin/libc.src.string.bcmp_benchmark3 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.01 ± 0.03 times faster than bin/libc.src.string.bcmp_benchmark3 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.01 ± 0.03 times faster than bin/libc.src.string.bcmp_benchmark3 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.01 ± 0.02 times faster than bin/libc.src.string.bcmp_benchmark2 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.02 ± 0.03 times faster than bin/libc.src.string.bcmp_benchmark2 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.03 ± 0.03 times faster than bin/libc.src.string.bcmp_benchmark2 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.03 ± 0.03 times faster than bin/libc.src.string.bcmp_benchmark2 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.05 ± 0.02 times faster than bin/libc.src.string.bcmp_benchmark1 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.05 ± 0.02 times faster than bin/libc.src.string.bcmp_benchmark1 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.05 ± 0.03 times faster than bin/libc.src.string.bcmp_benchmark1 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10
    1.05 ± 0.02 times faster than bin/libc.src.string.bcmp_benchmark1 --study-name="new bcmp" --sweep-mode --sweep-max-size=128 --output=/dev/null --num-trials=10

(1 = original, 2 = a variant of this patch that uses UMAXV.16B, 3 = this patch)

Reviewers: michaelrj-google, gchatelet, overmighty, SchrodingerZhu

Pull Request: https://github.com/llvm/llvm-project/pull/99260
2025-10-13 11:21:48 -07:00
Muhammad Bassiouni
878527651a [libc][math] Refactor exp2f16 implementation to header-only in src/__support/math folder. (#161993)
Part of #147386

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-10-11 23:27:00 +03:00
Joseph Huber
c18de24d9d [libc] Add a config option to disable slab reclaiming (#151599)
Summary:
Without slab reclaiming this interface is much simpler and it can speed
up cases with a lot of churn. Basically, wastes memory for performance.
2025-10-10 21:05:51 -05:00
Schrodinger ZHU Yifan
e07914b563 [libc] fix sysconf test for rv32 (#162685) 2025-10-09 14:26:07 -04:00
Jeff Bailey
42d26a185f [libc][docs] Update VSCode instructions for full host build (#162626)
The VSCode instructions were stale from the transition to the runtimes
directory. This updates will all the options give on the Full Host Build
page.

Tested:
Built libc target.
2025-10-09 17:10:47 +00:00
Anton Shepelev
1244fd24d9 [libc][math][c23] Add rsqrtf() function (#159615)
Closes #159614

**Changes:**
- Initial implementation of rsqrt for single precision float

**Some small unrelated style changes to this PR (that I missed in my
rsqrtf16 PR):**
- Added extra - to the top comments to make it look nicer in
libc/shared/math/rsqrtf16.h
- Put rsqrtf16 inside of libc/src/__support/math/CMakeLists.txt in
sorted order
- Rearanged libc_math_function rsqrtf16 in Bazel to match alphabetical
order
2025-10-08 23:37:01 -04:00
Joseph Huber
72ebda2ba5 [libc] Ensure the RPC server is alwaus used
Summary:
Previous change made us no longer link `exit` by default which implied
the RPC server. This is a required symbol for the loader. This will be
fixed later when I port the loader to LLVMOffload. For now just work
around it to fix the bots.
2025-10-08 17:25:16 -05:00
Aiden Grossman
4d2d21331b [NFC][CI] Use Fully Qualified Names for All Containers
Fix the rest of the containers sitting around in the monorepo.
2025-10-08 22:08:46 +00:00
Schrodinger ZHU Yifan
23981c4222 [libc] Refactor internal auxv usage to reduce getauxval dependencies (#162489) 2025-10-08 15:26:26 -04:00
Shreeyash Pandey
c57796dcb2 [libc][stdfix] Implement fxdivi functions (rdivi) (#154914)
This PR includes only one of the fxdivi functions (rdivi). It uses a
polynomial function for initial approximation followed by 4
newton-raphson iterations to calculate the reciprocal and finally
multiplies the numerator with it to get the result.


---------

Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-10-08 15:17:31 -04:00
Schrodinger ZHU Yifan
1892e6fbb3 [libc] fix rv32 mmap in auxv library (#162519)
Fix auxv rv32 build problem
2025-10-08 14:34:47 -04:00
Jackson Stogel
6308cd871c [libc] Fix integer overflow for large offsets in lseek. (#162394)
Currently, the return value `LIBC_NAMESPACE::syscall_impl<int>(SYS_lseek, fd, offset, whence)` will
overflow when seeking on files >4GB.
2025-10-08 17:04:52 +00:00
Joseph Huber
8c9c91f391 [libc] Make GPU _end kernel only call exit callbacks (#162371)
Summary:
We use the infrastructure to stand up a pretend hosted environment on
the GPU. Part of that is calling exit codes and handling the callback.
Exiting from inside a GPU region is problematic as it actually relies on
a lot of GPU magic behind the scenes. This is at least *correct* now as
we use `quick_exit` on the CPU when the GPU calls `exit`. However,
calling `quick_exit` will interfere with instrumentation or benchmarking
that expects a nice teardown order. For normal execution we should do
the friendly option and let the loader utility clean everything up
manually.
2025-10-08 10:50:19 -05:00
Schrodinger ZHU Yifan
8c3d929f0e [libc] use PR_GET_AUXV only if UAPI provides it (#162492) 2025-10-08 10:37:49 -04:00
Connector Switch
be301a6a3d [libc] add in_addr{, _t} type (#162452)
These types will be used in `arpa/inet.h` and `netinet/in.h`.
2025-10-08 22:08:22 +08:00
Schrodinger ZHU Yifan
0db5ba0ce6 [libc] Refactor AUXV handling with new auxv.h header library (#162326)
Closes https://github.com/llvm/llvm-project/issues/153666

This patch introduces a new centralized AUXV (auxiliary vector) handling
mechanism for LLVM libc on Linux, replacing the previous scattered
implementation across multiple files.

## Key Changes:

### New Files:
- **libc/src/__support/OSUtil/linux/auxv.h**: New header library
providing
  a clean interface for AUXV access with:
  - `auxv::Entry` struct for AUXV entries (type and value)
  - `auxv::Vector` class with iterator support for traversing AUXV
  - `auxv::get()` function for retrieving specific AUXV values
- Thread-safe initialization with fallback mechanisms (prctl and
/proc/self/auxv)

### Modified Files:

1. **libc/src/__support/OSUtil/linux/CMakeLists.txt**:
   - Added `auxv` header library declaration with proper dependencies:
     - libc.hdr.fcntl_macros
     - libc.src.__support.OSUtil.osutil
     - libc.src.__support.common
     - libc.src.__support.CPP.optional
     - libc.src.__support.threads.callonce

2. **libc/config/linux/app.h**:
   - Removed `AuxEntry` struct (moved to auxv.h as `auxv::Entry`)
   - Removed `auxv_ptr` from `AppProperties` struct
   - Simplified application properties structure

3. **libc/src/sys/auxv/linux/getauxval.cpp**:
   - Completely refactored to use new auxv.h interface
   - Removed ~200 lines of complex initialization code
   - Simplified to just call `auxv::get()` function
- Removed dependencies to external symbols (mman, prctl, fcntl, read,
close, open)

4. **libc/src/sys/auxv/linux/CMakeLists.txt**:
   - Updated dependencies to use new auxv header library
- Removed dependencies to external symbols (prctl, mman, fcntl, unistd,
etc.)

5. **libc/startup/linux/do_start.cpp**:
   - Updated to use new `auxv::Vector` interface
   - Changed from pointer-based to iterator-based AUXV traversal
- Updated field names (`aux_entry->id` → `aux_entry.type`,
`aux_entry->value` → `aux_entry.val`)
- Added call to `auxv::Vector::initialize_unsafe()` for early AUXV setup

6. **libc/startup/linux/CMakeLists.txt**:
   - Added dependency on `libc.src.__support.OSUtil.linux.auxv`
2025-10-08 10:00:05 -04:00
Joseph Huber
11fb8358fa [libc] Make LIBC_EXIT RPC code use quick exit
Summary:
This RPC call does the final exiting. The callbacks were handled on the
GPU side and this is only 'valid' in the pretend mode where we treat the
GPU like a CPU program. Doing this keeps us from crashing and burning
if people continue using the program while this is running as `exit`
would tear down the offloading library in memory and lead to segfaults.
This just drops everything where it is and lets the process manager
clean it up for us.
2025-10-07 14:16:34 -05:00
Michael Jones
3b9ec95436 [libc] Simplify mman tests (#161748)
Previously they called sysconf and capget. Those were blocking adding
bazel rules for those tests since sysconf isn't done.
2025-10-06 15:44:48 -07:00
Michael Jones
f265353f97 [libc] Clean up sys/resource (#161749)
Needed to support sys/resource in bazel
2025-10-06 15:42:37 -07:00
Muhammad Bassiouni
596ff855d0 [libc][math] Refactor exp2f implementation to header-only in src/__support/math folder. (#161992)
Part of #147386

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-10-06 21:23:44 +03:00
Connector Switch
6b1604ac30 [libc] add IPPROTO related macros (#161855) 2025-10-06 11:46:45 +08:00
Muhammad Bassiouni
3e78c313bc [libc][math] Refactor exp2 implementation to header-only in src/__support/math folder. (#161297)
Part of #147386

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-10-05 06:31:39 +03:00
Michael Jones
9345b597e9 [libc][NFC] Turn off faccessat on aarch64 (#161740)
The SYS_faccessat2 syscall isn't available on the aarch64 buildbot, so
disable this entrypoint for now.
2025-10-02 15:22:15 -07:00
Marcell Leleszi
44d471e706 [libc] Implement faccessat (#161065)
#160404

- Implement POSIX function "faccessat"
- Remove redundant param in facessat syscall in access implementation,
faccessat syscall does not take a flags arg
2025-10-02 12:33:21 -07:00
Michael Jones
c4709823bb [libc] Fix issue with fuzz input too short for atoi diff fuzz (#161705)
The string to integer differential fuzzer assumes at least one byte of
meaningful input, but wasn't explicitly checking that. Now it does.
2025-10-02 10:43:57 -07:00
Alexey Samsonov
5f0f4972c4 [libc] Unify and extend no_sanitize attributes for strlen. (#161316)
Fast strlen implementations (naive wide-reads, SIMD-based, and
x86_64/aarch64-optimized versions) all may perform
technically-out-of-bound reads, which leads to reports under ASan,
HWASan (on ARM machines), and also TSan (which also has the capability
to detect heap out-of-bound reads). So, we need to explicitly disable
instrumentation in all three cases.

Tragically, Clang didn't support `[[gnu::no_sanitize]]` syntax until
recently, and since we're supporting both GCC and Clang, we have to
revert to `__attribute__` syntax.
2025-10-01 17:26:22 -07:00
Muhammad Bassiouni
6c032fa600 [libc][math] Refactor exp10m1f16 implementation to header-only in src/__support/math folder. (#161119)
Part of #147386

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-10-01 11:21:19 +03:00
Schrodinger ZHU Yifan
38a4c9c639 [libc][msvc] fix mathlib build on WoA (#161258)
Fix build errors encountered when building math library on WoA.

1. Skip FEnv equality check for MSVC
2. Provide a placeholder type for vector types.
2025-09-29 15:40:21 -04:00
Muhammad Bassiouni
23d3caf854 [libc][math] Refactor exp10m1f implementation to header-only in src/__support/math folder. (#159897)
Part of #147386

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-09-29 07:58:03 +03:00
Joseph Huber
e2d5efd59f [libc] Update the memory helper functions for simd types (#160174)
Summary:
This unifies the interface to just be a bunch of `load` and `store`
functions that optionally accept a mask / indices for gathers and
scatters with masks.

I had to rename this from `load` and `store` because it conflicts with
the other version in `op_generic`. I might just work around that with a
trait instead.
2025-09-26 08:18:00 -05:00
Joseph Huber
b7e20c7414 [libc] Make all targets respect LLVM_PER_TARGET_RUNTIME_DIR (#160597)
Summary:
The libcxx and compiler-rt already install their headers according
to the triple if this option is enabled. We should do this by default so
these don't get mixed up when people potentially combine multiple
toolchains.
2025-09-25 07:54:21 -05:00
lntue
3c53adec68 [libc][NFC] Remove usage of the C keyword I. (#160567) 2025-09-24 14:18:32 -04:00
Krishna Pandey
1fda257728 [libc][math][c++23] Add log_bf16 math function (#157811)
This PR adds log_bf16 higher math function for BFloat16 type along with
the tests.

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-24 20:47:10 +05:30
Michael Jones
2e83f10121 [libc] Cleanup mman functions and tests (#159657)
Remove functions depending on each other, cleanup internal errno in
shm_common, remove various unnecessary includes.
2025-09-23 11:08:33 -07:00
Vinay Deshmukh
88bcb58186 [libc] Add -Wall for libc tests (#160220)
Relates to #119281
2025-09-23 10:18:46 -04:00
Zaky Hermawan
5ad347d1a1 [libc][POSIX][unistd] Implement gethostname (#128142)
The implementation is based on the specifications from:
https://man7.org/linux/man-pages/man2/gethostname.2.html

Closes https://github.com/llvm/llvm-project/issues/126602

---------

Signed-off-by: ZakyHermawan <zaky.hermawan9615@gmail.com>
2025-09-23 09:54:35 -04:00