[PATCH] D144889: [C2x] Support <string.h> in freestanding

James Y Knight via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 27 17:57:06 PST 2023


jyknight added a comment.

In D144889#4156974 <https://reviews.llvm.org/D144889#4156974>, @rsmith wrote:

> Likely because of GCC's perspective on this, the set of C headers provided by GCC, Clang, ICC, etc. has included the complete list of freestanding headers and more or less no others, with some libc implementations providing the full set and some providing just the non-freestanding ones. If we're moving away from that, we'll presumably need a new agreement between compiler folks and libc folks about which headers are provided by whom (and I expect it'll be "compilers provide what the C standard said before this change to freestanding and we pretend the change never happened").

Yeah...this seems like a pretty big divergence from the historical view compilers have for "freestanding" mode, and I think the implementation should be more along the lines of a "micro-libc", than something built into clang. Especially considering the potential future additions e.g. `errno.h`. If we look at this as a specification for what to provide in a "micro-libc", having such global state is not a major issue, but if we look at this as a "compiler builtin" sort of thing (ala traditional freestanding), then it's quite a problem.

So, I think the correct solution here is to just document what parts of a C2x-conforming "freestanding" Clang provides itself, and what remains for an external "mini-libc" implementation to provide.

It probably makes sense for one such external implementation to be provided by llvm-libc in the future -- I suspect it should have a separate "freestanding" target mode, which would omit all the runtime features like memory allocation and threads, and provide just the pure library functionality. But I'd also expect such an llvm-libc freestanding mode would also provide a lot more functionality than just the minimum requirements -- there's a whole lot more "pure library" functions in C than just the ones required in the new "freestanding" standard.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144889/new/

https://reviews.llvm.org/D144889



More information about the cfe-commits mailing list