This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add support for more file functions
Needs ReviewPublic

Authored by jhuber6 on Jul 27 2023, 1:17 PM.

Details

Summary

This patch adds support for more trivial file functions. This leaves out
specifically fgets. This is because as implemented this does not have
the correct behavior as it does not stop on EOF or newline since we map
it all to fread. This will probably need to be fixed somehow.

Diff Detail

Event Timeline

jhuber6 created this revision.Jul 27 2023, 1:17 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 27 2023, 1:17 PM
jhuber6 requested review of this revision.Jul 27 2023, 1:17 PM

This is because as implemented this does not have the correct behavior as it does not stop on EOF or newline since we map it all to fread.

Because the RPC maps it to fread or because the libc default impl does?

This is because as implemented this does not have the correct behavior as it does not stop on EOF or newline since we map it all to fread.

Because the RPC maps it to fread or because the libc default impl does?

Haven't tested w/ the CPU version of libc their version maps to a linux syscall which has similar semantics I think.

tianshilei1992 added inline comments.Aug 3 2023, 7:27 AM
libc/docs/gpu/support.rst
132

This two don't need RPC?

jhuber6 added inline comments.Aug 3 2023, 7:29 AM
libc/docs/gpu/support.rst
132

So that's actually a can of worms I'm not sure what the best way to handle is. These don't require RPC because the file class maintains some internal state about the result of the last action, e.g. if the last return value was negative. But, this means that calling feof on the GPU will return something different if the last call was on the CPU. However, it also means that if we didn't want that to happen we'd need everything to go through RPC with very little ability to optimize anything from the GPU side. I'm sort-of leaning towards treating this as a similar case if you were to statically link a MUSL application with a glibc one, you should kind of see them as separate and not expect them to work well when mixed.