Commit Graph

61 Commits

Author SHA1 Message Date
Siva Chandra Reddy 4e8830830e [libc] Add a missing deps to the linux syscalls target.
Submitted as obvious.
2020-03-18 12:48:53 -07:00
Guillaume Chatelet 04a309dd0b [libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
 - How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
 - How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
 - How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
 - Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
   - If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
   - With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
   - For msvc we'd need to resort on the compiler optimization passes.

Reviewers: sivachandra, abrachet

Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D74397
2020-03-18 17:43:21 +01:00
Alex Brachet 4d35055635 [libc] Add sigaction
Summary: This patch adds `sigaction` and the `sa_restorer` signal trampoline function `__restore_rt`

Reviewers: sivachandra, MaskRay, PaulkaToast

Reviewed By: sivachandra

Subscribers: gchatelet, mgorny, tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D75802
2020-03-18 01:08:59 -04:00
Paula Toth a9e05d5711 [libc] Add AOR testing dependencies for buildbot workers.
Summary: These dependencies are needed for testing on the buildbots until we migrate AORs into libc.

Reviewers: sivachandra

Reviewed By: sivachandra

Subscribers: MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D76330
2020-03-17 17:43:55 -07:00
Paula Toth 17566573b2 [libc] Resolve race condition in sub-process test runner.
Summary:
There seems to be a race condition between the pipe closing and the child process death. Likely these two events are not atomic on some versions of linux.

With the removal of `WNOHANG` we eliminate the race condition, however if the child closes the pipe intentionally then it could result in the test runner hanging. I find this situation less likely, where as I experience failures locally with this race condition rather consistently.

Reviewers: sivachandra, abrachet

Reviewed By: sivachandra, abrachet

Subscribers: MaskRay, jfb, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D76267
2020-03-17 13:00:00 -07:00
Siva Chandra Reddy 768ead0a6c [libc] Add a new rule `add_object`.
This rule can help add targets to generate special object files like the
crt1.o on linux. Also, it can be used to add specially compiled object
stubs which are to be linked into the entrypoint objects.

Reviewers: abrachet

Differential Revision: https://reviews.llvm.org/D76271
2020-03-17 12:33:36 -07:00
Siva Chandra Reddy 78d622a48c [libc] Add a README.md file to the AOR directory.
Also, add config.mk file which will help test the implementations in the
"math" directory for x86_64 with a simple "make check".
2020-03-16 12:29:24 -07:00
Kristof Beyls 0928368f62 [libc] Provide Arm Optimized Routines for the LLVM libc project.
This adds the Arm Optimized Routines (see
https://github.com/ARM-software/optimized-routines) source code under the
the LLVM license. The version of the code provided in this patch is v20.02
of the Arm Optimized Routines project.

This entire contribution is being committed as is even though it does
not currently fit the LLVM libc model and does not follow the LLVM
coding style. In the near future, implementations from this patch will be
moved over to their right place in the LLVM-libc tree. This will be done
over many small patches, all of which will go through the normal LLVM code
review process. See this libc-dev post for the plan:
http://lists.llvm.org/pipermail/libc-dev/2020-March/000044.html

Differential revision of the original upload: https://reviews.llvm.org/D75355
2020-03-16 12:19:31 -07:00
Alex Brachet af0b0e00fb [libc] [UnitTest] Add timeout to death tests
Summary:
This patch adds a timeout of 500ms to death tests. As we add multithreaded code and locks, deadlocks become more likely so timeout will be useful.

Additionally:
 - Better error handling in `invokeSubprocess`
 - Makes `ProcessStatus`'s methods const

Reviewers: sivachandra, MaskRay, gchatelet, PaulkaToast

Reviewed By: sivachandra, PaulkaToast

Subscribers: tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D75651
2020-03-11 23:57:20 -04:00
Alex Brachet b47c9f535c [libc] Add initial assert definition
Summary: This patch adds a temporary `__assert_fail` and `assert` definition to make it available to internal llvm libc code. `__assert_fail` writes to fd 2 directly instead of `stderr`, using SYS_write. I have not put it in its own linux directory because this is temporary and it should be using stdio's api in the future. It does not currently print out the line number (although we could do that by stringifying `__LINE__` if reviewers wish).

Reviewers: sivachandra, gchatelet, PaulkaToast

Reviewed By: sivachandra

Subscribers: mgorny, MaskRay, tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D75420
2020-03-11 23:45:58 -04:00
Paula Toth 270b528c7c [libc] Add docker container for llvm-libc buildbot worker.
Summary: Created a docker container to provide transparency and easy changes to the llvm-libc buildbot intfra.

Reviewers: sivachandra

Reviewed By: sivachandra

Subscribers: MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D75596
2020-03-11 17:35:41 -07:00
Siva Chandra Reddy 550be40515 [libc] Add simple implementations of mtx_lock and mtx_unlock.
These functions only support locking and unlocking of plain mutexes.
They will be extended in future changes to handled recursive and timed
mutexes.

Reviewers: phosek

Differential Revision: https://reviews.llvm.org/D74653
2020-03-09 21:56:02 -07:00
Siva Chandra Reddy fd8c133613 [libc] Take 2: Add linux implementations of thrd_create and thrd_join functions.
The following are the differences from the first version:

1. The kernel does not copy the stack for the new thread (it cannot).
The previous version missed this fact. In this new version, the new
thread's start args are copied on to the new stack in a known location
so that the new thread can sniff them out.
2. A start args sniffer for x86_64 has been added.
2. Default stack size has been increased to 64KB.

Reviewers: abrachet, phosek

Differential Revision: https://reviews.llvm.org/D75818
2020-03-09 21:28:11 -07:00
Alex Brachet 129c8b8081 add extern "C" to __errno_location's definition if in __cplusplus file 2020-03-09 03:10:59 -04:00
Alex Brachet 1348ca4046 [libc] [NFC] Use matchers in tests
Summary:
Use `EXPECT_THAT` where possible in tests NFC intended.

Added a `void *` template instantiation of `StreamWrapper::operator<<`

Reviewers: sivachandra, PaulkaToast

Reviewed By: sivachandra

Subscribers: MaskRay, tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D75717
2020-03-07 22:56:03 -05:00
Siva Chandra Reddy 3c88489a06 [libc]Revert "Add linux implementations of thrd_create and thrd_join functions."
This reverts commit abc040e953 as the bots
are failing because of this.
2020-03-05 20:46:13 -08:00
Alex Brachet 1962bc1dfb [libc] [UnitTest] Add Matchers
Summary: This patch adds gtest-like matchers and `EXPECT|ASSERT_THAT` macros. It also adds matchers `Succeeds` and `Fails` and has examples using these in test/src/signal/sigaddset_test.cpp.

Reviewers: sivachandra, gchatelet, PaulkaToast

Reviewed By: sivachandra, PaulkaToast

Subscribers: mgorny, MaskRay, tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D75487
2020-03-05 18:36:11 -05:00
Siva Chandra Reddy abc040e953 [libc] Add linux implementations of thrd_create and thrd_join functions.
Reviewers: abrachet, phosek

Differential Revision: https://reviews.llvm.org/D75380
2020-03-05 13:53:17 -08:00
Alex Brachet a499d68056 [libc] Create abort and _Exit
This revision creates abort and _Exit implementations

Differential Revision: https://reviews.llvm.org/D74949
2020-03-05 14:21:18 -05:00
Siva Chandra Reddy 80aba2b262 [libc] Add `errno_h` as a dependency to `sigaddset` and `sigemptyset`.
Summary: The bots are catching this missing dependency.

Reviewers: PaulkaToast, abrachet

Subscribers: mgorny, MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D75502
2020-03-02 23:46:30 -08:00
Alex Brachet cd76a02639 [libc] Add sigprocmask
Summary: This patch adds `sigprocmask`, `sigemptyset` and `sigaddset`

Reviewers: sivachandra, MaskRay, gchatelet

Reviewed By: sivachandra

Subscribers: mgorny, tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D75026
2020-03-02 03:47:21 -05:00
Siva Chandra Reddy d1536673c6 [libc] Add ability to generate enum types/values to HdrGen.
A target to generate the std C threads.h file has been added. This
utilizes the new feature added in this change.

Reviewers: phosek

Differential Revision: https://reviews.llvm.org/D75379
2020-02-28 23:27:32 -08:00
Guillaume Chatelet 1aab055dd8 [libc] Add CMake script to check host cpu features
Summary:
Tested on MacOSX and Linux.
For robustness we can go the OpenCV way and add individual c++ files with intrinsics.
https://github.com/opencv/opencv/blob/master/cmake/checks/cpu_avx2.cpp

Reviewers: sivachandra, abrachet

Subscribers: mgorny, MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D74897
2020-02-27 09:52:26 +01:00
Siva Chandra Reddy cab6ac2612 [libc] Add an optional `NAME` argument to `add_entrypoint_object` rule.
This argument can be used to specify the entrypoint name if it is different
from the target name.

Reviewers: gchatelet, abrachet

Differential Revision: https://reviews.llvm.org/D74948
2020-02-26 21:41:58 -08:00
Paula Toth 52073310e4 [libc] Fix typo of namespace in round implementation.
Summary: Fixed typos in namespace declarations and comments in the files under `src/math/round`.

Reviewers: sivachandra, abrachet

Reviewed By: sivachandra, abrachet

Subscribers: MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D75205
2020-02-26 12:24:07 -08:00
Alex Brachet 805f5836d1 [libc] Fix build when -DBUILD_SHARED_LIBS=On
Reviewers: gchatelet, sivachandra

Reviewed By: gchatelet, sivachandra

Subscribers: libc-commits, mgorny, MaskRay, tschuett

Differential Revision: https://reviews.llvm.org/D75136
2020-02-26 12:19:09 -05:00
Alex Brachet 29e2cb8749 [libc] [UnitTest] Give UnitTest gtest like colors
Summary:
This is a quality of life change to make it a little nicer to look at, NFC.
This patch makes the RUN and OK lines green and FAILED lines red to match gtest's output.

Reviewers: sivachandra, gchatelet, PaulkaToast

Reviewed By: gchatelet

Subscribers: MaskRay, tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D75103
2020-02-25 03:46:09 -05:00
Alex Brachet 0368997402 [libc] [UnitTest] Create death tests
Summary: This patch adds `EXPECT_EXITS` and `EXPECT_DEATH` macros for testing exit codes and deadly signals. They are less convoluted than their analogs in GTEST and don't have matchers but just take an int for either the exit code or the signal respectively. Nor do they have any regex match against the stdout/stderr of the child process.

Reviewers: sivachandra, gchatelet

Reviewed By: sivachandra

Subscribers: mgorny, MaskRay, tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D74665
2020-02-24 17:53:43 -05:00
Siva Chandra Reddy 4d812acba6 [libc] Add a README to the sub-directories under the utils directory.
Also, the source layout document has been updated to reflect the current
layout of the `utils` directory.

Reviewers: PaulkaToast

Differential Revision: https://reviews.llvm.org/D74502
2020-02-23 22:11:35 -08:00
Paula Toth a4f45ee73a [libc] Lay out framework for fuzzing libc functions.
Summary:
Added fuzzing test for strcpy and some documentation related to fuzzing.
This will be the first step in integrating this with oss-fuzz.

Reviewers: sivachandra, abrachet

Reviewed By: sivachandra, abrachet

Subscribers: gchatelet, abrachet, mgorny, MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D74091
2020-02-21 19:15:46 -08:00
Alex Brachet 1b1a97e9b5 Remove unused variable 2020-02-21 20:48:07 -05:00
Alex Brachet 5d2baa956a [libc] Add Initial Support for Signals
Summary:
This patch adds signal support on Linux. The current implementation gets the SIG* macros and types like `sigset_t` from <linux/signals.h>

This patch also adds raise(3), and internal routines  `block_all_signals` and `restore_signals`

Reviewers: sivachandra, MaskRay, gchatelet

Reviewed By: sivachandra

Subscribers: libc-commits, mgorny, tschuett

Differential Revision: https://reviews.llvm.org/D74528
2020-02-20 14:05:34 -05:00
Alex Brachet 2c73c26666 [libc] Add Convenience syscall Template Function
Summary: This patch adds a convenience template function so we don't need to cast all types to `long` manually when calling `__llvm_libc::syscall`.

Reviewers: sivachandra, MaskRay, gchatelet

Reviewed By: sivachandra

Subscribers: libc-commits, tschuett

Differential Revision: https://reviews.llvm.org/D74530
2020-02-13 14:39:16 -05:00
Alex Brachet a8cb0cf500 [libc][NFC] clang-format syscall.h.in
Reviewers: sivachandra

Reviewed By: sivachandra

Subscribers: MaskRay, tschuett, libc-commits

Differential Revision: https://reviews.llvm.org/D74570
2020-02-13 14:02:20 -05:00
Guillaume Chatelet 961aeb7a15
Fix unneeded semi column 2020-02-13 11:18:28 +01:00
Paula Toth 4a2fa55299 Remove leftover artifacts from use of gtest.
Reviewers: abrachet

Reviewed By: abrachet

Subscribers: mgorny, MaskRay, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D74008
2020-02-04 21:41:45 -08:00
Paula Toth 3101def847 [libc] Fix typo in header generation docs.
Reviewers: sivachandra, abrachet

Reviewed By: sivachandra, abrachet

Subscribers: libc-commits, MaskRay, tschuett

Tags: #libc-project, #llvm

Differential Revision: https://reviews.llvm.org/D72248
2020-02-04 11:43:59 -08:00
Siva Chandra Reddy 2a6ef2aecf [libc] Use cpp::Array instead of cpp::ArrayRef in memory/utils_test.
Building with address-sanitizer shows that using ArrayRef ends up
accessing a temporary outside its scope.
2020-01-31 11:45:09 -08:00
Guillaume Chatelet 85314e9b7a [libc] Add utils for memory functions
Summary: This patch adds a few low level functions needed to build libc memory functions.

Reviewers: sivachandra, jfb

Subscribers: mgorny, MaskRay, tschuett, libc-commits, ckennelly

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D73472
2020-01-31 10:15:02 +01:00
Siva Chandra Reddy 7f65892086 [libc] Add [EXPECT|ASSERT]_[TRUE|FALSE] unittest macros.
Also, other EXPECT_* and ASSERT_* macros have been extended to accept
bool values.

Reviewers: abrachet, gchatelet

Subscribers: MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D73668
2020-01-30 11:59:31 -08:00
Siva Chandra Reddy 3302586fae [libc] Add a missing `this->` in __llvm_libc::cpp:MutableArrayRef::end.
I had removed it to verify a review comment, but forgot to put it back.
2020-01-30 09:16:21 -08:00
Siva Chandra Reddy c6bc10636c [libc] Add a library of standalone C++ utilities.
Some of the existing utils in utils/UnitTest/Test.h have been moved to
this new library.

Reviewers: abrachet, gchatelet

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D73530
2020-01-29 13:44:02 -08:00
Siva Chandra Reddy b9826408e4 [libc] Fix build after 777180a32b.
Implicit conversion from llvm::StringRef to std::string was made
explicit in the above commit.
2020-01-29 13:32:38 -08:00
Guillaume Chatelet c2dcdf95eb [libc] Fix benchmarks CMakeLists.txt
Summary:
This is a follow up on https://reviews.llvm.org/rGaba80d0734d1#886881.
`target_link_options` requires CMake>=3.13.

Reviewers: abrachet

Subscribers: mgorny, MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D73452
2020-01-29 15:56:47 +01:00
Guillaume Chatelet 2c1a142a78 Fix missing dependency in LibcUnitTest
Summary: LibcUnitTest is missing a dependency on LLVMSupport. This prevents building with shared libraries.

Reviewers: sivachandra

Subscribers: mgorny, MaskRay, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D73337
2020-01-27 10:14:39 +01:00
Siva Chandra Reddy ec62bf2fd3 [libc] Move the implementation of mmap and munmap into a linux specific area.
This allows us to get rid of the PAGE_SIZE macro and use EXEC_PAGESIZE
from linux/param.h.

Few other points about this change:
1. The linux syscall functions have been moved into a linux specific area
instead of src/unistd/syscall.h. The Linux syscall function from unistd.h
is a public vararg function. What we have currently are linux speciif internal
overloaded C++ functions. So, moving them to a Linux only area is more
meaningful.
2. The implementations of mmap and munmap are now in a 'linux' directory
within src/sys/mman. The idea here is that platform specific
implementations will live in a platform specific subdirectories like these.
Infrastructure common to a platform will live in the platform's config
directory. For example, the linux syscall implementations live in
config/linux.

Reviewers: abrachet

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D73302
2020-01-24 15:42:28 -08:00
Guillaume Chatelet aba80d0734 [llvm-libc] Add memory function benchmarks
Summary:
This patch adds a benchmarking infrastructure for llvm-libc memory functions.

In a nutshell, the code can benchmark small and large buffers for the memcpy, memset and memcmp functions.
It also produces graphs of size vs latency by running targets of the form `render-libc-{memcpy|memset|memcmp}-benchmark-{small|big}`.

The configurations are provided as JSON files and the benchmark also produces a JSON file.
This file is then parsed and rendered as a PNG file via the `render.py` script (make sure to run `pip3 install matplotlib scipy numpy`).
The script can take several JSON files as input and will superimpose the curves if they are from the same host.

TODO:
 - The code benchmarks whatever is available on the host but should be configured to benchmark the -to be added- llvm-libc memory functions.
 - Add a README file with instructions and rationale.
 - Produce scores to track the performance of the functions over time to allow for regression detection.

Reviewers: sivachandra, ckennelly

Subscribers: mgorny, MaskRay, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D72516
2020-01-24 11:30:58 +01:00
Siva Chandra Reddy c7453fad06 [libc] Replace the use of gtest with a new light weight unittest framework.
Header files included wrongly using <...> are now included using the
internal path names as the new unittest framework allows us to do so.

Reviewers: phosek, abrachet

Differential Revision: https://reviews.llvm.org/D72743
2020-01-17 16:24:53 -08:00
Siva Chandra Reddy 880734aebb [libc] Add a convenience CMake rule to add testsuites.
Summary:
This rule helps avoid repeated setting of check-libc's dependency on the
various testsuites.

Reviewers: abrachet

Subscribers: mgorny, MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D72353
2020-01-07 23:04:52 -08:00
Siva Chandra Reddy 188f72ab20 [libc] Move implementations of strcat and strcpy to the string directory.
Summary:
Now that tests live in separate top-level directory, keeping the
implementations of individual functions in a directory of their own is
not meaningful. Hence, this change moves them into the higher level
string directory.

NFC intended.

Reviewers: MaskRay

Subscribers: mgorny, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D72295
2020-01-06 22:20:42 -08:00