Commit Graph

1582 Commits

Author SHA1 Message Date
Joseph Huber
ebcc6dba5f [libc] Don't install the GPU startup code for now
Summary:
This startup code is only intended to be used internally, we shouldn't
export it under a conflicting name. In the future we may package this in
an exportable format.
2023-03-21 21:01:27 -05:00
Michael Jones
9e2b164570 [libc] temporarily disable wctob entrypoint
Differential Revision: https://reviews.llvm.org/D146484
2023-03-20 17:42:00 -07:00
Michael Jones
3d9e646c7c [libc][obvious] fix missing stdio dependency
Differential Revision: https://reviews.llvm.org/D146482
2023-03-20 17:37:09 -07:00
Michael Jones
23ea2c4f4a [libc][obvious] remove currently unused types
Somehow having MBState and StructTmType in the definition for wchar was
causing test failures. This should fix those.

Differential Revision: https://reviews.llvm.org/D146476
2023-03-20 17:22:52 -07:00
Michael Jones
07cdf4a10d [libc][obvious] fix missing type headers
forgot to add wint_t and wchar_t type headers to the wchar
headergen definition.

Differential Revision: https://reviews.llvm.org/D146472
2023-03-20 16:43:09 -07:00
Michael Jones
46b5087227 [libc] add basic wide char functions
This patch adds the wchar header, as well as the functions to convert to
and from wide chars. The header also sets up the definitions for wint
and wchar.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145995
2023-03-20 16:36:21 -07:00
Michael Jones
99047c0501 [libc][bazel] add targets for sprintf
The bazel build is currently overlay mode only, so the FILE functions
are still out of reach for it, but sprintf only uses strings. This adds
targets for sprintf, snprintf, and all the interal printf pieces, as
well as tests.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D146100
2023-03-20 15:09:20 -07:00
Joseph Huber
6bd4d717d5 [libc] Add environment variables to GPU libc test for AMDGPU
This patch performs the same operation to copy over the `argv` array to
the `envp` array. This allows the GPU tests to use environment
variables.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D146322
2023-03-20 13:16:58 -05:00
Roland McGrath
4e298c32d5 [libc] Make string tests compatible with the Fuchsia build
Some test code was doing loose conversions caught by compiler
warnings in  the Fuchsia build.  This included duplicated code
in a few tests that was reconsolidated with the existing header
file copy of the same functions.

The MemoryMatcher abstraction presumes gtest-style matcher support,
which is not available in Fuchsia's zxtest library.  It's avoided
in favor of simpler memory-comparing assertions.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D146343
2023-03-20 10:22:52 -07:00
Joseph Huber
ae30ae23aa [libc][NFC] Add some missing comments to the RPC implementation
Summary:
These comments were accidentally dropped from the committed version. Add
them back in.
2023-03-20 09:30:12 -05:00
Mark de Wever
d0398d3593 Revert "Reland "[CMake] Bumps minimum version to 3.20.0.""
This reverts commit a72165e5df.

Some buildbots have not been updated yet.
2023-03-18 20:32:43 +01:00
Mark de Wever
a72165e5df Reland "[CMake] Bumps minimum version to 3.20.0."
This reverts commit 92523a35a8.

Test whether all CI runners are updated.
2023-03-18 13:33:42 +01:00
Joseph Huber
179a7f1ea2 [libc] Fix dependency to unit tests, and quitting in non-GPU mode
Summary:
Fixes the lack of a dependency after changing the order of some
includes. Also we weren't running any tests as the GPU was always
disabling them. Fix the logic.
2023-03-17 13:08:01 -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
8e4f9b1fcb [libc] Add initial support for an RPC mechanism for the GPU
This patch adds initial support for an RPC client / server architecture.
The GPU is unable to perform several system utilities on its own, so in
order to implement features like printing or memory allocation we need
to be able to communicate with the executing process. This is done via a
buffer of "sharable" memory. That is, a buffer with a unified pointer
that both the client and server can use to communicate.

The implementation here is based off of Jon Chesterfields minimal RPC
example in his work. We use an `inbox` and `outbox` to communicate
between if there is an RPC request and to signify when work is done.
We use a fixed-size buffer for the communication channel. This is fixed
size so that we can ensure that there is enough space for all
compute-units on the GPU to issue work to any of the ports. Right now
the implementation is single threaded so there is only a single buffer
that is not shared.

This implementation still has several features missing to be complete.
Such as multi-threaded support and asynchrnonous calls.

