musl-cross-make icon indicating copy to clipboard operation
musl-cross-make copied to clipboard

patches for building gcc on Apple Silicon

Open richard-vd opened this issue 3 years ago • 8 comments

The minimal patch by @jannau in richfelker/musl-cross-make#116 enables building gcc and running it natively on Apple Silicon. As I understand and have experienced it, the resulting gcc is not fully functional but for the purpose of cross compiling it is. Therefore I think this patch would be a good addition to this project.

This PR adds patches for all supported gcc versions from 6.5.0 and up.

richard-vd avatar Aug 08 '21 22:08 richard-vd

Can you cite anything justifying these patches? I suspect they're right but I'd like to see some rationale.

richfelker avatar Aug 10 '21 00:08 richfelker

Justification for the gcc/config/aarch64/aarch64.h change is there is no CPU detection for darwin/arm64 implemented.

I have no good justification for the host_hooks change except that seems to be done in every other host-*.c file. I'm puzzled why x86 darwin works without it and I wouldn't be surprised if the patch breaks it.

jannau avatar Aug 10 '21 07:08 jannau

I have tested the patch and it's looking good:

Using a MacBook Air M1 (Apple Silicon) and an iMac (Intel), on both machines I successfully compiled targets x86_64 and aarch64 for all gcc versions that this patch has been applied to. Then I compiled a Hello World C++ program with the resulting gcc-5.3.0 and gcc-9.2.0 and successfully ran the binaries in Linux on a Raspberry Pi 4 (aarch64) and on a Supermicro server (x86_64).

Fortunately the patch doesn't seem to break anything!

richard-vd avatar Aug 10 '21 17:08 richard-vd

Thanks for putting this together Richard.

I just tested this branch on an M1 machine. I compiled the x86_64 target, compiled my go/cgo/sqlite program using the x86_64 target output, then ran my built program on x86. Everything seems to work. 👍

johnelliott avatar Oct 30 '21 02:10 johnelliott

Added gcc-10.3.0 patch to this branch.

richard-vd avatar Dec 13 '21 15:12 richard-vd

Squashed yesterday's gcc-10.3.0 patch with the initial commit of this PR.

richard-vd avatar Dec 14 '21 14:12 richard-vd

Redone Apple silicon patches for gcc-6.5.0 .. gcc-10.3.0 using commits from gcc upstream.

richard-vd avatar Jan 23 '22 22:01 richard-vd

Added GCC 11.

richard-vd avatar May 22 '22 21:05 richard-vd