2432 Commits

Author SHA1 Message Date
Jan Patrick Lehr
ad554d6dbd
[libc] Adds AMDGPU gfx941 and gfx942 to archs (#76573)
This adds the ROCm device libs defines for both target architectures so
that we an compile libc on such GPUs.
2023-12-29 21:26:20 +01:00
Joseph Huber
31d7ad4d99 Revert [libc][Obvious] Correctly initialize the default clock frequency (#76582)
Summary:
This was actually set, I just forget where it was.
2023-12-29 14:24:00 -06:00
Joseph Huber
bae46d14eb
[libc][Obvious] Correctly initialize the default clock frequency (#76582)
Summary:
The AMDGPU architecture does not use a fixed frequency for all of its
architectures. However, the newer GPUs tend to have one that's
consistent between them (Except for Vega10). This was set up but not
actually used, so the implementation was just defaulting to whatever
value the global was being set to. Fix.
2023-12-29 14:17:33 -06:00
Guillaume Chatelet
c23991478a
[libc][NFC] Integrate FloatProperties into FPBits (#76506)
`FloatProperties` is always included when `FPBits` is. This will help
further refactoring.
2023-12-28 15:42:47 +01:00
Jan Patrick Lehr
fe94ae83ec
[libc][FIXME] Disable another test on GPU (#76444)
This test fails on some internal buildbot machines / setups. Disable for
now and to fix later.
2023-12-27 17:27:59 +01:00
Guillaume Chatelet
36b6f77565
[libc][NFC] Unify FPBits implementations (#76033)
`FPBits` is currently implemented as a general case and a specialization
for `long double` when `long double` is x86 80-bit extended precision.
This patch is a first of a series to provide an implementation based on
`FPType` instead of the C++ float type (which implementation is
architecture dependent).
2023-12-21 13:16:51 +01:00
Guillaume Chatelet
ba4d36951f
[libc] Make BigInt bit_cast-able to compatible types (#75063)
This is a second take on #74837 to fix #74258
2023-12-21 10:51:23 +01:00
michaelrj-google
b37c0486b2
[libc][NFC] clean up printf_core and scanf_core (#74535)
Add LIBC_INLINE annotations to functions and fix variable cases within
printf_core and scanf_core.
2023-12-20 15:12:54 -08:00
Schrodinger ZHU Yifan
7a87ff64e1
[libc] suppress stdlib explicitly for crt1.a (#76079)
[nd: updated oneline]
2023-12-20 09:42:35 -08:00
Schrodinger ZHU Yifan
8bbeed05c4
[libc] [startup] add cmake function to merge separated crt1 objects (#75413)
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-20 08:18:51 -08:00
Guillaume Chatelet
3ae5a9b67f
[libc][NFC] Rename MAX_EXPONENT to MAX_BIASED_EXPONENT (#75932)
As currently defined `MAX_EXPONENT` actually corresponds to the biased
exponent (i.e. an unsigned value).
2023-12-20 10:30:09 +01:00
Igor Popov
2176af7a26
Fix __float128 only available on Linux for x86_64 (#75909) 2023-12-20 09:36:01 +01:00
Nick Desaulniers
22764918b5
[libc] try fixing LlvmLibcStackChkFail.Smash a third time (#75988)
Build bots are failing in post submit. Unclear why but can't reproduce
locally.
Disable this test for asan for now.
2023-12-19 16:23:29 -08:00
Nick Desaulniers
8f6352fcb3
[libc] remove unnecessary dependency on assert from __stack_check_fail (#75985) 2023-12-19 15:55:22 -08:00
Nick Desaulniers
b3d024c673
[libc] try fixing LlvmLibcStackChkFail.Smash again (#75967)
Looks like adding attributes to lambdas wasn't added to ISO C++ until
C++23.
Forget lambdas and just use a static function.
2023-12-19 13:32:52 -08:00
Nick Desaulniers
edbd034248
[libc] disable asan for LlvmLibcStackChkFail.Smash (#75966)
Otherwise for ASAN configured runs of the test, the test will fail due
to the
sanitizer rather than via SIGABRT.
2023-12-19 12:39:27 -08:00
Nick Desaulniers
24d44ff473
[libc] __stack_chk_fail post submit test failures (#75962)
Use a size smaller than the smallest supported page size so that we
don't
clobber over any guard pages, which may result in a segfault before
__stack_chk_fail can be called.

Also, move __stack_chk_fail outside of our namespace.
2023-12-19 11:59:42 -08:00
Nick Desaulniers
315a5cce89
[libc] move __stack_chk_fail to src/ from startup/ (#75863)
__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-19 11:05:12 -08:00
Guillaume Chatelet
ea43c8ee73
[libc][NFC] Make EXP_MANT_MASK an implementation detail (#75810)
This mask is an implementation detail of `FPBits` and shouldn't really
leak outside of it.
2023-12-19 17:20:03 +01:00
Guillaume Chatelet
747061f9ba
[libc][NFC] Make QNAN_MASK an implementation detail of FPBits (#75945) 2023-12-19 17:16:31 +01:00
Guillaume Chatelet
1b4a0794b0
[libc][NFC] Use FPBits builders instead of custom constructs (#75942) 2023-12-19 16:45:36 +01:00
Guillaume Chatelet
64671dbebc
[libc] Remove unnecessary call in memfunction dispatchers (#75800)
Before this patch the compiler could generate unnecessary calls to the
selected implementation.
https://clang.llvm.org/docs/AttributeReference.html#flatten
2023-12-19 13:57:44 +01:00
Schrodinger ZHU Yifan
6c1f56fdb5
[libc] expose aux vector (#75806)
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-18 12:27:30 -08:00
lntue
791c5d0eb8
[libc] Improve get_object_files_for_test to reduce CMake configure time for tests. (#75552)
Profiling cmake shows that a significant time configuring `libc` folder
is spent on running `get_object_files_for_test` in the `test` folder (13
sec in `libc/test` folder / 16 sec in `libc` folder). By caching all
needed objects for each target instead of resolving every time, the time
cmake spends on configuring `libc/test` folder is reduced to ~1s.
2023-12-18 13:07:05 -05:00
Kazu Hirata
b8f89b84bc Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-16 15:02:17 -08:00
Guillaume Chatelet
57fcc23896
[libc] Fix improper initialization of StorageType (#75610)
`StorageType` may be a `BigInt` under the hood. Initializing it with
`-1` does not yields the maximum value.
2023-12-15 15:51:10 +01:00
Guillaume Chatelet
3546f4da19
[libc][NFC] Rename MANTISSA_WIDTH in FRACTION_LEN (#75489)
This one might be a bit controversial since the terminology has been
introduced from the start but I think `FRACTION_LEN` is a better name
here. AFAICT it really is "the number of bits after the decimal dot when
the number is in normal form."

`MANTISSA_WIDTH` is less precise as it's unclear whether we take the
leading bit into account.
This patch also renames most of the properties to use the `_LEN` suffix
and fixes useless casts or variables.
2023-12-15 13:57:35 +01:00
Guillaume Chatelet
b4fa7f4c94
[libc][NFC] Split str_to_float tests and reduce type clutter (#75471)
This is a follow up on #75353.
2023-12-15 09:44:10 +01:00
Nick Desaulniers
7c6b4be615
[libc] fix msan failure in mempcpy_test (#75532)
Internal builds of the unittests with msan flagged mempcpy_test.

    ==6862==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55e34d7d734a in length
llvm-project/libc/src/__support/CPP/string_view.h:41:11
#1 0x55e34d7d734a in string_view
llvm-project/libc/src/__support/CPP/string_view.h:71:24
#2 0x55e34d7d734a in
__llvm_libc_9999_0_0_git::testing::Test::testStrEq(char const*, char
const*, char const*, char const*,
__llvm_libc_9999_0_0_git::testing::internal::Location)
llvm-project/libc/test/UnitTest/LibcTest.cpp:284:13
#3 0x55e34d7d4e09 in LlvmLibcMempcpyTest_Simple::Run()
llvm-project/libc/test/src/string/mempcpy_test.cpp:20:3
#4 0x55e34d7d6dff in
__llvm_libc_9999_0_0_git::testing::Test::runTests(char const*)
llvm-project/libc/test/UnitTest/LibcTest.cpp:133:8
#5 0x55e34d7d86e0 in main
llvm-project/libc/test/UnitTest/LibcTestMain.cpp:21:10

SUMMARY: MemorySanitizer: use-of-uninitialized-value
llvm-project/libc/src/__support/CPP/string_view.h:41:11 in length

What's going on here is that mempcpy_test.cpp's Simple test is using
ASSERT_STREQ with a partially initialized char array. ASSERT_STREQ calls
Test::testStrEq which constructs a cpp:string_view. That constructor
calls the
private method cpp::string_view::length. When built with msan, the loop
is
transformed into multi-byte access, which then fails upon access.

I took a look at libc++'s __constexpr_strlen which just calls
__builtin_strlen(). Replacing the implementation of
cpp::string_view::length
with a call to __builtin_strlen() may still result in out of bounds
access when
the test is built with msan.

It's not safe to use ASSERT_STREQ with a partially initialized array.
Initialize the whole array so that the test passes.
2023-12-14 13:39:33 -08:00
Guillaume Chatelet
493cc71d72
[libc][NFC] Remove MantissaWidth traits (#75458)
Same as #75362, the traits does not bring a lot of value over
`FloatProperties::MANTISSA_WIDTH` (or `FPBits::MANTISSA_WIDTH`).
2023-12-14 15:07:09 +01:00
Guillaume Chatelet
f69c83f8da
[libc][NFC] Remove ExponentWidth traits (#75362)
Is it redundant with `FloatProperties::EXPONENT_WIDTH` and does bear its
weight.
2023-12-14 10:07:48 +01:00
Nick Desaulniers
c0ad6e2fa6
[libc] fix unit tests (#75361)
Fixes #75261
2023-12-13 09:55:29 -08:00
Guillaume Chatelet
6b37d8b73f
[libc][NFC] Shorten type names in tests (#75358) 2023-12-13 18:09:40 +01:00
Nick Desaulniers
eaa11526c8
[libc] fix -Wmacro-redefined (#75261)
When building with compiler-rt enabled, warnings such as the following
are
observed:


llvm-project/llvm/build/projects/compiler-rt/../libc/include/llvm-libc-macros/linux/sys-stat-macros.h:46:9:
    warning: 'S_IXOTH' macro redefined [-Wmacro-redefined]
    #define S_IXOTH 00001
            ^

llvm-project/llvm/build/projects/compiler-rt/../libc/include/llvm-libc-macros/linux/fcntl-macros.h:61:9:
    note: previous definition is here
    #define S_IXOTH 01
            ^
It looks like we have these multiply defined. Deduplicate these flags;
users
should expect to find them in sys/stat.h. S_FIFO was wrong anyways
(should
have been S_IFIFO).
2023-12-13 08:39:39 -08:00
Guillaume Chatelet
213c49807f
[reland][libc][NFC] Implement FPBits in terms of FloatProperties to reduce clutter (#75196) (#75318)
Also make type naming consistent by using `UIntType` instead of
`intU_t`.
This patch is a reland of #75196 but does not include the "use `FPBits`
instead of `FPBits_t`, `FPB`" part. This needs more work.
2023-12-13 12:22:02 +01:00
Guillaume Chatelet
a9af317fbe
Revert "[libc][NFC] Implement FPBits in terms of FloatProperties to reduce clutter" (#75304)
Reverts llvm/llvm-project#75196

GCC complains about change of meaning for `FPBits`
```
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/FPUtil/generic/FMod.h:188:9: error: declaration of ‘using FPBits = struct __llvm_libc_18_0_0_git::fputil::FPBits<T>’ changes meaning of ‘FPBits’ [-fpermissive]
  188 |   using FPBits = FPBits<T>;
      |         ^~~~~~
```

I'll reland with a different name.
2023-12-13 09:55:27 +01:00
Guillaume Chatelet
f64a0576ad
[libc][NFC] Implement FPBits in terms of FloatProperties to reduce clutter (#75196)
Also make type naming consistent:
 - `UIntType` instead of `intU_t`
 - `FPBits` instead of `FPBits_t`, `FPB`
2023-12-13 09:23:06 +01:00
Schrodinger ZHU Yifan
2c0abdf2df
[libc] [riscv] support build with scudo on riscv64 (#74951)
This patch fixes cmake configuration when building with
LLVM_LIBC_INCLUDE_SCUDO. In libc, LIBC_TARGET_ARCHITECTURE is renamed
from `riscv64` to `riscv`. However, `compiler-rt`, hence `scudo`,
distinguishes `riscv32` and `riscv64` in the support list. As a result,
we need to translate the architecture name accordingly.
2023-12-13 16:14:11 +08:00
michaelrj-google
8180ea8694
[libc] Add bind function (#74014)
This patch adds the bind function to go with the socket function. It
also cleans up a lot of socket related data structures.
2023-12-12 13:36:11 -08:00
Schrodinger ZHU Yifan
3568521e3d
[libc] fix issues around stack protector (#74567)
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-12 12:31:51 -08:00
Guillaume Chatelet
f22a65c158
[libc][NFC] Reuse FloatProperties constant instead of creating new ones (#75187)
Also exposes a bit more of `FloatProperties` and adds documentation.
This should have been several patches but I was lazy.
2023-12-12 15:56:06 +01:00
Guillaume Chatelet
1e47a157f8
[libc][NFC] Remove last use of BitsType in FloatProperties (#75174)
Also start to expose some of the internals to avoid duplication.
2023-12-12 14:00:25 +01:00
Guillaume Chatelet
dd85e67dc4
[libc] Add mask functions to math_extras (#75169) 2023-12-12 13:23:21 +01:00
Guillaume Chatelet
198238a598
[libc][NFC] Remove remaining specializations in FloatProperties (#75165)
This patch sinks `EXPLICIT_BIT_MASK` into `get_explicit_mantissa` - the
only function using it. Then it sinks the content of
`FPCommonProperties` directly into `FPProperties`.
2023-12-12 13:06:02 +01:00
Guillaume Chatelet
b00e445c4d
[libc][NFC] Make EXPONENT_BIAS int32_t (#75046)
`EXPONENT_BIAS` is almost always used with signed arithmetic. Making it
an `int32_t` from the start reduces the chances to run into
implementation defined behavior (cast from unsigned to signed is
implementation-defined until C++20).


https://en.cppreference.com/w/cpp/language/implicit_conversion#:~:text=If%20the%20destination%20type%20is%20signed,arithmetic%20overflow%2C%20which%20is%20undefined).
2023-12-12 13:03:26 +01:00
Guillaume Chatelet
b9be9f66c7
[libc] Make the bit header compatible with uint128 types (#75161) 2023-12-12 11:54:54 +01:00
Guillaume Chatelet
2bab0e0167
[libc][NFC] Swap ifdef logic for UInt128 (#75160) 2023-12-12 11:44:27 +01:00
michaelrj-google
b1a91b7ee0
[libc][NFC] fix uint128 init in float properties (#75084)
An unsigned integer was being initialized with -1 to set all its bits to
1, but this doesn't work for the BigInt class which may be used as an
integer type on systems that don't support uint128 natively. This patch
moves the initialization to use ~T(0) instead.
2023-12-11 10:46:10 -08:00
Guillaume Chatelet
e4f3ec2579
[libc][NFC] Simplify FloatProperties implementation (#74821)
This is a follow up on #74481 that migrates code from all
specializations into `FPCommonProperties` (except for
`EXPLICIT_BIT_MASK` in the `X86_Binary80` specialization)
2023-12-11 17:40:47 +01:00
Guillaume Chatelet
7e761ba854
[libc][NFC] Simplify FloatProperties implementation (#74481)
Factor in common properties of `FloatProperties`.

This is a first patch of a series to simplify `FloatProperties` and
`FPBits` implementations.
2023-12-11 17:14:20 +01:00