Depends on D145912

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145913
2023-03-17 12:55:31 -05:00
Tue Ly
11da3de82d [libc][Obvious] Reduce the size of the tests for hypot(f). 2023-03-16 21:17:20 -04:00
Sam James
2e8ef93439 [libc] [test] Add missing <cstdint> include
Fixes build w/ GCC 13:
```
[587/7274] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc_system_str_to_float_comparison_test.dir/str_to_float_comparison_test.cpp.o
FAILED: projects/libc/test/src/__support/CMakeFiles/libc_system_str_to_float_comparison_test.dir/str_to_float_comparison_test.cpp.o
/usr/lib/llvm/16/bin/clang++ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/sam/git/llvm-project/build/projects/libc/test/src/__support -I/home/sam/git/llvm-project/libc/test/src/__support -I/home/sam/git/llvm-project/build/include -I/home/sam/git/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -std=c++17 -MD -MT projects/libc/test/src/__support/CMakeFiles/libc_system_str_to_float_comparison_test.dir/str_to_float_comparison_test.cpp.o -MF projects/libc/test/src/__support/CMakeFiles/libc_system_str_to_float_comparison_test.dir/str_to_float_comparison_test.cpp.o.d -o projects/libc/test/src/__support/CMakeFiles/libc_system_str_to_float_comparison_test.dir/str_to_float_comparison_test.cpp.o -c /home/sam/git/llvm-project/libc/test/src/__support/str_to_float_comparison_test.cpp
/home/sam/git/llvm-project/libc/test/src/__support/str_to_float_comparison_test.cpp:34:15: error: unknown type name 'uint32_t'
static inline uint32_t hexCharToU32(char in) {
              ^
/home/sam/git/llvm-project/libc/test/src/__support/str_to_float_comparison_test.cpp:39:15: error: unknown type name 'uint32_t'
static inline uint32_t fastHexToU32(const char *inStr) {
              ^
```

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D146111
2023-03-16 19:03:59 +00:00
Siva Chandra Reddy
b0f9206057 [libc][Obvious] Remove the STARTUP attribute from the api test listing. 2023-03-16 17:48:17 +00:00
Joseph Huber
06c8602526 [libc] Remove unused startup source file
Summary:
This was not removed from the previous patch. Fix that.
2023-03-16 12:41:52 -05:00
Joseph Huber
d9c1dbc204 [libc] Remove startup option from integration tests
This generalizes handling of the integration tests. We now implicitly
depend on the `libc.startup.${LIBC_TARGET_OS}.crt1` file rather than
passing it in manually. This simplifies the interface.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D146237
2023-03-16 12:38:41 -05:00
Joseph Huber
a704c312f1 [libc] Add missing dependencies to RISC-V startup implementation
Summary:
Just like the last patch, the threads and envrion dependencies were
missing. This lead to linker failures when building the tests.
2023-03-16 09:13:18 -05:00
Joseph Huber
501a8724bd [libc] Add missing environ dependency to AArch64 startup implementation
Summary:
Just like the last patch, this dependency was missing. This lead to
linker failures when building the tests.
2023-03-16 08:06:14 -05:00
Joseph Huber
2389f00019 [libc] Add missing threads dependency to AArch64 startup implementation
Summary:
The changes in D146184 made the integration tests use the inhereted
dependencies from the startup code like a normal target. For the AArch64
target this resulted in the threads depenency not being pulled in
because it was not present in the original code.
2023-03-16 08:00:14 -05:00
Joseph Huber
f62523032d [libc] Inherit integration test dependencies from the startup target
All integration tests rely on the startup code to be run. Currently we
manually include a few of these dependencies that are relevant for the
Linux target. This patch changes this to make the integration test's
dependencies include all the dependencies of the startup code. This
simplifies the code and makes it easier to support different targets.
The changes here cause the integration test to be dependent on more
targets than previously necessary, but it should be fine.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D146184
2023-03-16 07:33:22 -05:00
Mikhail R. Gadelha
1990ce74dc [libc] Enable __llvm_libc_syscall and fork
This patch enables the remaining calls from unistd.

The test cases had to be updated to:
1. Use SYS_symlinkat if SYS_symlink is not available
2. Use SYS_readlinkat if SYS_readlink is not available
3. Use SYS_unlinkat if SYS_unlink is not available
4. Use SYS_openat if SYS_open is not available

We also abort compilation if neither of the syscalls mentioned above are
available.

Differential Revision: https://reviews.llvm.org/D146161
2023-03-16 06:16:14 -03:00
Mikhail R. Gadelha
fe99de31d9 [libc] Enable spawn lib in riscv
In this patch we add support for the spawn lib in riscv.

Only small changes were required, the biggest one was to use of dup3
instead of dup2, if the latter is not available. This follows our
implementation of dup2.

Differential Revision: https://reviews.llvm.org/D146145
2023-03-16 06:16:14 -03:00
Mikhail R. Gadelha
63ed8ab4db [libc] Update supported riscv libs
This patch removes some duplicated libs added to entrypoints.txt, adds
new libs supported to entrypoints.txt and updates header.txt

Differential Revision: https://reviews.llvm.org/D146065
2023-03-16 06:16:14 -03:00
Siva Chandra Reddy
08b9835072 [libc][docs] Add a section about allocations and deallocations to the style doc.
Fixes #59277 - The main part of that bug has already been addressed. This commit
just adds documentation.

Reviewed By: jeffbailey

