Notes from the LLVM libc round table @ EuroLLVM 2024

Attendance : Google, ARM, Fuchsia, mostly from the embedded word + a few desktop people as well

For those present at the round table, feel free to add more questions or amend the notes as I’m not sure I covered it all.

Questions & Answers

  • How to package LLVM libc? Especially, how to release multilib for our IDEs?
    • We don’t release packages as part of LLVM because the library is still incomplete. That would be up to a vendor to do the release (at least for now)
  • How do we ensure conformance? Are we running Perennial, SuperTest, or PlumHall?
    • These test suites are not open source so we can’t run them as part of the build bots unfortunately.
    • There is the glibc test suite, it is not thorough but that would be a good start?
  • How do I customize XXX (malloc in this case)?
    • LLVM libc can be built in two flavors :
      • “full build” provides all the implemented functions, in the long run it will be able to replace your libc
      • “overlay” provides the functions you choose so you can use some of the LLVM libc functions on top of your current libc
    • To provide say “malloc/free” just use overlay mode without these functions and provide your own statically at link time.
  • We have a lot of dimensions to cover (endianness, pointer size, sw/hw floating point), how do we configure LLVM libc?
    • Some of the configuration comes from the target triple and are provided by the compiler, LLVM libc then uses defined preprocessor to pick the right code path
    • The rest of the configuration is provided by the user through a config file.
  • Locale, they impact quite a few functions in the libc, what’s the status on this? For the embedded word handling locale is expensive can we somewhat disable them?
    • No work has been done on locale for now
    • Flags could be added to customize the libc and “bake” locale as a compilation parameter (i.e. ANSI C locale) or disable all locale dependent functions.
  • How complete is LLVM libc? Can I use it? What’s left to be done?
    • “Complete” really depends on your use case, LLVM libc is used internally at Google and by Fuchsia.
    • The overlay mode has allowed Fuchsia to gradually replace most of their original libc by LLVM libc functions.
    • You should give it a try and see what’s missing for you, don’t hesitate to request specific functions (discourse / github issues) or contribute them to the project.
    • We maintain a list of functions on our website : e.g. Date and Time Functions — The LLVM C Library
  • We have --stdlib=libcxx for the standard library and --rtlib=compiler-rt for the runtime, how do we go about libc?
    • Yes we want to provide a flag for tight integration with the compiler but we’ll have to wait for LLVM libc to be complete before doing so. This would only be possible with the “full build” version obviously.
  • How do I build a complete cross toolchain where libc / libcxx and compiler-rt are built on top of each other?
    • The build system is constantly evolving but I don’t think we support this for now.
    • The Fuchsia team is definitely interested in this use case but there is a chicken and egg problem with libc-hdrgen for now I believ @petrhosek
  • Is crt0 part of the libc? How do we handle TLS? Can we disable it?
    • I’m not familiar with this part of the codebase but we do provide startup code.
    • As for all of LLVM libc, the behavior here could be customized through configure options.
  • How about security? For instance, x87 instructions like fldenv have security implications (loading CPU state from memory) but musl’s printf uses long double even to format single precision
    • Again I think we should be able to provide a configure option to restrict x87 usage if this makes sense. That said, we want to strike a good balance between customization, usefulness and maintainability of the options. This could also be done by having LLVM libc buildable with -mno-x87.

@nickdesaulniers @lntue @michaelrj-google

3 Likes

AFAIK, crt0 (the startup component for static linkage) is provided in libc. It is generated as a relocatable object combined from startup object (global configuration, system ABI compliance, global initialization) and TLS initialization object (stack canary and TLS object).

1 Like