Sysroot for LLVM libc

I wanted to build a sysroot for testing out the LLVM libc changes, and it looks like targeting x86_64-linux-llvm started to be added in 7672216 but wasn’t completed. There have been a couple of threads on here where people wanted the same thing so I figured I may as well take a stab at it.

I’ve got a tentative patch (not cleaned up for submitting at all yet and is just brute-forcing the config!) that does a few things:

  1. Recognises the -llvm environment as a target

  2. Defaults to compiler-rt

  3. Defaults to -static

  4. Forces crt1.o since we don’t provide any of the variants.

“Hello world” builds locally for me when pointed at a sysroot that I’ve built with a targeted clang, lld, libc, compiler-rt and the Linux headers installed.

Does this sound like a good approach? I know this will change over time as we add dynamic linking (etc), but it seems like it’s worth having in for now. If yes, I’ll do this up properly and add documentation on how to use it to the website.

Yeah that’s something I never got around to. Can’t decide if we should just make it a separate Toolchain or we should just make it modified GNU. The multi-arch triple support is probably for compatibility with GNU names, because everything in LLVM libc is already at lib/x86_64-unknown-linux-llvm for example. I think the baremetal toolchain shows the expected way to set up the include / library files. @MaskRay should we make this an entirely separate toolchain?

Gnu.cpp currently contains code for Android, uclibc, and musl, which was why I just edited here.

If doing this as a separate toolchain makes sense, I suspect the various MIPS and RISC ABI detection stuff should be factored out for reuse. That’s a bigger cleanup (and probably a wider RFC) that I don’t mind doing as long as we’re not in a rush. =)

I thinking modifying Gnu.cpp and Linux.cpp is acceptable. Most changes in these files are related to include/library search paths and linker options, which will be shared with *-linux-llvm triples.

Thanks, @MaskRay !

@jhuber6 I’m out this coming week (and was out last week), but I’ll finish cleaning this up and getting it ready. Are you OK being a reviewer for it these (I think there will also be patches to compiler-rt to install things to system locations for linux-llvm as well)

In the meantime if anyone is following along, here’s the branch. I added a sysroot.md file under docs/ that’s still just a sketch and don’t quite work, but if you’ve built a sysroot before it’ll generally get you most of the way there.

More in a few weeks!

1 Like