Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

figure out how to link clang itself against musl #151

Open
nickdesaulniers opened this issue May 20, 2021 · 9 comments
Open

figure out how to link clang itself against musl #151

nickdesaulniers opened this issue May 20, 2021 · 9 comments

Comments

@nickdesaulniers
Copy link
Member

follow on to #150 , though perhaps less important. For kernel.org builds of LLVM, we should see if we can link clang itself against musl (dynamically; static linking I assume is orthogonal). @arndb had done some experiments with this (it would be good to share notes here). I've been fooling around with static linking against musl and LTO'ing in musl in here (though that's irrelevant to dynamically linking against musl; thought I'd post it somewhere so that I don't forget).

@MaskRay
Copy link
Member

MaskRay commented May 20, 2021

This is difficult to be done purely in llvm-project's CMake build system. Some musl linked external libraries are needed: libtinfo, libz, libstdc++/libc++. One will need a musl targeting toolchain to build these external libraries, then build a clang+libc++ (the built clang produces object files linking against the build musl libc++), finally re-build clang with the libc++ using clang.

musl-cross-make can build a GCC toolchain, but the author does not have extra bandwidth to support Clang.
@pattop's https://www.openwall.com/lists/musl/2021/01/11/1 may be helpful.

@kraj
Copy link

kraj commented May 20, 2021

we do cross build clang in Yocto/OE world to run on musl targets, I wonder if same clang can be targeted at x86_64 and used

@pattop
Copy link

pattop commented May 20, 2021

The current state of my musl-cross-make clang support is here https://github.com/apexrtos/musl-cross-make/tree/clang. It includes some patches for my embedded work, but the native x86_64 toolchain should be fully functional.

make COMPILER=clang
make COMPILER=clang OUTPUT=/tmp/musl-clang install

should be all you need to do to get a working musl-clang toolchain with some arm targets and x86_64. I've never tried to build clang with this though.

@MaskRay if you have time it would be great if you could review my build process & patches. Ideally it would be merged into musl-cross-make upstream but that doesn't look to be possible at the moment. There's enough complexity here that I think it's worth having one recipe for people to use.

@nickdesaulniers
Copy link
Member Author

@compnerd has something hacked up that seems to be working:
https://gist.github.com/compnerd/ebbc625a359d1d3e292e1fd2007ecb52

@nickdesaulniers
Copy link
Member Author

I'm working through trying to get this working in https://github.com/ClangBuiltLinux/llvm-musl-bootstrap/pull/1/files.

@Ericson2314
Copy link

What @sternenseemann did in #150 (comment) using Musl, so we have static linking and musl link both working.

@dzbarsky
Copy link

@nickdesaulniers you might be interested in https://github.com/dzbarsky/static-clang/ (Also, hi, long time no see!)

@nickdesaulniers
Copy link
Member Author

yo @dzbarsky I bookmarked that shit yesterday

@dzbarsky
Copy link

Nice, I fixed/cleaned up a few things and tagged a 17.0.1 release. It works for my purposes but if you see something off, let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants