Experimental musl Port for FreeBSD

From: ShengYi Hung <aokblast_at_FreeBSD.org>
Date: Sat, 25 Jul 2026 17:31:05 UTC
Hi all FreeBSD hackers,

Since Claude reset my token quota last week and I couldn't use all of 
it, I decided to spend some time on an interesting side project: porting 
musl to FreeBSD.

The repository is available here:
https://github.com/aokblast/musl-freebsd

At the moment it only supports x86_64, and about 96% of the musl libc 
test suite passes. This includes support for the thread library, 
TLS, getauxval, and dlopen.

This is not intended for upstream. The implementation is fairly hacky, 
and musl upstream does not accept AI-generated code. It is simply an 
experimental side project, but I think it is still interesting to have a 
working musl port on FreeBSD for experimentation.

To build musl, run:

|./configure \ CC=clang \ AR=llvm-ar \ RANLIB=llvm-ranlib \ 
--target=x86_64-portbld-freebsd16.0 \ --prefix={your install prefix} \ 
--syslibdir={your install prefix}/syslib |

For example, I use |/opt/musl| as the installation prefix.

I also wrote a compiler wrapper that makes it easier to build programs 
against musl:
https://gist.github.com/aokblast/cd7d1f4339604e651492e8bf49e3d028

It currently uses musl's CRT together with the system-provided 
compiler-rt. Note that libpthread, libm, libdl, and several other C 
libraries are only stub libraries in musl and the real implementations 
are inside libc itself, so you do not need to pass additional linker 
flags for them.

Feedback and testing are welcome.