Hic inserere motto

Building gcc 4.9.4 with musl on Gentoo

November 05, 2019 — shinohai

Lately I have been experimenting a lot more with musl as a replacement for the continually shitty glibc. While musl was a standard part of cuntoo, it appears that particular project is mostly abandoned by it's author and I want to be more responsible for my own toolkit anyway. So starting with the most recent vanilla musl gentoo stage3, I decided getting my preferred compiler working would be first order of business. I tried the portage route with a simple `emerge -av =sys-devel/gcc-4.9.4-r1` which sang along happily for a while until hitting "configure: error: cannot run C compiled programs." and a few other errors.

After spending some time researching the errors and trying various fixes, I managed to produce a patch that will allow me to manually perform the ebuild steps and get a working gcc for musl. I used the following steps:

Download the sources:

ebuild /var/db/repos/gentoo/sys-devel/gcc/gcc-4.9.4-r1.ebuild fetch


ebuild /var/db/repos/gentoo/sys-devel/gcc/gcc-4.9.4-r1.ebuild configure

Go to the source work directory (located at /var/tmp/portage/sys-devel/gcc-4.9.4-r1/work/gcc-4.9.4) and download this patch (sig) and verify, then patch:

patch -p1 < gcc-4.9.4-musl.patch

After patching, complete the manual ebuild steps:

ebuild /var/db/repos/gentoo/sys-devel/gcc/gcc-4.9.4-r1.ebuild compile

ebuild /var/db/repos/gentoo/sys-devel/gcc/gcc-4.9.4-r1.ebuild install

ebuild /var/db/repos/gentoo/sys-devel/gcc/gcc-4.9.4-r1.ebuild merge

Enjoy your shiny new compiler.

(chroot) shinohai ~ # gcc-config -l
 [1] x86_64-gentoo-linux-musl-4.9.4 *
 [2] x86_64-gentoo-linux-musl-8.3.0

Next order of business will be trying a fellow named ave1's Ada build for musl and making a POST1 on the results, in addition to publishing the steps I used to get SBCL working in this environment as well.

1. As this post was being written, TMSR's Caesar and vassals decided to bikeshed the meaning of posts vs. articles today. I guess there was no one on the list to berate all day, so words had to suffice. It's a lulzy read, and naturally every inch of that particular cock was swallowed without hesitation.

Tags: News, Linux