summaryrefslogtreecommitdiff
path: root/libc/startup/linux/do_start.cpp
AgeCommit message (Collapse)Author
2025-10-08[libc] Refactor AUXV handling with new auxv.h header library (#162326)Schrodinger ZHU Yifan
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-07-23[libc][NFC] Add stdint.h proxy header to fix dependency issue with ↵lntue
<stdint.h> includes. (#150303) https://github.com/llvm/llvm-project/issues/149993
2024-09-11[libc] fix tls teardown while being used (#108229)Schrodinger ZHU Yifan
The call chain to `Mutex:lock` can be polluted by stack protector. For completely safe, let's postpone the main TLS tearing down to a separate phase. fix #108030
2024-08-11Revert "libc: Remove `extern "C"` from main declarations" (#102827)Schrodinger ZHU Yifan
Reverts llvm/llvm-project#102825
2024-08-11libc: Remove `extern "C"` from main declarations (#102825)David Blaikie
This is invalid in C++, and clang recently started warning on it as of #101853
2024-08-05[libc][startup] fix main thread TLS unmapped with wrong value (#102009)Schrodinger ZHU Yifan
We have been unmapping a wrong address all the time. ```c munmap(0x704cffebb000, 41048) = 0 munmap(0x704cffec6000, 69632) = 0 munmap(0x704cffe9f000, 41048) = 0 munmap(0x704cffeaa000, 69632) = 0 munmap(0x704cffe83000, 41048) = 0 munmap(0x704cffe8e000, 69632) = 0 munmap(0x704cffe67000, 41048) = 0 munmap(0x704cffe72000, 69632) = 0 munmap(0x704cffe4b000, 41048) = 0 munmap(0x704cffe56000, 69632) = 0 munmap(0x704cffe2f000, 41048) = 0 munmap(0x704cffe3a000, 69632) = 0 munmap(0x704cfff51028, 41048) = -1 EINVAL (Invalid argument) ```
2024-07-27revert all tid changes (#100915)Schrodinger ZHU Yifan
2024-07-20reland "[libc] implement cached process/thread identity (#98989)" (#99765)Schrodinger ZHU Yifan
2024-07-18Revert "[libc] implement cached process/thread identity" (#99559)Schrodinger ZHU Yifan
Reverts llvm/llvm-project#98989
2024-07-18[libc] implement cached process/thread identity (#98989)Schrodinger ZHU Yifan
migrated from https://github.com/llvm/llvm-project/pull/95965 due to corrupted git history
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini
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 Hosek
This is a part of #97655.
2024-06-25[libc][arm32] define argc type and stack alignment (#96367)Nick Desaulniers (paternity leave)
https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst#6212stack-constraints-at-a-public-interface mentions that the stack on ARM32 is double word aligned. Remove confused comments around ArgcType. argc is always an int, passed on the stack, so we need to store a pointer to it (regardless of ILP32 or LP64).
2024-06-24[libc][startup] create header for ElfW and use in startup (#96510)Nick Desaulniers (paternity leave)
This is necessary for 32b platforms such as ARM and i386. Link: #94128
2024-01-24[libc][NFC] remove TODO about AppProperties (#79356)Schrodinger ZHU Yifan
``` AppProperties app; ``` is marked as a weak symbol in header now. One can just use `&app != nullptr` to check if `app` is defined. There is no need to define it for overlay mode.
2024-01-22[libc] support PIE relocations (#78993)Schrodinger ZHU Yifan
For some reasons, we are using `-fpie` (libc/cmake/modules/LLVMLibCObjectRules.cmake:31) without supporting it. According to @lntue, some of the hermetic tests are broken without proper PIE support. This patch implements basic relocations support for PIE.
2024-01-04[libc] major refactor of startup library (#76092)Schrodinger ZHU Yifan
* separate initialization routines into _start and do_start for all architectures. * lift do_start as a separate object library to avoid code duplication. * (addtionally) address the problem of building hermetic libc with -fstack-pointer-* The `crt1.o` is now a merged result of three components: ``` ___ |___ x86_64 | |_______ start.cpp.o <- _start (loads process initial stack and aligns stack pointer) | |_______ tls.cpp.o <- init_tls, cleanup_tls, set_thread_pointer (TLS related routines) |___ do_start.cpp.o <- do_start (sets up global variables and invokes the main function) ```