aboutsummaryrefslogtreecommitdiff
path: root/libc/src/__support/OSUtil
AgeCommit message (Collapse)AuthorFilesLines
2026-01-12[libc] Provide a minimal implementation of elf.h (#172766)Petr Hosek2-37/+18
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.
2025-12-17[libc] Support opaque FILE* on baremetal (#168931)Petr Hosek2-38/+43
This change expands the stdio support on baremetal to support opaque FILE*. This builds on top of the existing baremetal embedding API; we treat the standard FILE* streams as pointers that point to the cookie symbols which are a part of the embedding API. This also allows users to define their own FILE* streams, but we don't (yet) support the API that return FILE* such as fopen or fopencookie.
2025-11-28[libc] Add clock_gettime for Darwin (#167160)Shreeyash Pandey1-2/+1
This patch adds support for clock_gettime for Darwin. Darwin syscall 'gettimeofday' is used to query the time from the system. Many headers in llvm-libc-types, namely clockid_t, struct_timespec, struct_timeval, suseconds_t, time_t_32, time_t_64, are modified to include header guards as Darwin has its own implementation of primitive types.
2025-11-28[libc][darwin] add internal::exit (#166357)Shreeyash Pandey3-3/+30
Add internal::exit for MacOS/Darwin
2025-11-10Reapply "[libc] Return errno from OFD failure paths in fcntl." (#166658) ↵Jackson Stogel1-1/+1
(#166846) The previous implementation in #166252 (rolled back in #166658) caused buildbot failures due to a bug in an added test. The modified `UseAfterClose` did not pass a `struct flock` value to `fcntl`: https://github.com/llvm/llvm-project/blob/2d5170594147b42a37698760d6e0194eec4f1390/libc/test/src/fcntl/fcntl_test.cpp#L175 Which ASAN caught and errored in the `fcntl` implementation when the unspecified argument was accessed: https://github.com/llvm/llvm-project/blob/c12cb2892c808af459eaa270b8738a2b375ecc9b/libc/src/__support/OSUtil/linux/fcntl.cpp#L59
2025-11-05Revert "[libc] Return errno from OFD failure paths in fcntl." (#166658)Jackson Stogel1-1/+1
Reverts llvm/llvm-project#166252 Causing buildbot failures on `libc-x86_64-debian-dbg-asan`.
2025-11-05[libc] Return errno from OFD failure paths in fcntl. (#166252)Jackson Stogel1-1/+1
This patch also configures fcntl lock tests to run with F_OFD_* command variants, as all existing lock tests do not exercise process-associated- or OFD-specific functionality.
2025-10-09[libc] fix sysconf test for rv32 (#162685)Schrodinger ZHU Yifan2-1/+16
2025-10-08[libc] Refactor internal auxv usage to reduce getauxval dependencies (#162489)Schrodinger ZHU Yifan2-11/+5
2025-10-08[libc] fix rv32 mmap in auxv library (#162519)Schrodinger ZHU Yifan1-1/+6
Fix auxv rv32 build problem
2025-10-08[libc] use PR_GET_AUXV only if UAPI provides it (#162492)Schrodinger ZHU Yifan1-2/+4
2025-10-08[libc] Refactor AUXV handling with new auxv.h header library (#162326)Schrodinger ZHU Yifan2-0/+163
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-09-01Revert "[libc] Migrate from baremetal stdio.h to generic stdio.h" (#156371)William Huynh2-38/+39
Reverts llvm/llvm-project#152748
2025-09-01[libc] Migrate from baremetal stdio.h to generic stdio.h (#152748)William Huynh2-39/+38
This is a follow up to the RFC here: https://discourse.llvm.org/t/rfc-implementation-of-stdio-on-baremetal/86944 This provides the stdout/stderr/stdin symbols (which now don't have to provided by the user). This allows the user to have access to all functions, currently I've only tested `fprintf` but in theory everything that works in the generic folder should work in the baremetal configuration. All streams are _non-buffered_, which does NOT require flushing. It is based on the CookieFile that already existed
2025-08-06[libc] add getrandom vDSO symbol (#151630)Schrodinger ZHU Yifan3-1/+9
2025-06-18[libc] Internal getrandom implementation (#144427)sribee82-0/+48
Implemented an internal getrandom to avoid calls to the public one in table.h --------- Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-06-13[libc][NFC] clean internal fd handling (#143991)Michael Jones3-32/+60
The previous internal fcntl implementation modified errno directly, this patch fixes that. This patch also moves open and close into OSUtil since they are used in multiple places. There are more places that need similar cleanup but only got comments in this patch to keep it relatively reviewable. Related to: https://github.com/llvm/llvm-project/issues/143937
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue2-2/+2
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-05-29[LibC] Refactor arm64 to aarch64 for darwin. (#141509)Aly ElAshram3-1/+1
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.
2025-05-09[libc][uefi] add crt1 (#132150)Tristan Ross4-7/+120
Adds `crt1.o` for the UEFI platform in the LLVM C library. This makes things start to become useful.
2025-03-27[libc] Update headers on aarch64 (#133180)Michael Jones1-0/+1
The entrypoints for aarch64 are mostly up to date, but the headers are not. This patch fixes that, and also makes explicit the dependency from OSUtils/linux on sys/syscalls.h
2025-03-14[libc] init uefi (#131246)Tristan Ross5-0/+96
Initial UEFI OS target support after the headers. This just defines enough that stuff might try and compile. Test with: ``` $ cmake -S llvm -B build -G Ninja -DLLVM_RUNTIME_TARGETS=x86_64-unknown-uefi-llvm -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_ENABLE_RUNTIMES=libc -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_LIBC_FULL_BUILD=true -DCMAKE_C_COMPILER_WORKS=true -DCMAKE_CXX_COMPILER_WORKS=true -DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LIBCXX=true -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-uefi-llvm -DCMAKE_INSTALL_LIBDIR=build/target/lib $ ninja -C build ```
2025-03-10[libc] Add `-Wno-sign-conversion` & re-attempt `-Wconversion` (#129811)Vinay Deshmukh1-1/+2
Relates to https://github.com/llvm/llvm-project/issues/119281#issuecomment-2699470459
2025-03-05Revert "[libc] Enable -Wconversion for tests. (#127523)"Augie Fackler1-2/+1
This reverts commit 1e6e845d49a336e9da7ca6c576ec45c0b419b5f6 because it changed the 1st parameter of adjust() to be unsigned, but libc itself calls adjust() with a negative argument in align_backward() in op_generic.h.
2025-03-04[libc] Enable -Wconversion for tests. (#127523)Vinay Deshmukh1-1/+2
Relates to: #119281
2024-12-03libc: fixup include path and bazel stale comments (#118510)Nick Desaulniers1-1/+1
Downstream builders are having issues with this local include. Use a fuller path that's more standard throughout the codebase. Also some of the comments in the bazel overlay are stale. Remove them. Reported-by: Brooks Moses <bmoses@google.com>
2024-12-02[libc][NFC] Rename RPC opcodes to better reflect their usageJoseph Huber2-2/+2
Summary: RPC_ is a generic prefix here, use LIBC_ to indicate that these are opcodes used to implement the C library
2024-11-19[libc] Replace usage of GPU helpers with ones from 'gpuintrin.h' (#116454)Joseph Huber1-0/+1
Summary: These are provided by a resource header now, cut these from the dependencies and only provide the ones we use for RPC.
2024-11-01[libc][cmake] make i386 distinct from x86_64 (#114477)Nick Desaulniers2-0/+11
Configured via: $ cmake ../runtimes -G Ninja -DLLVM_ENABLE_LLD=ON \ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libc" \ -DLIBC_TARGET_TRIPLE=i386-linux-gnu -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ Link: #93709
2024-10-31[libc][i386] syscall support (#114264)Nick Desaulniers2-1/+91
Link: #93709
2024-10-15[libc] Remove dependency on `cpp::function` in `rpc.h` (#112422)Joseph Huber2-3/+4
Summary: I'm going to attempt to move the `rpc.h` header to a separate folder that we can install and include outside of `libc`. Before doing this I'm going to try to trim up the file so there's not as many things I need to copy to make it work. This dependency on `cpp::functional` is a low hanging fruit. I only did it so that I could overload the argument of the work function so that passing the id was optional in the lambda, that's not a *huge* deal and it makes it more explicit I suppose.
2024-09-13[libc] Fix vdso VER_FLG_BASE redefinition in overlay mod. (#108628)lntue1-0/+2
2024-09-13[libc] fix build issue in overlay mode (#108583)Schrodinger ZHU Yifan1-2/+2
2024-09-11[libc] Add osutils for Windows and make libc and its tests build on Windows ↵Sirui Mu5-0/+81
target (#104676) This PR first adds osutils for Windows, and changes some libc code to make libc and its tests build on the Windows target. It then temporarily disables some libc tests that are currently problematic on Windows. Specifically, the changes besides the addition of osutils include: - Macro `LIBC_TYPES_HAS_FLOAT16` is disabled on Windows. `clang-cl` generates calls to functions in `compiler-rt` to handle float16 arithmetic and these functions are currently not linked in on Windows. - Macro `LIBC_TYPES_HAS_INT128` is disabled on Windows. - The invocation to `::aligned_malloc` is changed to an invocation to `::_aligned_malloc`. - The following unit tests are temporarily disabled because they currently fail on Windows: - `test.src.__support.big_int_test` - `test.src.__support.arg_list_test` - `test.src.fenv.getenv_and_setenv_test` - Tests involving `__m128i`, `__m256i`, and `__m512i` in `test.src.string.memory_utils.op_tests.cpp` - `test_range_errors` in `libc/test/src/math/smoke/AddTest.h` and `libc/test/src/math/smoke/SubTest.h`
2024-09-11[libc] implement vdso (#91572)Schrodinger ZHU Yifan12-0/+618
2024-07-27revert all tid changes (#100915)Schrodinger ZHU Yifan4-91/+0
2024-07-22[libc] No need to use recursion in fcntl (#99893)Mikhail R. Gadelha1-8/+10
This patch removes the recursion in fcntl introduced by PR #99675 as it is not required and may be dangerous in some cases: some toolchains define F_GETLK == F_GETLK64 causing infinite recursion.
2024-07-22[libc] Change fcntl cmd when only fcntl64 is available (#99675)Mikhail R. Gadelha1-9/+23
In some systems like rv32, only fcntl64 is available and it employs a different structure for file locking and the correspoding F_GETLK64, F_SETLK64, and F_SETLKW64 commands. So if we use fcntl64, the F_GETLK, F_SETLK, and F_SETLKW commands need to be changed to their 64 versions. This patch adds new cases to the swich(cmd) in our implementation of fcntl to do that. The default case was moved to outside the switch, so we don't need to change anything, the F_GETLK, F_SETLK, and F_SETLKW commands will just go through the old implementation.
2024-07-20reland "[libc] implement cached process/thread identity (#98989)" (#99765)Schrodinger ZHU Yifan4-0/+91
2024-07-18Revert "[libc] implement cached process/thread identity" (#99559)Schrodinger ZHU Yifan4-91/+0
Reverts llvm/llvm-project#98989
2024-07-18[libc] implement cached process/thread identity (#98989)Schrodinger ZHU Yifan4-0/+91
migrated from https://github.com/llvm/llvm-project/pull/95965 due to corrupted git history
2024-07-15[libc] Mark external baremetal I/O symbols as extern "C" (#98871)Petr Hosek1-3/+3
These need to use C ABI.
2024-07-14[libc] Extend the baremetal I/O vendor ABI (#98683)Petr Hosek2-6/+45
This refines and extends the external ABI for I/O, later changes will update the baremetal implementations of I/O functions to use these.
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek20-40/+74
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini20-74/+40
declaration" (#98593) Reverts llvm/llvm-project#98075 bots are broken
2024-07-11[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)Petr Hosek20-40/+74
This is a part of #97655.
2024-07-11Reland: [libc] Move off_t and stdio macros to proxy hdrs (#98384)Michael Jones2-0/+2
reland of https://github.com/llvm/llvm-project/pull/98215 Additionally adds proxy headers for FILE and the fopencookie types The arm32 build has been failing due to redefinitions of the off_t type. This patch fixes this by moving off_t to a proper proxy header. To do this, it also moves stdio macros to a proxy header to hopefully avoid including this proxy header alongside this public stdio.h.
2024-07-09Revert "[libc] Move off_t and stdio macros to proxy hdrs" (#98242)Michael Jones2-2/+0
Reverts llvm/llvm-project#98215 Breaks linux bots
2024-07-09[libc] Move the internal extern "C" symbols inside the namespace (#98232)Petr Hosek2-4/+4
This ensures that these symbols inherit the namespace visibility.
2024-07-09[libc] Move off_t and stdio macros to proxy hdrs (#98215)Michael Jones2-0/+2
The arm32 build has been failing due to redefinitions of the off_t type. This patch fixes this by moving off_t to a proper proxy header. To do this, it also moves stdio macros to a proxy header to hopefully avoid including this proxy header alongside this public stdio.h.