aboutsummaryrefslogtreecommitdiff
path: root/libc/startup
AgeCommit message (Collapse)AuthorFilesLines
2024-09-11[libc] Stub TLS functions on the GPU temporarily (#108267)Joseph Huber2-0/+6
Summary: There's an extern weak symbol for this, we should just factor these into a more common interface. Stub them temporarily to make the bots happy. PTXAS does not handle extern weak.
2024-09-11[libc] fix tls teardown while being used (#108229)Schrodinger ZHU Yifan1-5/+6
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-20[libc] Include startup code when installing all (#105203)Michael Jones1-1/+0
Previously the libc startup code was marked `EXCLUDE_FROM_ALL` due to build issues. This patch removes that as no longer necessary.
2024-08-18[libc] Add single threaded kernel attributes to AMDGPU startup utility (#104651)Joseph Huber1-2/+6
Summary: I fixed the errors here recently so I can actually use these. This shouldn't impact much, just should hopefully make the code generated slightly better.
2024-08-11Revert "libc: Remove `extern "C"` from main declarations" (#102827)Schrodinger ZHU Yifan3-3/+3
Reverts llvm/llvm-project#102825
2024-08-11libc: Remove `extern "C"` from main declarations (#102825)David Blaikie3-3/+3
This is invalid in C++, and clang recently started warning on it as of #101853
2024-08-08[libc] Implement 'getenv' on the GPU target (#102376)Joseph Huber10-9/+22
Summary: This patch implements 'getenv'. I was torn on how to implement this, since realistically we only have access to this environment pointer in the "loader" interface. An alternative would be to use an RPC call every time, but I think that's overkill for what this will be used for. A better solution is just to emit a common `DataEnvironment` that contains all of the host visible resources to initialize. Right now this is the `env_ptr`, `clock_freq`, and `rpc_client`. I did this by making the `app.h` interface that Linux uses more general, could possibly move that into a separate patch, but I figured it's easier to see with the usage.
2024-08-05[libc][startup] fix main thread TLS unmapped with wrong value (#102009)Schrodinger ZHU Yifan1-1/+1
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-31[Clang] Suppress missing architecture error when doing LTO (#100652)Joseph Huber1-1/+1
Summary: The `nvlink-wrapper` can do LTO now, which means we can still create some LLVM-IR without needing an architecture. In the case that we try to invoke `nvlink` internally, that will still fail. This patch simply defers the error until later so we can use `--lto-emit-llvm` to get the IR without specifying an architecture.
2024-07-27revert all tid changes (#100915)Schrodinger ZHU Yifan2-6/+0
2024-07-26[libc] Fix relocatable link attempting to pull in standard libsJoseph Huber1-1/+1
2024-07-26[libc] Make `crt1.o` available to clang for GPU builds (#100599)Joseph Huber1-0/+10
Summary: We want to provide the `crt1.o` object inside of the current build so that other projects can use it for tests. Because it's currently an object library (as is also required for the dependencies for the hermetic tests) this cannot be renamed and is not emitted by default. Here we simply add an executable that emits bitcode so that CMake will give it a name.
2024-07-20reland "[libc] implement cached process/thread identity (#98989)" (#99765)Schrodinger ZHU Yifan2-0/+6
2024-07-18Revert "[libc] implement cached process/thread identity" (#99559)Schrodinger ZHU Yifan2-6/+0
Reverts llvm/llvm-project#98989
2024-07-18[libc] implement cached process/thread identity (#98989)Schrodinger ZHU Yifan2-0/+6
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 Hosek9-18/+27
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini9-27/+18
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 Hosek9-18/+27
This is a part of #97655.
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-07[libc] fix aarch64 GCC build (#97932)Schrodinger ZHU Yifan1-1/+12
This PR fix several build errors on aarch64 targets when building with gcc: - uninitialized values leading to `Werrors` - undefined builtin functions - glibc header pollution
2024-06-25[libc][arm32] define argc type and stack alignment (#96367)Nick Desaulniers (paternity leave)1-2/+2
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)2-4/+6
This is necessary for 32b platforms such as ARM and i386. Link: #94128
2024-06-21[libc][startup] check that we're cross compiling and using LLD (#96357)Nick Desaulniers (paternity leave)1-1/+5
We only need to set `--target=` for LLD when cross compiling. This should fix the host build using BFD or targeting the host. Fixes: #96342
2024-06-21[libc][startup] set --target= for linker when cross compiling (#96342)Nick Desaulniers (paternity leave)1-1/+1
Otherwise the startup objects will fail to link since they were cross compiled, but the linker is not informed of the intent to cross compile, which results in linker errors when the host architecture does not match the target architecture.
2024-05-21[libc] Provide __libc_{init,fini}_array for baremetal (#90828)Petr Hosek3-0/+70
These are provided by newlib and many baremetal projects assume they're available rather than providing their own implementation.
2024-02-23[libc][NFC] Remove all trailing spaces from libc (#82831)Joseph Huber1-3/+3
Summary: There are a lot of random training spaces on various lines. This patch just got rid of all of them with `sed 's/\ \+$//g'.
2024-02-23[libc][NFC] Remove redundant external clock symbol for AMDGPU (#82794)Joseph Huber1-6/+0
Summary: The AMDGPU target needs an external clock symbol so the driver can set the frequency with the correct value. This was left over from the previous implementation and I forgot to remove it when actually implementing the timing utilities.
2024-02-22[libc] Rework the GPU build to be a regular target (#81921)Joseph Huber3-44/+13
Summary: This is a massive patch because it reworks the entire build and everything that depends on it. This is not split up because various bots would fail otherwise. I will attempt to describe the necessary changes here. This patch completely reworks how the GPU build is built and targeted. Previously, we used a standard runtimes build and handled both NVPTX and AMDGPU in a single build via multi-targeting. This added a lot of divergence in the build system and prevented us from doing various things like building for the CPU / GPU at the same time, or exporting the startup libraries or running tests without a full rebuild. The new appraoch is to handle the GPU builds as strict cross-compiling runtimes. The first step required https://github.com/llvm/llvm-project/pull/81557 to allow the `LIBC` target to build for the GPU without touching the other targets. This means that the GPU uses all the same handling as the other builds in `libc`. The new expected way to build the GPU libc is with `LLVM_LIBC_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda`. The second step was reworking how we generated the embedded GPU library by moving it into the library install step. Where we previously had one `libcgpu.a` we now have `libcgpu-amdgpu.a` and `libcgpu-nvptx.a`. This patch includes the necessary clang / OpenMP changes to make that not break the bots when this lands. We unfortunately still require that the NVPTX target has an `internal` target for tests. This is because the NVPTX target needs to do LTO for the provided version (The offloading toolchain can handle it) but cannot use it for the native toolchain which is used for making tests. This approach is vastly superior in every way, allowing us to treat the GPU as a standard cross-compiling target. We can now install the GPU utilities to do things like use the offload tests and other fun things. Some certain utilities need to be built with `--target=${LLVM_HOST_TRIPLE}` as well. I think this is a fine workaround as we will always assume that the GPU `libc` is a cross-build with a functioning host. Depends on https://github.com/llvm/llvm-project/pull/81557
2024-02-21[libc] Fix startup utilities failing to install in full build mode (#82522)Joseph Huber1-1/+2
Summary: Currently, doing `ninja install` will fail in fullbuild mode due to the startup utilities not being built by default. This was hidden previously by the fact that if tests were run, it would build the startup utilities and thus they would be present. This patch solves this issue by making the `libc-startup` target a dependncy on the final library. Furthermore we simply factor out the library install directory into the base CMake directory next to the include directory handling. This change makes the `crt` files get installed in `lib/x86_64-unknown-linu-gnu` instead of just `lib`. This fixes an error I had where doing a runtimes failed to install its libraries because the install step always errored.
2024-02-05[libc] Refactor _build_gpu_objects cmake function. (#80631)lntue3-11/+4
2024-01-24[libc][NFC] remove TODO about AppProperties (#79356)Schrodinger ZHU Yifan1-1/+0
``` 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 Yifan1-8/+21
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 Yifan12-671/+503
* 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) ```
2023-12-20[libc] suppress stdlib explicitly for crt1.a (#76079)Schrodinger ZHU Yifan1-1/+1
[nd: updated oneline]
2023-12-20[libc] [startup] add cmake function to merge separated crt1 objects (#75413)Schrodinger ZHU Yifan1-11/+60
As part of startup refactoring, this patch adds a function to merge multiple objects into a single relocatable object: cc -r obj1.o obj2.o -o obj.o A relocatable object is an object file that is not fully linked into an executable or a shared library. It is an intermediate file format that can be passed into the linker. A crt object can have arch-specific code and arch-agnostic code. To reduce code cohesion, the implementation is splitted into multiple units. As a result, we need to merge them into a single relocatable object.
2023-12-19[libc] move __stack_chk_fail to src/ from startup/ (#75863)Nick Desaulniers1-5/+0
__stack_chk_fail should be provided by libc.a, not startup files. Add __stack_chk_fail to existing linux and arm entrypoints. On Windows (when not targeting MinGW), it seems that the corresponding function identifier is __security_check_cookie, so no entrypoint is added for Windows. Baremetal targets also ought to be compileable with `-fstack-protector*` There is no common header for this prototype, since calls to __stack_chk_fail are meant to be inserted by the compiler upon function return when compiled `-fstack-protector*`.
2023-12-18[libc] expose aux vector (#75806)Schrodinger ZHU Yifan3-27/+12
This patch lifts aux vector related definitions to app.h. Because startup's refactoring is in progress, this patch still contains duplicated changes. This problem will be addressed very soon in an incoming patch.
2023-12-12[libc] fix issues around stack protector (#74567)Schrodinger ZHU Yifan4-18/+25
If a function is declared with stack-protector, the compiler may try to load the TLS. However, inside certain runtime functions, TLS may not be available. This patch disables stack protectors for such routines to fix the problem. Closes #74487.
2023-12-04[libc][NFC] unify startup library's code style with the rest (#74041)Schrodinger ZHU Yifan3-44/+45
This PR unifies the startup library's code style with the rest of libc.
2023-11-20[libc] Remove the optional arguments for NVPTX constructors (#69536)Joseph Huber1-3/+5
Summary: We call the global constructors by function pointer. For whatever reason the NVPTX architecture relies very specifically on the arguments to the function pointer invocation matching what the function is implemented as. This is problematic as most of these constructors are generated with no arguments. This patch removes the extended arguments that GNU and LLVM use for the constructors optionally so that it can support the common case.
2023-11-09[libc][fix] Call GPU destructors in the correct orderJoseph Huber2-4/+4
Summary: I was mistakenly iterating the list backwards. Regular semantics puts both arrays in priority order but the destructors are called backwards.
2023-10-19[libc] Fix accidental LIBC_NAMESPACE_clock_freq (#69620)alfredfo1-1/+1
See-also: https://github.com/llvm/llvm-project/pull/69548
2023-10-04[libc] Add x86-64 stack protector support.tnv012-1/+21
2023-09-26[libc] Start to refactor riscv platform abstraction to support both 32 and ↵Mikhail R. Gadelha2-0/+0
64 bits versions This patch enables the compilation of libc for rv32 by unifying the current rv64 and rv32 implementation into a single rv implementation. We updated the cmake file to match the new riscv32 arch and force LIBC_TARGET_ARCHITECTURE to be "riscv" whenever we find "riscv32" or "riscv64". This is required as LIBC_TARGET_ARCHITECTURE is used in the path for several platform specific implementations. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D148797
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet5-86/+86
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-21[libc] Remove the 'rpc_reset' routine from the RPC implementation (#66700)Joseph Huber2-12/+2
Summary: This patch removes the `rpc_reset` function. This was previously used to initialize the RPC client on the device by setting up the pointers to communicate with the server. The purpose of this was to make it easier to initialize the device for testing. However, this prevented us from enforcing an invariant that the buffers are all read-only from the client side. The expected way to initialize the server is now to copy it from the host runtime. This will allow us to maintain that the RPC client is in the constant address space on the GPU, potentially through inference, and improving caching behaviour.
2023-09-14[libc] Fix start up crash on 32 bit systems (#66210)Mikhail R. Gadelha1-7/+17
This patch changes the default types of argc/argv so it's no longer a uint64_t in all systems, instead, it's now a uintptr_t, which fixes crashes in 32-bit systems that expect 32-bit types. This patch also adds two uintptr_t types (EnvironType and AuxEntryType) for the same reason. The patch also adds a PgrHdrTableType type behind an ifdef that's Elf64_Phdr in 64-bit systems and Elf32_Phdr in 32-bit systems.
2023-09-11[libc] Manually set the AMDGPU code object version (#65986)Joseph Huber1-0/+2
Summary: There is currently effort to change over the default AMDGPU code object version https://github.com/llvm/llvm-project/pull/65410. However, this unfortunately causes problems in the LLVM LibC test suite that leads to a hang while executing. This is most likely a bug to do with indirect call optimization, as it can be avoided without optimizations or with manually preventing inlining in the AMDGPU startup code. This patch sets the AMDGPU code object version to be four explicitly on the LibC test suite. This should unblock the efforts to move the default to 5 without breaking the test suite. This isn't a great solution, but there is currently some time pressure to get COV5 landed and this seems to be the easiest solution.
2023-08-30[libc] Fix set_thread_ptr call in rv32 start up codeMikhail R. Gadelha1-1/+1
This patch changes the instruction in set_thread_ptr from ld to mv, as rv32 doesn't have the ld instruction, and mv is supported by both rv32 and rv64. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D159110
2023-08-07[libc][cleanup] Fix most conversion warningsMichael Jones3-25/+31
This patch is large, but is almost entirely just adding casts to calls to syscall_impl. Much of the work was done programatically, with human checking when the syntax or types got confusing. Reviewed By: mcgrathr Differential Revision: https://reviews.llvm.org/D156950