3318 Commits

Author SHA1 Message Date
Joseph Huber
a8b7c809ee Update libc/docs/configure.rst 2024-07-29 13:45:04 +02:00
Joseph Huber
55b063f3f5 [libc] Fix leftover debug commandline argument
Summary:
Fixes https://github.com/llvm/llvm-project/issues/100289

(cherry picked from commit 0420d2f97eac49af5e816b0e3f2a9135d1673168)
2024-07-29 13:45:04 +02:00
Joseph Huber
bdeb078aa2 [libc] Only add '-fno-builtin-*' on the entrypoints that use them (#100481)
Summary:
The GPU build needs to be able to inline stuff in LTO. Builtin
transformations cause problems on the functions that the optimizer does
heavy libcall recognition on. Previously we moved to using
`-fno-builtin-*` to allow us to only disable the problematic ones.
However, this still didn't allow inlining because each function had the
attribute that told the inliner not to inlining a nobuiltin function
into a non-nobuiltin function

This patch fixes that by only applying these attributes to the
entrypoints that define them. That is enough to prevent recursive calls
within the definitoins themselves.

(cherry picked from commit 8e43acbfedf53ded43ec693ddaaf518cb7416c1c)
2024-07-26 09:27:36 +02:00
Joseph Huber
dcc22f9844 [NVPTX] Fix internal indirect call prototypes not obeying the ABI (#100131)
Summary:
The NVPTX backend optimizes the ABI for functions that are internal,
however, this is not legal for indirect call prototypes. Previously, we
would modify the ABI on an aggregate byval type passed to an indirect
call prototype, which would make PTXAS error. This patch just passes the
function as a nullptr to force strict ABI compliance without
modification in the helper function.

Fixes https://github.com/llvm/llvm-project/issues/100055

(cherry picked from commit e0649a5dfc6b859d652318f578bc3d49674787a4)
2024-07-24 09:11:55 +02:00
Joseph Huber
e7a2405383
[libc] Remove workarounds for lack of functional NVPTX linker (#96972)
Summary:
Currently we have several hacks to work around the fact that the NVPTX
linker, 'nvlink', does not support static libraries or LTO linking.
The patch in https://github.com/llvm/llvm-project/pull/96561 introduces
a wrapper in the toolchain that allows us to use a standard `ld.lld`
like interface. This means all the divergence with this target can be
removed.

Depends on https://github.com/llvm/llvm-project/pull/96561
2024-07-22 22:16:50 -05:00
aaryanshukla
ba0744ed2c
[libc][newheadergen]: yaml.load instead of safe_load (#100024)
Co-authored-by: Rose Zhang <rosezhang@google.com>
2024-07-22 17:33:14 -07:00
RoseZhang03
d4da96d6b1
Revert "[libc] New HeaderGen Switch Flip" (#100003)
Reverts llvm/llvm-project#99929
2024-07-22 18:35:27 -05:00
Michael Jones
173514ff12
[libc] Disable epoll_pwait2 for now. (#99967)
This patch reverts #99781 and part of #99771 since `epoll_pwait2` is not
in fact available on all supported systems. It is my opinion that we
shouldn't provide a version of a function that doesn't perform as
expected, which is why this revert needs to happen.

The `epoll_pwait2` function can be reenabled when we have a way to check
if it is available on the target system, tracking bug for that is #80060
2024-07-22 15:34:24 -07:00
Michael Jones
9da087147a
[libc][NFC] clean up some includes (#99719)
While looking through the list of includes for #99693 I found these
includes that also need to be cleaned up. I removed the extra includes
in expm1.cpp, but the include in thread.h needs more attention so I just
marked it with a todo.
2024-07-22 14:54:33 -07:00
RoseZhang03
93eb9ec368
[libc] New HeaderGen Switch Flip (#99929)
Flipped option from OFF to ON for automatically building libc with New
HeaderGen.
2024-07-22 21:52:36 +00:00
Joseph Huber
aac3a2a291
[libc] Fix callback type in exit_handlers.cpp not matching (#97642)
Summary:
This file is an object library, but uses the `LIBC_COPT_PUBLIC_PACKAING`
option. This will always be undefined which leads to a type mismatch
when uses actually try to link against it. This patch simply removes
this and turns it into a header only library. This means that the
implementations of the callback lists and the mutexes need to live in
their respective files. The result is that `atexit` needs to be defined
for `at_quick_exit` to be valid.
2024-07-22 15:28:48 -05:00
RoseZhang03
8972979c37
[libc] Updated header_generation.rst (#99712)
Added new headergen documentation.
2024-07-22 20:15:26 +00:00
Petr Hosek
da2f7201f3
[libc] Include cbrt in baremetal targets (#99916)
This is a follow up to #99262.
2024-07-22 12:10:51 -07:00
Mikhail R. Gadelha
c80b799e90
[libc] No need to use recursion in fcntl (#99893)
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 13:40:47 -03:00
OverMighty
70843bf658
[libc][math] Optimize copysign{,f,f16} and fabs{,f,f16} with builtins when available (#99037) 2024-07-22 18:37:44 +02:00
Joseph Huber
6911f823ad [libc] Fix invalid format specifier in benchmark
Summary:
This value is a uint32_t but is printed as a uint64_t, leading to
invalid offsets when done on AMDGPU due to its packed format extending
past the buffer.
2024-07-22 11:21:22 -05:00
Mikhail R. Gadelha
cda5b2b4b8
[libc] Change fcntl cmd when only fcntl64 is available (#99675)
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-22 12:18:48 -03:00
Joseph Huber
65825cd543
[libc] Use <assert.h> in overlay mode for LIBC_ASSERT (#99875)
Summary:
This uses `internal::exit` which is not built in overlay mode, leading
to linker errors. Fix this to just use `assert.h`.
2024-07-22 10:12:43 -05:00
Mikhail R. Gadelha
28e6095082
[libc] Add working entrypoints to riscv (#99885)
Added new fsqrt entrypoints and updated headers.txt, which I missed in PR #99771
2024-07-22 12:06:28 -03:00
Mikhail R. Gadelha
7ddcf7acf2
[libc] Change fsfilcnt_t and fsblkcnt_t to be 64-bits long (#99876)
In 32-bit systems with 64-bit offsets, both fsfilcnt_t and fsblkcnt_t are 64-bit long, just like 64-bit systems. This patch changes both types to be 64-bit long for all platforms and follows the reasoning used to change off_t: the standard only requires it to be an unsigned int, so making it 64-bit long doesn't violate this property.

It should be NFC for 64-bit systems.
2024-07-22 12:06:03 -03:00
Joseph Huber
bc4c3bf1b7 [libc] Remove special case handing around test case that was fixed
Summary:
I needed to hack something around this for a previous backend bug, it's
since been fixed as far as I'm aware.
2024-07-22 08:44:02 -05:00
OverMighty
5b8479bc28
[libc][CMake] Set library type of libc_diff_test_utils to STATIC (#99869)
Fixes linker errors due to hidden symbols when running CMake with
-DBUILD_SHARED_LIBS=ON.
2024-07-22 14:42:12 +02:00
jameshu15869
197b142232
[libc] Add N Threads Benchmark Helper (#99834)
This PR adds a `BENCHMARK_N_THREADS()` helper to register benchmarks
with a specific number of threads. This PR replaces the flags used
originally to allow any amount of threads.
2024-07-21 21:56:40 -05:00
Mikhail R. Gadelha
eaa07c00b1
[libc] Fix statvfs test case when SYS_statfs64 is used (#99827)
When SYS_statfs64 is used, struct statfs64 is used instead of struct statfs. This patch adds a define to select the appropriate struct, similar to how it's done internally.

This patch also enables fstatvfs and statvfs on riscv, which would not be compiled without this change.
2024-07-21 21:21:05 -03:00
lntue
74a1ca504b
[libc][math] Update getpayload and fmul/fadd/fsub/ffma with NaN inputs. (#99812) 2024-07-21 19:27:06 -04:00
jameshu15869
a964f2e8a1
[libc] Improve Benchmark UI (#99796)
This PR changes the output to resemble Google Benchmark. e.g.

```
Running Suite: LlvmLibcIsAlNumGpuBenchmark
Benchmark            |  Cycles |     Min |     Max | Iterations |   Time (ns) |   Stddev |  Threads |
-----------------------------------------------------------------------------------------------------
IsAlnum              |      92 |      76 |     482 |         23 |       86500 |       76 |       64 |
IsAlnumSingleThread  |      87 |      76 |     302 |         20 |       72000 |       49 |        1 |
IsAlnumSingleWave    |      87 |      76 |     302 |         20 |       72000 |       49 |       32 |
IsAlnumCapital       |      89 |      76 |     299 |         17 |       78500 |       52 |       64 |
IsAlnumNotAlnum      |      87 |      76 |     303 |         20 |       76000 |       49 |       64 |
```
2024-07-21 16:40:01 -05:00
Job Henandez Lara
c1562374c8
[libc][math][c23] Add entrypoints and tests for dsqrt{l,f128} (#99815) 2024-07-21 15:55:11 -04:00
Job Henandez Lara
af0f58cf14
[libc][math][c23] Add entrypoints and tests for fsqrt{,l,f128} (#99669) 2024-07-21 11:17:41 -04:00
Joseph Huber
c8e69fa4a0 [libc] Fix GPU 'printf' on strings with padding
Summary:
We get the `strlen` to know how much memory to allocate here, but it
wasn't taking into account if the padding was larger than the string
itself. This patch sets it to an empty string so we always add the
minimum size. This implementation is slightly wasteful with memory, but
I am not concerned with a few extra bytes here and there for some memory
that gets immediately free'd.
2024-07-20 22:36:12 -05:00
Mikhail R. Gadelha
ae2012d701
[libc] Disable epoll_create fail test when SYS_epoll_create1 is used internally (#99785)
The fail test case only makes sense if SYS_epoll_create is used internally to implement epoll_create, since the only argument to epoll_create (size) is dropped if SYS_epoll_create1 is used.
2024-07-20 19:30:31 -03:00
Mikhail R. Gadelha
16c24a850d [libc] Disable bind test for riscv
Currently it's returning ENXIO on bind and the build bots are failing
2024-07-20 19:25:47 -03:00
Mikhail R. Gadelha
569814e862
[libc] Implement pwait2 using pwait (#99781)
This patch implements pwait2 using pwait. The implementation is an
approximation of pwait2, since pwait only only supports timeouts in
milliseconds, not nanoseconds, as required by pwait2.
2024-07-20 17:27:39 -03:00
Mikhail R. Gadelha
2308c7f5c5
[libc] Enable most of the libc entrypoitns for riscv (#99771)
This patch enables most of the libc entrypoints for riscv, except for fstatvfs, statvfs, dmull and fmull which are currently failing compilation. float16 is also not added, as rv32 doesn't seem to support it yet.

This patch also fixes the call to seek, which should take an off_t, and was missed in PR #68269.
2024-07-20 15:47:09 -03:00
Mikhail R. Gadelha
91bf0a0739
[libc] Added static casts to fix implicit conversion warnings in 32-bit systems
This patch fixes:

randomness.h and getauxval.cpp were passing ssize_t as size_t
kernel_statx.h was assigning an uint64_t to uintptr_t
fopencookie.cpp was trying to create a FileIOResult using ssize_t but the constructor expected a size_t
thread.h was trying to call free_stack (which takes a size_t) with an unsigned long long. free_stack does the calculations using uintptr_t, so I changed the passing values to size_t
2024-07-20 15:12:31 -03:00
Schrodinger ZHU Yifan
29be889c2c
reland "[libc] implement cached process/thread identity (#98989)" (#99765) 2024-07-20 10:25:40 -07:00
Petr Hosek
d386a5582b
[libc] Make static_assert available even if NDEBUG is set (#99742)
This addresses an issue introduced in #98826 where static_assert was
made defined only when NDEBUG is not set which is different from all
other C libraries and breaks any code that uses static_assert and
doesn't guard it with NDEBUG.
2024-07-20 00:56:52 -07:00
aaryanshukla
a3ebb669d1
[libc][math]: updated math docs for newhdrgen (#99715) 2024-07-19 18:43:27 -07:00
aaryanshukla
a2f61ba08b
[libc][math]fadd implementation (#99694)
- **[libc] math fadd**
- **[libc][math] implemented fadd**
2024-07-19 14:40:34 -07:00
lntue
837d606458
[libc] Temporarily disable hypotf sNaN tests for NVPTX targets. (#99708)
https://lab.llvm.org/buildbot/#/builders/101/builds/2269
2024-07-19 17:24:40 -04:00
Mikhail R. Gadelha
9b02b75c4d
[libc] Increase test timeout (#99678)
This patch increases the timeout of the libc test from 1s to 10s, mostly because rv32 runs in a qemu image and sometimes 1s is just not enough for the test to finish when there are other tests running in parallel
2024-07-19 15:44:35 -03:00
aaryanshukla
a8b90c8352
[libc][newheadergen]: adding entry_point testing (#99587) 2024-07-19 11:18:25 -07:00
Mikhail R. Gadelha
ac11430983
[libc] Fix missing sysroot path for kernel headers when crosscompiling (#99588)
When crosscompiling, we need to search for the linux kernel headers in the sysroot but since #97486 the linux kernel headers were always searched in /usr/include.

This patch fixes this behaviour by prepending a '=' to where we search for the kernel headers. As per the gcc/clang's documentation a '=' before the path is replaced by the sysroot.

This patch also includes a fix for rv32, that fails to compile due to a missing definition of CLOCK_REALTIME after this change.
2024-07-19 12:20:16 -03:00
lntue
9da9127fec
[libc][math] Fix signaling nan handling of hypot(f) and improve hypotf performance. (#99432)
The errors were reported by Paul Zimmermann with the CORE-MATH project's
test suites:
```
zimmerma@tartine:/tmp/core-math$ CORE_MATH_CHECK_STD=true LIBM=$L ./check.sh hypot
Running worst cases check in --rndn mode...
FAIL x=snan y=inf ref=qnan z=inf
Running worst cases check in --rndz mode...
FAIL x=snan y=inf ref=qnan z=inf
Running worst cases check in --rndu mode...
FAIL x=snan y=inf ref=qnan z=inf
Running worst cases check in --rndd mode...
Spurious inexact exception for x=0x1.ffffffffffffep+24 y=0x1p+0 (z=0x1.0000000000001p+25)
```
2024-07-19 10:40:44 -04:00
Joseph Huber
7e37d02102 [libc] Fix headers for statvfs implementation
Summry:
@lntue
2024-07-19 09:26:55 -05:00
jameshu15869
ef47bbb471
[libc] Add AMDGPU Timing to CMake (#99603)
`libc/benchmarks/gpu/timing/CMakeLists.txt` did not correctly build
`amdgpu` utils. This PR fixes that issue by adding `amdgpu` to the loop
that adds the correct sub directories.
2024-07-19 06:57:55 -05:00
RoseZhang03
043aca3990
[libc] newhdrgen: removed Include class (#99584)
Include class is not used (includes are made through Macro class, Type
class, and imports from .h.def files).
2024-07-18 23:19:09 +00:00
Michael Jones
adacb5010f
[libc] Restore DECLS_FILE_PATH property (#99583)
The DECLS_FILE_PATH property is supposed to be set on the targets for
the generated headers for the GPU build installation. It got missed when
creating the cmake rule for new headergen.
2024-07-18 16:00:29 -07:00
RoseZhang03
0004ca670a
[libc] Removed __LIBC_CONST_ATTR attribute and updated math.yaml with the new math functions (#99571)
- deleted attribute from fabs function
- added math functions from #98972
- also updated statvfs files so that it can be generated
2024-07-18 22:58:34 +00:00
Michael Jones
f1a8db1a1f
[libc][newhdrgen] Remove redundant yaml prefixes (#99581)
Since the yaml files are already organized into folders, the name of the
file doesn't also need to be prefixed by what folder it's in.
2024-07-18 15:32:32 -07:00
OverMighty
f61c9a9485
[libc][CMake] Set library type of libcMPFRWrapper to STATIC (#99527)
Fixes linker errors due to hidden symbols when running CMake with
-DBUILD_SHARED_LIBS=ON.
2024-07-18 23:16:48 +02:00