From 92b341e50cbcecfddf154b1f6b2fcc91f54c98cb Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Sat, 14 Feb 2026 16:53:07 +0900 Subject: [PATCH] [Testing] Add support for building binutils with mingw64 --- .gitignore | 2 +- .../binutils/binutils-2.24-mingw64.patch | 51 +++++++++++++++++++ third_party/binutils/build.sh | 16 ++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 third_party/binutils/binutils-2.24-mingw64.patch diff --git a/.gitignore b/.gitignore index bfc97737a..bf5b1d98c 100644 --- a/.gitignore +++ b/.gitignore @@ -95,10 +95,10 @@ node_modules/.bin/ /attic/ /content/ /third_party/binutils/binutils-2.24.tar.gz +/third_party/binutils/binutils-2.24/ /third_party/binutils/bin/ /third_party/binutils/powerpc-none-elf/ /third_party/binutils/share/ -/third_party/binutils/binutils* /third_party/vasm/ /tools/shader-playground/*.dll /profile_print_times.py diff --git a/third_party/binutils/binutils-2.24-mingw64.patch b/third_party/binutils/binutils-2.24-mingw64.patch new file mode 100644 index 000000000..0f92f18df --- /dev/null +++ b/third_party/binutils/binutils-2.24-mingw64.patch @@ -0,0 +1,51 @@ +diff -u -P -r libiberty/strerror.c libiberty/strerror.c +--- libiberty/strerror.c 2013-11-04 07:33:39.000000000 -0800 ++++ libiberty/strerror.c 2026-02-14 00:00:00.000000000 -0800 +@@ -469,8 +469,12 @@ + + #else + ++#ifndef sys_nerr + extern int sys_nerr; ++#endif ++#ifndef sys_errlist + extern char *sys_errlist[]; ++#endif + + #endif + +diff -u -P -r libiberty/waitpid.c libiberty/waitpid.c +--- libiberty/waitpid.c 2013-11-04 07:33:39.000000000 -0800 ++++ libiberty/waitpid.c 2026-02-14 00:00:00.000000000 -0800 +@@ -24,6 +24,13 @@ + #include + #endif + ++#if defined(_WIN32) || defined(__MINGW32__) ++pid_t ++waitpid (pid_t pid, int *stat_loc, int options ATTRIBUTE_UNUSED) ++{ ++ return -1; ++} ++#else + pid_t + waitpid (pid_t pid, int *stat_loc, int options ATTRIBUTE_UNUSED) + { +@@ -33,3 +40,4 @@ + return wpid; + } + } ++#endif +diff -u -P -r intl/dcigettext.c intl/dcigettext.c +--- intl/dcigettext.c 2013-11-04 07:33:39.000000000 -0800 ++++ intl/dcigettext.c 2026-02-14 00:00:00.000000000 -0800 +@@ -148,7 +148,9 @@ + char *getwd (); + # define getcwd(buf, max) getwd (buf) + # else ++# if !defined HAVE_UNISTD_H + char *getcwd (); ++# endif + # endif + # ifndef HAVE_STPCPY + static char *stpcpy PARAMS ((char *dest, const char *src)); diff --git a/third_party/binutils/build.sh b/third_party/binutils/build.sh index 587356210..272ca33d0 100644 --- a/third_party/binutils/build.sh +++ b/third_party/binutils/build.sh @@ -37,6 +37,12 @@ echo "" echo "Patching binutils with vmx128 support..." patch -p0 < $THIS_SCRIPT_DIR/binutils-$SNAPSHOT_VERSION-vmx128.patch +if [ "$(uname -o 2>/dev/null)" = "Msys" ] && [ -n "$MINGW_PREFIX" ]; then + echo "" + echo "Patching binutils for mingw64 compatibility..." + patch -p0 < $THIS_SCRIPT_DIR/binutils-$SNAPSHOT_VERSION-mingw64.patch +fi + echo "" echo "Running ./configure..." ./configure \ @@ -58,6 +64,16 @@ echo "" echo "Running make install..." make install +if [ "$(uname -o 2>/dev/null)" = "Msys" ] && [ -n "$MINGW_PREFIX" ]; then + echo "" + echo "Copying MinGW runtime DLLs..." + for dll in libiconv-2.dll zlib1.dll; do + if [ -f "$MINGW_PREFIX/bin/$dll" ] && [ ! -f "$THIS_SCRIPT_DIR/bin/$dll" ]; then + cp "$MINGW_PREFIX/bin/$dll" "$THIS_SCRIPT_DIR/bin/" + fi + done +fi + cd .. echo ""