Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc][posix 2001] implement fileno #85150

Closed
nickdesaulniers opened this issue Mar 13, 2024 · 6 comments · Fixed by #85628
Closed

[libc][posix 2001] implement fileno #85150

nickdesaulniers opened this issue Mar 13, 2024 · 6 comments · Fixed by #85628
Assignees
Labels
good first issue https://github.com/llvm/llvm-project/contribute libc

Comments

@nickdesaulniers
Copy link
Member

nickdesaulniers commented Mar 13, 2024

libc++ unconditionally depends on posix fileno. We should implement this in libc.

see man 3 fileno.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/fileno.html

@nickdesaulniers nickdesaulniers added good first issue https://github.com/llvm/llvm-project/contribute libc labels Mar 13, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 13, 2024

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
Copy link
Collaborator

llvmbot commented Mar 13, 2024

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

Author: Nick Desaulniers (nickdesaulniers)

libc++ depends on posix fileno. We should implement this in libc.

see man 3 fileno.

https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 13, 2024

@llvm/issue-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

libc++ depends on posix fileno. We should implement this in libc.

see man 3 fileno.

https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/

@Sh0g0-1758
Copy link
Contributor

Hey, @nickdesaulniers, I would like to work on this. Can you provide me some pointers to get started.

@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Mar 15, 2024

Hi @Sh0g0-1758 ! Thanks for your interest.

I think these are the steps you can follow to implement this:

  1. define the entrypoint in libc/config/linux/x86_64/entrypoints.txt, under the list of functions from stdio.h, I'd add an entry for libc.src.stdio.fileno. The build should now fail to configure during cmake because that target hasn't been defined anywhere yet.
  2. I'd define libc.src.stdio.fileno in libc/src/stdio/CMakeLists.txt. Perhaps using add_stdio_entrypoint_object since files on the GPU require RPC calls. The build should still fail to configure at this point.
  3. Define fileno in libc/src/stdio/generic/CMakeLists.txt. The build should fail to configure since fileno.cpp and fileno.h do not yet exist.
  4. create libc/src/stdio/generic/fileno.cpp and libc/src/stdio/fileno.h. Make sure to include the license block. At this point the build should configure and succeed.
  5. implement fileno in libc/src/stdio/generic/fileno.cpp.
  6. write tests in libc/test/src/stdio/fileop_test.cpp. ninja libc_stdio_unittests should run the suite with the newly added tests.
  7. update libc/spec/posix.td to add a FunctionSpec for fileno to the HeaderSpec for stdio.h.

Take a crack at it, and let us know if you get stuck!

@Sh0g0-1758
Copy link
Contributor

Sh0g0-1758 commented Mar 18, 2024

Hey, @nickdesaulniers, made PR with the changes. Can you please suggest changes in it, if any.

nickdesaulniers pushed a commit that referenced this issue Mar 18, 2024
chencha3 pushed a commit to chencha3/llvm-project that referenced this issue Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue https://github.com/llvm/llvm-project/contribute libc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants