Trying to create a pure LLVM toolchain on musl based distribution

Hello David,

I don't know much about the specifics of Musl, so I'm responding generally.

As I understand it, clang expects to find the compiler-rt libraries
relative to the resource directory, which you can find out the
location of with clang --print-resource-dir . By default it is
lib/clang/9.0.0 assuming you are building from master. I think that
-DCMAKE_INSTALL_PREFIX=/usr has broken that assumption. I think that
you would either need to take out the CMAKE_INSTALL_PREFIX or change
the location of the resource directory, which I think that you can
alter at build time.

You're right, I've just checked both packages in Alpine and Arch and they indeed move the /usr/lib/linux directory under the clang's one. I've fixed that it worked, now I still have to find the solution regarding crtbeginS.so and crtendS.so.

Thanks :slight_smile:

I don't think that there is a way of preventing clang adding
crtbeginS.o and crtendS.o without --nostdlib or --nostartfiles but
using these options will also not add the other crt*.o files that you
may be expecting.

There is a line in lib/Driver/Toolchains/Gnu.cpp which the Linux driver uses:
const bool HasCRTBeginEndFiles =
       ToolChain.getTriple().hasEnvironment() ||
       (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
It looks like Musl may need to be included there?

I'll have a look, I don't know much the lowest part of the toolchain build process so I don't understand very much what's going on there. Hopefully someone that has better low-level knowledges and use musl will be able to guide me for this.

What can I tell is that musl provide those files:

usr/lib/Scrt1.o
usr/lib/crt1.o
usr/lib/crti.o
usr/lib/crtn.o
usr/lib/ld-musl-x86_64.so.1

Regards,