Commit Graph

4659 Commits

Author SHA1 Message Date
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
Joseph Huber
0b9d816b3e [libc] Remove separate RPC test handling (#160206)
Summary:
This was originally kept separate so it didn't pollute the name space,
but now I'm thinking it's just easier to bundle it in with the default
interface. This means that we'll have a bit of extra code for people
using the server.h file to handle libc opcodes, but it's minimal (3
functions) and it simplifies this.

I'm doing this because I'm hoping to move the GPU tester binary to
liboffload which handles `libc` opcodes internally except these. This is
the easier option compared to adding a hook to register custom handlers
there.
2025-09-22 19:44:41 -05:00
lntue
e361c0fbe5 [libc] Fix stdbit C tests for older clang. (#160157) 2025-09-22 17:51:27 +00: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
Maksim Levental
c1d838e6f2 [libc] fix error: implicit conversion loses floating-point precision: 'double' to 'float' in shared_math_test.cpp (#159934)
This test fails under `-Werror=implicit-float-conversion` (like in our
pre-merge CI) because `dsqrtl` returns a double
2b937daa13/libc/src/__support/math/dsqrtl.h (L18)

Fixes https://github.com/llvm/llvm-project/issues/159932
2025-09-20 17:07:40 +00:00
Muhammad Bassiouni
2b937daa13 [libc][math] Refactor dsqrtl implementation to header-only in src/__support/math folder. (#154868)
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-20 07:24:21 +03: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
lntue
21821f50cf [libc] Update floating testing infra for MSVC compatibility. (#159810) 2025-09-19 13:44:42 -04:00
Krishna Pandey
b2ad5f5992 [libc][math] Fix sNaN tests for AArch64 (#159483)
Fixes: #134917,
https://github.com/llvm/llvm-project/pull/100632#issuecomment-2258772681,
#159417

---------

Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-18 23:12:45 +05:30
Michael Jones
b7f0bb9c29 [libc][bazel] Add (v)asprintf targets and tests (#159476) 2025-09-18 10:17:57 -07:00
lntue
5f76369997 [libc][math] Update test/src/math/smoke/FmaTest.h to not rely on compiler runtime. (#159503) 2025-09-18 02:34:47 -04:00
lntue
7cc5989593 [libc] Some MSVC compatibility fixes in src/__support. (#159428) 2025-09-17 17:26:47 -04:00
lntue
e8fd84de17 [libc] Temporarily disable floating point exception check for rsqrtf16 on aarch64. (#159417) 2025-09-17 15:01:53 -04:00
lntue
f549bb2ddc [libc][math] Adjust rsqrtf16 exception checks. (#159411) 2025-09-17 14:17:53 -04:00
Anton Shepelev
80f9c72a1e [libc][math][c23] Add rsqrtf16() function (#137545)
Addresses #132818 
Part of #95250
2025-09-17 10:19:20 -04:00
Joseph Huber
b76dc2b9ba [libc] Clean up mask helpers after allowing implicit conversions (#158681)
Summary:
I landed a change in clang that allows integral vectors to implicitly
convert to boolean ones. This means I can simplify the interface and
remove the need to cast to bool on every use. Also do some other
cleanups of the traits.
2025-09-16 12:39:56 -05:00
Petr Hosek
5bf399ba95 [libc] Move preinit/init/fini arrays to namespace (#158746)
In change #146863 we moved definitions of preinit/init/fini arrays to
header but unintentionally moved outside of the namespace. Since the
namespace also controls the visibility (through LIBC_NAMESPACE_DECL), as
a consequence these symbols no longer have the hidden visibility which
changes the codegen from:

```
 4: 4c11          ldr     r4, [pc, #0x44]         @ 0x4c <__libc_init_array+0x4c>
 6: 4812          ldr     r0, [pc, #0x48]         @ 0x50 <__libc_init_array+0x50>
 8: 447c          add     r4, pc
 a: 4478          add     r0, pc
 c: 1b00          subs    r0, r0, r4
```

to:

```
 4: 4813          ldr     r0, [pc, #0x4c]         @ 0x54 <__libc_init_array+0x54>
 6: 4914          ldr     r1, [pc, #0x50]         @ 0x58 <__libc_init_array+0x58>
 8: 4478          add     r0, pc
 a: 4479          add     r1, pc
 c: 6804          ldr     r4, [r0]
 e: 6808          ldr     r0, [r1]
10: 1b00          subs    r0, r0, r4
```

The `ldr` will trigger a fault in case where these symbols aren't
pointing to a valid memory location which is sometimes the case when the
array is empty.
2025-09-15 23:48:38 -07:00