llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.59k stars 11.34k forks source link

[libc] implement pipe2 #85289

Open michaelrj-google opened 5 months ago

michaelrj-google commented 5 months ago

The pipe2 is defined on linux here: https://man7.org/linux/man-pages/man2/pipe.2.html

This is a simple syscall wrapper, so implementation should be straightforward.

Build System

In entrypoints.txt

In unistd/CMakeLists.txt

In linux.td

Code

Create unistd/pipe2.h

Create unistd/linux/pipe2.cpp

Testing

Create test/src/unistd/pipe2_test.cpp

Add your tests to test/src/unistd/CMakeLists.txt

llvmbot commented 5 months ago

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. In the comments of the issue, request for it to be assigned to you.
  2. Fix the issue locally.
  3. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  4. Create a Git commit.
  5. Run git clang-format HEAD~1 to format your changes.
  6. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

llvmbot commented 5 months ago

@llvm/issue-subscribers-good-first-issue

Author: Michael Jones (michaelrj-google)

The pipe2 is defined on linux here: https://man7.org/linux/man-pages/man2/pipe.2.html This is a simple syscall wrapper, so implementation should be straightforward. ### Build System In [entrypoints.txt](https://github.com/llvm/llvm-project/blob/main/libc/config/linux/x86_64/entrypoints.txt) - [ ] Add the new function to the list of entrypoints for unistd.h (you need to do this before it will build) In [unistd/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/main/libc/src/unistd/CMakeLists.txt) - [ ] Add new entrypoint objects to the list - [ ] Also add it to the list for unistd/linux/CMakeLists.txt In [linux.td](https://github.com/llvm/llvm-project/blob/main/libc/spec/linux.td) - [ ] Add the functions to the list of functions for unistd.h (this can be confusing, ask for help if you're stuck). ### Code Create `unistd/pipe2.h` - [ ] look at [dup.h](https://github.com/llvm/llvm-project/blob/main/libc/src/unistd/dup.h) for an example of how this should be laid out (copying the whole file and modifying it is fine). Create `unistd/linux/pipe2.cpp` - [ ] Again, look at look at [linux/dup.cpp](https://github.com/llvm/llvm-project/blob/main/libc/src/unistd/linux/dup.cpp) for an example. ### Testing Create `test/src/unistd/pipe2_test.cpp` - [ ] This needs to test the function succeeding and failing - [ ] This is only testing the code you wrote, so don't worry too much about testing parts of the interface that the kernel handles. Add your tests to [test/src/unistd/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/main/libc/test/src/unistd/CMakeLists.txt) - [ ] Hopefully self-explanatory
llvmbot commented 5 months ago

@llvm/issue-subscribers-libc

Author: Michael Jones (michaelrj-google)

The pipe2 is defined on linux here: https://man7.org/linux/man-pages/man2/pipe.2.html This is a simple syscall wrapper, so implementation should be straightforward. ### Build System In [entrypoints.txt](https://github.com/llvm/llvm-project/blob/main/libc/config/linux/x86_64/entrypoints.txt) - [ ] Add the new function to the list of entrypoints for unistd.h (you need to do this before it will build) In [unistd/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/main/libc/src/unistd/CMakeLists.txt) - [ ] Add new entrypoint objects to the list - [ ] Also add it to the list for unistd/linux/CMakeLists.txt In [linux.td](https://github.com/llvm/llvm-project/blob/main/libc/spec/linux.td) - [ ] Add the functions to the list of functions for unistd.h (this can be confusing, ask for help if you're stuck). ### Code Create `unistd/pipe2.h` - [ ] look at [dup.h](https://github.com/llvm/llvm-project/blob/main/libc/src/unistd/dup.h) for an example of how this should be laid out (copying the whole file and modifying it is fine). Create `unistd/linux/pipe2.cpp` - [ ] Again, look at look at [linux/dup.cpp](https://github.com/llvm/llvm-project/blob/main/libc/src/unistd/linux/dup.cpp) for an example. ### Testing Create `test/src/unistd/pipe2_test.cpp` - [ ] This needs to test the function succeeding and failing - [ ] This is only testing the code you wrote, so don't worry too much about testing parts of the interface that the kernel handles. Add your tests to [test/src/unistd/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/main/libc/test/src/unistd/CMakeLists.txt) - [ ] Hopefully self-explanatory
muffpy commented 5 months ago

Interested

muffpy commented 5 months ago

@michaelrj-google Under build system, did you mean add the function spec for pipe2 to posix.td? I don't see a header spec for unistd.h in linux.td.

michaelrj-google commented 5 months ago

I did mean to put it in linux.td since it's specifically a linux function and not in posix. If there isn't a unistd.h HeaderSpec in linux.td yet then you'll have to create a new one and add it to the list of headers at the bottom.

muffpy commented 5 months ago

@michaelrj-google Should this HeaderSpec in linux.td contain FunctionSpecs for every syscall in libc/src/unistd/ or just for pipe2?

michaelrj-google commented 5 months ago

just pipe2 is fine for the moment

muffpy commented 5 months ago

@michaelrj-google I am unable to generate the test file for pipe2_test.cpp. I have tried:

$ cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="libc"  -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
$ ninja libc_unistd_unittests

but the output does not show a test for pipe2.

Please take a look at my patch 85514.