aboutsummaryrefslogtreecommitdiffstats
path: root/musl/patches-in-mcm/gcc-13.2.0
diff options
context:
space:
mode:
Diffstat (limited to 'musl/patches-in-mcm/gcc-13.2.0')
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0000-nostdinc.diff26
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0001-posix_memalign.patch42
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0002-gcc-poison-system-directories.patch203
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0003-specs-turn-on-Wl-z-now-by-default.patch44
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0004-static-pie.diff89
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch272
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0005-m68k-sqrt.diff20
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0006-Enable-Wformat-and-Wformat-security-by-default.patch34
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0007-Enable-Wtrampolines-by-default.patch25
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch53
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch54
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch28
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0011-libiberty-copy-PIC-objects-during-build-process.patch24
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0012-libgcc_s.patch57
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0013-nopie.patch75
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch24
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0019-aarch64-disable-multilib-support.patch26
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0020-s390x-disable-multilib-support.patch25
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0021-ppc64-le-disable-multilib-support.patch81
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0022-x86_64-disable-multilib-support.patch26
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0023-riscv-disable-multilib-support.patch76
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0024-always-build-libgcc_eh.a.patch51
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch256
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0028-configure-fix-detection-of-atomic-builtins-in-libato.patch57
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch27
-rw-r--r--musl/patches-in-mcm/gcc-13.2.0/0035-Fix-ICE-observed-in-PR110280.patch61
26 files changed, 1756 insertions, 0 deletions
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0000-nostdinc.diff b/musl/patches-in-mcm/gcc-13.2.0/0000-nostdinc.diff
new file mode 100644
index 0000000..f1ec338
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0000-nostdinc.diff
@@ -0,0 +1,26 @@
+diff --git a/configure b/configure
+index 6157a8c87fb..2a4a05b4edf 100755
+--- a/configure
++++ b/configure
+@@ -16653,7 +16653,7 @@ else
+ fi
+
+
+-RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET"
++RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET -nostdinc++"
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking where to find the target ar" >&5
+ $as_echo_n "checking where to find the target ar... " >&6; }
+diff --git a/configure.ac b/configure.ac
+index 2ff48941754..01ecc8c42d9 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -3515,7 +3515,7 @@ ACX_CHECK_INSTALLED_TARGET_TOOL(STRIP_FOR_TARGET, strip)
+ ACX_CHECK_INSTALLED_TARGET_TOOL(WINDRES_FOR_TARGET, windres)
+ ACX_CHECK_INSTALLED_TARGET_TOOL(WINDMC_FOR_TARGET, windmc)
+
+-RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET"
++RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET -nostdinc++"
+
+ GCC_TARGET_TOOL(ar, AR_FOR_TARGET, AR, [binutils/ar])
+ GCC_TARGET_TOOL(as, AS_FOR_TARGET, AS, [gas/as-new])
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0001-posix_memalign.patch b/musl/patches-in-mcm/gcc-13.2.0/0001-posix_memalign.patch
new file mode 100644
index 0000000..04240c2
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0001-posix_memalign.patch
@@ -0,0 +1,42 @@
+From 47b4bd4deb2c356bb07d2a96f22127aefafec3a4 Mon Sep 17 00:00:00 2001
+From: Szabolcs Nagy <nsz@port70.net>
+Date: Fri, 26 Jan 2018 20:32:50 +0000
+Subject: [PATCH 01/35] posix_memalign
+
+---
+ gcc/config/i386/pmm_malloc.h | 9 +++++----
+ 1 file changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h
+index 3527283693b..c4071b64b53 100644
+--- a/gcc/config/i386/pmm_malloc.h
++++ b/gcc/config/i386/pmm_malloc.h
+@@ -27,12 +27,13 @@
+ #include <stdlib.h>
+
+ /* We can't depend on <stdlib.h> since the prototype of posix_memalign
+- may not be visible. */
++ may not be visible and we can't pollute the namespace either. */
+ #ifndef __cplusplus
+-extern int posix_memalign (void **, size_t, size_t);
++extern int _mm_posix_memalign (void **, size_t, size_t)
+ #else
+-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
++extern "C" int _mm_posix_memalign (void **, size_t, size_t) throw ()
+ #endif
++__asm__("posix_memalign");
+
+ static __inline void *
+ _mm_malloc (size_t __size, size_t __alignment)
+@@ -42,7 +43,7 @@ _mm_malloc (size_t __size, size_t __alignment)
+ return malloc (__size);
+ if (__alignment == 2 || (sizeof (void *) == 8 && __alignment == 4))
+ __alignment = sizeof (void *);
+- if (posix_memalign (&__ptr, __alignment, __size) == 0)
++ if (_mm_posix_memalign (&__ptr, __alignment, __size) == 0)
+ return __ptr;
+ else
+ return NULL;
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0002-gcc-poison-system-directories.patch b/musl/patches-in-mcm/gcc-13.2.0/0002-gcc-poison-system-directories.patch
new file mode 100644
index 0000000..b14c921
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0002-gcc-poison-system-directories.patch
@@ -0,0 +1,203 @@
+From 4fa620d8c3e6730211bfb071eb4c817320491bd0 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Fri, 29 Mar 2013 08:59:00 +0400
+Subject: [PATCH 02/35] gcc: poison-system-directories
+
+Add /sw/include and /opt/include based on the original
+zecke-no-host-includes.patch patch. The original patch checked for
+/usr/include, /sw/include and /opt/include and then triggered a failure and
+aborted.
+
+Instead, we add the two missing items to the current scan. If the user
+wants this to be a failure, they can add "-Werror=poison-system-directories".
+
+Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+
+Upstream-Status: Pending
+---
+ gcc/common.opt | 4 ++++
+ gcc/config.in | 6 ++++++
+ gcc/configure | 16 ++++++++++++++++
+ gcc/configure.ac | 10 ++++++++++
+ gcc/doc/invoke.texi | 9 +++++++++
+ gcc/gcc.cc | 2 ++
+ gcc/incpath.cc | 21 +++++++++++++++++++++
+ 7 files changed, 68 insertions(+)
+
+diff --git a/gcc/common.opt b/gcc/common.opt
+index 862c474d3c8..64c4277c991 100644
+--- a/gcc/common.opt
++++ b/gcc/common.opt
+@@ -711,6 +711,10 @@ Wreturn-local-addr
+ Common Var(warn_return_local_addr) Init(1) Warning
+ Warn about returning a pointer/reference to a local or temporary variable.
+
++Wpoison-system-directories
++Common Var(flag_poison_system_directories) Init(1) Warning
++Warn for -I and -L options using system directories if cross compiling
++
+ Wshadow
+ Common Var(warn_shadow) Warning
+ Warn when one variable shadows another. Same as -Wshadow=global.
+diff --git a/gcc/config.in b/gcc/config.in
+index 4cad077bfbe..0679fbbf4c6 100644
+--- a/gcc/config.in
++++ b/gcc/config.in
+@@ -236,6 +236,12 @@
+ #endif
+
+
++/* Define to warn for use of native system header directories */
++#ifndef USED_FOR_TARGET
++#undef ENABLE_POISON_SYSTEM_DIRECTORIES
++#endif
++
++
+ /* Define if you want all operations on RTL (the basic data structure of the
+ optimizer and back end) to be checked for dynamic type safety at runtime.
+ This is quite expensive. */
+diff --git a/gcc/configure b/gcc/configure
+index c7b26d1927d..8c46369f73f 100755
+--- a/gcc/configure
++++ b/gcc/configure
+@@ -1026,6 +1026,7 @@ enable_maintainer_mode
+ enable_link_mutex
+ enable_link_serialization
+ enable_version_specific_runtime_libs
++enable_poison_system_directories
+ enable_plugin
+ enable_host_shared
+ enable_libquadmath_support
+@@ -1788,6 +1789,8 @@ Optional Features:
+ --enable-version-specific-runtime-libs
+ specify that runtime libraries should be installed
+ in a compiler-specific directory
++ --enable-poison-system-directories
++ warn for use of native system header directories
+ --enable-plugin enable plugin support
+ --enable-host-shared build host code as shared libraries
+ --disable-libquadmath-support
+@@ -31753,6 +31756,19 @@ if test "${enable_version_specific_runtime_libs+set}" = set; then :
+ fi
+
+
++# Check whether --enable-poison-system-directories was given.
++if test "${enable_poison_system_directories+set}" = set; then :
++ enableval=$enable_poison_system_directories;
++else
++ enable_poison_system_directories=no
++fi
++
++if test "x${enable_poison_system_directories}" = "xyes"; then
++
++$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
++
++fi
++
+ # Substitute configuration variables
+
+
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index 09082e8ccae..5504bf6eb01 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -7292,6 +7292,16 @@ AC_ARG_ENABLE(version-specific-runtime-libs,
+ [specify that runtime libraries should be
+ installed in a compiler-specific directory])])
+
++AC_ARG_ENABLE([poison-system-directories],
++ AS_HELP_STRING([--enable-poison-system-directories],
++ [warn for use of native system header directories]),,
++ [enable_poison_system_directories=no])
++if test "x${enable_poison_system_directories}" = "xyes"; then
++ AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES],
++ [1],
++ [Define to warn for use of native system header directories])
++fi
++
+ # Substitute configuration variables
+ AC_SUBST(subdirs)
+ AC_SUBST(srcdir)
+diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
+index af0e5933fdb..b6731a4673c 100644
+--- a/gcc/doc/invoke.texi
++++ b/gcc/doc/invoke.texi
+@@ -384,6 +384,7 @@ Objective-C and Objective-C++ Dialects}.
+ -Wpacked -Wno-packed-bitfield-compat -Wpacked-not-aligned -Wpadded
+ -Wparentheses -Wno-pedantic-ms-format
+ -Wpointer-arith -Wno-pointer-compare -Wno-pointer-to-int-cast
++-Wno-poison-system-directories
+ -Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls
+ -Wrestrict -Wno-return-local-addr -Wreturn-type
+ -Wno-scalar-storage-order -Wsequence-point
+@@ -8426,6 +8427,14 @@ made up of data only and thus requires no special treatment. But, for
+ most targets, it is made up of code and thus requires the stack to be
+ made executable in order for the program to work properly.
+
++@opindex Wno-poison-system-directories
++@item -Wno-poison-system-directories
++Do not warn for @option{-I} or @option{-L} options using system
++directories such as @file{/usr/include} when cross compiling. This
++option is intended for use in chroot environments when such
++directories contain the correct headers and libraries for the target
++system rather than the host.
++
+ @opindex Wfloat-equal
+ @opindex Wno-float-equal
+ @item -Wfloat-equal
+diff --git a/gcc/gcc.cc b/gcc/gcc.cc
+index 16bb07f2cdc..33b56e721d2 100644
+--- a/gcc/gcc.cc
++++ b/gcc/gcc.cc
+@@ -1146,6 +1146,8 @@ proper position among the other output files. */
+ "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
+ "%X %{o*} %{e*} %{N} %{n} %{r}\
+ %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
++ %{Wno-poison-system-directories:--no-poison-system-directories} \
++ %{Werror=poison-system-directories:--error-poison-system-directories} \
+ %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
+ VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \
+ %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
+diff --git a/gcc/incpath.cc b/gcc/incpath.cc
+index 4d44321183f..0f3f071b44c 100644
+--- a/gcc/incpath.cc
++++ b/gcc/incpath.cc
+@@ -26,6 +26,7 @@
+ #include "intl.h"
+ #include "incpath.h"
+ #include "cppdefault.h"
++#include "diagnostic-core.h"
+
+ /* Microsoft Windows does not natively support inodes.
+ VMS has non-numeric inodes. */
+@@ -399,6 +400,26 @@ merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose)
+ }
+ fprintf (stderr, _("End of search list.\n"));
+ }
++
++#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
++ if (flag_poison_system_directories)
++ {
++ struct cpp_dir *p;
++
++ for (p = heads[INC_QUOTE]; p; p = p->next)
++ {
++ if ((!strncmp (p->name, "/usr/include", 12))
++ || (!strncmp (p->name, "/usr/local/include", 18))
++ || (!strncmp (p->name, "/usr/X11R6/include", 18))
++ || (!strncmp (p->name, "/sw/include", 11))
++ || (!strncmp (p->name, "/opt/include", 12)))
++ warning (OPT_Wpoison_system_directories,
++ "include location \"%s\" is unsafe for "
++ "cross-compilation",
++ p->name);
++ }
++ }
++#endif
+ }
+
+ /* Use given -I paths for #include "..." but not #include <...>, and
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0003-specs-turn-on-Wl-z-now-by-default.patch b/musl/patches-in-mcm/gcc-13.2.0/0003-specs-turn-on-Wl-z-now-by-default.patch
new file mode 100644
index 0000000..bfb0a6e
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0003-specs-turn-on-Wl-z-now-by-default.patch
@@ -0,0 +1,44 @@
+From ff4dd4ce33133e675b7bedc86b73357c04631cb9 Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:45:49 +0000
+Subject: [PATCH 03/35] specs: turn on -Wl,-z,now by default
+
+Previously, we also used to turn on -z relro here, but we now build
+binutils with --enable-relro, which is functionally equivalent.
+
+Binutils does not appear to have a similar option for enabling -z
+now by default.
+---
+ gcc/doc/invoke.texi | 3 +++
+ gcc/gcc.cc | 1 +
+ 2 files changed, 4 insertions(+)
+
+diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
+index b6731a4673c..f393c7846c6 100644
+--- a/gcc/doc/invoke.texi
++++ b/gcc/doc/invoke.texi
+@@ -17961,6 +17961,9 @@ For example, @option{-Wl,-Map,output.map} passes @option{-Map output.map} to the
+ linker. When using the GNU linker, you can also get the same effect with
+ @option{-Wl,-Map=output.map}.
+
++NOTE: In Alpine Linux, for LDFLAGS, the option
++@option{-Wl,-z,now} is used. To disable, use @option{-Wl,-z,nonow}.
++
+ @opindex u
+ @item -u @var{symbol}
+ Pretend the symbol @var{symbol} is undefined, to force linking of
+diff --git a/gcc/gcc.cc b/gcc/gcc.cc
+index 33b56e721d2..f82fae23c22 100644
+--- a/gcc/gcc.cc
++++ b/gcc/gcc.cc
+@@ -1144,6 +1144,7 @@ proper position among the other output files. */
+ "%{flto|flto=*:%<fcompare-debug*} \
+ %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
+ "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
++ "-z now " \
+ "%X %{o*} %{e*} %{N} %{n} %{r}\
+ %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
+ %{Wno-poison-system-directories:--no-poison-system-directories} \
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0004-static-pie.diff b/musl/patches-in-mcm/gcc-13.2.0/0004-static-pie.diff
new file mode 100644
index 0000000..9073217
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0004-static-pie.diff
@@ -0,0 +1,89 @@
+diff -rNU3 gcc-13.2.0.old/gcc/common.opt gcc-13.2.0/gcc/common.opt
+--- gcc-13.2.0.old/gcc/common.opt 2023-07-27 08:13:04.000000000 +0000
++++ gcc-13.2.0/gcc/common.opt 2023-08-30 18:18:22.940099965 +0000
+@@ -3669,11 +3669,11 @@
+
+ no-pie
+ Driver RejectNegative Negative(shared)
+-Don't create a dynamically linked position independent executable.
++Don't create a position independent executable.
+
+ pie
+ Driver RejectNegative Negative(no-pie)
+-Create a dynamically linked position independent executable.
++Create a position independent executable.
+
+ static-pie
+ Driver RejectNegative Negative(pie)
+diff -rNU3 gcc-13.2.0.old/gcc/config/gnu-user.h gcc-13.2.0/gcc/config/gnu-user.h
+--- gcc-13.2.0.old/gcc/config/gnu-user.h 2023-07-27 08:13:04.000000000 +0000
++++ gcc-13.2.0/gcc/config/gnu-user.h 2023-08-30 18:15:07.990098698 +0000
+@@ -51,13 +51,12 @@
+ #define GNU_USER_TARGET_STARTFILE_SPEC \
+ "%{shared:; \
+ pg|p|profile:%{static-pie:grcrt1.o%s;:gcrt1.o%s}; \
+- static:crt1.o%s; \
+- static-pie:rcrt1.o%s; \
++ static|static-pie:%{" PIE_SPEC ":rcrt1.o%s;:crt1.o%s}; \
+ " PIE_SPEC ":Scrt1.o%s; \
+ :crt1.o%s} " \
+ GNU_USER_TARGET_CRTI " \
+- %{static:crtbeginT.o%s; \
+- shared|static-pie|" PIE_SPEC ":crtbeginS.o%s; \
++ %{shared|" PIE_SPEC ":crtbeginS.o%s; \
++ static:crtbeginT.o%s; \
+ :crtbegin.o%s} \
+ %{fvtable-verify=none:%s; \
+ fvtable-verify=preinit:vtv_start_preinit.o%s; \
+@@ -73,11 +72,11 @@
+ GNU userspace "finalizer" file, `crtn.o'. */
+
+ #define GNU_USER_TARGET_ENDFILE_SPEC \
+- "%{!static:%{fvtable-verify=none:%s; \
++ "%{static|static-pie:; \
++ fvtable-verify=none:%s; \
+ fvtable-verify=preinit:vtv_end_preinit.o%s; \
+- fvtable-verify=std:vtv_end.o%s}} \
+- %{static:crtend.o%s; \
+- shared|static-pie|" PIE_SPEC ":crtendS.o%s; \
++ fvtable-verify=std:vtv_end.o%s} \
++ %{shared|" PIE_SPEC ":crtendS.o%s; \
+ :crtend.o%s} " \
+ GNU_USER_TARGET_CRTN " " \
+ CRTOFFLOADEND
+@@ -106,7 +105,7 @@
+ #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
+-#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
++#define LINK_EH_SPEC "%{!static|" PIE_SPEC ":--eh-frame-hdr} "
+ #endif
+
+ #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \
+diff -rNU3 gcc-13.2.0.old/gcc/gcc.cc gcc-13.2.0/gcc/gcc.cc
+--- gcc-13.2.0.old/gcc/gcc.cc 2023-07-27 08:13:04.000000000 +0000
++++ gcc-13.2.0/gcc/gcc.cc 2023-08-30 18:15:11.750098722 +0000
+@@ -1003,7 +1003,7 @@
+ #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
+ #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
+ #else
+-#define PIE_SPEC "pie"
++#define PIE_SPEC "pie|static-pie"
+ #define FPIE1_SPEC "fpie"
+ #define NO_FPIE1_SPEC FPIE1_SPEC ":;"
+ #define FPIE2_SPEC "fPIE"
+@@ -1027,12 +1027,12 @@
+ #ifndef LINK_PIE_SPEC
+ #ifdef HAVE_LD_PIE
+ #ifndef LD_PIE_SPEC
+-#define LD_PIE_SPEC "-pie"
++#define LD_PIE_SPEC "-pie %{static|static-pie:--no-dynamic-linker -z text -Bsymbolic}"
+ #endif
+ #else
+ #define LD_PIE_SPEC ""
+ #endif
+-#define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
++#define LINK_PIE_SPEC "%{shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
+ #endif
+
+ #ifndef LINK_BUILDID_SPEC
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch b/musl/patches-in-mcm/gcc-13.2.0/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch
new file mode 100644
index 0000000..d229bcf
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch
@@ -0,0 +1,272 @@
+From 67c0f5789630b27149f60ff831999ef7c1dba5d5 Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:46:56 +0000
+Subject: [PATCH 05/35] On linux targets pass --as-needed by default to the
+ linker, but always link the sanitizer libraries with --no-as-needed.
+
+---
+ gcc/config/aarch64/aarch64-linux.h | 1 +
+ gcc/config/alpha/linux-elf.h | 2 +-
+ gcc/config/arm/linux-elf.h | 1 +
+ gcc/config/gnu-user.h | 6 +++---
+ gcc/config/i386/gnu-user.h | 2 +-
+ gcc/config/i386/gnu-user64.h | 1 +
+ gcc/config/ia64/linux.h | 2 +-
+ gcc/config/mips/gnu-user.h | 1 +
+ gcc/config/riscv/linux.h | 1 +
+ gcc/config/rs6000/linux64.h | 4 ++--
+ gcc/config/rs6000/sysv4.h | 2 +-
+ gcc/config/s390/linux.h | 2 +-
+ gcc/config/sparc/linux.h | 2 +-
+ gcc/gcc.cc | 28 ++++++++++++++++++++--------
+ 14 files changed, 36 insertions(+), 19 deletions(-)
+
+diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h
+index 4277f03da2a..b131983a546 100644
+--- a/gcc/config/aarch64/aarch64-linux.h
++++ b/gcc/config/aarch64/aarch64-linux.h
+@@ -35,6 +35,7 @@
+ #define CPP_SPEC "%{pthread:-D_REENTRANT}"
+
+ #define LINUX_TARGET_LINK_SPEC "%{h*} \
++ --as-needed \
+ %{static:-Bstatic} \
+ %{shared:-shared} \
+ %{symbolic:-Bsymbolic} \
+diff --git a/gcc/config/alpha/linux-elf.h b/gcc/config/alpha/linux-elf.h
+index 03f783f2ad1..d946e700dda 100644
+--- a/gcc/config/alpha/linux-elf.h
++++ b/gcc/config/alpha/linux-elf.h
+@@ -37,7 +37,7 @@ along with GCC; see the file COPYING3. If not see
+
+ #define ELF_DYNAMIC_LINKER GNU_USER_DYNAMIC_LINKER
+
+-#define LINK_SPEC "-m elf64alpha %{G*} %{relax:-relax} \
++#define LINK_SPEC "-m elf64alpha --as-needed %{G*} %{relax:-relax} \
+ %{O*:-O3} %{!O*:-O1} \
+ %{shared:-shared} \
+ %{!shared: \
+diff --git a/gcc/config/arm/linux-elf.h b/gcc/config/arm/linux-elf.h
+index 7b7b7cbbe14..49c050c6f2c 100644
+--- a/gcc/config/arm/linux-elf.h
++++ b/gcc/config/arm/linux-elf.h
+@@ -70,6 +70,7 @@
+ %{rdynamic:-export-dynamic} \
+ %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} \
+ -X \
++ --as-needed \
+ %{mbig-endian:-EB} %{mlittle-endian:-EL}" \
+ SUBTARGET_EXTRA_LINK_SPEC
+
+diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
+index eda8010b133..b26b17f2f2a 100644
+--- a/gcc/config/gnu-user.h
++++ b/gcc/config/gnu-user.h
+@@ -136,7 +136,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define LIBASAN_EARLY_SPEC "%{!shared:libasan_preinit%O%s} " \
+ "%{static-libasan:%{!shared:" \
+ LD_STATIC_OPTION " --whole-archive -lasan --no-whole-archive " \
+- LD_DYNAMIC_OPTION "}}%{!static-libasan:-lasan}"
++ LD_DYNAMIC_OPTION "}}%{!static-libasan:%{!fuse-ld=gold:--push-state} --no-as-needed -lasan %{fuse-ld=gold:--as-needed;:--pop-state}}"
+ #undef LIBHWASAN_EARLY_SPEC
+ #define LIBHWASAN_EARLY_SPEC "%{!shared:libhwasan_preinit%O%s} " \
+ "%{static-libhwasan:%{!shared:" \
+@@ -146,12 +146,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define LIBTSAN_EARLY_SPEC "%{!shared:libtsan_preinit%O%s} " \
+ "%{static-libtsan:%{!shared:" \
+ LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \
+- LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}"
++ LD_DYNAMIC_OPTION "}}%{!static-libtsan:%{!fuse-ld=gold:--push-state} --no-as-needed -ltsan %{fuse-ld=gold:--as-needed;:--pop-state}}"
+ #undef LIBLSAN_EARLY_SPEC
+ #define LIBLSAN_EARLY_SPEC "%{!shared:liblsan_preinit%O%s} " \
+ "%{static-liblsan:%{!shared:" \
+ LD_STATIC_OPTION " --whole-archive -llsan --no-whole-archive " \
+- LD_DYNAMIC_OPTION "}}%{!static-liblsan:-llsan}"
++ LD_DYNAMIC_OPTION "}}%{!static-liblsan:%{!fuse-ld=gold:--push-state} --no-as-needed -llsan %{fuse-ld=gold:--as-needed;:--pop-state}}"
+ #endif
+
+ #undef TARGET_F951_OPTIONS
+diff --git a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h
+index a79b739089d..e0752673dff 100644
+--- a/gcc/config/i386/gnu-user.h
++++ b/gcc/config/i386/gnu-user.h
+@@ -68,7 +68,7 @@ along with GCC; see the file COPYING3. If not see
+ { "link_emulation", GNU_USER_LINK_EMULATION },\
+ { "dynamic_linker", GNU_USER_DYNAMIC_LINKER }
+
+-#define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) %{shared:-shared} \
++#define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) --as-needed %{shared:-shared} \
+ %{!shared: \
+ %{!static: \
+ %{!static-pie: \
+diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
+index 3b63b99acf6..759bf0db86f 100644
+--- a/gcc/config/i386/gnu-user64.h
++++ b/gcc/config/i386/gnu-user64.h
+@@ -56,6 +56,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
+ %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
+ %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
++ --as-needed \
+ %{shared:-shared} \
+ %{!shared: \
+ %{!static: \
+diff --git a/gcc/config/ia64/linux.h b/gcc/config/ia64/linux.h
+index 5dfd428aa17..02656dad7fc 100644
+--- a/gcc/config/ia64/linux.h
++++ b/gcc/config/ia64/linux.h
+@@ -58,7 +58,7 @@ do { \
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-ia64.so.2"
+
+ #undef LINK_SPEC
+-#define LINK_SPEC "\
++#define LINK_SPEC " --as-needed \
+ %{shared:-shared} \
+ %{!shared: \
+ %{!static: \
+diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h
+index a4e5380b589..3cc61bce69f 100644
+--- a/gcc/config/mips/gnu-user.h
++++ b/gcc/config/mips/gnu-user.h
+@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3. If not see
+ #undef GNU_USER_TARGET_LINK_SPEC
+ #define GNU_USER_TARGET_LINK_SPEC "\
+ %{G*} %{EB} %{EL} %{mips*} %{shared} \
++ -as-needed \
+ %{!shared: \
+ %{!static: \
+ %{rdynamic:-export-dynamic} \
+diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
+index 3e625e0f867..f8c2c351e5a 100644
+--- a/gcc/config/riscv/linux.h
++++ b/gcc/config/riscv/linux.h
+@@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see
+ "%{mabi=ilp32:_ilp32}"
+
+ #define LINK_SPEC "\
++-as-needed \
+ -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv" LD_EMUL_SUFFIX " \
+ %{mno-relax:--no-relax} \
+ %{mbig-endian:-EB} \
+diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
+index 9e457033d11..08016bf224d 100644
+--- a/gcc/config/rs6000/linux64.h
++++ b/gcc/config/rs6000/linux64.h
+@@ -377,13 +377,13 @@ extern int dot_symbols;
+ " -m elf64ppc")
+ #endif
+
+-#define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " %{!shared: %{!static: \
++#define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " --as-needed %{!shared: %{!static: \
+ %{!static-pie: \
+ %{rdynamic:-export-dynamic} \
+ -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}}} \
+ %(link_os_extra_spec32)"
+
+-#define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " %{!shared: %{!static: \
++#define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " --as-needed %{!shared: %{!static: \
+ %{!static-pie: \
+ %{rdynamic:-export-dynamic} \
+ -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}}} \
+diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
+index ae932fc22f0..c8ff0c6dc8e 100644
+--- a/gcc/config/rs6000/sysv4.h
++++ b/gcc/config/rs6000/sysv4.h
+@@ -780,7 +780,7 @@ GNU_USER_TARGET_CC1_SPEC
+ #define GNU_USER_DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
+ #endif
+
+-#define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
++#define LINK_OS_LINUX_SPEC "-m elf32ppclinux --as-needed %{!shared: %{!static: \
+ %{rdynamic:-export-dynamic} \
+ -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
+
+diff --git a/gcc/config/s390/linux.h b/gcc/config/s390/linux.h
+index 02aa1edaff8..64df5801134 100644
+--- a/gcc/config/s390/linux.h
++++ b/gcc/config/s390/linux.h
+@@ -82,7 +82,7 @@ along with GCC; see the file COPYING3. If not see
+
+ #undef LINK_SPEC
+ #define LINK_SPEC \
+- "%{m31:-m elf_s390}%{m64:-m elf64_s390} \
++ "%{m31:-m elf_s390}%{m64:-m elf64_s390} --as-needed \
+ %{shared:-shared} \
+ %{!shared: \
+ %{static:-static} \
+diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h
+index 0e33b3cac2c..c2f44546e62 100644
+--- a/gcc/config/sparc/linux.h
++++ b/gcc/config/sparc/linux.h
+@@ -81,7 +81,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
+
+ #undef LINK_SPEC
+-#define LINK_SPEC "-m elf32_sparc %{shared:-shared} \
++#define LINK_SPEC "-m elf32_sparc --as-needed %{shared:-shared} \
+ %{!mno-relax:%{!r:-relax}} \
+ %{!shared: \
+ %{!static: \
+diff --git a/gcc/gcc.cc b/gcc/gcc.cc
+index f82fae23c22..da6417dd0d1 100644
+--- a/gcc/gcc.cc
++++ b/gcc/gcc.cc
+@@ -754,8 +754,11 @@ proper position among the other output files. */
+ #ifdef LIBASAN_EARLY_SPEC
+ #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
+ #elif defined(HAVE_LD_STATIC_DYNAMIC)
+-#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
+- "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \
++#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION "}" \
++ " %{!static-libasan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
++ " -lasan " \
++ " %{static-libasan:" LD_DYNAMIC_OPTION "}" \
++ " %{!static-libasan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
+ STATIC_LIBASAN_LIBS
+ #else
+ #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS
+@@ -790,8 +793,11 @@ proper position among the other output files. */
+ #ifdef LIBTSAN_EARLY_SPEC
+ #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
+ #elif defined(HAVE_LD_STATIC_DYNAMIC)
+-#define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \
+- "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
++#define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION "}" \
++ " %{!static-libtsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
++ " -ltsan " \
++ " %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
++ " %{!static-libtsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
+ STATIC_LIBTSAN_LIBS
+ #else
+ #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS
+@@ -808,8 +814,11 @@ proper position among the other output files. */
+ #ifdef LIBLSAN_EARLY_SPEC
+ #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
+ #elif defined(HAVE_LD_STATIC_DYNAMIC)
+-#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \
+- "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
++#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION "}" \
++ " %{!static-liblsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
++ " -llsan " \
++ " %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
++ " %{!static-liblsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
+ STATIC_LIBLSAN_LIBS
+ #else
+ #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS
+@@ -824,8 +833,11 @@ proper position among the other output files. */
+ #define STATIC_LIBUBSAN_LIBS \
+ " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}"
+ #ifdef HAVE_LD_STATIC_DYNAMIC
+-#define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
+- "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
++#define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION "}" \
++ " %{!static-libubsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
++ " -lubsan " \
++ " %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
++ " %{!static-libubsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
+ STATIC_LIBUBSAN_LIBS
+ #else
+ #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0005-m68k-sqrt.diff b/musl/patches-in-mcm/gcc-13.2.0/0005-m68k-sqrt.diff
new file mode 100644
index 0000000..652efb1
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0005-m68k-sqrt.diff
@@ -0,0 +1,20 @@
+diff --git a/gcc/config/m68k/m68k.md b/gcc/config/m68k/m68k.md
+index 59a456cd496..dbfddea41bd 100644
+--- a/gcc/config/m68k/m68k.md
++++ b/gcc/config/m68k/m68k.md
+@@ -4174,13 +4174,13 @@
+ (define_expand "sqrt<mode>2"
+ [(set (match_operand:FP 0 "nonimmediate_operand" "")
+ (sqrt:FP (match_operand:FP 1 "general_operand" "")))]
+- "TARGET_HARD_FLOAT"
++ "(TARGET_68881 && TARGET_68040) || TARGET_COLDFIRE_FPU"
+ "")
+
+ (define_insn "sqrt<mode>2_68881"
+ [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
+ (sqrt:FP (match_operand:FP 1 "general_operand" "f<FP:dreg>m")))]
+- "TARGET_68881"
++ "TARGET_68881 && TARGET_68040"
+ {
+ if (FP_REG_P (operands[1]))
+ return "f<FP:round>sqrt%.x %1,%0";
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0006-Enable-Wformat-and-Wformat-security-by-default.patch b/musl/patches-in-mcm/gcc-13.2.0/0006-Enable-Wformat-and-Wformat-security-by-default.patch
new file mode 100644
index 0000000..55dff36
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0006-Enable-Wformat-and-Wformat-security-by-default.patch
@@ -0,0 +1,34 @@
+From bb25e8489384504cd59e4a2538720863da1fb29c Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:47:43 +0000
+Subject: [PATCH 06/35] Enable -Wformat and -Wformat-security by default.
+
+---
+ gcc/c-family/c.opt | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
+index a75038930ae..b98726f33ed 100644
+--- a/gcc/c-family/c.opt
++++ b/gcc/c-family/c.opt
+@@ -704,7 +704,7 @@ Warn about function calls with format strings that write past the end
+ of the destination region. Same as -Wformat-overflow=1.
+
+ Wformat-security
+-C ObjC C++ ObjC++ Var(warn_format_security) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0)
++C ObjC C++ ObjC++ Var(warn_format_security) Init(1) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0)
+ Warn about possible security problems with format functions.
+
+ Wformat-signedness
+@@ -725,7 +725,7 @@ C ObjC C++ ObjC++ Var(warn_format_zero_length) Warning LangEnabledBy(C ObjC C++
+ Warn about zero-length formats.
+
+ Wformat=
+-C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0) IntegerRange(0, 2)
++C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format) Init(1) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0) IntegerRange(0, 2)
+ Warn about printf/scanf/strftime/strfmon format string anomalies.
+
+ Wformat-overflow=
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0007-Enable-Wtrampolines-by-default.patch b/musl/patches-in-mcm/gcc-13.2.0/0007-Enable-Wtrampolines-by-default.patch
new file mode 100644
index 0000000..eb7aae8
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0007-Enable-Wtrampolines-by-default.patch
@@ -0,0 +1,25 @@
+From 4a728ad48a7b437cc6f2697e26603bf648149f86 Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:48:24 +0000
+Subject: [PATCH 07/35] Enable -Wtrampolines by default.
+
+---
+ gcc/common.opt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/gcc/common.opt b/gcc/common.opt
+index 64c4277c991..c24839d32bc 100644
+--- a/gcc/common.opt
++++ b/gcc/common.opt
+@@ -803,7 +803,7 @@ Common Var(warn_system_headers) Warning
+ Do not suppress warnings from system headers.
+
+ Wtrampolines
+-Common Var(warn_trampolines) Warning
++Common Var(warn_trampolines) Init(1) Warning
+ Warn whenever a trampoline is generated.
+
+ Wtrivial-auto-var-init
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch b/musl/patches-in-mcm/gcc-13.2.0/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch
new file mode 100644
index 0000000..69c1bf7
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch
@@ -0,0 +1,53 @@
+From 32f24560d0602f7735d5e9efd92fe3151bd72cea Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:49:40 +0000
+Subject: [PATCH 08/35] Disable ssp on -nostdlib, -nodefaultlibs and
+ -ffreestanding Change the buffer size.
+
+---
+ gcc/gcc.cc | 8 +++++++-
+ gcc/params.opt | 2 +-
+ 2 files changed, 8 insertions(+), 2 deletions(-)
+
+diff --git a/gcc/gcc.cc b/gcc/gcc.cc
+index da6417dd0d1..b5a6f200635 100644
+--- a/gcc/gcc.cc
++++ b/gcc/gcc.cc
+@@ -983,6 +983,12 @@ proper position among the other output files. */
+ #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}"
+ #endif
+
++#ifdef ENABLE_DEFAULT_SSP
++#define NO_SSP_SPEC "%{nostdlib|nodefaultlibs|ffreestanding:-fno-stack-protector} "
++#else
++#define NO_SSP_SPEC ""
++#endif
++
+ #ifndef LINK_SSP_SPEC
+ #ifdef TARGET_LIBC_PROVIDES_SSP
+ #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
+@@ -1282,7 +1288,7 @@ static const char *cc1_options =
+ %{-version:--version}\
+ %{-help=*:--help=%*}\
+ %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}}\
+- %{fsyntax-only:-o %j} %{-param*}\
++ %{fsyntax-only:-o %j} %{-param*} " NO_SSP_SPEC "\
+ %{coverage:-fprofile-arcs -ftest-coverage}\
+ %{fprofile-arcs|fprofile-generate*|coverage:\
+ %{!fprofile-update=single:\
+diff --git a/gcc/params.opt b/gcc/params.opt
+index 823cdb2ff85..5b096899b40 100644
+--- a/gcc/params.opt
++++ b/gcc/params.opt
+@@ -1006,7 +1006,7 @@ Common Joined UInteger Var(param_ssa_name_def_chain_limit) Init(512) Param Optim
+ The maximum number of SSA_NAME assignments to follow in determining a value.
+
+ -param=ssp-buffer-size=
+-Common Joined UInteger Var(param_ssp_buffer_size) Init(8) IntegerRange(1, 65536) Param Optimization
++Common Joined UInteger Var(param_ssp_buffer_size) Init(4) IntegerRange(1, 65536) Param Optimization
+ The lower bound for a buffer to be considered for stack smashing protection.
+
+ -param=stack-clash-protection-guard-size=
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch b/musl/patches-in-mcm/gcc-13.2.0/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch
new file mode 100644
index 0000000..f4dd52f
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch
@@ -0,0 +1,54 @@
+From c7ec8da7280d7f97f5543eb9ddeca7600aafc43c Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:50:33 +0000
+Subject: [PATCH 09/35] Ensure that msgfmt doesn't encounter problems during
+ gcc bootstrapping.
+
+Solves error messages like the following:
+
+msgfmt: /var/tmp/portage/sys-devel/gcc-4.1.2/work/build/./gcc/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6)
+
+The libgcc_s.so used during build doesn't satisfy the needs of the
+libstdc++.so that msgfmt is linked against. On the other hand, msgfmt
+is used as a stand-alone application here, and what library it uses
+behind the scenes is of no concern to the gcc build process.
+Therefore, simply invoking it "as usual", i.e. without any special
+library path, will make it work as expected here.
+
+2011-09-19 Martin von Gagern
+
+References:
+https://bugs.gentoo.org/372377
+https://bugs.gentoo.org/295480
+---
+ libstdc++-v3/po/Makefile.am | 1 +
+ libstdc++-v3/po/Makefile.in | 1 +
+ 2 files changed, 2 insertions(+)
+
+diff --git a/libstdc++-v3/po/Makefile.am b/libstdc++-v3/po/Makefile.am
+index 12d34910830..61b13762b71 100644
+--- a/libstdc++-v3/po/Makefile.am
++++ b/libstdc++-v3/po/Makefile.am
+@@ -38,6 +38,7 @@ MSGFMT = msgfmt
+ EXTRA_DIST = string_literals.cc POTFILES.in $(PACKAGE).pot $(LOCALE_IN)
+
+ .po.mo:
++ env --unset=LD_LIBRARY_PATH \
+ $(MSGFMT) -o $@ $<
+
+ all-local: all-local-$(USE_NLS)
+diff --git a/libstdc++-v3/po/Makefile.in b/libstdc++-v3/po/Makefile.in
+index 8e93445acd2..d6ff06e5ddb 100644
+--- a/libstdc++-v3/po/Makefile.in
++++ b/libstdc++-v3/po/Makefile.in
+@@ -561,6 +561,7 @@ uninstall-am:
+
+
+ .po.mo:
++ env --unset=LD_LIBRARY_PATH \
+ $(MSGFMT) -o $@ $<
+
+ all-local: all-local-$(USE_NLS)
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch b/musl/patches-in-mcm/gcc-13.2.0/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch
new file mode 100644
index 0000000..f56d41a
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch
@@ -0,0 +1,28 @@
+From aaa029bcee68298695b7c4278c90b6bc320d098c Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:52:07 +0000
+Subject: [PATCH 10/35] Don't declare asprintf if defined as a macro.
+
+---
+ include/libiberty.h | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/include/libiberty.h b/include/libiberty.h
+index 1d5c779fcff..19e3cb1e31c 100644
+--- a/include/libiberty.h
++++ b/include/libiberty.h
+@@ -652,8 +652,11 @@ extern void *bsearch_r (const void *, const void *,
+ /* Like sprintf but provides a pointer to malloc'd storage, which must
+ be freed by the caller. */
+
++/* asprintf may be declared as a macro by glibc with __USE_FORTIFY_LEVEL. */
++#ifndef asprintf
+ extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
+ #endif
++#endif
+
+ /* Like asprintf but allocates memory without fail. This works like
+ xmalloc. */
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0011-libiberty-copy-PIC-objects-during-build-process.patch b/musl/patches-in-mcm/gcc-13.2.0/0011-libiberty-copy-PIC-objects-during-build-process.patch
new file mode 100644
index 0000000..b12d4f9
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0011-libiberty-copy-PIC-objects-during-build-process.patch
@@ -0,0 +1,24 @@
+From 65e01e749205c9af218b01233cebd0077538d0ee Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:53:00 +0000
+Subject: [PATCH 11/35] libiberty: copy PIC objects during build process
+
+---
+ libiberty/Makefile.in | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
+index 72608f3e4a7..58356884728 100644
+--- a/libiberty/Makefile.in
++++ b/libiberty/Makefile.in
+@@ -265,6 +265,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
+ $(AR) $(AR_FLAGS) $(TARGETLIB) \
+ $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS); \
+ $(RANLIB) $(TARGETLIB); \
++ cp $(TARGETLIB) ../ ; \
+ cd ..; \
+ else true; fi
+
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0012-libgcc_s.patch b/musl/patches-in-mcm/gcc-13.2.0/0012-libgcc_s.patch
new file mode 100644
index 0000000..d8bbc60
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0012-libgcc_s.patch
@@ -0,0 +1,57 @@
+From 453a815bf2844971a91eaef800af188d9e86b784 Mon Sep 17 00:00:00 2001
+From: Szabolcs Nagy <nsz@port70.net>
+Date: Sat, 24 Oct 2015 20:09:53 +0000
+Subject: [PATCH 12/35] libgcc_s
+
+---
+ gcc/config/i386/i386-expand.cc | 4 ++--
+ libgcc/config/i386/cpuinfo.c | 6 +++---
+ libgcc/config/i386/t-linux | 2 +-
+ 3 files changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
+index 0d817fc3f3b..2e99db00db9 100644
+--- a/gcc/config/i386/i386-expand.cc
++++ b/gcc/config/i386/i386-expand.cc
+@@ -12691,10 +12691,10 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
+ {
+ case IX86_BUILTIN_CPU_INIT:
+ {
+- /* Make it call __cpu_indicator_init in libgcc. */
++ /* Make it call __cpu_indicator_init in libgcc.a. */
+ tree call_expr, fndecl, type;
+ type = build_function_type_list (integer_type_node, NULL_TREE);
+- fndecl = build_fn_decl ("__cpu_indicator_init", type);
++ fndecl = build_fn_decl ("__cpu_indicator_init_local", type);
+ call_expr = build_call_expr (fndecl, 0);
+ return expand_expr (call_expr, target, mode, EXPAND_NORMAL);
+ }
+diff --git a/libgcc/config/i386/cpuinfo.c b/libgcc/config/i386/cpuinfo.c
+index 50b6d8248a2..724ced402a1 100644
+--- a/libgcc/config/i386/cpuinfo.c
++++ b/libgcc/config/i386/cpuinfo.c
+@@ -63,7 +63,7 @@ __cpu_indicator_init (void)
+ __cpu_features2);
+ }
+
+-#if defined SHARED && defined USE_ELF_SYMVER
+-__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0");
+-__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0");
++#ifndef SHARED
++int __cpu_indicator_init_local (void)
++ __attribute__ ((weak, alias ("__cpu_indicator_init")));
+ #endif
+diff --git a/libgcc/config/i386/t-linux b/libgcc/config/i386/t-linux
+index 8506a635790..564296f788e 100644
+--- a/libgcc/config/i386/t-linux
++++ b/libgcc/config/i386/t-linux
+@@ -3,5 +3,5 @@
+ # t-slibgcc-elf-ver and t-linux
+ SHLIB_MAPFILES = libgcc-std.ver $(srcdir)/config/i386/libgcc-glibc.ver
+
+-HOST_LIBGCC2_CFLAGS += -mlong-double-80 -DUSE_ELF_SYMVER $(CET_FLAGS)
++HOST_LIBGCC2_CFLAGS += -mlong-double-80 $(CET_FLAGS)
+ CRTSTUFF_T_CFLAGS += $(CET_FLAGS)
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0013-nopie.patch b/musl/patches-in-mcm/gcc-13.2.0/0013-nopie.patch
new file mode 100644
index 0000000..28a765e
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0013-nopie.patch
@@ -0,0 +1,75 @@
+From 7d7d12137c666761a8dd61179c9651b85dae9b41 Mon Sep 17 00:00:00 2001
+From: Szabolcs Nagy <nsz@port70.net>
+Date: Sat, 7 Nov 2015 02:08:05 +0000
+Subject: [PATCH 13/35] nopie
+
+---
+ gcc/configure | 27 +++++++++++++++++++++++++++
+ gcc/configure.ac | 13 +++++++++++++
+ 2 files changed, 40 insertions(+)
+
+diff --git a/gcc/configure b/gcc/configure
+index 8c46369f73f..e59cbee1767 100755
+--- a/gcc/configure
++++ b/gcc/configure
+@@ -32268,6 +32268,33 @@ fi
+ $as_echo "$gcc_cv_no_pie" >&6; }
+ if test "$gcc_cv_no_pie" = "yes"; then
+ NO_PIE_FLAG="-no-pie"
++else
++ # Check if -nopie works.
++ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -nopie option" >&5
++$as_echo_n "checking for -nopie option... " >&6; }
++if test "${gcc_cv_nopie+set}" = set; then :
++ $as_echo_n "(cached) " >&6
++else
++ saved_LDFLAGS="$LDFLAGS"
++ LDFLAGS="$LDFLAGS -nopie"
++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h. */
++int main(void) {return 0;}
++_ACEOF
++if ac_fn_cxx_try_link "$LINENO"; then :
++ gcc_cv_nopie=yes
++else
++ gcc_cv_nopie=no
++fi
++rm -f core conftest.err conftest.$ac_objext \
++ conftest$ac_exeext conftest.$ac_ext
++ LDFLAGS="$saved_LDFLAGS"
++fi
++{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_nopie" >&5
++$as_echo "$gcc_cv_nopie" >&6; }
++ if test "$gcc_cv_nopie" = "yes"; then
++ NO_PIE_FLAG="-nopie"
++ fi
+ fi
+
+
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index 5504bf6eb01..57268319de1 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -7552,6 +7552,19 @@ AC_CACHE_CHECK([for -no-pie option],
+ LDFLAGS="$saved_LDFLAGS"])
+ if test "$gcc_cv_no_pie" = "yes"; then
+ NO_PIE_FLAG="-no-pie"
++else
++ # Check if -nopie works.
++ AC_CACHE_CHECK([for -nopie option],
++ [gcc_cv_nopie],
++ [saved_LDFLAGS="$LDFLAGS"
++ LDFLAGS="$LDFLAGS -nopie"
++ AC_LINK_IFELSE([int main(void) {return 0;}],
++ [gcc_cv_nopie=yes],
++ [gcc_cv_nopie=no])
++ LDFLAGS="$saved_LDFLAGS"])
++ if test "$gcc_cv_nopie" = "yes"; then
++ NO_PIE_FLAG="-nopie"
++ fi
+ fi
+ AC_SUBST([NO_PIE_FLAG])
+
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch b/musl/patches-in-mcm/gcc-13.2.0/0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch
new file mode 100644
index 0000000..937cad8
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch
@@ -0,0 +1,24 @@
+From 6bb5b7d9161d05f31b001d8211a9c63caf63fd2f Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 06:59:43 +0000
+Subject: [PATCH 15/35] build: fix CXXFLAGS_FOR_BUILD passing
+
+---
+ Makefile.in | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/Makefile.in b/Makefile.in
+index 06a9398e172..6ff2b3f9925 100644
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -178,6 +178,7 @@ BUILD_EXPORTS = \
+ # built for the build system to override those in BASE_FLAGS_TO_PASS.
+ EXTRA_BUILD_FLAGS = \
+ CFLAGS="$(CFLAGS_FOR_BUILD)" \
++ CXXFLAGS="$(CXXFLAGS_FOR_BUILD)" \
+ LDFLAGS="$(LDFLAGS_FOR_BUILD)"
+
+ # This is the list of directories to built for the host system.
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0019-aarch64-disable-multilib-support.patch b/musl/patches-in-mcm/gcc-13.2.0/0019-aarch64-disable-multilib-support.patch
new file mode 100644
index 0000000..5a8148f
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0019-aarch64-disable-multilib-support.patch
@@ -0,0 +1,26 @@
+From 41d00a2eb0754acf71958808bd17dbebeb517b84 Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Thu, 6 Jan 2022 03:12:55 +0000
+Subject: [PATCH 19/35] aarch64: disable multilib support
+
+multilib is unsupported on Alpine GCC
+---
+ gcc/config/aarch64/t-aarch64-linux | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/gcc/config/aarch64/t-aarch64-linux b/gcc/config/aarch64/t-aarch64-linux
+index 57bf4100fcd..172894b57ef 100644
+--- a/gcc/config/aarch64/t-aarch64-linux
++++ b/gcc/config/aarch64/t-aarch64-linux
+@@ -22,7 +22,7 @@ LIB1ASMSRC = aarch64/lib1funcs.asm
+ LIB1ASMFUNCS = _aarch64_sync_cache_range
+
+ AARCH_BE = $(if $(findstring TARGET_BIG_ENDIAN_DEFAULT=1, $(tm_defines)),_be)
+-MULTILIB_OSDIRNAMES = mabi.lp64=../lib64$(call if_multiarch,:aarch64$(AARCH_BE)-linux-gnu)
++MULTILIB_OSDIRNAMES = mabi.lp64=../lib
+ MULTIARCH_DIRNAME = $(call if_multiarch,aarch64$(AARCH_BE)-linux-gnu)
+
+ MULTILIB_OSDIRNAMES += mabi.ilp32=../libilp32$(call if_multiarch,:aarch64$(AARCH_BE)-linux-gnu_ilp32)
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0020-s390x-disable-multilib-support.patch b/musl/patches-in-mcm/gcc-13.2.0/0020-s390x-disable-multilib-support.patch
new file mode 100644
index 0000000..ef2f449
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0020-s390x-disable-multilib-support.patch
@@ -0,0 +1,25 @@
+From 85b42bfbba71616831d14360b16998acb28790fd Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Thu, 6 Jan 2022 03:13:59 +0000
+Subject: [PATCH 20/35] s390x: disable multilib support
+
+multilib is not supported on Alpine GCC at present
+---
+ gcc/config/s390/t-linux64 | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/gcc/config/s390/t-linux64 b/gcc/config/s390/t-linux64
+index cc6ab367072..7f498ee1cdc 100644
+--- a/gcc/config/s390/t-linux64
++++ b/gcc/config/s390/t-linux64
+@@ -7,5 +7,5 @@
+
+ MULTILIB_OPTIONS = m64/m31
+ MULTILIB_DIRNAMES = 64 32
+-MULTILIB_OSDIRNAMES = ../lib64$(call if_multiarch,:s390x-linux-gnu)
+-MULTILIB_OSDIRNAMES += $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:s390-linux-gnu)
++MULTILIB_OSDIRNAMES = m64=../lib
++MULTILIB_OSDIRNAMES+= m32=../lib32
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0021-ppc64-le-disable-multilib-support.patch b/musl/patches-in-mcm/gcc-13.2.0/0021-ppc64-le-disable-multilib-support.patch
new file mode 100644
index 0000000..dbdc788
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0021-ppc64-le-disable-multilib-support.patch
@@ -0,0 +1,81 @@
+From 7b53df284242638e940c0155b6c21e88cea1f55b Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Thu, 6 Jan 2022 03:14:33 +0000
+Subject: [PATCH 21/35] ppc64[le]: disable multilib support
+
+multilib is not presently supported on Alpine GCC
+---
+ gcc/config/rs6000/t-linux | 6 ++++--
+ gcc/config/rs6000/t-linux64 | 4 ++--
+ gcc/config/rs6000/t-linux64bele | 4 ++--
+ gcc/config/rs6000/t-linux64lebe | 4 ++--
+ 4 files changed, 10 insertions(+), 8 deletions(-)
+
+diff --git a/gcc/config/rs6000/t-linux b/gcc/config/rs6000/t-linux
+index 4e371255533..128c75c7d39 100644
+--- a/gcc/config/rs6000/t-linux
++++ b/gcc/config/rs6000/t-linux
+@@ -2,7 +2,8 @@
+ # or soft-float.
+ ifeq (,$(filter $(with_cpu),$(SOFT_FLOAT_CPUS))$(findstring soft,$(with_float)))
+ ifneq (,$(findstring powerpc64,$(target)))
+-MULTILIB_OSDIRNAMES := .=../lib64$(call if_multiarch,:powerpc64-linux-gnu)
++MULTILIB_OSDIRNAMES := m64=../lib
++MULTILIB_OSDIRNAMES += m32=../lib32
+ else
+ MULTIARCH_DIRNAME := $(call if_multiarch,powerpc-linux-gnu)
+ endif
+@@ -10,7 +11,8 @@ ifneq (,$(findstring powerpcle,$(target)))
+ MULTIARCH_DIRNAME := $(subst -linux,le-linux,$(MULTIARCH_DIRNAME))
+ endif
+ ifneq (,$(findstring powerpc64le,$(target)))
+-MULTILIB_OSDIRNAMES := $(subst -linux,le-linux,$(MULTILIB_OSDIRNAMES))
++MULTILIB_OSDIRNAMES := m64=../lib
++MULTILIB_OSDIRNAMES += m32=../lib32
+ endif
+ endif
+
+diff --git a/gcc/config/rs6000/t-linux64 b/gcc/config/rs6000/t-linux64
+index 01a94242308..b3a76379c03 100644
+--- a/gcc/config/rs6000/t-linux64
++++ b/gcc/config/rs6000/t-linux64
+@@ -28,8 +28,8 @@
+ MULTILIB_OPTIONS := m64/m32
+ MULTILIB_DIRNAMES := 64 32
+ MULTILIB_EXTRA_OPTS :=
+-MULTILIB_OSDIRNAMES := m64=../lib64$(call if_multiarch,:powerpc64-linux-gnu)
+-MULTILIB_OSDIRNAMES += m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:powerpc-linux-gnu)
++MULTILIB_OSDIRNAMES := m64=../lib
++MULTILIB_OSDIRNAMES += m32=../lib32
+
+ rs6000-linux.o: $(srcdir)/config/rs6000/rs6000-linux.cc
+ $(COMPILE) $<
+diff --git a/gcc/config/rs6000/t-linux64bele b/gcc/config/rs6000/t-linux64bele
+index 97c1ee6fb4d..08d72639cb6 100644
+--- a/gcc/config/rs6000/t-linux64bele
++++ b/gcc/config/rs6000/t-linux64bele
+@@ -2,6 +2,6 @@
+
+ MULTILIB_OPTIONS += mlittle
+ MULTILIB_DIRNAMES += le
+-MULTILIB_OSDIRNAMES += $(subst =,.mlittle=,$(subst lible32,lib32le,$(subst lible64,lib64le,$(subst lib,lible,$(subst -linux,le-linux,$(MULTILIB_OSDIRNAMES))))))
+-MULTILIB_OSDIRNAMES += $(subst $(if $(findstring 64,$(target)),m64,m32).,,$(filter $(if $(findstring 64,$(target)),m64,m32).mlittle%,$(MULTILIB_OSDIRNAMES)))
++MULTILIB_OSDIRNAMES = m64=../lib
++MULTILIB_OSDIRNAMES+= m32=../lib32
+ MULTILIB_MATCHES := ${MULTILIB_MATCHES_ENDIAN}
+diff --git a/gcc/config/rs6000/t-linux64lebe b/gcc/config/rs6000/t-linux64lebe
+index 2e63bdb9fc9..c6e1c5db65d 100644
+--- a/gcc/config/rs6000/t-linux64lebe
++++ b/gcc/config/rs6000/t-linux64lebe
+@@ -2,6 +2,6 @@
+
+ MULTILIB_OPTIONS += mbig
+ MULTILIB_DIRNAMES += be
+-MULTILIB_OSDIRNAMES += $(subst =,.mbig=,$(subst libbe32,lib32be,$(subst libbe64,lib64be,$(subst lib,libbe,$(subst le-linux,-linux,$(MULTILIB_OSDIRNAMES))))))
+-MULTILIB_OSDIRNAMES += $(subst $(if $(findstring 64,$(target)),m64,m32).,,$(filter $(if $(findstring 64,$(target)),m64,m32).mbig%,$(MULTILIB_OSDIRNAMES)))
++MULTILIB_OSDIRNAMES := m64=../lib
++MULTILIB_OSDIRNAMES += m32=../lib32
+ MULTILIB_MATCHES := ${MULTILIB_MATCHES_ENDIAN}
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0022-x86_64-disable-multilib-support.patch b/musl/patches-in-mcm/gcc-13.2.0/0022-x86_64-disable-multilib-support.patch
new file mode 100644
index 0000000..2b2f3e7
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0022-x86_64-disable-multilib-support.patch
@@ -0,0 +1,26 @@
+From 96e7e1e9a899d9bb5fcbdf788bd529d0390c626f Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Thu, 6 Jan 2022 03:14:54 +0000
+Subject: [PATCH 22/35] x86_64: disable multilib support
+
+multilib is not presently supported on Alpine GCC
+---
+ gcc/config/i386/t-linux64 | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/gcc/config/i386/t-linux64 b/gcc/config/i386/t-linux64
+index 138956b0962..bc03dab874f 100644
+--- a/gcc/config/i386/t-linux64
++++ b/gcc/config/i386/t-linux64
+@@ -33,6 +33,6 @@
+ comma=,
+ MULTILIB_OPTIONS = $(subst $(comma),/,$(TM_MULTILIB_CONFIG))
+ MULTILIB_DIRNAMES = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
+-MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-linux-gnu)
+-MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:i386-linux-gnu)
++MULTILIB_OSDIRNAMES = m64=../lib
++MULTILIB_OSDIRNAMES+= m32=../lib32
+ MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-linux-gnux32)
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0023-riscv-disable-multilib-support.patch b/musl/patches-in-mcm/gcc-13.2.0/0023-riscv-disable-multilib-support.patch
new file mode 100644
index 0000000..b919def
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0023-riscv-disable-multilib-support.patch
@@ -0,0 +1,76 @@
+From b26224acf342eacb33491f6ea0da1faf73d35715 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
+Date: Mon, 3 Jan 2022 07:14:48 +0100
+Subject: [PATCH 23/35] riscv: disable multilib support
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From the musl wiki [1]:
+
+ musl does not support sharing an include directory between archs
+ […], and thus is not compatible with GCC-style multilib. It is
+ recommended that distributions build GCC with multilib disabled,
+ and use library directories named lib, not lib64 or lib32.
+
+For this reason, we patch existing GCC configuration files (gcc/config)
+to pin MULTILIB_OSDIRNAMES to lib, there is also a corresponding GCC
+upstream bug about this issue [2]. Avoiding the use of lib64 and lib32
+directories is a bit more difficult on the RISC-V architecture. This is
+due to the fact that the default RISC-V configuration does not only use
+the lib64 and lib32 directories but also subdirectories within these
+directories for different RISC-V ABIs (e.g. lp64d, lp64, …) [3].
+
+This patch aligns the RISC-V configuration with other architectures by
+pinning MULTILIB_OSDIRNAMES to lib for rv64gc (our default RISC-V
+-march). Furthermore, this patch removes the ABI-specific startfile
+prefix spec. Since both of these impact the default LIBRARY_PATH [4]
+this patch thereby aligns the default RISC-V LIBRARY_PATH with that from
+other Alpine architectures and thereby fixes #13369 [5].
+
+Incidentally, this also fixes gccgo on riscv64, as without this patch
+gccgo is otherwise not able to find the *.gox files for the Go standard
+library.
+
+[1]: https://wiki.musl-libc.org/guidelines-for-distributions.html#Multilib/multi_arch
+[2]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90077
+[3]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103889#c14
+[4]: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/gcc.c;h=d4c8746b0aa322286decf92aa72a12f0a393b655;hb=HEAD#l9122
+[5]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13369
+---
+ gcc/config/riscv/linux.h | 8 --------
+ gcc/config/riscv/t-linux | 7 +++++--
+ 2 files changed, 5 insertions(+), 10 deletions(-)
+
+diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
+index f8c2c351e5a..8d9881eadeb 100644
+--- a/gcc/config/riscv/linux.h
++++ b/gcc/config/riscv/linux.h
+@@ -61,11 +61,3 @@ along with GCC; see the file COPYING3. If not see
+ %{static:-static}}"
+
+ #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
+-
+-#define STARTFILE_PREFIX_SPEC \
+- "/lib" XLEN_SPEC "/" ABI_SPEC "/ " \
+- "/usr/lib" XLEN_SPEC "/" ABI_SPEC "/ " \
+- "/lib/ " \
+- "/usr/lib/ "
+-
+-#define RISCV_USE_CUSTOMISED_MULTI_LIB select_by_abi
+diff --git a/gcc/config/riscv/t-linux b/gcc/config/riscv/t-linux
+index 216d2776a18..1a8a863853e 100644
+--- a/gcc/config/riscv/t-linux
++++ b/gcc/config/riscv/t-linux
+@@ -1,3 +1,6 @@
+-# Only XLEN and ABI affect Linux multilib dir names, e.g. /lib32/ilp32d/
+-MULTILIB_DIRNAMES := $(patsubst rv32%,lib32,$(patsubst rv64%,lib64,$(MULTILIB_DIRNAMES)))
++MULTILIB_OPTIONS := march=rv64gc
++MULTILIB_DIRNAMES := rv64gc
++
++MULTILIB_DIRNAMES := $(patsubst rv32%,lib32,$(patsubst rv64%,lib,$(MULTILIB_DIRNAMES)))
+ MULTILIB_OSDIRNAMES := $(patsubst lib%,../lib%,$(MULTILIB_DIRNAMES))
++MULTILIB_MATCHES := march?rv64gc=march?rv64imafdc
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0024-always-build-libgcc_eh.a.patch b/musl/patches-in-mcm/gcc-13.2.0/0024-always-build-libgcc_eh.a.patch
new file mode 100644
index 0000000..6b0514e
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0024-always-build-libgcc_eh.a.patch
@@ -0,0 +1,51 @@
+From a72e0613f79f6b6867819317accb7a714031a08c Mon Sep 17 00:00:00 2001
+From: Ariadne Conill <ariadne@dereferenced.org>
+Date: Fri, 21 Aug 2020 07:05:41 +0000
+Subject: [PATCH 24/35] always build libgcc_eh.a
+
+highly inspired by:
+ http://landley.net/hg/aboriginal/file/7e0747a665ab/sources/patches/gcc-core-libgcceh.patch
+---
+ libgcc/Makefile.in | 11 ++++++-----
+ 1 file changed, 6 insertions(+), 5 deletions(-)
+
+diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
+index 6c4dc79ab71..023cede18a7 100644
+--- a/libgcc/Makefile.in
++++ b/libgcc/Makefile.in
+@@ -960,8 +960,9 @@ ifneq ($(LIBUNWIND),)
+ all: libunwind.a
+ endif
+
++all: libgcc_eh.a
+ ifeq ($(enable_shared),yes)
+-all: libgcc_eh.a libgcc_s$(SHLIB_EXT)
++all: libgcc_s$(SHLIB_EXT)
+ ifneq ($(LIBUNWIND),)
+ all: libunwind$(SHLIB_EXT)
+ libgcc_s$(SHLIB_EXT): libunwind$(SHLIB_EXT)
+@@ -1163,10 +1164,6 @@ install-libunwind:
+ install-shared:
+ $(mkinstalldirs) $(DESTDIR)$(inst_libdir)
+
+- $(INSTALL_DATA) libgcc_eh.a $(DESTDIR)$(inst_libdir)/
+- chmod 644 $(DESTDIR)$(inst_libdir)/libgcc_eh.a
+- $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcc_eh.a
+-
+ $(subst @multilib_dir@,$(MULTIDIR),$(subst \
+ @shlib_base_name@,libgcc_s,$(subst \
+ @shlib_slibdir_qual@,$(MULTIOSSUBDIR),$(SHLIB_INSTALL))))
+@@ -1183,6 +1180,10 @@ ifeq ($(enable_gcov),yes)
+ $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcov.a
+ endif
+
++ $(INSTALL_DATA) libgcc_eh.a $(DESTDIR)$(inst_libdir)/
++ chmod 644 $(DESTDIR)$(inst_libdir)/libgcc_eh.a
++ $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcc_eh.a
++
+ parts="$(INSTALL_PARTS)"; \
+ for file in $$parts; do \
+ rm -f $(DESTDIR)$(inst_libdir)/$$file; \
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch b/musl/patches-in-mcm/gcc-13.2.0/0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
new file mode 100644
index 0000000..fcf74ee
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
@@ -0,0 +1,256 @@
+From 7b50823d8a4131e5a55d2499a0f5a52b3d91eed2 Mon Sep 17 00:00:00 2001
+From: Drew DeVault <sir@cmpwn.com>
+Date: Wed, 9 Dec 2020 07:42:06 +0000
+Subject: [PATCH 27/35] configure: Add --enable-autolink-libatomic, use in
+ LINK_GCC_C_SEQUENCE_SPEC [PR81358]
+
+This fixes issues with RISC-V.
+---
+ Makefile.in | 1 +
+ gcc/config.in | 6 ++++++
+ gcc/config/gnu-user.h | 12 +++++++++++-
+ gcc/configure | 31 ++++++++++++++++++++++++++++++-
+ gcc/configure.ac | 21 +++++++++++++++++++++
+ gcc/doc/install.texi | 8 ++++++++
+ gcc/doc/tm.texi | 8 +++++++-
+ gcc/doc/tm.texi.in | 8 +++++++-
+ gcc/gcc.cc | 12 +++++++++++-
+ 9 files changed, 102 insertions(+), 5 deletions(-)
+
+diff --git a/Makefile.in b/Makefile.in
+index 6ff2b3f9925..394b105b271 100644
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -235,6 +235,7 @@ HOST_EXPORTS = \
+ RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)"; export RANLIB_FOR_TARGET; \
+ READELF_FOR_TARGET="$(READELF_FOR_TARGET)"; export READELF_FOR_TARGET; \
+ TOPLEVEL_CONFIGURE_ARGUMENTS="$(TOPLEVEL_CONFIGURE_ARGUMENTS)"; export TOPLEVEL_CONFIGURE_ARGUMENTS; \
++ TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS; \
+ HOST_LIBS="$(STAGE1_LIBS)"; export HOST_LIBS; \
+ GMPLIBS="$(HOST_GMPLIBS)"; export GMPLIBS; \
+ GMPINC="$(HOST_GMPINC)"; export GMPINC; \
+diff --git a/gcc/config.in b/gcc/config.in
+index 0679fbbf4c6..ee81139b385 100644
+--- a/gcc/config.in
++++ b/gcc/config.in
+@@ -118,6 +118,12 @@
+ #endif
+
+
++/* Define if libatomic should always be linked. */
++#ifndef USED_FOR_TARGET
++#undef ENABLE_AUTOLINK_LIBATOMIC
++#endif
++
++
+ /* Define to 1 to specify that we are using the BID decimal floating point
+ format instead of DPD */
+ #ifndef USED_FOR_TARGET
+diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
+index b26b17f2f2a..3f64ea46180 100644
+--- a/gcc/config/gnu-user.h
++++ b/gcc/config/gnu-user.h
+@@ -109,8 +109,18 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
+ #endif
+
++#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC)
++# ifdef LD_AS_NEEDED_OPTION
++# define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION
++# else
++# define LINK_LIBATOMIC_SPEC "-latomic"
++# endif
++#elif !defined(LINK_LIBATOMIC_SPEC)
++# define LINK_LIBATOMIC_SPEC ""
++#endif
++
+ #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \
+- "%{static|static-pie:--start-group} %G %{!nolibc:%L} \
++ "%{static|static-pie:--start-group} %G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L} \
+ %{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}"
+
+ #undef LINK_GCC_C_SEQUENCE_SPEC
+diff --git a/gcc/configure b/gcc/configure
+index e59cbee1767..787c35d4e25 100755
+--- a/gcc/configure
++++ b/gcc/configure
+@@ -984,6 +984,7 @@ with_changes_root_url
+ enable_languages
+ with_multilib_list
+ with_multilib_generator
++enable_autolink_libatomic
+ with_zstd
+ with_zstd_include
+ with_zstd_lib
+@@ -1713,6 +1714,9 @@ Optional Features:
+ --disable-shared don't provide a shared libgcc
+ --disable-gcov don't provide libgcov and related host tools
+ --enable-languages=LIST specify which front-ends to build
++ --enable-autolink-libatomic
++ enable automatic linking of libatomic (ignored if
++ not built)
+ --disable-rpath do not hardcode runtime library paths
+ --enable-sjlj-exceptions
+ arrange to use setjmp/longjmp exception handling
+@@ -8329,7 +8333,6 @@ else
+ fi
+
+
+-
+ # Check whether --with-multilib-generator was given.
+ if test "${with_multilib_generator+set}" = set; then :
+ withval=$with_multilib_generator; :
+@@ -8337,6 +8340,32 @@ else
+ with_multilib_generator=default
+ fi
+
++# If libatomic is available, whether it should be linked automatically
++# Check whether --enable-autolink-libatomic was given.
++if test "${enable_autolink_libatomic+set}" = set; then :
++ enableval=$enable_autolink_libatomic;
++ case $enable_autolink_libatomic in
++ yes | no) ;;
++ *) as_fn_error $? "'$enable_autolink_libatomic' is an invalid value for
++--enable-autolink-libatomic. Valid choices are 'yes' and 'no'." "$LINENO" 5 ;;
++ esac
++
++else
++ enable_autolink_libatomic=''
++fi
++
++
++if test x$enable_autolink_libatomic = xyes; then
++ if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then
++
++$as_echo "#define ENABLE_AUTOLINK_LIBATOMIC 1" >>confdefs.h
++
++ else
++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libatomic is not build for this target, --enable-autolink-libatomic ignored" >&5
++$as_echo "$as_me: WARNING: libatomic is not build for this target, --enable-autolink-libatomic ignored" >&2;}
++ fi
++fi
++
+
+ # -------------------------
+ # Checks for other programs
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index 57268319de1..56bcaa87620 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -1199,6 +1199,27 @@ AC_ARG_WITH(multilib-generator,
+ :,
+ with_multilib_generator=default)
+
++# If libatomic is available, whether it should be linked automatically
++AC_ARG_ENABLE(autolink-libatomic,
++[AS_HELP_STRING([--enable-autolink-libatomic],
++ [enable automatic linking of libatomic (ignored if not built)])],
++[
++ case $enable_autolink_libatomic in
++ yes | no) ;;
++ *) AC_MSG_ERROR(['$enable_autolink_libatomic' is an invalid value for
++--enable-autolink-libatomic. Valid choices are 'yes' and 'no'.]) ;;
++ esac
++], [enable_autolink_libatomic=''])
++
++if test x$enable_autolink_libatomic = xyes; then
++ if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then
++ AC_DEFINE(ENABLE_AUTOLINK_LIBATOMIC, 1,
++ [Define if libatomic should always be linked.])
++ else
++ AC_MSG_WARN([libatomic is not build for this target, --enable-autolink-libatomic ignored])
++ fi
++fi
++
+ # -------------------------
+ # Checks for other programs
+ # -------------------------
+diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
+index b30d3691fe6..ccc8e5dbb00 100644
+--- a/gcc/doc/install.texi
++++ b/gcc/doc/install.texi
+@@ -2377,6 +2377,14 @@ files, but these changed header paths may conflict with some compilation
+ environments. Enabled by default, and may be disabled using
+ @option{--disable-canonical-system-headers}.
+
++@item --enable-autolink-libatomic
++@itemx --disable-autolink-libatomic
++Tell GCC that it should automatically link libatomic; if supported by
++the linker, the file is only linked as needed. This flag is ignored
++when libatomic is not built. Note that this conigure flag is in particular
++useful when building an offloading-target compiler; as for those, a
++user had to specify @code{-foffload=target=-latomic} otherwise.
++
+ @item --with-glibc-version=@var{major}.@var{minor}
+ Tell GCC that when the GNU C Library (glibc) is used on the target it
+ will be version @var{major}.@var{minor} or later. Normally this can
+diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
+index a660e33739b..6183c407a2b 100644
+--- a/gcc/doc/tm.texi
++++ b/gcc/doc/tm.texi
+@@ -381,7 +381,13 @@ the argument @option{-lgcc} to tell the linker to do the search.
+
+ @defmac LINK_GCC_C_SEQUENCE_SPEC
+ The sequence in which libgcc and libc are specified to the linker.
+-By default this is @code{%G %L %G}.
++By default this is @code{%G LINK_LIBATOMIC_SPEC %L %G}.
++@end defmac
++
++@defmac LINK_LIBATOMIC_SPEC
++This macro is used in the default @code{LINK_GCC_C_SEQUENCE_SPEC} to link
++libatomic. By default, it is unset unless @code{ENABLE_AUTOLINK_LIBATOMIC}
++is set.
+ @end defmac
+
+ @defmac POST_LINK_SPEC
+diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
+index f7ab5d48a63..281540aba68 100644
+--- a/gcc/doc/tm.texi.in
++++ b/gcc/doc/tm.texi.in
+@@ -381,7 +381,13 @@ the argument @option{-lgcc} to tell the linker to do the search.
+
+ @defmac LINK_GCC_C_SEQUENCE_SPEC
+ The sequence in which libgcc and libc are specified to the linker.
+-By default this is @code{%G %L %G}.
++By default this is @code{%G LINK_LIBATOMIC_SPEC %L %G}.
++@end defmac
++
++@defmac LINK_LIBATOMIC_SPEC
++This macro is used in the default @code{LINK_GCC_C_SEQUENCE_SPEC} to link
++libatomic. By default, it is unset unless @code{ENABLE_AUTOLINK_LIBATOMIC}
++is set.
+ @end defmac
+
+ @defmac POST_LINK_SPEC
+diff --git a/gcc/gcc.cc b/gcc/gcc.cc
+index 59390fd39d6..dae1dd4cf79 100644
+--- a/gcc/gcc.cc
++++ b/gcc/gcc.cc
+@@ -974,13 +974,23 @@ proper position among the other output files. */
+ # define ASM_DEBUG_OPTION_SPEC ""
+ #endif
+
++#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC)
++# ifdef LD_AS_NEEDED_OPTION
++# define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION
++# else
++# define LINK_LIBATOMIC_SPEC "-latomic"
++# endif
++#elif !defined(LINK_LIBATOMIC_SPEC)
++# define LINK_LIBATOMIC_SPEC ""
++#endif
++
+ /* Here is the spec for running the linker, after compiling all files. */
+
+ /* This is overridable by the target in case they need to specify the
+ -lgcc and -lc order specially, yet not require them to override all
+ of LINK_COMMAND_SPEC. */
+ #ifndef LINK_GCC_C_SEQUENCE_SPEC
+-#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}"
++#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L %G}"
+ #endif
+
+ #ifdef ENABLE_DEFAULT_SSP
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0028-configure-fix-detection-of-atomic-builtins-in-libato.patch b/musl/patches-in-mcm/gcc-13.2.0/0028-configure-fix-detection-of-atomic-builtins-in-libato.patch
new file mode 100644
index 0000000..f92fc7b
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0028-configure-fix-detection-of-atomic-builtins-in-libato.patch
@@ -0,0 +1,57 @@
+From 5bbbd320e54ab5341cfba83e8af98685131caba1 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
+Date: Sun, 29 Aug 2021 12:23:34 +0200
+Subject: [PATCH 28/35] configure: fix detection of atomic builtins in
+ libatomic configure script
+
+Alpine's --enable-autolink-libatomic (which is enabled for riscv64 by
+default) causes the libatomic configure script to incorrectly detect
+which builtins are available on riscv64. This then causes incorrect code
+generation for libatomic since it assumes compiler builtins to be
+available which are not actually available on riscv64.
+
+This commit fixes this issue by disabling linking of libatomic configure
+test code entirely, thereby preventing linking against libatomic.
+
+See:
+
+* https://gitlab.alpinelinux.org/alpine/aports/-/issues/12948
+* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101996#c6
+---
+ libatomic/configure.tgt | 20 ++++++++++++++++++++
+ 1 file changed, 20 insertions(+)
+
+diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt
+index a92ae9e8309..90b579ca4d8 100644
+--- a/libatomic/configure.tgt
++++ b/libatomic/configure.tgt
+@@ -30,6 +30,26 @@
+ # on ${target_cpu}. For example to allow proper use of multilibs.
+ configure_tgt_pre_target_cpu_XCFLAGS="${XCFLAGS}"
+
++# The libatomic configure script performs several checks to determine
++# whether builtins for atomic operations are available. When compiling
++# with --enable-autolink-libatomic the test code compiled by the
++# configure script is also linked against libatomic. This causes it
++# to think that builtins are available, even if there are not, since
++# the tested symbols are provided by libatomic.
++#
++# This is a hack to ensure that we don't link against libatomic by not
++# linking any configure test code at all when --enable-autolink-libatomic
++# is given.
++#
++# See:
++#
++# * https://gitlab.alpinelinux.org/alpine/aports/-/issues/12817
++# * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101996#c4
++#
++if test x$enable_autolink_libatomic = xyes; then
++ gcc_no_link=yes
++fi
++
+ case "${target_cpu}" in
+ alpha*)
+ # fenv.c needs this option to generate inexact exceptions.
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch b/musl/patches-in-mcm/gcc-13.2.0/0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch
new file mode 100644
index 0000000..4418cd5
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch
@@ -0,0 +1,27 @@
+From 430c701a3cefbe09a9c7c8a2f5bbe957f9b2ecb2 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <samuel@sholland.org>
+Date: Thu, 30 Jun 2022 16:44:51 +0000
+Subject: [PATCH 29/35] libstdc++: do not throw exceptions for non-C locales on
+ musl targets
+
+---
+ libstdc++-v3/config/locale/generic/c_locale.cc | 3 ---
+ 1 file changed, 3 deletions(-)
+
+diff --git a/libstdc++-v3/config/locale/generic/c_locale.cc b/libstdc++-v3/config/locale/generic/c_locale.cc
+index 8849d78fdfa..aff467f98fe 100644
+--- a/libstdc++-v3/config/locale/generic/c_locale.cc
++++ b/libstdc++-v3/config/locale/generic/c_locale.cc
+@@ -242,9 +242,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ // Currently, the generic model only supports the "C" locale.
+ // See http://gcc.gnu.org/ml/libstdc++/2003-02/msg00345.html
+ __cloc = 0;
+- if (strcmp(__s, "C"))
+- __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
+- "name not valid"));
+ }
+
+ void
+--
+2.41.0
+
diff --git a/musl/patches-in-mcm/gcc-13.2.0/0035-Fix-ICE-observed-in-PR110280.patch b/musl/patches-in-mcm/gcc-13.2.0/0035-Fix-ICE-observed-in-PR110280.patch
new file mode 100644
index 0000000..b9a7eaf
--- /dev/null
+++ b/musl/patches-in-mcm/gcc-13.2.0/0035-Fix-ICE-observed-in-PR110280.patch
@@ -0,0 +1,61 @@
+From ef740fff300fd9eb8285fb5611f6205705ee54ec Mon Sep 17 00:00:00 2001
+From: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
+Date: Fri, 23 Jun 2023 15:27:17 +0530
+Subject: [PATCH 35/35] Fix ICE observed in PR110280.
+
+gcc/ChangeLog:
+ PR tree-optimization/110280
+ * match.pd (vec_perm_expr(v, v, mask) -> v): Explicitly build vector
+ using build_vector_from_val with the element of input operand, and
+ mask's type if operand and mask's types don't match.
+
+gcc/testsuite/ChangeLog:
+ PR tree-optimization/110280
+ * gcc.target/aarch64/sve/pr110280.c: New test.
+---
+ gcc/match.pd | 9 ++++++++-
+ gcc/testsuite/gcc.target/aarch64/sve/pr110280.c | 12 ++++++++++++
+ 2 files changed, 20 insertions(+), 1 deletion(-)
+ create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr110280.c
+
+diff --git a/gcc/match.pd b/gcc/match.pd
+index 91182448250..c3bb4fbc0a7 100644
+--- a/gcc/match.pd
++++ b/gcc/match.pd
+@@ -8292,7 +8292,14 @@ and,
+
+ (simplify
+ (vec_perm vec_same_elem_p@0 @0 @1)
+- @0)
++ (if (types_match (type, TREE_TYPE (@0)))
++ @0
++ (with
++ {
++ tree elem = uniform_vector_p (@0);
++ }
++ (if (elem)
++ { build_vector_from_val (type, elem); }))))
+
+ /* Push VEC_PERM earlier if that may help FMA perception (PR101895). */
+ (simplify
+diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr110280.c b/gcc/testsuite/gcc.target/aarch64/sve/pr110280.c
+new file mode 100644
+index 00000000000..d3279f38362
+--- /dev/null
++++ b/gcc/testsuite/gcc.target/aarch64/sve/pr110280.c
+@@ -0,0 +1,12 @@
++/* { dg-do compile } */
++/* { dg-options "-O3 -fdump-tree-optimized" } */
++
++#include "arm_sve.h"
++
++svuint32_t l()
++{
++ _Alignas(16) const unsigned int lanes[4] = {0, 0, 0, 0};
++ return svld1rq_u32(svptrue_b8(), lanes);
++}
++
++/* { dg-final { scan-tree-dump-not "VEC_PERM_EXPR" "optimized" } } */
+--
+2.41.0
+