434 Commits

Author SHA1 Message Date
Jorge Gorbe Moya
f9a6ea4489
[libc][bazel] Add BUILD targets for complex functions and tests. (#129618)
This involved a little bit of yak shaving because one of the new tests
depends on MPC, and we didn't have targets for it yet, so I ended up
needing to add a similar setup to what we have for MPFR.
2025-03-04 11:05:01 -08:00
Mikhail Goncharov
a278b28a94 [bazel] fix build after bafd44bff58cff9efe569a221b232bab004d55cd 2025-02-28 10:20:16 +01:00
Alexey Samsonov
bafd44bff5
[libc][bazel] Add py_binary rule to build hdrgen. (#129161) 2025-02-27 20:07:04 -08:00
Michael Jones
524711c344
[libc][bazel] Add targets for strfrom<float> (#128956)
Add targets and tests for strfromf, strfromd and strfroml.

No idea why the standard committee decided that the long double function
should be "strfroml" instead of "strfromld" which would match "strtold"
and leave them space to add string from integer functions in future.
2025-02-26 15:30:40 -08:00
Michael Jones
579ead1a69
[libc][bazel] Add targets for stdbit functions (#128934)
Adds targets for the stdbit functions. Since the names follow a strict
pattern, this is done via list comprehensions. I don't want to handwrite
all 50.
2025-02-26 13:04:52 -08:00
Michael Jones
7f5a2cbe76
[libc][bazel] add targets to build the scanf family (#128082)
Now that scanf is a little cleaner, this patch adds rules to build it
via bazel.
2025-02-21 14:27:04 -08:00
Karlo Basioli
0510d4ea59
[bazel]Fix bazel build after 631a6e0004e57ca85569b99ea411418627925697 2025-01-24 10:40:48 +01:00
Alexey Samsonov
508398021d
[libc] Add hardening for FixedVector data structure and fix exposed bug. (#122159)
Add LIBC_ASSERT statements to FixedVector implementation, and zero out
the memory when the elements are removed to flag out-of-bound access and
dangling pointer/reference access.

This change unmasks the bug in one of FixedVector uses for atexit
handlers: dangling reference use, which was actually led to crashes in
the wild (with prod blockstore implementation). Fix it in this CL.
2025-01-08 13:03:59 -08:00
Alexey Samsonov
4cceea1acc
[libc][bazel] Remove customization from several libc BUILD rules. (#121843)
Get rid of the following arguments to libc_support_library and
libc_function rules:

* `defines` (for raw_mutex.h) - it wasn't used correctly (e.g. didn't
provide actual value for spin count), and we can instead fallback to
defaults set in the header itself (or rely on library-level configure
options).
* `features` - there's no need to disable sanitization for a subset of
memory functions -- it generally should be the vendor / user
responsibility to control it (e.g. don't include instrumented libc
functions in the build, since they would be provided by sanitizer
runtimes instead).
* `local_defines` (for printf_parser) - no longer needed, since
LIBC_COPT_MOCK_ARG_LIST has been removed in
e0be78be427931e94d287002b9c3910f6bc6a22c

This also removes two ad-hoc BUILD rules (strcpy_sanitized and
printf_mock_parser) which are no longer needed and can be replaced by
strcpy and printf_parser, respectively.

Co-authored-by: Alexey Samsonov <samsonov@google.com>
2025-01-06 14:24:34 -08:00
JoelWee
f0247081fa
Fix after #121482 (#121764) 2025-01-06 13:17:37 +00:00
Alexey Samsonov
9a95c097d0
[libc] Remove some unused includes from headers under src/math/generic. (#121632)
These were indicated by Clang include-cleaner.
2025-01-04 10:02:48 -08:00
Tristan Ross
7477b61b24
[libc] Add unistd overlay (#119312)
Reverts the revert #119295 of #118882 by expanding #118882 with
additional fixes which made CI unhappy.
2024-12-17 10:40:22 -08:00
Nick Desaulniers
1d0ca626d8
[bazel] fix libc build (#119433)
Due to moving strings out of string.

Link: #118899
2024-12-10 12:29:49 -08:00
Dmitri Gribenko
6f190cabe0 [bazel] Port e6cf5d2863b77895ae7183952514bedd9e8dde16 2024-12-06 10:30:09 +01:00
Schrodinger ZHU Yifan
e6cf5d2863
Reapply "[libc][windows] start time API implementation (#117775)" (#118886) 2024-12-05 18:21:03 -05:00
Joseph Huber
9fd052a122 Revert "[libc][windows] start time API implementation (#117775)"
This reverts commit 0adff0af20c7d9bae8bd8bdf402506c10369ead1.

Breaks the GPU build
2024-12-05 14:43:06 -06:00
Schrodinger ZHU Yifan
0adff0af20
[libc][windows] start time API implementation (#117775)
Add a `clock_gettime` emulation layer and use it to implement the `time`
entrypoint.

For windows, the monotonic clock is emulated using `QPC`.
The realtime clock is emulated using `GetSystemTimePreciseAsFileTime`.
2024-12-05 14:08:27 -05:00
Michael Jones
a0c4f854ca
[libc] Change ctype to be encoding independent (#110574)
The previous implementation of the ctype functions assumed ASCII.
This patch changes to a switch/case implementation that looks odd, but
actually is easier for the compiler to understand and optimize.
2024-12-03 12:36:04 -08:00
Daniel Thornburgh
95b680e4c3
[libc] Rename libc/src/__support/endian.h to endian_internal.h (#115950)
This prevents a conflict with the Linux system endian.h when built in
overlay mode for CPP files in __support.

This issue appeared in PR #106259.
2024-11-13 10:28:07 -08:00
Michael Jones
36cbc09e63
[libc][bazel] config macros is a support library (#115776)
Previously __support_macros_config was a cc_library, but making it a
libc_support_library makes things cleaner.
2024-11-11 14:16:53 -08:00
Pranav Kant
cb98366ea4
[bazel][libc] Add exp10m1f (#115565) 2024-11-08 15:32:25 -08:00
Michael Jones
aae5a38e4e
[libc][bazel] Mark socket functions weak (#115088)
Downstream ther'es a user that needs the syscall wrappers to be weak. I
intend to set up a proper mechanism for just listing which functions
should be weak eventually, but for now this is necessary.
2024-11-06 10:29:07 -08:00
Alexey Samsonov
2f48765b45
[libc][bazel] Remove -mllvm --tail-merge-threshold=0 from Bazel. (#115061)
Follow-up on the `-mllvm --tail-merge-threshold=0` removal promised in
aeccc16497a84d61200f7ccfa3864096349260d3 (see
b2a9ea4420127d10b18ae648b16757665f8bbd7c commit message on why we don't
need this in Bazel, and will only keep in AArch64-specific compile flags
in CMake build).
2024-11-06 10:51:08 +01:00
Dmitri Gribenko
21f8e8c918 [bazel][libc] Port 9cfe3028ca7977fb582fa3b15b875e8772fc8fc0 (part 2) 2024-11-05 12:35:02 +01:00
Pranav Kant
2d2371df0f
[bazel][libc] Fix bazel build (#114917) 2024-11-04 19:10:57 -08:00
Benjamin Kramer
1b1e325583 [bazel][libc] Port 33bdb53d864e3e244d8fd5649062f17b7d4c958d 2024-11-03 18:11:55 +01:00
Alexey Samsonov
14f3cdc8e2
[libc][bazel] Add BUILD rules for float16 math functions. (#114187)
Adds libc_math_function rules for various f16* and *f16 functions.
Closes #114140
2024-10-30 19:05:24 -07:00
Dmitry Chernenkov
872981bd23 [Bazel] Fix layering for libc 2024-10-29 14:34:51 +00:00
Dmitry Chernenkov
340cd4e631 [Bazel] fix for abc49cc19463970d5523d7d3332e4c1f83bc2ef7 2024-10-29 14:13:20 +00:00
Michael Jones
6c4267fb17
[libcxx][libc] Hand in Hand PoC with from_chars (#91651)
Implements std::from_chars for float and double.

The implementation uses LLVM-libc to do the real parsing. Since this is
the first time libc++
uses LLVM-libc there is a bit of additional infrastructure code. The
patch is based on the
[RFC] Project Hand In Hand (LLVM-libc/libc++ code sharing)

https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701
2024-10-21 15:04:06 -07:00
Krasimir Georgiev
25b58c877c
bazelbuild: fix for commit 2ce10 (#113142)
bazelbuild: fix for
2ce10f0491.

No functional changes intended.
2024-10-21 13:08:49 +02:00
Benjamin Kramer
c7d1163554 [bazel] Port 7be4ab0a86f9a52f1b49dad5665617441ec24a2e 2024-10-18 12:28:15 +02:00
Danial Klimkin
53b3c9e408
[bazel] Fix libc/hdr past c63112a9118277a20ae440f3f69189c0937e8f4d (#111135) 2024-10-04 13:21:25 +02:00
Keith Smiley
e7edd53e2d
[bazel] Port c63112a9118277a20ae440f3f69189c0937e8f4d (#110706) 2024-10-01 10:34:43 -07:00
lntue
fa17977c31
[libc][bazel] Remove specializations from libc_math_function. (#109802)
There are no more specializations `libc/src/math/x86_64` or
`libc/src/math/aarch64` anymore. All implementations are going through
the generic implementation.
2024-09-24 11:26:06 -04:00
Dmitry Chernenkov
3ec5e74c0d [Bazel] Fix layering for 127349fcba81646389e4b8202b35405a5fdbef47 2024-09-24 13:00:12 +00:00
OverMighty
127349fcba
[libc][math] Add floating-point cast independent of compiler runtime (#105152)
Fixes build and tests with compiler-rt on x86.
2024-09-23 19:35:39 +02:00
Michael Jones
f6b4c34d4f
[libc] Add functions to send/recv messages (#106467)
This patch adds the necessary functions to send and receive messages
over a socket. Those functions are: recv, recvfrom, recvmsg, send,
sendto, sendmsg, and socketpair for testing.
2024-09-19 14:43:00 -07:00
Michael Jones
f009f72df5
[libc] Add printf strerror conversion (%m) (#105891)
This patch adds the %m conversion to printf, which prints the
strerror(errno). Explanation of why is below, this patch also updates
the docs, tests, and build system to accomodate this.

The standard for syslog in posix specifies it uses the same format as
printf, but adds %m which prints the error message string for the
current value of errno. For ease of implementation, it's standard
practice for libc implementers to just add %m to printf instead of
creating a separate parser for syslog.
2024-09-19 10:48:08 -07:00
Benjamin Kramer
4de7026ce3 [bazel] Split linux time targets to avoid dependency cycles
clock_gettime is much heavier than the others as it depends on vdso.
2024-09-17 10:28:03 +02:00
Benjamin Kramer
d044732a25 [bazel] Port a205a854e06d36c1d0def3e3bc3743defdb6abc1 2024-09-15 23:14:38 +02:00
Pranav Kant
a592e4b4b0
[bazel] add vdso dependency to time_linux lib (#108647)
This is a quick fix to unbreak Bazel build. The right solution would
probably add vdso.cpp in the support library which includes circular
dependency and needs more restructuring.
2024-09-13 14:35:59 -07:00
Mikhail Goncharov
59731eebf8 [bazel] port ded080152acceca5d68014d63f5027a6d8266cbb 2024-09-12 12:01:03 +02:00
Michael Jones
4618b67b48
[libc][bazel] Enable epoll_pwait2 on bazel (#108254)
The wrapper for epoll_pwait2 has been difficult to enable since it
requires a very new version of the linux kernel (5.11). On cmake we
still need to create a mechanism to check if we can build it, but our
current bazel users are all on a new enough kernel version we can just
enable it.
2024-09-11 14:36:10 -07:00
lntue
1896ee3889
[libc] Fix undefined behavior for nan functions. (#106468)
Currently the nan* functions use nullptr dereferencing to crash with
SIGSEGV if the input is nullptr. Both `nan(nullptr)` and `nullptr`
dereferencing are undefined behaviors according to the C standard.
Employing `nullptr` dereference in the `nan` function implementation is
ok if users only linked against the pre-built library, but it might be
completely removed by the compilers' optimizations if it is built from
source together with the users' code.

See for instance:  https://godbolt.org/z/fd8KcM9bx

This PR uses volatile load to prevent the undefined behavior if libc is
built without sanitizers, and leave the current undefined behavior if
libc is built with sanitizers, so that the undefined behavior can be
caught for users' codes.
2024-09-11 14:13:31 -04:00
Jordan Rupprecht
02ab43596f
[bazel][libc][NFC] Add missing dep for standalone compile (#107957)
One more after 277371943fa48f2550df02870951f5e5a77efef5
2024-09-09 22:39:29 -05:00
lntue
277371943f
[libc][bazel] Update bazel overlay for math functions and their tests. (#107862) 2024-09-09 14:15:46 -04:00
Michael Jones
d851b5c12c
[libc] Make str_to_float independent of fenv (#102369)
The str_to_float conversion code doesn't need the features provided by
fenv and the dependency is creating a blocker for hand-in-hand. This
patch uses a workaround to remove this dependency.
2024-08-08 14:39:07 -07:00
Joseph Huber
cf416e0a1b
[libc] Use proxy headers for limits.h values (#102378)
Summary:
This defines some constants that may conflict with the system when in
overlay mode. Use the proxy header instead.

Fixes: https://github.com/llvm/llvm-project/issues/102368
2024-08-07 17:01:28 -05:00
RoseZhang03
0759508ff4
[libc] add sin/cos/tan functions to bazel build file (#101756)
Needed to add sin/cos/tan fuzz tests to google3
2024-08-05 21:16:25 +00:00