Differential Revision: https://reviews.llvm.org/D146115
2023-03-15 20:41:51 -07:00
Siva Chandra Reddy
be721a38c6 [libc][docs] Move the link to "Compiler Support" under "Status".
Also, fixed a minor typo in compiler_support.rst.

Reviewed By: jeffbailey, gchatelet

Differential Revision: https://reviews.llvm.org/D146112
2023-03-15 20:41:10 -07: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
22838f6084 [libc] Do not attempt to determine CPU features in GPU mode
Summary:
We don't use these features in the GPU build, trying to determine them
can cause errors. We should just return early if this is the case.
2023-03-15 20:44:12 -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
Tue Ly
e35c71493b [libc][NFC] Clean up clang-tidy warnings for src/__support and src/math.
Clean up some warnings from running libc-lint for these folders.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D146048
2023-03-15 18:47:31 -04:00
Jeff Bailey
1b89aeb517 [libc] Add instructions for linux headers
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D146049
2023-03-15 03:02:16 +00:00
Joseph Huber
dab75a4378 [libc] Remove leftover debug prints 2023-03-14 15:14:12 -05:00
Joseph Huber
ab107b3fac [libc] Fix CMake deduplication -Xclang arguments
Summary:
We use `-Xclang` to pass the GPU binary to be embedded. In the case of
multi-source objects this will be passed more than once, but CMake
implicitly deduplicates arguments. Use the special generator to prevent
this from happening.
2023-03-14 15:04:37 -05:00
Joseph Huber
597cef4486 [libc] Fix GPU fatbinary dependencies for multi-source object libraries
Summary:
Multi-source object libraries require some additional handling, this
logic wasn't correctly settending the dependency on each filename
individually and was instead using the last one. This meant that only
the last file was built for multi-object libraries.
2023-03-14 15:04:37 -05:00
Michael Jones
7aec387dbe [libc][NFC] add an atof test for a fuzz failure
The differential fuzzer found that glibc and our libc disagree on the
result for "0x30000002222225p-1077", with ours being rounded up and
theirs rounded down. Ours is more correct for the nearest rounding mode,
so only a test is added.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D145821
2023-03-14 11:42:57 -07:00
Joseph Huber
c2a17bff24 [libc] Set the stub filename to the target name instead of the source
The GPU target requires some weird special case handling to create fat
binaries. CMake offers no way to set the name of an object library. The
only way to do this is to create a file with the desired name and use
that. Currently we name it after the source filename. However, this
breaks if there is more than a single source. This patch changes the
logic to instead look up the object target name and use that. E.g.
`src.__support.OSUtil.osutil` will be `osutil.cpp`.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145912
2023-03-14 10:31:04 -05:00
Joseph Huber
022f2fa3ad [libc] Remove dummy archive and file from integration test
This doesn't seem to be used anymore after recent changes that removed
the `--sysroot` method for the integration tests.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D146040
2023-03-14 09:30:05 -05:00
Joseph Huber
a031f72187 [libc] Correctly pass the compile options to the internal GPU compilation
Summary:
We use an internal option to create the GPU binary used for testing.
This wasn't getting the proper flags passed to it due to a missing
variable name.
2023-03-14 08:19:13 -05:00
Guillaume Chatelet
a49118a3f4 [reland][libc][NFC] Move memcmp implementations in subfolders 2023-03-14 13:03:47 +00:00
Guillaume Chatelet
00c5233139 Revert "[libc][NFC] Move memcmp implementations in subfolders"
this broke arm32 build bots
This reverts commit 7f20e2a8d2.
2023-03-14 13:00:40 +00:00
Guillaume Chatelet
7f20e2a8d2 [libc][NFC] Move memcmp implementations in subfolders 2023-03-14 12:47:24 +00:00
Siva Chandra
537e6e7095 [libc] Enable more functions on riscv64.
The list of headers has also been updated. Some duplicated entrypoints
have been removed.
2023-03-14 06:33:08 +00:00
Jeff Bailey
ea471e2aa8 [libc] Update cross-compilation instructions
* Add various options so that it uses the build lld and compiler-rt
 * Add instructions on how to use the newly built libc
 * Remove trailing comments in code-block for cut and pastability

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145878
2023-03-14 05:31:20 +00:00
Siva Chandra Reddy
547e345666 [libc] Make libc_errno point to internal errno for non-public builds.
The macro llvmlibc_errno has also been removed. This change completes
the switch to using a hermetic errno for unit tests.

Fixes #61037

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D146005
2023-03-14 04:21:56 +00:00
Siva Chandra Reddy
55612b8ec4 [libc] Switch sys/stat implementations over to libc_errno.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D146004
2023-03-14 04:02:45 +00:00
Siva Chandra Reddy
7e6462d90c [libc][NFC] Switch nanosleep_test and getcwd_test to libc_errno. 2023-03-14 01:25:47 +00:00
Siva Chandra Reddy
bb03705726 [libc] Switch termios implementations to libc_errno. 2023-03-14 01:00:58 +00:00