From 8bae8a8388e370d39b027a8f14c9dad53163f907 Mon Sep 17 00:00:00 2001 From: Damien Ciabrini Date: Sun, 3 Sep 2023 21:57:03 +0200 Subject: [PATCH] Bump gcc to 11.4 for macOS M1 support Recent M1 SoC can be supported by bumping gcc to a recent version with macOS arm support. Tweak the Makefile and compile flags to build succesfully for this new architecture. Ref dciabrin/homebrew-ngdevkit#4 --- Makefile | 61 ++++++++++-------------- patches/gcc-0001-macos-arm-silicon.patch | 55 +++++++++++++++++++++ 2 files changed, 80 insertions(+), 36 deletions(-) create mode 100644 patches/gcc-0001-macos-arm-silicon.patch diff --git a/Makefile b/Makefile index 22d73e4..b61ef08 100644 --- a/Makefile +++ b/Makefile @@ -38,9 +38,12 @@ LOCAL_PACKAGE_DIR= EXTRA_BUILD_CMD=true EXTRA_BUILD_FLAGS= +# Common tools +REALPATH=realpath + # Version of external dependencies SRC_BINUTILS=binutils-2.35.2 -SRC_GCC=gcc-5.5.0 +SRC_GCC=gcc-11.4.0 SRC_NEWLIB=newlib-4.0.0 SRC_GDB=gdb-9.2 SRC_SDCC=sdcc-src-4.2.0 @@ -49,46 +52,30 @@ TOOLCHAIN=ngbinutils nggcc ngnewlib ngsdcc nggdb # GCC: compilation flags to support all compilers / OS # -# Note: building gcc 5.x with clang 13 and gcc 11 requires -# various flags to disable new checks that are enabled by -# default and make the compilation fail due to the gcc 5.x -# codebase being rather old at this point... -# -# -Wno-narrowing: tree-object-size.c:73:65: error: narrowing conversion of ‘-1’ from ‘int’ to ‘long unsigned int’ -# -DHAVE_DESIGNATED_UNION_INITIALIZERS: recog.h:357:5: warning: macro expansion producing 'defined' has undefined behavior -# --std=c++98: diagnostic-core.h:67:13: note: candidate function not viable: no known conversion from 'source_location' (aka 'unsigned int') to 'const char *' for 1st argument -# --std=gnu++14: reload1.c:115:24: error: use of an operand of type ‘bool’ in ‘operator++’ is forbidden in C++17 -# --std=gnu++14: m68k.c:1781:7: error: ISO C++17 does not allow 'register' storage class specifier -# --std=gnu++14: build/gencondmd: Undefined symbols for architecture x86_64 -# -Wno-reserved-user-defined-literal: defaults.h:126:27: error: invalid suffix on literal; C++11 requires a space between literal and identifier +# per-file workarounds: # -DCINTERFACE: fix build issue on MSYS2/UCRT64, caused by windows.h being included after gcc/system.h # -# The other options are just there to silent warnings -# GCC_C_BUILD_FLAGS=\ -Wno-strict-prototypes -Wno-implicit-function-declaration \ --Wno-old-style-definition -Wno-missing-prototypes -Wimplicit-fallthrough=0 \ --Wno-unknown-warning-option -Wno-use-after-free +-Wno-old-style-definition -Wno-missing-prototypes \ +-Wno-unknown-warning-option -Wno-array-bounds GCC_CXX_BUILD_FLAGS=\ --Wno-narrowing \ --DHAVE_DESIGNATED_UNION_INITIALIZERS \ --Wno-reserved-user-defined-literal -GCC_CXX_BUILD_FLAGS+= \ -Wno-array-bounds -Wno-deprecated \ --Wno-format-security -Wno-string-compare -Wno-shift-negative-value \ --Wno-invalid-offsetof -Wno-ignored-attributes \ --Wno-literal-suffix -Wno-unknown-warning-option \ --Wno-enum-compare-switch -Wno-odr -Wno-address +-Wno-format-security -Wno-string-plus-int -Wno-shift-count-overflow \ +-Wno-ignored-attributes -Wno-unknown-warning-option \ +-Wno-enum-compare-switch -Wno-mismatched-tags -Wno-c++11-narrowing GCC_GMAKE_OVERRIDES= \ +--eval 'override CFLAGS-prefix.o = -DPREFIX=\"$$(prefix)\" -DBASEVER=$$(BASEVER_s) -DCINTERFACE' \ +--eval 'override CFLAGS-diagnostic-color.o = -DCINTERFACE' \ --eval 'override GCC_WARN_CFLAGS = ' \ --eval 'override GCC_WARN_CXXFLAGS = ' \ --eval 'override WARN_CFLAGS = ' \ --eval 'override WARN_CXXFLAGS = ' \ ---eval 'override CFLAGS-prefix.o = -DPREFIX=\"$$(prefix)\" -DBASEVER=$$(BASEVER_s) -DCINTERFACE' \ ---eval 'override CFLAGS-toplev.o = --std=c++98 -DTARGET_NAME=\"m68k-neogeo-elf\"' \ ---eval 'override CFLAGS-reload1.o = --std=gnu++14' \ ---eval 'override CFLAGS-m68k.o = --std=gnu++14' \ ---eval 'override CFLAGS-build/gencondmd.o = --std=gnu++14' +--eval 'override LOOSE_WARN = ' \ +--eval 'override C_LOOSE_WARN = ' \ +--eval 'override STRICT_WARN = ' \ +--eval 'override C_STRICT_WARN = ' + # GDB: compilation flags to support all compilers / OS GDB_C_BUILD_FLAGS=\ @@ -101,10 +88,13 @@ GDB_LD_BUILD_FLAGS= GDB_PKG_CONFIG_PATH= ifeq ($(shell uname -s),Darwin) -GDB_C_BUILD_FLAGS+=-I/usr/local/opt/readline/include -GDB_CXX_BUILD_FLAGS+=-I/usr/local/opt/readline/include -GDB_LD_BUILD_FLAGS+=-L/usr/local/opt/readline/lib -GDB_PKG_CONFIG_PATH+=/usr/local/opt/readline/lib/pkgconfig +HOMEBREW_PREFIX=$(shell brew --prefix) +GDB_C_BUILD_FLAGS+=-I$(HOMEBREW_PREFIX)/opt/readline/include +GDB_CXX_BUILD_FLAGS+=-I$(HOMEBREW_PREFIX)/opt/readline/include +GDB_LD_BUILD_FLAGS+=-L$(HOMEBREW_PREFIX)/opt/readline/lib +GDB_PKG_CONFIG_PATH+=$(HOMEBREW_PREFIX)/opt/readline/lib/pkgconfig + +REALPATH=grealpath endif @@ -231,7 +221,7 @@ $(BUILD)/nggcc: $(BUILD)/ngbinutils toolchain/$(SRC_GCC) --datadir=$(prefix)/m68k-neogeo-elf/lib \ --includedir=$(prefix)/m68k-neogeo-elf/include \ --bindir=$(prefix)/bin \ - --src=$$(realpath $$CURPWD/toolchain/$(SRC_GCC) --relative-to $$PWD) \ + --src=$$($(REALPATH) $$CURPWD/toolchain/$(SRC_GCC) --relative-to $$PWD) \ --with-system-zlib \ --with-cpu=m68000 \ --with-threads=single \ @@ -311,7 +301,6 @@ $(BUILD)/nggdb: toolchain/$(SRC_BINUTILS) toolchain/$(SRC_GDB) $(BUILD)/ngsdcc: toolchain/sdcc-$(SRC_SDCC:sdcc-src-%=%) @echo compiling sdcc... CURPWD=$$(pwd) && \ - unset CPPFLAGS && \ $(EXTRA_BUILD_CMD) && \ mkdir -p $(BUILD)/ngsdcc && \ cd $(BUILD)/ngsdcc && \ diff --git a/patches/gcc-0001-macos-arm-silicon.patch b/patches/gcc-0001-macos-arm-silicon.patch new file mode 100644 index 0000000..467ae95 --- /dev/null +++ b/patches/gcc-0001-macos-arm-silicon.patch @@ -0,0 +1,55 @@ +From 9c6e71079b46ad5433165feaa2001450f2017b56 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Przemys=C5=82aw=20Buczkowski?= +Date: Mon, 16 Aug 2021 13:16:21 +0100 +Subject: [PATCH] GCC: Patch for Apple Silicon compatibility + +This patch fixes a linker error occuring when compiling +the cross-compiler on macOS and ARM64 architecture. + +Adapted from: +https://github.com/richfelker/musl-cross-make/issues/116#issuecomment-823612404 + +Change-Id: Ia3ee98a163bbb62689f42e2da83a5ef36beb0913 +Reviewed-on: https://review.haiku-os.org/c/buildtools/+/4329 +Reviewed-by: John Scipione +Reviewed-by: Adrien Destugues +--- + gcc/config/aarch64/aarch64.h | 2 +- + gcc/config/host-darwin.c | 4 ++++ + 2 files changed, 5 insertions(+), 1 deletion(-) + +diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h +index 976f9afae5..736b83ff0b 100644 +--- a/gcc/config/aarch64/aarch64.h ++++ b/gcc/config/aarch64/aarch64.h +@@ -1000,7 +1000,7 @@ extern const char *aarch64_rewrite_mcpu (int argc, const char **argv); + #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 HAVE_LOCAL_CPU_DETECT + # define EXTRA_SPEC_FUNCTIONS \ +diff --git a/gcc/config/host-darwin.c b/gcc/config/host-darwin.c +index 8f700eec85..b737abc006 100644 +--- a/gcc/config/host-darwin.c ++++ b/gcc/config/host-darwin.c +@@ -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 @@ darwin_gt_pch_use_address (void *addr, size_t sz, int fd, size_t off) + + return ret; + } ++ ++const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER; +-- +2.39.2 +