32 Commits

Author SHA1 Message Date
Joseph Huber
79253cfe6b
[libc] Fix integration tests on w64 amdgpu targets (#152303)
Summary:
We need `malloc` to return a larger size now that it's aligned properly
and we use a bunch of threads. Also the `match_any` test was wrong
because it assumed a 32-bit lanemask.
2025-08-06 08:36:06 -05:00
Schrodinger ZHU Yifan
e797c71609
Reland "[libc] make integration test malloc work properly when threaded" (#152236)
Reverts llvm/llvm-project#152096
2025-08-05 23:12:19 -04:00
Jan Patrick Lehr
6393a9edde
Revert "[libc] make integration test malloc work properly when threaded" (#152096)
Reverts llvm/llvm-project#151622

This broke our libc on GPU bot:
https://lab.llvm.org/buildbot/#/builders/10/builds/10864
2025-08-05 09:26:59 +02:00
Schrodinger ZHU Yifan
8eab158396
[libc] make integration test malloc work properly when threaded (#151622)
Make the simple bump allocation backed by atomic operations.
2025-08-04 23:49:51 -04:00
lntue
66603dd1f1
[libc][NFC] Add stdint.h proxy header to fix dependency issue with <stdint.h> includes. (#150303)
https://github.com/llvm/llvm-project/issues/149993
2025-07-23 20:19:52 -04:00
lntue
d87eea35fa
[libc] Move libc_errno.h to libc/src/__support and make 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-06-11 16:25:27 -04:00
Schrodinger ZHU Yifan
b7c7dbd473
Revert "libc: Remove extern "C" from main declarations" (#102827)
Reverts llvm/llvm-project#102825
2024-08-11 13:40:50 -07:00
David Blaikie
1b71c471c7
libc: Remove extern "C" from main declarations (#102825)
This is invalid in C++, and clang recently started warning on it as of
#101853
2024-08-11 13:17:27 -07:00
Petr Hosek
5ff3ff33ff
[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)
This is a part of #97655.
2024-07-12 09:28:41 -07:00
Mehdi Amini
ce9035f5bd
Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration" (#98593)
Reverts llvm/llvm-project#98075

bots are broken
2024-07-12 09:12:13 +02:00
Petr Hosek
3f30effe1b
[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)
This is a part of #97655.
2024-07-11 12:35:22 -07:00
Joseph Huber
ffed34e025 [libc] Fix getauxval being defined in a namespace 2024-06-17 19:52:06 -05:00
Joseph Huber
44ca65661e
[libc] Only include getauxval on AARCH64 targets (#95844)
Summary:
Not all platforms support this function or header, but it was being
included by every test. Move it inside of the `ifdef` for the only user,
which is aarch64.
2024-06-17 15:51:26 -05:00
Schrodinger ZHU Yifan
2efe3d7fc0
Reland "[libc] fix aarch64 linux full build (#95358)" (#95423)
Reverts llvm/llvm-project#95419 and Reland #95358.

This PR is full of temporal fixes. After a discussion with @lntue, it is
better to avoid further changes to the cmake infrastructure for now as a
rework to the cmake utilities will be landed in the future.
2024-06-13 20:34:32 -07:00
Schrodinger ZHU Yifan
9e5428e6b0
Revert "[libc] fix aarch64 linux full build (#95358)" (#95419) 2024-06-13 08:37:20 -07:00
Schrodinger ZHU Yifan
ca05204f9a
[libc] fix aarch64 linux full build (#95358) 2024-06-13 07:45:25 -07:00
RoseZhang03
07bd439457
[libc] added quick_exit function (#93620)
- In /libc/src/__support/ OSUtil, changed quick_exit to just exit, and
put in namespace
LIBC_NAMESPACE::internal.
- In /libc/src/stdlib added quick_exit
- Added test files for quick_exit
2024-05-31 10:19:10 -07:00
Joseph Huber
47b7c91abe
[libc] Rework the GPU build to be a regular target (#81921)
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-22 15:29:29 -06:00
michaelrj-google
3eb1e6d8e9
[libc] Move libc_errno inside of LIBC_NAMESPACE (#80774)
Having libc_errno outside of the namespace causes versioning issues when
trying to link the tests against LLVM-libc. Most of this patch is just
moving libc_errno inside the namespace in tests. This isn't necessary in
the function implementations since those are already inside the
namespace.
2024-02-06 10:36:05 +01:00
lntue
0881d0f009
[libc] Refactor _build_gpu_objects cmake function. (#80631) 2024-02-05 10:44:19 -05:00
Guillaume Chatelet
73874f7a39
[libc][NFC] Use specific ASSERT macros to test errno (#79573)
This patch provides specific test macros to deal with `errno`.
This will help abstract away the differences between unit test and integration/hermetic tests in #79319.
In one case we use `libc_errno` which is a struct, in the other case we deal directly with `errno`.
2024-01-26 15:18:22 +01:00
Guillaume Chatelet
b6bc9d72f6
[libc] Mass replace enclosing namespace (#67032)
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-26 11:45:04 +02:00
Joseph Huber
76af6e77c0
[libc] Manually set the AMDGPU code object version (#65986)
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-09-11 13:07:56 -05:00
Joseph Huber
9417d9fc38 [libc] Make the bump pointer explicitly return null on buffer oveerrun
We use a simple bump ptr in the `libc` tests. If we run out of data we
can currently return other static memory and have weird failure cases.
We should fail more explicitly here by returning a null pointer instead.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D150529
2023-05-15 06:15:52 -05:00
Joseph Huber
2e1c0ec629 [libc] Support global constructors and destructors on NVPTX
This patch adds the necessary hacks to support global constructors and
destructors. This is an incredibly hacky process caused by the primary
fact that Nvidia does not provide any binary tools and very little
linker support. We first had to emit references to these functions and
their priority in D149451. Then we dig them out of the module once it's
loaded to manually create the list that the linker should have made for
us. This patch also contains a few Nvidia specific hacks, but it passes
the test, albeit with a stack size warning from `ptxas` for the
callback. But this should be fine given the resource usage of a common
test.

This also adds a dependency on LLVM to the NVPTX loader, which hopefully doesn't
cause problems with our CUDA buildbot.

Depends on D149451

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D149527
2023-05-04 07:13:00 -05:00
Joseph Huber
9f5c6dcf59 [libc] Search for the CUDA patch explicitly when testing
The packaged version of the `libc` library does not depend on the CUDA
installation because it only uses `clang` and emits LLVM-IR. However,
for testing we directly need the CUDA toolkit to emit and execute the
files. This patch explicitly passes `--cuda-path` to the relevant
compilations for NVPTX testing.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D147653
2023-04-05 15:14:47 -05:00
Joseph Huber
39e91098b5 [libc] Enable integration tests targeting the GPU
This patch enables integration tests running on the GPU. This uses the
RPC interface implemented in D145913 to compile the necessary
dependencies for the integration test object. We can then use this to
compile the objects for the GPU directly and execute them using the AMD
HSA loader combined with its RPC server. For example, the compiler is
performing the following actions to execute the integration tests.

```
$ clang++ --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nostdlib -flto -ffreestanding \
    crt1.o io.o quick_exit.o test.o rpc_client.o args_test.o -o image
$ ./amdhsa_loader image 1 2 5
args_test.cpp:24: Expected 'my_streq(argv[3], "3")' to be true, but is false
```

This currently only works with a single threaded client implementation
running on AMDGPU. Further work will implement multiple clients for AMD
and the ability to run on NVPTX as well.

Depends on D145913

Reviewed By: sivachandra, JonChesterfield

Differential Revision: https://reviews.llvm.org/D146256
2023-03-17 12:55:32 -05:00
Joseph Huber
38d7f855b8 [libc] Add missing return statements to wrapper functions
Summary:
I forgot to add return statements to these memory comparison functions.
This should hopefully resolve some BB errors.
2023-03-15 22:16:27 -05:00
Joseph Huber
929ad8bc7c [libc] Add aliases to C memory functions for integration tests
The integration tests require the C memory functions as the compiler may
emit calls to them directly. The tests normally use the `__internal__`
variant that is built for testing, but these memory functions were
linked directly to preserve the entrypoint. Instead, we forward delcare
the internal versions and map the entrypoints to them manually inside
the integration test. This allows us to use the internal versions of
these files like the rest of the test objects.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D146177
2023-03-15 20:15:05 -05:00
Siva Chandra Reddy
5b1ad43c2b [libc] Declare __dso_handle in the integration test instead of startup.
Fixes #61355. The __dso_handle decl was introduced incorrectly into the startup
objects during the integration test cleanup which moved the integration tests
away from using an artificial sysroot to using -nostdlib. Having it in the
startup creates the duplicate symbol error when one does not use -nostdlib.
Since this is an integration test only problem, it is meaningful to keep it in
the integration test anyway.

Differential Revision: https://reviews.llvm.org/D145898
2023-03-13 07:47:00 +00:00
Siva Chandra Reddy
43de233e29 [libc][NFC] Remove allocator definition in the api-test.
The integration tests already have allocators so we will get all of them
from there.
2023-03-05 00:25:02 +00:00
Siva Chandra Reddy
af1315c28f [libc][NFC] Move UnitTest and IntegrationTest to the 'test' directory.
This part of the effort to make all test related pieces into the `test`
directory. This helps is excluding test related pieces in a straight
forward manner if LLVM_INCLUDE_TESTS is OFF. Future patches will also move
the MPFR wrapper and testutils into the 'test' directory.
2023-02-07 19:45:51 +00:00