Monthly LLVM libc meeting

Notes from today’s meeting:

  • Clang pretty much builds against LLVM-libc

    • Status:

      • Total Discovered Tests: 56775

      • Skipped : 46 (0.08%)

      • Unsupported : 5249 (9.25%)

      • Passed : 51448 (90.62%)

      • Expectedly Failed: 26 (0.05%)

      • Failed : 6 (0.01%)

    • llvm-strings is now a blocking failure, so check-clang doesn’t work

    • Needed:

      • erf

      • libc++ config with exceptions on

      • nl_langinfo (in progress) completed

      • mbrtoc32 and c32rtomb

      • Fix for PR51712-large-array-constexpr-check-oom.cpp

  • Docs update

    • Adding a security.md

      • Jeff proposes saying that LLVM-libc is prerelease right now, we aren’t going to track CVEs or security vulnerabilities explicitly right now

      • Victor: Will ask Peter Smith to confirm

      • Roland: Fuchsia is using it in production, but aren’t assuming that the code is perfect

    • Mike: has been watching LLVM-libc for a while, waiting for shared libraries

      • Used Claude to see how much is required to get a full LLVM-libc system

      • Wants to upstream the work, it’s like 650 commits

        • Includes a linker
      • Need to figure out where to draw the line between fixing code that shouldn’t use glibc-isms vs adding code to LLVM-libc

      • Jeff: Suggests meeting 1:1 since they’re closer in timezone.

      • Also been working on trying to replace bionic on android with LLVM-libc as an aarch64 system

      • Roland: There’s no one good answer on “should we follow another libc”.

        • Adding gnu extensions to existing functions gets complicated.

        • Suggestion: Classify the changes into something that’s more or less standardized.

      • Mike: also been looking into LTOing the libc, trying to fix that

      • Sriram: From the libc side what are the plans for libm? Specifically around LTO for libm on embedded.

      • Paul: LTO should work from the libc side, except for the malloc stuff that’s waiting on the providence checker.

      • Sriram: How will we handle libc functions that the compiler can emit its own calls to?

        • Paul: There’s work ongoing to improve the compiler’s libcall handling. There are a couple known blockers.
      • If there are math LTO issues then CC Paul.

    • For improving review capacity:

      • Michael’s been considering trying to do some sort of lesson on how to do code review, probably start with maintainers.
  • UTF-16 wchar

    • Bowen has been working on adding UTF-16 support

    • The mbrtowc and wcrtomb will probably need some intentional non-conformance since the standard expects wchar to be a single character.

    • The problem is that the standard expects a single wchar to represent the whole character, but for UTF-16 a wchar may be one or two characters.

    • Roland: Suggests matching either the standard or what existing “wchar as UTF-16” systems have done

    • Bowen: The most common wchar as UTF-16 system is windows, their functions replace the wchar with 0xFFFD when it should be two characters, mingw generally defers to the windows conversion, cygwin reads 3 UTF-8 characters and writes one UTF-16 then reads the last UTF-8 and writes one UTF-16.

    • Roland: Given that mingw and cygwin don’t match windows implies there is design space here, people may not like the windows API. Ideally we should try targeting those systems.

    • Muhammad: Maybe mingw and cygwin were trying for a more unix-like API on windows.

  • LIBC_INLINE

    • Roland was the original reason for the LIBC_INLINE macro, the reason for it was trying to control linkage with COMDAT. That was trying to avoid doing “hermetic partial links”, but that’s been done now.

    • For Fuchsia, LIBC_INLINE isn’t necessary anymore, we can clean this up as required for all functions in headers.

    • Alex: Are there pointers for why LIBC_INLINE was necessary for classes vs out of line functions?

      • Roland: The relevant C++ standard piece is Vague Linkage, implemented via COMDAT. Things in a class have vague linkage by default.
    • Tue: Can we clarify when we need inline for inside a class?

      • Roland: If a function is inside the class definition it doesn’t matter.
  • config.json

    • See: Fuchsia (public)

    • Roland has been looking into formalizing config.json and similar

    • Would need to change a bunch of cmake flags, would this break people?

    • How would this be most reviewable?

    • Also are people particularly attached to the current spelling?

    • Tue: One option may be deprecate the old spelling in one release while adding the new spelling, then remove the old spelling in the next release.

    • Roland: That sounds like a reasonable transition plan, would also like to clean up things that are currently just cmake flags and don’t have config.json options.

    • Petr: Sounds like a good plan.

    • Roland: Open question around having formulaic individual option names, or alternately have an option for providing your own json.

      • There’s an existing option to provide your own full config.

      • Would it be useful to have that as the only option or should we also let people set cmake flags to tweak their config.

  • File redesign

    • Petr has been looking into refactoring FILE*, would like to redo how FILE* is set up on baremetal.

    • Ideally unify FILE* on linux, baremetal, and GPU.

    • Petr’s been working through prototypes to figure out how FILE* should be set up, finally has something that seems like a good solution.

      • The proposed solution shrinks the FILE struct from 128 to 96 bytes, also avoids pointer indirection in the common path.

      • This implementation uses CRTP and some static RTTI in the LLVM style.

    • Need to figure out if this is ready for review.

    • [libc] Parametrize File with a backend · petrhosek/llvm-project@16a4f0f · GitHub

      • Michael: Yeah this looks good to go for review, it addresses my concerns around popen, fopencookie, etc.

      • Also avoids function pointers on linux when not using fopencookie.

    • Followup PR will hopefully clean up baremetal and GPU.

There’s at least one more known blocker around speculative loads (if enabled) for functions like strlen, at least if one allows inlining as well (which is mostly disabled due to the no_builtins attributes most builds add). Inlining a function that does speculative loads currently will result in the compiler detecting UB if we do read outside of the object and optimizing as such. I have PRs up to expose llvm.speculative.load through clang ( [Clang] Implement __builtin_speculative_load by boomanaiden154 · Pull Request #242576 · llvm/llvm-project · GitHub , and [Clang] Add clang::oracle_function attribute by boomanaiden154 · Pull Request #242484 · llvm/llvm-project · GitHub ) that will allow for an implementation that fixes this (assuming we can get it to optimize as well).