From eef86b0edfa3b068888f0e4ad8b8e0f6491aafe3 Mon Sep 17 00:00:00 2001 From: AltoXorg <56553686+Alto1772@users.noreply.github.com> Date: Sat, 28 Dec 2024 04:29:55 +0800 Subject: [PATCH] Mac support (#5) * Set gcc-11 in mac builds * Revert "Revert "Hopefully add Mac support"" This reverts commit 72a67a01ff1b56fe3a1016fdce4dabf532ad9992. * matrix.TARGET.HOST_GCC * -Wno-implicit-int * forgot the ld * revert CFLAGS in ./configure * review * patch Co-authored-by: cadmic * Use macos-14 to build due to the other one no longer being accepted by gha * gcc-13 * macos-13 --------- Co-authored-by: angie Co-authored-by: cadmic --- .github/workflows/build.yml | 22 ++++++++++++---------- config.sub | 2 +- ld/ldlex.l | 10 ++++++++-- libiberty/strerror.c | 6 ++++++ 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d2d9041..b400258 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: Build -on: [push] +on: [push, pull_request] jobs: build: @@ -13,18 +13,20 @@ jobs: OS: 'ubuntu-20.04', CFLAGS: '-static -fno-stack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0', HOST: 'i386-pc-linux', - ARCHIVE_NAME: 'mips-binutils-egcs-2.9.5-linux.tar.gz' + ARCHIVE_NAME: 'mips-binutils-egcs-2.9.5-linux.tar.gz', + HOST_GCC: 'gcc' + } + - { + OS: 'macos-13', + CFLAGS: '-DDARWIN -Wno-implicit-int -Wno-return-type -Wno-error -Wno-implicit-function-declaration -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0', + HOST: 'i386-apple-darwin', + ARCHIVE_NAME: 'mips-binutils-egcs-2.9.5-mac.tar.gz', + HOST_GCC: 'gcc-13' } - # - { - # OS: 'macos-latest', - # CFLAGS: '-DDARWIN -Wno-return-type -Wno-error -Wno-implicit-function-declaration -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0', - # HOST: 'i386-apple-darwin', - # ARCHIVE_NAME: 'mips-binutils-egcs-2.9.5-mac.tar.gz' - # } name: Building binutils for ${{ matrix.TARGET.OS }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install dependencies (Ubuntu) shell: bash @@ -35,7 +37,7 @@ jobs: - name: Configure for mips shell: bash run: | - ./configure --target=mips-linux --prefix=/opt/cross --disable-gprof --disable-gdb --disable-werror --host=${{ matrix.TARGET.HOST }} --build=${{ matrix.TARGET.HOST }} + CC="${{ matrix.TARGET.HOST_GCC }}" CFLAGS="-Wno-implicit-int" ./configure --target=mips-linux --prefix=/opt/cross --disable-gprof --disable-gdb --disable-werror --host=${{ matrix.TARGET.HOST }} --build=${{ matrix.TARGET.HOST }} - name: Make shell: bash diff --git a/config.sub b/config.sub index f0f2e99..72b4523 100755 --- a/config.sub +++ b/config.sub @@ -905,7 +905,7 @@ case $os in | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ - | -interix* | -uwin* | -rhapsody* | -openstep* | -oskit*) + | -interix* | -uwin* | -rhapsody* | -openstep* | -oskit*| -darwin*) # Remember, each alternative MUST END IN *, to match a version number. ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ diff --git a/ld/ldlex.l b/ld/ldlex.l index 561b8af..173ba62 100644 --- a/ld/ldlex.l +++ b/ld/ldlex.l @@ -76,9 +76,15 @@ static unsigned int lineno_stack[MAX_INCLUDE_DEPTH]; static unsigned int include_stack_ptr = 0; static int vers_node_nesting = 0; +#ifdef DARWIN +#define YY_SIZE_T yy_size_t +#else +#define YY_SIZE_T int +#endif + static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string, size_t size)); -static void yy_input PARAMS ((char *, int *result, int max_size)); +static void yy_input PARAMS ((char *, YY_SIZE_T *result, int max_size)); static void comment PARAMS ((void)); static void lex_warn_invalid PARAMS ((char *where, char *what)); @@ -581,7 +587,7 @@ ldlex_popstate () static void yy_input (buf, result, max_size) char *buf; - int *result; + YY_SIZE_T *result; int max_size; { *result = 0; diff --git a/libiberty/strerror.c b/libiberty/strerror.c index 644cc75..bd0f892 100644 --- a/libiberty/strerror.c +++ b/libiberty/strerror.c @@ -460,6 +460,12 @@ static int num_error_names = 0; static int sys_nerr; static const char **sys_errlist; +#elif defined(DARWIN) + +// macOS added 'const' to these declarations, and clang complains if they are otherwise +extern const int sys_nerr; +extern const char *sys_errlist[]; + #else extern int sys_nerr;