ps3dev / ps3toolchain

A script to autobuild an open source toolchain for the PS3.
BSD 2-Clause "Simplified" License
280 stars 92 forks source link

Building the ps3 toolchain on Apple M1 (arm64) #114

Open bucanero opened 2 years ago

bucanero commented 2 years ago

I just got a new laptop (with Apple's M1 chip) and I had to rebuild the toolchain from scratch.

Good news: the PS3 toolchain and PSL1GHT SDK can be rebuilt on arm64 arch. But... patches and fixes must be done here & there to compile. 😅

For the toolchain:

I had to fix gcc-7.2.0 with this patch 0023-apple-silicon.diff: https://github.com/richfelker/musl-cross-make/pull/129/files

diff -ru a/gcc/config/host-darwin.c b/gcc/config/host-darwin.c
--- a/gcc/config/host-darwin.c 2021-05-14 10:42:08.000000000 +0200
+++ b/gcc/config/host-darwin.c 2021-08-07 22:51:11.000000000 +0200
@@ -22,6 +22,8 @@
 #include "coretypes.h"
 #include "diagnostic-core.h"
 #include "config/host-darwin.h"
+#include "hosthooks.h"
+#include "hosthooks-def.h"
 /* Yes, this is really supposed to work.  */
 static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096)));
@@ -75,3 +77,5 @@
   return ret;
 }
+
+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
diff -ru a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
--- a/gcc/config/aarch64/aarch64.h  2018-02-01 22:09:06.000000000 +0100
+++ b/gcc/config/aarch64/aarch64.h  2021-08-10 00:50:52.000000000 +0200
@@ -930,7 +930,7 @@
 #define MCPU_TO_MARCH_SPEC_FUNCTIONS \
   { "rewrite_mcpu", aarch64_rewrite_mcpu },
-#if defined(__aarch64__)
+#if defined(__aarch64__) && ! defined(__APPLE__)
 extern const char *host_detect_local_cpu (int argc, const char **argv);
 # define EXTRA_SPEC_FUNCTIONS                  \
   { "local_cpu_detect", host_detect_local_cpu },        \

I also had to fix gdb-7.5.1 too, adding #include <sys/ioctl.h> in two files, as shown in #103

bucanero commented 2 years ago

Related to this topic, I have submitted a couple of PRs to fix some library path issues: