Commit Graph

2488 Commits

Author SHA1 Message Date
lntue
ce8fcad5f4
[libc] Fix float.h header to include the system float.h first and add more definitions. (#78857) 2024-01-20 14:44:51 -05:00
Petr Hosek
b86d02375e
[libc] Redo the install targets (#78795)
Prior to this change, we wouldn't build headers that aren't referenced
by other parts of the libc which would result in a build error during
installation. To address this, we make the header target a dependency of
the libc archive. Additionally, we also redo the install targets, moving
the install targets closer to build targets and simplifying the
hierarchy and generally matching what we do for other runtimes.
2024-01-19 15:45:22 -08:00
Nick Desaulniers
2c0d20668a
[libc] remove extra -Werror (#78761)
-Werror is now a global default as of
commit c52b467875 ("Reapply "[libc] build with -Werror (#73966)"
(#74506)")
2024-01-19 12:28:06 -08:00
lntue
c80d68a676
[libc] Add float.h header. (#78737) 2024-01-19 12:04:34 -05:00
Joseph Huber
cebe4de66f [libc] Fix test failing on GPU using deprecated 'add_unittest'
Summary:
We use `add_libc_test' now because it works for both hermetic and unit
tests. If the test needs to be unit test only you use `UNIT_TEST_ONLY`
as an argument.
2024-01-19 10:38:41 -06:00
Guillaume Chatelet
508c4efe1e
[libc][NFC] Use Sign in NormalFloat (#78579) 2024-01-19 09:56:01 +01:00
Guillaume Chatelet
14f0c06f48
[libc] Fix is_subnormal for Intel Extended Precision (#78592)
Also turn a set of `get_biased_exponent() == 0` into `is_subnormal()`
which is clearer.
2024-01-19 09:36:03 +01:00
Guillaume Chatelet
28d64c1237
[libc][NFC] Simplify FPBits expressions (#78590) 2024-01-19 09:34:28 +01:00
Guillaume Chatelet
508c6aa8f3
[libc][NFC] Fix "type qualifiers ignored on cast result type" GCC warning (#78509)
GCC complains about "type qualifiers ignored on cast result type".
Upon investigation the correct fix was to remove all `volatile` and use the `-frounding-math` option.
2024-01-19 09:27:03 +01:00
Petr Hosek
dbc0955314
[libc] Provide sys/queue.h (#78081)
This header first appeared in 4.4BSD and is provided by a number of C
libraries including Newlib. Several of our embedded projects use this
header and so to make LLVM libc a drop-in replacement, we need to
provide it as well.

For the initial commit, we only implement singly linked variants (SLIST
and STAILQ). The doubly linked variants (LIST, TAILQ and CIRCLEQ) can be
implemented in the future as needed.
2024-01-18 21:45:58 -08:00
Joseph Huber
a9ca820529
[libc] Use clang's scoped atomics if available from the compiler (#74769)
Summary:
A recent patch in https://github.com/llvm/llvm-project/pull/72280
provided `clang` the ability to easily use scoped atomics. These are a
special modifier on atomics that some backends support. They are
intended for providing more fine-grained control over the affected
memory of an atomic action. The default is a "system" scope, e.g.
coherence with the GPU and CPU memory on a heterogeneous system. If we
use "device" scope, that implies that the memory is only ordered with
respect to the current GPU.

These builtins are direct replacements for the GCC atomic builitins in
cases where the backend doesn't do anything with the information, so
these should be a drop-in. This introduces some noise, but hopefully it
isn't too contentious.
2024-01-18 14:43:09 -06:00
Nick Desaulniers
3044d75485
[libc][arm] add more math.h entrypoints (#77839)
In particular, we have internal customers that would like to use nanf
and
scalbnf.

The differences between various entrypoint files can be checked via:

    $ comm -3 <(grep libc\.src path/to/entrypoints.txt | sort) \
       <(grep libc\.src path/to/other/entrypoints.txt | sort)
2024-01-18 08:18:13 -08:00
Nick Desaulniers
de03c46b8b
[libc] reverts for 32b arm (#78307)
These were fixed properly by f1f1875c18.

- Revert "[libc] temporarily set -Wno-shorten-64-to-32 (#77396)"
- Revert "[libc] make off_t 32b for 32b arm (#77350)"
2024-01-18 08:17:19 -08:00
Guillaume Chatelet
e6a6a90fe7
[libc][NFC] Use the Sign type for DyadicFloat (#78577) 2024-01-18 15:03:35 +01:00
Guillaume Chatelet
11ec512f44
[libc][NFC] Introduce a Sign type for FPBits (#78500)
Another patch is needed to cover `DyadicFloat` and `NormalFloat`
constructors.
2024-01-18 13:40:49 +01:00
Guillaume Chatelet
bc4f3e31a9
[libc][NFC] Selectively disable GCC warnings (#78462) 2024-01-18 10:36:21 +01:00
michaelrj-google
47d5967023
[libc][obvious] disable fabsf128 on aarch64 (#78511)
It's not working on the buildbot, so I've disabled it until we fix it.
2024-01-17 14:22:50 -08:00
Guillaume Chatelet
5ddd7bc38c
[reland][libc][NFC] Refactor FPBits and remove LongDoubleBits specialization (#78465)
- [reland] #78192 
- [reland] #78447 
- Turn `as` static function into a `to_storage_type` member function.
2024-01-17 17:38:48 +01:00
Guillaume Chatelet
d8627cb138
Revert "[reland][libc][NFC] Refactor FPBits and remove LongDoubleBits specialization" (#78457)
Reverts llvm/llvm-project#78447
This broke the gcc buildbot.
2024-01-17 16:50:52 +01:00
Guillaume Chatelet
cab041fe63
[reland][libc][NFC] Refactor FPBits and remove LongDoubleBits specialization (#78447)
- [reland] #78192
- Make the implementation work when `__uint128_t` is not available on
the plaftorm.
2024-01-17 16:15:09 +01:00
Nick Desaulniers
337b771592
Revert "[libc][NFC] Refactor FPBits and remove LongDoubleBits specialization (#78192)" (#78329)
This reverts commit fdbf255c96.

Causes build breakage on 32b arm (see reports:
https://github.com/llvm/llvm-project/pull/78192).

These are reproducible for the 32b arm baremetal target on x86 hosts as
well.
2024-01-16 12:09:58 -08:00
Nick Desaulniers
f1f1875c18
[libc][cmake] reset COMPILE_DEFINITIONS (#77810)
While trying to enable -Werror (#74506), the 32b ARM build bot reported
an
error stemming from -Wshorten-64-to-32 related to usages of `off_t`.

I failed to fix these properly in #77350 (the 32b ARM build is not a
fullbuild)
and #77396.

It turns out, the preprocessor defines `-D_LARGEFILE_SOURCE` and
`-D_FILE_OFFSET_BITS=64` were being set for llvmlibc when using the
cmake build
system. In particular, these preprocessor defines are feature test
macros used
by glibc, and which have effects no the corresponding ABI for types like
`off_t` (for instance, should `off_t` be 32b or 64b on 32b targets).

But who was setting these? Turns out that the use of
add_compile_definitions
in llvm/cmake/modules/HandleLLVMOptions.cmake was setting these (and
more),
which is then inherited by every subdirectory. While some of these
defines
maybe make sense for host builds, they do not make sense for libraries
for the
target. The full list of defines being set prior to this commit:

- `-D_GNU_SOURCE`
- `-D_FILE_OFFSET_BITS=64`
- `-D_DEBUG`
- `-D_GLIBCXX_ASSERTIONS`
- `-D_LARGEFILE_SOURCE`
- `-D_FILE_OFFSET_BITS=64`
- `-D__STDC_CONSTANT_MACROS`
- `-D__STDC_FORMAT_MACROS`
- `-D__STDC_LIMIT_MACROS`

If we desire any of the above, we should manually reset them.

Fix this by resetting COMPILE_DEFINITIONS for the libc/ subdirectory.

Side note: to debug 'directory properties' in cmake, you first need to
use
`get_directory_property` to fetch the corresponding value into a
variable
first, then that variable can be printed via `message`.

Link:
https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html#index-_005fFILE_005fOFFSET_005fBITS
Link:
https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html#index-_005fFILE_005fOFFSET_005fBITS

Fixes: #77395
2024-01-16 08:14:06 -08:00
Guillaume Chatelet
fdbf255c96
[libc][NFC] Refactor FPBits and remove LongDoubleBits specialization (#78192)
This patch removes the `FPBits` specialization for x86 Extended Precision by moving it up to `FPRep`.
It also introduces enums (`Exponent`, `BiasedExponent` and `Significand`) to represent the exponent and significant parts of the floating point numbers. These enums are used to construct and observe floating point representations.

Additionally, we remove `LongDoubleBits.h` that is now unnecessary.
2024-01-16 15:41:40 +01:00
Petr Hosek
c20811b659
[libc] Fix libc-hdrgen crosscompiling (#78227)
The support introduced in 675702f356b0c3a540fa2e8af4192f7d658b2988 is
not working correctly in all scenarios. Instead of setup_host_tool
function, we can use the existing targets introduced by add_tablegen
macro.
2024-01-16 07:39:06 -06:00
AtariDreams
e06b5a2435
[libc] Give more functions restrict qualifiers (NFC) (#78061)
strsep, strtok_r, strlcpy, and strlcat take restricted pointers as
parameters.
Add the restrict qualifiers to them.

Sources:
https://man7.org/linux/man-pages/man3/strsep.3.html
https://man7.org/linux/man-pages/man3/strtok_r.3.html
https://man.freebsd.org/cgi/man.cgi?strlcpy
2024-01-15 12:12:09 -06:00
lntue
cd753c70e6
[libc][math] Remove wrong fabsf128 entrypoint in aarch64 list. (#77974) 2024-01-12 15:27:24 -05:00
lntue
1048b5999b
[libc][math] Add C23 math function fabsf128. (#77825) 2024-01-12 15:00:16 -05:00
Petr Hosek
b348126b21
[libc] Build native libc-hdrgen when crosscompiling (#77848)
When crosscompiling tools for a different architecture, we need to build
native libc-hdrgen which can be achieved using the existing CMake
support for crosscompiling tablegen tools.
2024-01-12 11:36:01 -08:00
Guillaume Chatelet
5794854213
[libc][NFC] Use 16-byte indices for _mmXXX_shuffle_epi8 (#77781)
This is less confusing since the implementation only cares about the 4
lower bits.
2024-01-11 16:25:55 +01:00
Guillaume Chatelet
9ca6e5bb86
[libc] Fix buggy AVX2 / AVX512 memcmp (#77081)
Fixes #77080.
2024-01-11 11:45:37 +01:00
Guillaume Chatelet
1ee93ac099
[libc] Add memcmp / bcmp fuzzers (#77741) 2024-01-11 11:06:46 +01:00
michaelrj-google
b932f03bda
[libc] Disable Death Tests While Hermetic (#77388)
The death test infrastructure seems to depend on operator new, which
isn't currently supported in our hermetic tests. This patch just
disables the death tests in hermetic mode since they only overlap in the
nan tests.
2024-01-09 15:04:22 -08:00
Nick Desaulniers
70cea91e0f
[libc] temporarily set -Wno-shorten-64-to-32 (#77396)
This is still broken after #77350. Disable the warning for now, and fix
properly once the buildbot it back to green.

Link: https://github.com/llvm/llvm-project/issues/77395
2024-01-08 16:21:49 -08:00
Nick Desaulniers
1689bbea17 [libc] fix up #77384 2024-01-08 16:18:31 -08:00
Nick Desaulniers
6958986f77
[libc] fix -Wconversion (#77384)
Fixes the following from GCC:

    llvm-project/libc/src/string/memory_utils/op_x86.h:236:24: error:
conversion from ‘long unsigned int’ to ‘uint32_t’ {aka ‘unsigned int’}
may
    change value [-Werror=conversion]
      236 |   return (xored >> 32) | (xored & 0xFFFFFFFF);
          |          ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

Link:
https://lab.llvm.org/buildbot/#/builders/250/builds/16236/steps/8/logs/stdio
Link: https://github.com/llvm/llvm-project/pull/74506
2024-01-08 16:08:22 -08:00
Nick Desaulniers
f700d748f0
[libc] fix more -Wmissing-brace (#77382)
Similar to #77345, the buildbots are observing similar warnings for the
sse2
implementation.

llvm-project/libc/src/__support/HashTable/sse2/bitmask_impl.inc:36:13:
    error: suggest braces around initialization of subobject
    [-Werror,-Wmissing-braces]
    return {bitmask};
            ^~~~~~~
            {      }
llvm-project/libc/src/__support/HashTable/sse2/bitmask_impl.inc:45:13:
    error: suggest braces around initialization of subobject
    [-Werror,-Wmissing-braces]
    return {static_cast<uint16_t>(~mask_available().word)};
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            {                                            }

Link:
https://lab.llvm.org/buildbot/#/builders/163/builds/49350/steps/8/logs/stdio
Link: https://github.com/llvm/llvm-project/pull/74506
2024-01-08 13:57:10 -08:00
Nick Desaulniers
ce1305a3ce
[libc] make off_t 32b for 32b arm (#77350)
Fixes the following diagnostic:

    llvm-project/libc/src/sys/mman/linux/mmap.cpp:44:59: error: implicit
conversion loses integer precision: 'off_t' (aka 'long long') to 'long'
    [-Werror,-Wshorten-64-to-32]
     size, prot, flags, fd, offset);
                            ^~~~~~

It looks like off_t is a curious types on different platforms. FWICT,
it's 32b
on arm (at least for arm-linux-gnueabi) but 64b elsewhere (including 32b
riscv32-linux-gnu).
2024-01-08 13:09:58 -08:00
Nick Desaulniers
c1023c585d
[libc] fix -Wmissing-braces (#77345)
Fixes the following errors observed on the aarch64 fullbuild:


/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/HashTable/generic/bitmask_impl.inc:116:13:
    error: suggest braces around initialization of subobject
    [-Werror,-Wmissing-braces]
return {static_cast<bitmask_t>(mask_available().word ^
repeat_byte(0x80))};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{ }
    In file included from

/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/search/hdestroy.cpp:10:

/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/__support/HashTable/table.h:336:41:
    error: suggest braces around initialization of subobject
    [-Werror,-Wmissing-braces]
      iterator end() const { return {0, 0, {0}, *this}; }
                                            ^
                                            {}

Link:
https://lab.llvm.org/buildbot/#/builders/223/builds/33868/steps/6/logs/stdio
Link: https://github.com/llvm/llvm-project/pull/74506
2024-01-08 10:18:36 -08:00
Nick Desaulniers
c52b467875
Reapply "[libc] build with -Werror (#73966)" (#74506)
This reverts commit 6886a52d6d.

Most of the errors observed in postsubmit have been addressed. We can
fix-forward the remaining ones.

Link: https://lab.llvm.org/buildbot/#/changes/117129
2024-01-08 09:07:35 -08:00
Nick Desaulniers
12101ca8e3
[libc] set -Wno-frame-address for thread.cpp (#77140)
The aarch64 code is using __builtin_return_address with a non-zero
parameter,
which generates the following warning:

llvm-project/libc/src/__support/threads/linux/thread.cpp:171:38: error:
calling '__builtin_frame_address' with a nonzero argument is unsafe
        [-Werror,-Wframe-address]
171 | return reinterpret_cast<uintptr_t>(__builtin_frame_address(1));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
    
Disable this diagnostic just for this file so that we can enable
-Werror.
    
Fixes: #77007
2024-01-08 08:51:44 -08:00
Joseph Huber
fece9818ab [libc] Attempt to fix incorrect pathin on Linux builds 2024-01-07 13:40:10 -06:00
Joseph Huber
38228d5efe
[libc] Fix GPU tests not running after recent patches (#77248)
Summary:
A previous patch added a dependency on the stack protectors, this was
not built on the GPU targets so every test was disabled. It turns out
that disabled tests still get targets so we need to specifically check
if the it is in the target's set of entrypoints before we can use it.

Another patch, because the build-bot was down, snuck in that prevented
the new math tests from being run. The problem is that the `signal.h`
header requires target specific definitions but was being used
unconditionally. I have made changes that disable building this header
if the file is not defined in the config. This required disbaling the
signal_to_string utility, so that will simply be missing from targets
that don't define it.
2024-01-07 13:33:16 -06:00
Nick Desaulniers
dcdb4a36ae
[libc][cmake] append per obj compile options instead of prepending (#77126)
This allows individual object files to override the common compile
commands in
their local CMakeLists' add_object_library call.

For example, the common compile commands contain -Wall and -Wextra.
Before
this patch, the per object COMPILE_OPTIONS were prepended to these, so
that
builds of individual object files could not individually disable
specific
diagnostics from those groups explicitly.

After this patch, the per-object file compile objects are appended to
the list
of compiler flags, enabling this use case.

ARGN is a bit of cmake magic; let's be explicit in the APPEND that we're
appending the compile options.

Link: #77007
2024-01-05 13:31:35 -08:00
Nick Desaulniers
5352ce32fc
[libc] fix -Warray-bounds in block_offset (#77001)
GCC reports an instance of -Warray-bounds in block_offset.  Reimplement
block_offset in terms of memcpy_inline which was created to avoid this
diagnostic. See the linked issue for the full trace of diagnostic.

Fixes: https://github.com/llvm/llvm-project/issues/76877
2024-01-05 08:19:04 -08:00
Nishant Mittal
e297238911
[libc][math] fix nan* death tests failing in asan builds (#77110) 2024-01-05 10:51:16 -05:00
Nishant Mittal
736cc0cbf0
[libc][math] fix failing nanl_test build (#77102) 2024-01-05 09:49:51 -05:00
Nishant Mittal
0504e93288
[libc][math] Implement nan(f|l) functions (#76690)
Specification: https://en.cppreference.com/w/c/numeric/math/nan
2024-01-05 08:23:23 -05:00
Schrodinger ZHU Yifan
2bc994456c
[libc] major refactor of startup library (#76092)
* separate initialization routines into _start and do_start for all
architectures.
* lift do_start as a separate object library to avoid code duplication.
* (addtionally) address the problem of building hermetic libc with
-fstack-pointer-*

The `crt1.o` is now a merged result of three components:

```
___
  |___ x86_64
  |      |_______ start.cpp.o    <- _start (loads process initial stack and aligns stack pointer)
  |      |_______ tls.cpp.o      <- init_tls, cleanup_tls, set_thread_pointer (TLS related routines) 
  |___ do_start.cpp.o            <- do_start (sets up global variables and invokes the main function) 
```
2024-01-04 12:51:14 -08:00
Nishant Mittal
79a2e2b9e8
[libc][math] Fix is_quiet_nan function in FPBits (#76931) 2024-01-04 12:24:54 -05:00
Guillaume Chatelet
d02471ede5
[libc][NFC] Simplify FPBits (#76835)
This patch reduces the scope of `FPBits` exported variables and
functions.
It also moves storage up into `FPRep` and tries to make the default and
specialized versions of `FPBits` more uniform.

The next step is to move the specialization from `FPBits` to `FPRep` so
we can manipulate floating point representations through `FPType` 
alone - that is - independently from the host architecture.
2024-01-04 16:14:28 +01:00