pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

gcc-bootstrap: add new package 10.5.0



Module Name:	pkgsrc-wip
Committed By:	Dmytro Kazankov <dkazankov%NetBSD.org@localhost>
Pushed By:	dkazankov
Date:		Wed Oct 15 10:16:22 2025 +0300
Changeset:	4f34db8a4af2ee389421eb95b31dacfb534bf88f

Added Files:
	gcc-bootstrap/DESCR
	gcc-bootstrap/Makefile
	gcc-bootstrap/distinfo
	gcc-bootstrap/patches/patch-contrib_download__prerequisites
	gcc-bootstrap/patches/patch-fixincludes_inclhack.def
	gcc-bootstrap/patches/patch-gcc_Makefile.in
	gcc-bootstrap/patches/patch-gcc_ada_Makefile.rtl
	gcc-bootstrap/patches/patch-gcc_ada_adaint.c
	gcc-bootstrap/patches/patch-gcc_ada_adaint.h
	gcc-bootstrap/patches/patch-gcc_ada_cstreams.c
	gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-osinte____netbsd.adb
	gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-osinte____netbsd.ads
	gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-taprop____posix.adb
	gcc-bootstrap/patches/patch-gcc_ada_libgnat_g-socthi.ads
	gcc-bootstrap/patches/patch-gcc_ada_libgnat_g-socthi____bsd.adb
	gcc-bootstrap/patches/patch-gcc_ada_s-oscons-tmplt.c
	gcc-bootstrap/patches/patch-gcc_ada_sysdep.c
	gcc-bootstrap/patches/patch-gcc_config.gcc
	gcc-bootstrap/patches/patch-gcc_config.host
	gcc-bootstrap/patches/patch-gcc_config_aarch64_aarch64-builtins.c
	gcc-bootstrap/patches/patch-gcc_config_aarch64_aarch64-netbsd.h
	gcc-bootstrap/patches/patch-gcc_config_aarch64_driver-aarch64.c
	gcc-bootstrap/patches/patch-gcc_config_arm_arm.h
	gcc-bootstrap/patches/patch-gcc_config_arm_bpabi.h
	gcc-bootstrap/patches/patch-gcc_config_arm_elf.h
	gcc-bootstrap/patches/patch-gcc_config_arm_netbsd-eabi.h
	gcc-bootstrap/patches/patch-gcc_config_arm_netbsd-elf.h
	gcc-bootstrap/patches/patch-gcc_config_sparc_sparc.c
	gcc-bootstrap/patches/patch-gcc_configure
	gcc-bootstrap/patches/patch-gcc_ggc-common.c
	gcc-bootstrap/patches/patch-gcc_ginclude_stddef.h
	gcc-bootstrap/patches/patch-gcc_lto_lto.c
	gcc-bootstrap/patches/patch-gcc_opts-common.c
	gcc-bootstrap/patches/patch-gcc_opts-jobserver.h
	gcc-bootstrap/patches/patch-gcc_plugin.c
	gcc-bootstrap/patches/patch-gcc_targhooks.c
	gcc-bootstrap/patches/patch-gmp_gen-sieve.c
	gcc-bootstrap/patches/patch-gmp_mpn_generic_compute_powtab.c
	gcc-bootstrap/patches/patch-gmp_mpz_millerrabin.c
	gcc-bootstrap/patches/patch-gmp_mpz_nextprime.c
	gcc-bootstrap/patches/patch-gmp_mpz_primorial_ui.c
	gcc-bootstrap/patches/patch-gmp_primesieve.c
	gcc-bootstrap/patches/patch-gnattools_configure
	gcc-bootstrap/patches/patch-include_plugin-api.h
	gcc-bootstrap/patches/patch-isl_configure
	gcc-bootstrap/patches/patch-libffi_configure
	gcc-bootstrap/patches/patch-libffi_testsuite_libffi.call_float2.c
	gcc-bootstrap/patches/patch-libgcc_config.host
	gcc-bootstrap/patches/patch-libgcc_crtstuff.c
	gcc-bootstrap/patches/patch-libgfortran_intrinsics_execute_command_line.c
	gcc-bootstrap/patches/patch-libgfortran_intrinsics_string_intrinsics_inc.c
	gcc-bootstrap/patches/patch-libgfortran_io_format.c
	gcc-bootstrap/patches/patch-libgfortran_io_io.h
	gcc-bootstrap/patches/patch-libgfortran_io_list__read.c
	gcc-bootstrap/patches/patch-libgfortran_io_read.c
	gcc-bootstrap/patches/patch-libgfortran_runtime_environ.c
	gcc-bootstrap/patches/patch-libiberty_pex-unix.c
	gcc-bootstrap/patches/patch-libquadmath_printf_printf_fphex.c
	gcc-bootstrap/patches/patch-libquadmath_printf_quadmath-printf.c
	gcc-bootstrap/patches/patch-libquadmath_strtod_strtod__l.c
	gcc-bootstrap/patches/patch-libstdc++-v3_include_bits_std_abs.h
	gcc-bootstrap/patches/patch-libstdc++-v3_include_bits_stl_function.h
	gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cmath
	gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cstring
	gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cwchar
	gcc-bootstrap/patches/patch-libstdc++-v3_libsupc++_new__opa.cc
	gcc-bootstrap/patches/patch-libstdc++-v3_src_c++11_system_error.cc

Log Message:
gcc-bootstrap: add new package 10.5.0

GCC bootstrap builder (includes GNAT) provides minimal set of GCC
compilers (C, C++, Ada) that can bootstrap GNAT. It is not intended to
be included in the main tree but to provide a reproducible build. This
project replaces bootstrap compilers for pkgsrc's GNAT <= 6 which can
not build newer GNAT >= 13.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=4f34db8a4af2ee389421eb95b31dacfb534bf88f

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 gcc-bootstrap/DESCR                                |   6 +
 gcc-bootstrap/Makefile                             | 202 +++++++
 gcc-bootstrap/distinfo                             |  72 +++
 .../patches/patch-contrib_download__prerequisites  |  17 +
 .../patches/patch-fixincludes_inclhack.def         |  36 ++
 gcc-bootstrap/patches/patch-gcc_Makefile.in        |  15 +
 gcc-bootstrap/patches/patch-gcc_ada_Makefile.rtl   | 147 +++++
 gcc-bootstrap/patches/patch-gcc_ada_adaint.c       |  88 +++
 gcc-bootstrap/patches/patch-gcc_ada_adaint.h       |  35 ++
 gcc-bootstrap/patches/patch-gcc_ada_cstreams.c     |  25 +
 .../patch-gcc_ada_libgnarl_s-osinte____netbsd.adb  | 147 +++++
 .../patch-gcc_ada_libgnarl_s-osinte____netbsd.ads  | 670 +++++++++++++++++++++
 .../patch-gcc_ada_libgnarl_s-taprop____posix.adb   |  27 +
 .../patches/patch-gcc_ada_libgnat_g-socthi.ads     |  15 +
 .../patch-gcc_ada_libgnat_g-socthi____bsd.adb      | 363 +++++++++++
 .../patches/patch-gcc_ada_s-oscons-tmplt.c         |  94 +++
 gcc-bootstrap/patches/patch-gcc_ada_sysdep.c       |  42 ++
 gcc-bootstrap/patches/patch-gcc_config.gcc         | 250 ++++++++
 gcc-bootstrap/patches/patch-gcc_config.host        |  15 +
 .../patch-gcc_config_aarch64_aarch64-builtins.c    |  18 +
 .../patch-gcc_config_aarch64_aarch64-netbsd.h      |  18 +
 .../patch-gcc_config_aarch64_driver-aarch64.c      | 184 ++++++
 gcc-bootstrap/patches/patch-gcc_config_arm_arm.h   |  45 ++
 gcc-bootstrap/patches/patch-gcc_config_arm_bpabi.h |  22 +
 gcc-bootstrap/patches/patch-gcc_config_arm_elf.h   |  14 +
 .../patches/patch-gcc_config_arm_netbsd-eabi.h     |  57 ++
 .../patches/patch-gcc_config_arm_netbsd-elf.h      |  80 +++
 .../patches/patch-gcc_config_sparc_sparc.c         |  18 +
 gcc-bootstrap/patches/patch-gcc_configure          |  15 +
 gcc-bootstrap/patches/patch-gcc_ggc-common.c       |  51 ++
 gcc-bootstrap/patches/patch-gcc_ginclude_stddef.h  |  18 +
 gcc-bootstrap/patches/patch-gcc_lto_lto.c          |  19 +
 gcc-bootstrap/patches/patch-gcc_opts-common.c      |  13 +
 gcc-bootstrap/patches/patch-gcc_opts-jobserver.h   |  28 +
 gcc-bootstrap/patches/patch-gcc_plugin.c           |  18 +
 gcc-bootstrap/patches/patch-gcc_targhooks.c        |  17 +
 gcc-bootstrap/patches/patch-gmp_gen-sieve.c        |  17 +
 .../patches/patch-gmp_mpn_generic_compute_powtab.c |  67 +++
 gcc-bootstrap/patches/patch-gmp_mpz_millerrabin.c  |  16 +
 gcc-bootstrap/patches/patch-gmp_mpz_nextprime.c    |  43 ++
 gcc-bootstrap/patches/patch-gmp_mpz_primorial_ui.c |  31 +
 gcc-bootstrap/patches/patch-gmp_primesieve.c       |  17 +
 gcc-bootstrap/patches/patch-gnattools_configure    |  18 +
 gcc-bootstrap/patches/patch-include_plugin-api.h   |  20 +
 gcc-bootstrap/patches/patch-isl_configure          |  26 +
 gcc-bootstrap/patches/patch-libffi_configure       |  16 +
 .../patch-libffi_testsuite_libffi.call_float2.c    |  15 +
 gcc-bootstrap/patches/patch-libgcc_config.host     |  36 ++
 gcc-bootstrap/patches/patch-libgcc_crtstuff.c      |  27 +
 ...h-libgfortran_intrinsics_execute_command_line.c |  15 +
 ...-libgfortran_intrinsics_string_intrinsics_inc.c |  17 +
 .../patches/patch-libgfortran_io_format.c          |  17 +
 gcc-bootstrap/patches/patch-libgfortran_io_io.h    |  18 +
 .../patches/patch-libgfortran_io_list__read.c      |  17 +
 gcc-bootstrap/patches/patch-libgfortran_io_read.c  |  44 ++
 .../patches/patch-libgfortran_runtime_environ.c    |  26 +
 gcc-bootstrap/patches/patch-libiberty_pex-unix.c   |  16 +
 .../patch-libquadmath_printf_printf_fphex.c        |  12 +
 .../patch-libquadmath_printf_quadmath-printf.c     |  34 ++
 .../patches/patch-libquadmath_strtod_strtod__l.c   |  39 ++
 .../patch-libstdc++-v3_include_bits_std_abs.h      |  15 +
 .../patch-libstdc++-v3_include_bits_stl_function.h |  49 ++
 .../patch-libstdc++-v3_include_c_global_cmath      |  15 +
 .../patch-libstdc++-v3_include_c_global_cstring    |  15 +
 .../patch-libstdc++-v3_include_c_global_cwchar     |  15 +
 .../patch-libstdc++-v3_libsupc++_new__opa.cc       |  17 +
 .../patch-libstdc++-v3_src_c++11_system_error.cc   |  15 +
 67 files changed, 3646 insertions(+)

diffs:
diff --git a/gcc-bootstrap/DESCR b/gcc-bootstrap/DESCR
new file mode 100644
index 0000000000..169112c325
--- /dev/null
+++ b/gcc-bootstrap/DESCR
@@ -0,0 +1,6 @@
+GCC bootstrap builder (includes GNAT).
+
+Provides minimal set of GCC compilers (C, C++, Ada) that can bootstrap
+GNAT. It is not intended to be included in the main tree but to
+provide a reproducible build. This project replaces bootstrap
+compilers for pkgsrc's GNAT <= 6 which can not build newer GNAT >= 13.
diff --git a/gcc-bootstrap/Makefile b/gcc-bootstrap/Makefile
new file mode 100644
index 0000000000..6354833992
--- /dev/null
+++ b/gcc-bootstrap/Makefile
@@ -0,0 +1,202 @@
+# $NetBSD: Makefile,v 1.1 2025/07/02 08:30:00 dkazankov Exp $
+
+DISTNAME=	gcc-${PKGVERSION_NOREV}
+PKGNAME=	gcc-bootstrap-10.5.0
+CATEGORIES=	cross
+MASTER_SITES=	${MASTER_SITE_GNU:=gcc/${DISTNAME}/}
+EXTRACT_SUFX=	.tar.xz
+
+MAINTAINER=	dkazankov%NetBSD.org@localhost
+HOMEPAGE=	https://gcc.gnu.org/
+COMMENT=	GCC bootsrap builder (includes GNAT)
+LICENSE=	gnu-gpl-v2 AND gnu-gpl-v3 AND gnu-lgpl-v2 AND gnu-lgpl-v3
+
+DISTFILES=	${DEFAULT_DISTFILES}
+
+USE_LANGUAGES=	#empty
+
+USE_TOOLS+=		gmake makeinfo sed tar perl pax bzip2
+USE_TOOLS.NetBSD+=	gsed
+
+TOOL_DEPENDS+=		gcc10-aux-[0-9]*:../../lang/gcc10-aux
+
+# Relocations result in a linker error on AArch64, but not x86.
+MKPIE_SUPPORTED=	no
+
+CHECK_RELRO_SKIP+=	${PKGBASE}/lib/*
+
+GNU_CONFIGURE=		yes
+GNU_CONFIGURE_STRICT=	no
+
+UNLIMIT_RESOURCES+=	datasize
+UNLIMIT_RESOURCES+=	stacksize
+
+CHECK_PORTABILITY_SKIP+=	contrib/*
+
+.include "../../mk/bsd.prefs.mk"
+
+ISL16=			isl-0.16.1
+SITES.${ISL16}.tar.bz2=	${MASTER_SITE_GNU:=gcc/infrastructure/}
+DISTFILES+=		${ISL16}.tar.bz2
+
+post-extract:
+	${MV} ${WRKDIR}/${ISL16} ${WRKSRC}/isl
+
+.if ${OS_VARIANT} == "SmartOS"
+SUBST_CLASSES+=		ccs
+SUBST_STAGE.ccs=	pre-configure
+SUBST_FILES.ccs=	contrib/make_sunver.pl
+SUBST_SED.ccs=		-e 's,/usr/ccs/bin,/usr/bin,g'
+.endif
+
+# Use C preprocessed symbols on NetBSD (only)
+.if ${OPSYS} == "NetBSD"
+SUBST_CLASSES+=		patch1
+SUBST_MESSAGE.patch1=	Replace nanosleep, gettimeofday in ${SUBST_FILES.patch1}
+SUBST_STAGE.patch1=	pre-configure
+SUBST_FILES.patch1=	gcc/ada/libgnat/s-osprim__posix.adb
+SUBST_SED.patch1=	-e "s,\"nanosleep\",\"__gnat_nanosleep\","
+SUBST_SED.patch1+=	-e "s,\"gettimeofday\",\"__gnat_gettimeofday\","
+
+SUBST_CLASSES+=		patch2
+SUBST_MESSAGE.patch2=	Replace select with __gnat_select in ${SUBST_FILES.patch2}
+SUBST_STAGE.patch2=	pre-configure
+SUBST_FILES.patch2=	gcc/ada/libgnat/g-socthi.ads
+SUBST_SED.patch2=	-e "s,\"select\",\"__gnat_select\","
+
+SUBST_CLASSES+=		patch3
+SUBST_MESSAGE.patch3=	Replace socket with __gnat_socket in ${SUBST_FILES.patch3}
+SUBST_STAGE.patch3=	pre-configure
+SUBST_FILES.patch3=	gcc/ada/libgnat/g-socthi__bsd.adb
+SUBST_SED.patch3=	-e "s,\"socket\",\"__gnat_socket\","
+.endif
+
+## Build outside ${WRKSRC}
+OBJDIR=		${WRKDIR}/build
+
+#GARCH=		${MACHINE_ARCH:S/amd64/x86_64/}
+#BUILD_TARGET=	${GARCH}-${LOWER_OPSYS}${OS_VERSION}
+
+pre-configure:
+	${MKDIR} ${OBJDIR}
+
+CONFIGURE_DIRS=		${OBJDIR}
+CONFIGURE_SCRIPT=	${WRKSRC}/configure
+GNU_CONFIGURE_PREFIX=	${PREFIX}/${PKGBASE}
+
+# Disable fixincludes on SmartOS, header changes result in broken includes
+# being generated, see https://github.com/joyent/pkgsrc-legacy/issues/270
+# Same on QNX.
+.if ${OS_VARIANT} == "SmartOS" || ${OPSYS} == "QNX"
+SUBST_CLASSES+=		fixinc
+SUBST_STAGE.fixinc=	post-extract
+SUBST_FILES.fixinc=	gcc/Makefile.in
+SUBST_SED.fixinc=	-e "s,\./fixinc.sh,-c true,"
+.endif
+
+CONFIGURE_ENV.QNX+=	ACCEPT_INFERIOR_RM_PROGRAM=yes
+# Make invokes further configure scripts
+MAKE_ENV.QNX+=		ACCEPT_INFERIOR_RM_PROGRAM=yes
+MAKE_ENV.QNX+=		GENAUTOMATA_LDFLAGS="-Wl,--stack,10000000"
+
+.if ${MACHINE_PLATFORM:MNetBSD-*-*}
+# on NetBSD, use the native SSP code in libc
+CONFIGURE_ARGS+=	--disable-libssp
+.else
+CONFIGURE_ARGS+=	--enable-libssp
+.endif
+
+.if ${MACHINE_PLATFORM:MNetBSD-*-*}
+# Match base libstdc++ major
+SUBST_CLASSES+=		libstdc
+SUBST_STAGE.libstdc=	pre-configure
+SUBST_FILES.libstdc=	libstdc++-v3/configure
+SUBST_MESSAGE.libstdc=	Bumping libstdc++ major to 7
+SUBST_SED.libstdc=	-e 's,libtool_VERSION=6:,libtool_VERSION=7:,g'
+.endif
+
+CONFIGURE_ARGS+=	--enable-languages=ada,c,c++
+CONFIGURE_ARGS+=	--disable-bootstrap
+CONFIGURE_ARGS+=	--disable-shared
+CONFIGURE_ARGS+=	--disable-nls
+CONFIGURE_ARGS+=	--disable-multilib
+CONFIGURE_ARGS+=	--enable-long-long
+CONFIGURE_ARGS+=	--with-local-prefix=${PREFIX}/${PKGBASE}
+CONFIGURE_ARGS+=	--enable-threads=posix
+CONFIGURE_ARGS+=	--without-zstd
+CONFIGURE_ARGS+=	--without-system-zlib
+CONFIGURE_ARGS+=	--enable-__cxa_atexit
+CONFIGURE_ARGS+=	--with-gxx-include-dir=${PREFIX}/${PKGBASE}/include/c++/
+CONFIGURE_ARGS+=	--disable-libstdcxx-pch
+CONFIGURE_ARGS+=	--disable-lto
+
+.if !empty(OSX_SDK_PATH)
+CONFIGURE_ARGS.Darwin+=	--with-sysroot=${OSX_SDK_PATH:Q}
+.endif
+CONFIGURE_ARGS.NetBSD+=	--with-gnu-ld --with-ld=/usr/bin/ld
+CONFIGURE_ARGS.NetBSD+=	--with-gnu-as --with-as=/usr/bin/as
+
+MAKE_ENV.NetBSD+=	ac_cv_func_clock_gettime=yes
+MAKE_ENV.NetBSD+=	ac_cv_func_gethostbyname_r=no
+MAKE_ENV.NetBSD+=	ac_cv_func_freelocale=no
+MAKE_ENV.NetBSD+=	ac_cv_func_newlocale=no
+MAKE_ENV.NetBSD+=	ac_cv_func_uselocale=no
+MAKE_ENV.SunOS+=	ac_cv_func_mkostemp=no
+
+.if ${MACHINE_PLATFORM:MNetBSD-*-i386} || ${MACHINE_PLATFORM:MLinux-*-i386}
+CONFIGURE_ARGS+=	--with-arch=i486 --with-tune=i486
+.endif
+
+.if ${MACHINE_PLATFORM:MNetBSD-*-x86_64} || ${MACHINE_PLATFORM:MLinux-*-x86_64}
+CONFIGURE_ARGS+=	--with-arch=nocona --with-tune=nocona --with-fpmath=sse
+.endif
+
+.if ${MACHINE_PLATFORM:MDarwin-[0-8].*-*}
+CONFIGURE_ARGS+=	--with-dwarf2
+.endif
+
+# ${WRKSRC}/fixincludes/ looks for sed and compiles the path to sed into
+# a binary so we need to make sure we give it the installed sed and not
+# the tool wrapped one.
+MAKE_ENV+=		ac_cv_path_SED=${TOOLS_SED}
+MAKE_ENV+=		lt_cv_path_SED=${TOOLS_SED}
+
+.include "../../devel/binutils/buildlink3.mk"
+CONFIGURE_ARGS+=	--with-gnu-as --with-as=${PREFIX}/bin/gas
+
+CTF_FILES_SKIP+=	*/gengtype	# CPU limit exceeded
+
+post-install:
+	cd ${DESTDIR}${PREFIX} && \
+	find ${PKGBASE} \
+	    \( -type f -or -type l \) -and \
+	    \( -path ${PKGBASE}/bin/\* -or -path ${PKGBASE}/include/\* -or \
+		-path ${PKGBASE}/lib/\* -or -path ${PKGBASE}/libexec/\* \) -and \
+	    ! -path ${PKGBASE}/bin/${MACHINE_GNU_PLATFORM}\* -and \
+	    ! -path ${PKGBASE}/lib/\*/include-fixed/\* \
+	    -print | \
+	${PAX} -wd | \
+	${BZIP2} >${WRKDIR}/${PKGBASE}-${MACHINE_GNU_PLATFORM}-${PKGVERSION_NOREV}.tar.bz2
+
+GENERATE_PLIST+= \
+	cd ${DESTDIR}${PREFIX} && \
+	${FIND} ${PKGBASE} \( -type f -o -type l \) -print | ${SORT};
+
+.include "../../devel/gmp/inplace.mk"
+.include "../../math/mpcomplex/inplace.mk"
+.include "../../math/mpfr/inplace.mk"
+
+.include "../../mk/dlopen.buildlink3.mk"
+.include "../../mk/pthread.buildlink3.mk"
+
+.include "../../mk/bsd.pkg.mk"
+
+CC=	${PREFIX}/gcc10-aux/bin/gcc
+CXX=	${PREFIX}/gcc10-aux/bin/g++
+
+PREPEND_PATH+=	${PREFIX}/gcc10-aux/bin
+
+CFLAGS=		-O2
+CPPFLAGS=	#empty
+CXXFLAGS=	-O2
+LDFLAGS=	-static -static-libstdc++ -static-libgcc
diff --git a/gcc-bootstrap/distinfo b/gcc-bootstrap/distinfo
new file mode 100644
index 0000000000..64e0c318e0
--- /dev/null
+++ b/gcc-bootstrap/distinfo
@@ -0,0 +1,72 @@
+$NetBSD: distinfo,v 1.2 2025/01/07 19:54:31 riastradh Exp $
+
+BLAKE2s (gcc-10.5.0.tar.xz) = af4a8b262d9d4e534e8e1c311897e68e7d64f147ad1eed42e77f9674da188bf3
+SHA512 (gcc-10.5.0.tar.xz) = d86dbc18b978771531f4039465e7eb7c19845bf607dc513c97abf8e45ffe1086a99d98f83dfb7b37204af22431574186de9d5ff80c8c3c3a98dbe3983195bffd
+Size (gcc-10.5.0.tar.xz) = 77846412 bytes
+BLAKE2s (isl-0.16.1.tar.bz2) = 01c3fc657326e81414986eb7ede6f73e540b97009745ced125cdf7f4a8d80f61
+SHA512 (isl-0.16.1.tar.bz2) = c188667a84dc5bdddb4ab7c35f89c91bf15a8171f4fcaf41301cf285fb7328846d9a367c096012fec4cc69d244f0bc9e95d84c09ec097394cd4093076f2a041b
+Size (isl-0.16.1.tar.bz2) = 1626446 bytes
+SHA1 (patch-contrib_download__prerequisites) = 9cdcde21ab174052911447d20762ddfd40aa8791
+SHA1 (patch-fixincludes_inclhack.def) = 7b00974d3f52a8364190a607f52a5d7e8a6db41a
+SHA1 (patch-gcc_Makefile.in) = b426628d83ed6b15a93193158e963d65b9607e21
+SHA1 (patch-gcc_ada_Makefile.rtl) = 1b6a18dce5ffe752be942f6e328d487692f3b33a
+SHA1 (patch-gcc_ada_adaint.c) = d80d7fc48e35b31e27a2b6fe8926481174352ed8
+SHA1 (patch-gcc_ada_adaint.h) = 7b6a3e386f7b9549f981dd7e06165180da3b4211
+SHA1 (patch-gcc_ada_cstreams.c) = 047746f1da085917082dafe8b87fdc5e757e1237
+SHA1 (patch-gcc_ada_libgnarl_s-osinte____netbsd.adb) = 84268061686b15a8ef9013242e3d258b82b9f13e
+SHA1 (patch-gcc_ada_libgnarl_s-osinte____netbsd.ads) = 2d1179230289a243bb004b9f16c747cda9761b60
+SHA1 (patch-gcc_ada_libgnarl_s-taprop____posix.adb) = 505d0ba78a21a8a6cc6213a9809c44c284fe2334
+SHA1 (patch-gcc_ada_libgnat_g-socthi.ads) = 60df08c6ca3ef50c63df9562844819e5823f0129
+SHA1 (patch-gcc_ada_libgnat_g-socthi____bsd.adb) = 796a4a69f76bd382526df279ef0e58615bddae5c
+SHA1 (patch-gcc_ada_s-oscons-tmplt.c) = a48b5ae3c061144b8406e27cbbc084385fef5131
+SHA1 (patch-gcc_ada_sysdep.c) = 5b8705680ee1a2c9c2686d14d4cbbba8c5fb4fb2
+SHA1 (patch-gcc_config.gcc) = 4767d5b16794f4485879ed10e172cb2f86bc0777
+SHA1 (patch-gcc_config.host) = 8920ce841f6088b365c9b590e3ea9535bd880b40
+SHA1 (patch-gcc_config_aarch64_aarch64-builtins.c) = 87185f5c2e2dbe4195cb19fe6213d2d616d5519b
+SHA1 (patch-gcc_config_aarch64_aarch64-netbsd.h) = abf19e2445bce1773162bddef16cd7f41eb36827
+SHA1 (patch-gcc_config_aarch64_driver-aarch64.c) = 7e17b49924ddd9ff33d049d6539e4df77d14d3e5
+SHA1 (patch-gcc_config_arm_arm.h) = 9d554349869d67d6393552c33a7824f0dd53cb11
+SHA1 (patch-gcc_config_arm_bpabi.h) = 0b0de5ad95442e34397cb46739ef6e36048d6f45
+SHA1 (patch-gcc_config_arm_elf.h) = 57748157084319cb92d892f2ea5b2f3355567551
+SHA1 (patch-gcc_config_arm_netbsd-eabi.h) = 85eb89de6f2e64fac50251f06d7e4eab35903dae
+SHA1 (patch-gcc_config_arm_netbsd-elf.h) = 367d83c808fd7b5b1989d0490b532ad06b425b31
+SHA1 (patch-gcc_config_sparc_sparc.c) = e9cb956f3769642bcd0ba4a477d16c73dea46014
+SHA1 (patch-gcc_configure) = 6a2d8eeeed2bf08c3c81291178e669dc91c913ce
+SHA1 (patch-gcc_ggc-common.c) = 3e325767922ab7d2079fdb9a3d6b6aa531a2fea5
+SHA1 (patch-gcc_ginclude_stddef.h) = bb9c7c85decd29d4b76bb59c1f640e7e958b1971
+SHA1 (patch-gcc_lto_lto.c) = 7bd85ac8ade76a28c394f6fbe5d495f91824f79f
+SHA1 (patch-gcc_opts-common.c) = 8cfb8e50a8690b1094449f4eb2d278ddeeb4b633
+SHA1 (patch-gcc_opts-jobserver.h) = 7206af8d26fa773ce1df9234ee5cdd4afcc80918
+SHA1 (patch-gcc_plugin.c) = fe897fa051c5a1e69af423c354a07baa7332043e
+SHA1 (patch-gcc_targhooks.c) = b28d8a9696d07bbfb00b7d8c55193ba99447ff1d
+SHA1 (patch-gmp_gen-sieve.c) = 7e95627a7f46e9db965de5620999c7bdc6ef6606
+SHA1 (patch-gmp_mpn_generic_compute_powtab.c) = 2301acc51d23bb5558360f133c037a39dec2bd7f
+SHA1 (patch-gmp_mpz_millerrabin.c) = dc92fc81042028ffa1722a85cf42f225bee32cd5
+SHA1 (patch-gmp_mpz_nextprime.c) = 12d7ba775972bf8ef1501131dbbb4bffeb4b0214
+SHA1 (patch-gmp_mpz_primorial_ui.c) = 973d4faadb27bb353bf68f28fd76a5bf0d6315fb
+SHA1 (patch-gmp_primesieve.c) = 3477e4de710bc1eb4297d53e54dc7173cf961217
+SHA1 (patch-gnattools_configure) = aa6181ee8723a1199d84acea1331645205b558cc
+SHA1 (patch-include_plugin-api.h) = f39ef61b50b08daf85872ce2764877f5bc32779d
+SHA1 (patch-isl_configure) = 5523c76d95b229b3cd25461b4c2b7af24bf2534e
+SHA1 (patch-libffi_configure) = 22006b20d7f655e2455a7ad613d676703b6c1ccc
+SHA1 (patch-libffi_testsuite_libffi.call_float2.c) = 27b84a11378fb648dfaad0c70abedd77a0a1c1a8
+SHA1 (patch-libgcc_config.host) = 1dda38390749c8727281099d86d763e1896a54b1
+SHA1 (patch-libgcc_crtstuff.c) = 38d03a3b417aa3116986641f0f7b595166206623
+SHA1 (patch-libgfortran_intrinsics_execute_command_line.c) = 05b554ffce113efa6b92cae1dfeda6dfefeed92c
+SHA1 (patch-libgfortran_intrinsics_string_intrinsics_inc.c) = 2c027c7bd318342c0498d46f9712a55a86ab76c7
+SHA1 (patch-libgfortran_io_format.c) = 9bbc5e4f6277bdec785b3690fd08259939a2aa1a
+SHA1 (patch-libgfortran_io_io.h) = d44676239a7f45e42054d24bd5224f43c20055c0
+SHA1 (patch-libgfortran_io_list__read.c) = 589cdb8dcd180b781ededc086e8775224fca5779
+SHA1 (patch-libgfortran_io_read.c) = cf21493396d07a5e8ad0dfb70a8d25a11482fc98
+SHA1 (patch-libgfortran_runtime_environ.c) = c7217704a00f4c0314bbc1838ac6fc966cc854d0
+SHA1 (patch-libiberty_pex-unix.c) = 52896635b2578e8338a82ad3a3e9fd4d911c8489
+SHA1 (patch-libquadmath_printf_printf_fphex.c) = 4e3927bb2ba9013e1ef69e38d0481c930b77a2fc
+SHA1 (patch-libquadmath_printf_quadmath-printf.c) = 9c862bd2e07f8724646896a9f93bb8bb15bb4185
+SHA1 (patch-libquadmath_strtod_strtod__l.c) = 1a3a419218fb260c1c4a0ed08f5a72bde683d039
+SHA1 (patch-libstdc++-v3_include_bits_std_abs.h) = 2a32b52dc2d958085525461bd6da0a7b299ee09d
+SHA1 (patch-libstdc++-v3_include_bits_stl_function.h) = 2757a988fb0a19825abb9963dc236effa9e3ea80
+SHA1 (patch-libstdc++-v3_include_c_global_cmath) = 24ec0941fcad205ce090b969a90ce5e85e235775
+SHA1 (patch-libstdc++-v3_include_c_global_cstring) = 0a87e7939448957bb352d8a50d5d3cb07f2f9a5d
+SHA1 (patch-libstdc++-v3_include_c_global_cwchar) = 9408c1876183fa3f9d4440acdc96217c8a47ed87
+SHA1 (patch-libstdc++-v3_libsupc++_new__opa.cc) = 4183b00a5ee6e61524da4755c825a0c08fd01ed6
+SHA1 (patch-libstdc++-v3_src_c++11_system_error.cc) = 2c4b5326f4a4f518b202055aa3fbcc76c27f51dd
diff --git a/gcc-bootstrap/patches/patch-contrib_download__prerequisites b/gcc-bootstrap/patches/patch-contrib_download__prerequisites
new file mode 100644
index 0000000000..4dd8261487
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-contrib_download__prerequisites
@@ -0,0 +1,17 @@
+$NetBSD: patch-contrib_download__prerequisites,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Non-portable test
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90142
+
+--- contrib/download_prerequisites.orig	2017-04-11 16:34:07.000000000 +0000
++++ contrib/download_prerequisites
+@@ -122,7 +122,7 @@ md5_check() {
+   md5_checksum_output=$(md5 -r "${file_to_check}")
+   # Grab the text before the first space
+   md5_checksum_detected="${md5_checksum_output%% *}"
+-  [ "${md5_checksum_expected}" == "${md5_checksum_detected}" ] \
++  [ "${md5_checksum_expected}" = "${md5_checksum_detected}" ] \
+     || die "Cannot verify integrity of possibly corrupted file ${file_to_check}"
+   echo "${file_to_check}: OK"
+ }
diff --git a/gcc-bootstrap/patches/patch-fixincludes_inclhack.def b/gcc-bootstrap/patches/patch-fixincludes_inclhack.def
new file mode 100644
index 0000000000..016230209b
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-fixincludes_inclhack.def
@@ -0,0 +1,36 @@
+$NetBSD: patch-fixincludes_inclhack.def,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+A workaround for Catalina SDK bug from
+https://github.com/Homebrew/homebrew-core/pull/44762
+
+--- fixincludes/inclhack.def.orig	2020-03-04 08:29:59.000000000 +0000
++++ fixincludes/inclhack.def
+@@ -1269,6 +1269,28 @@ fix = {
+ };
+ 
+ /*
++ *  macOS 10.15 <Availability.h> does not define __OSX_AVAILABLE_STARTING on
++ *  non-clang compilers.
++ */
++fix = {
++    hackname  = darwin_availability;
++    mach      = "*-*-darwin*";
++    files     = Availability.h;
++    select    = "#endif /\\* __OSX_AVAILABLE_STARTING \\*/";
++    c_fix     = format;
++    c_fix_arg = <<- _EOFix_
++	#endif /* __OSX_AVAILABLE_STARTING */
++	#ifndef __OSX_AVAILABLE_STARTING
++	  #define __OSX_AVAILABLE_STARTING(_osx, _ios)
++	  #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep)
++	  #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg)
++	#endif
++	_EOFix_;
++
++    test_text = "#endif /* __OSX_AVAILABLE_STARTING */";
++};
++
++/*
+  *  macOS 10.12 <AvailabilityInternal.h> uses __attribute__((availability))
+  *  unconditionally.
+  */
diff --git a/gcc-bootstrap/patches/patch-gcc_Makefile.in b/gcc-bootstrap/patches/patch-gcc_Makefile.in
new file mode 100644
index 0000000000..7b39375e8a
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_Makefile.in
@@ -0,0 +1,15 @@
+$NetBSD: patch-gcc_Makefile.in,v 1.4 2025/01/10 11:57:07 riastradh Exp $
+
+Add a hack to increase the stack for genautomata on QNX.
+
+--- gcc/Makefile.in.orig	2023-07-07 10:08:18.855156357 +0300
++++ gcc/Makefile.in	2025-08-06 16:11:38.341539562 +0300
+@@ -2860,7 +2860,7 @@
+ genprog = $(genprogerr) check checksum match
+ 
+ # These programs need libs over and above what they get from the above list.
+-build/genautomata$(build_exeext) : BUILD_LIBS += -lm
++build/genautomata$(build_exeext) : BUILD_LIBS += -lm $(GENAUTOMATA_LDFLAGS)
+ 
+ build/genrecog$(build_exeext) : build/hash-table.o build/inchash.o
+ build/gencfn-macros$(build_exeext) : build/hash-table.o build/vec.o \
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_Makefile.rtl b/gcc-bootstrap/patches/patch-gcc_ada_Makefile.rtl
new file mode 100644
index 0000000000..80a4e96f0f
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_Makefile.rtl
@@ -0,0 +1,147 @@
+$NetBSD: patch-gcc_ada_Makefile.rtl,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Add NetBSD as a target and generate the required files correctly.
+
+--- gcc/ada/Makefile.rtl.orig	2021-04-08 13:56:27.725736525 +0200
++++ gcc/ada/Makefile.rtl	2021-10-09 18:43:45.974586137 +0200
+@@ -1739,6 +1739,131 @@
+   MISCLIB = -lutil
+ endif
+ 
++# x86 NetBSD
++ifeq ($(strip $(filter-out %86 netbsd%,$(target_cpu) $(target_os))),)
++  LIBGNAT_TARGET_PAIRS = \
++  a-intnam.ads<libgnarl/a-intnam__freebsd.ads \
++  s-inmaop.adb<libgnarl/s-inmaop__posix.adb \
++  s-intman.adb<libgnarl/s-intman__posix.adb \
++  s-mudido.adb<libgnarl/s-mudido__affinity.adb \
++  s-osinte.adb<libgnarl/s-osinte__netbsd.adb \
++  s-osinte.ads<libgnarl/s-osinte__netbsd.ads \
++  s-osprim.adb<libgnat/s-osprim__posix.adb \
++  s-taprop.adb<libgnarl/s-taprop__posix.adb \
++  s-taspri.ads<libgnarl/s-taspri__posix.ads \
++  s-tpopsp.adb<libgnarl/s-tpopsp__posix.adb \
++  g-socthi.adb<libgnat/g-socthi__bsd.adb \
++  $(TRASYM_DWARF_UNIX_PAIRS) \
++  $(ATOMICS_TARGET_PAIRS) \
++  $(X86_64_TARGET_PAIRS) \
++  system.ads<libgnat/system-freebsd.ads
++
++  GNATLIB_SHARED = gnatlib-shared-dual
++
++  EXTRA_GNATRTL_NONTASKING_OBJS += g-sse.o g-ssvety.o
++  EXTRA_GNATRTL_NONTASKING_OBJS += $(TRASYM_DWARF_UNIX_OBJS)
++
++  EH_MECHANISM=-gcc
++  THREADSLIB= -lpthread -lrt
++  GMEM_LIB = gmemlib
++  LIBRARY_VERSION := $(LIB_VERSION)
++  MISCLIB = -lutil
++endif
++
++
++# x86-64 NetBSD
++ifeq ($(strip $(filter-out %86_64 netbsd%,$(target_cpu) $(target_os))),)
++  LIBGNAT_TARGET_PAIRS = \
++  a-intnam.ads<libgnarl/a-intnam__freebsd.ads \
++  s-inmaop.adb<libgnarl/s-inmaop__posix.adb \
++  s-intman.adb<libgnarl/s-intman__posix.adb \
++  s-mudido.adb<libgnarl/s-mudido__affinity.adb \
++  s-osinte.adb<libgnarl/s-osinte__netbsd.adb \
++  s-osinte.ads<libgnarl/s-osinte__netbsd.ads \
++  s-osprim.adb<libgnat/s-osprim__posix.adb \
++  s-taprop.adb<libgnarl/s-taprop__posix.adb \
++  s-taspri.ads<libgnarl/s-taspri__posix.ads \
++  s-tpopsp.adb<libgnarl/s-tpopsp__posix.adb \
++  g-socthi.adb<libgnat/g-socthi__bsd.adb \
++  $(TRASYM_DWARF_UNIX_PAIRS) \
++  $(ATOMICS_TARGET_PAIRS) \
++  $(X86_64_TARGET_PAIRS) \
++  system.ads<libgnat/system-freebsd.ads
++
++  GNATLIB_SHARED = gnatlib-shared-dual
++
++  EXTRA_GNATRTL_NONTASKING_OBJS += g-sse.o g-ssvety.o
++  EXTRA_GNATRTL_NONTASKING_OBJS += $(TRASYM_DWARF_UNIX_OBJS)
++
++  EH_MECHANISM=-gcc
++  THREADSLIB= -lpthread -lrt
++  GMEM_LIB = gmemlib
++  LIBRARY_VERSION := $(LIB_VERSION)
++  MISCLIB = -lutil
++endif
++
++# arm NetBSD
++ifeq ($(strip $(filter-out %arm netbsd%,$(target_cpu) $(target_os))),)
++  LIBGNAT_TARGET_PAIRS = \
++  a-intnam.ads<libgnarl/a-intnam__freebsd.ads \
++  s-inmaop.adb<libgnarl/s-inmaop__posix.adb \
++  s-intman.adb<libgnarl/s-intman__posix.adb \
++  s-mudido.adb<libgnarl/s-mudido__affinity.adb \
++  s-osinte.adb<libgnarl/s-osinte__netbsd.adb \
++  s-osinte.ads<libgnarl/s-osinte__netbsd.ads \
++  s-osprim.adb<libgnat/s-osprim__posix.adb \
++  s-taprop.adb<libgnarl/s-taprop__posix.adb \
++  s-taspri.ads<libgnarl/s-taspri__posix.ads \
++  s-tpopsp.adb<libgnarl/s-tpopsp__posix.adb \
++  g-socthi.adb<libgnat/g-socthi__bsd.adb \
++  $(TRASYM_DWARF_UNIX_PAIRS) \
++  $(ATOMICS_TARGET_PAIRS) \
++  $(X86_64_TARGET_PAIRS) \
++  system.ads<libgnat/system-freebsd.ads
++
++  GNATLIB_SHARED = gnatlib-shared-dual
++
++  EXTRA_GNATRTL_NONTASKING_OBJS += g-sse.o g-ssvety.o
++  EXTRA_GNATRTL_NONTASKING_OBJS += $(TRASYM_DWARF_UNIX_OBJS)
++
++  EH_MECHANISM=-gcc
++  THREADSLIB= -lpthread -lrt
++  GMEM_LIB = gmemlib
++  LIBRARY_VERSION := $(LIB_VERSION)
++  MISCLIB = -lutil
++endif
++
++# aarch64 NetBSD
++ifeq ($(strip $(filter-out %aarch64 netbsd%,$(target_cpu) $(target_os))),)
++  LIBGNAT_TARGET_PAIRS = \
++  a-intnam.ads<libgnarl/a-intnam__freebsd.ads \
++  s-inmaop.adb<libgnarl/s-inmaop__posix.adb \
++  s-intman.adb<libgnarl/s-intman__posix.adb \
++  s-mudido.adb<libgnarl/s-mudido__affinity.adb \
++  s-osinte.adb<libgnarl/s-osinte__netbsd.adb \
++  s-osinte.ads<libgnarl/s-osinte__netbsd.ads \
++  s-osprim.adb<libgnat/s-osprim__posix.adb \
++  s-taprop.adb<libgnarl/s-taprop__posix.adb \
++  s-taspri.ads<libgnarl/s-taspri__posix.ads \
++  s-tpopsp.adb<libgnarl/s-tpopsp__posix.adb \
++  g-socthi.adb<libgnat/g-socthi__bsd.adb \
++  $(TRASYM_DWARF_UNIX_PAIRS) \
++  $(ATOMICS_TARGET_PAIRS) \
++  $(X86_64_TARGET_PAIRS) \
++  system.ads<libgnat/system-freebsd.ads
++
++  GNATLIB_SHARED = gnatlib-shared-dual
++
++  EXTRA_GNATRTL_NONTASKING_OBJS += g-sse.o g-ssvety.o
++  EXTRA_GNATRTL_NONTASKING_OBJS += $(TRASYM_DWARF_UNIX_OBJS)
++
++  EH_MECHANISM=-gcc
++  THREADSLIB= -lpthread -lrt
++  GMEM_LIB = gmemlib
++  LIBRARY_VERSION := $(LIB_VERSION)
++  MISCLIB = -lutil
++endif
++
+ # x86-64 DragonFly
+ ifeq ($(strip $(filter-out %86_64 dragonfly%,$(target_cpu) $(target_os))),)
+   LIBGNAT_TARGET_PAIRS = \
+@@ -2502,7 +2627,7 @@
+       s-osprim.adb<libgnat/s-osprim__darwin.adb \
+       $(ATOMICS_TARGET_PAIRS) \
+       system.ads<libgnat/system-darwin-x86.ads
+-
++p
+     ifeq ($(strip $(MULTISUBDIR)),/x86_64)
+       SO_OPTS += -m64
+       LIBGNAT_TARGET_PAIRS += $(X86_64_TARGET_PAIRS)
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_adaint.c b/gcc-bootstrap/patches/patch-gcc_ada_adaint.c
new file mode 100644
index 0000000000..bba40b4fd9
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_adaint.c
@@ -0,0 +1,88 @@
+$NetBSD: patch-gcc_ada_adaint.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+NetBSD does not use symbol versioning, which requires some functions
+to be preprocessed in C. This patch adds those functions definitions,
+not only for NetBSD, but for any other system too.
+
+--- gcc/ada/adaint.c.orig	2023-07-07 10:08:18.875156655 +0300
++++ gcc/ada/adaint.c
+@@ -817,7 +817,8 @@
+ }
+ 
+ #if defined (_WIN32) || defined (__linux__) || defined (__sun__) \
+-  || defined (__FreeBSD__) || defined(__DragonFly__) || defined (__QNX__)
++  || defined (__FreeBSD__) || defined(__DragonFly__) || defined (__QNX__) \
++  || defined (__NetBSD__)
+ #define HAS_TARGET_WCHAR_T
+ #endif
+ 
+@@ -3544,6 +3545,69 @@
+   */
+ }
+ 
++#if defined(__NetBSD__)
++/* It's 2021, and NetBSD still doesn't use symbol versioning in their
++ * libraries.  They mimic this by having header macros rename the function
++ * at compile time.  If we don't wrap the functions, the osinte specification
++ * for NetBSD would need to import e.g. __sigaltstack14 instead of sigaltstack.
++ * By wrapping, new versions won't break gnat.
++ */
++int
++__gnat_sigemptyset (sigset_t *set) {
++   return sigemptyset (set);
++}
++int
++__gnat_sigfillset (sigset_t *set) {
++   return sigfillset (set);
++}
++int
++__gnat_sigaddset (sigset_t *set, int signo) {
++   return sigaddset (set, signo);
++}
++int
++__gnat_sigdelset (sigset_t *set, int signo) {
++   return sigdelset (set, signo);
++}
++int
++__gnat_sigismember (sigset_t *set, int signo) {
++   return sigismember (set, signo);
++}
++int
++__gnat_sigaltstack (const stack_t *ss, stack_t *oss) {
++   return sigaltstack (ss, oss);
++}
++int
++__gnat_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) {
++   return sigaction (sig, act, oact);
++}
++int
++__gnat_clock_getres (clockid_t clock_id, struct timespec *res) {
++   return clock_getres (clock_id, res);
++}
++int
++__gnat_clock_gettime (clockid_t clock_id, struct timespec *tp) {
++   return clock_gettime (clock_id, tp);
++}
++int
++__gnat_nanosleep (const struct timespec *rqtp, struct timespec *rmtp) {
++   return nanosleep (rqtp, rmtp);
++}
++int
++__gnat_gettimeofday (struct timeval * tp, struct timezone * tzp) {
++   return gettimeofday (tp, tzp);
++}
++
++int
++__gnat_select(int nfds, fd_set * readfds, fd_set * writefds,
++              fd_set * exceptfds, struct timeval * timeout) {
++   return select (nfds, readfds, writefds, exceptfds, timeout);
++}
++int
++__gnat_socket (int domain, int type, int protocol) {
++   return socket (domain, type, protocol);
++}
++#endif
++
+ #ifdef __cplusplus
+ }
+ #endif
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_adaint.h b/gcc-bootstrap/patches/patch-gcc_ada_adaint.h
new file mode 100644
index 0000000000..0daf039ee3
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_adaint.h
@@ -0,0 +1,35 @@
+$NetBSD: patch-gcc_ada_adaint.h,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Due to the lack of symbol versioning in NetBSD, some functions need
+to be exported from C to be used correctly. This patch addresses
+that issue and makes sure that other systems also work correclty.
+
+--- gcc/ada/adaint.h.orig	2023-07-07 10:08:18.875156655 +0300
++++ gcc/ada/adaint.h
+@@ -345,6 +345,26 @@
+ 
+ extern const void * __gnat_get_executable_load_address  (void);
+ 
++#if defined(__NetBSD__)
++#include <signal.h>
++extern int    __gnat_sigemptyset (sigset_t *);
++extern int    __gnat_sigfillset  (sigset_t *);
++extern int    __gnat_sigaddset   (sigset_t *, int);
++extern int    __gnat_sigdelset   (sigset_t *, int);
++extern int    __gnat_sigismember (sigset_t *, int);
++extern int    __gnat_sigaltstack (const stack_t *, stack_t *);
++extern int    __gnat_sigaction   (int, const struct sigaction *, struct sigaction *);
++#include <time.h>
++extern int    __gnat_nanosleep     (const struct timespec *, struct timespec *);
++extern int    __gnat_gettimeofday  (struct timeval *, struct timezone *);
++#include <sys/select.h>
++extern int    __gnat_select        (int, fd_set *, fd_set *, fd_set *, struct timeval *);
++#include <sys/socket.h>
++extern int    __gnat_socket        (int, int, int);
++extern int    __gnat_clock_getres  (clockid_t, struct timespec *);
++extern int    __gnat_clock_gettime (clockid_t, struct timespec *);
++#endif
++
+ #ifdef __cplusplus
+ }
+ #endif
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_cstreams.c b/gcc-bootstrap/patches/patch-gcc_ada_cstreams.c
new file mode 100644
index 0000000000..d911712299
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_cstreams.c
@@ -0,0 +1,25 @@
+$NetBSD: patch-gcc_ada_cstreams.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Add missing defines
+
+--- gcc/ada/cstreams.c.orig	2021-08-28 18:42:21.323680378 +0000
++++ gcc/ada/cstreams.c	2021-08-28 18:43:48.045445919 +0000
+@@ -188,7 +188,8 @@
+ 	  *p = '\\';
+     }
+ 
+-#elif defined (__FreeBSD__) || defined (__DragonFly__) || defined (__OpenBSD__)
++#elif defined (__FreeBSD__) || defined (__DragonFly__) \
++  || defined (__OpenBSD__) || defined (__NetBSD__)
+ 
+   /* Use realpath function which resolves links and references to . and ..
+      on those Unix systems that support it. Note that GNU/Linux provides it but
+@@ -270,7 +271,7 @@
+ }
+ 
+ #elif defined (__linux__) || defined (__sun__) || defined (__FreeBSD__) \
+-  || defined (__APPLE__)
++  || defined (__APPLE__) || defined (__NetBSD__)
+ /* section for platforms having ftello/fseeko */
+ 
+ __int64
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-osinte____netbsd.adb b/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-osinte____netbsd.adb
new file mode 100644
index 0000000000..570255eb5b
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-osinte____netbsd.adb
@@ -0,0 +1,147 @@
+$NetBSD: patch-gcc_ada_libgnarl_s-osinte____netbsd.adb,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Add NetBSD interface.
+
+--- gcc/ada/libgnarl/s-osinte__netbsd.adb.orig	2021-10-08 11:29:30.470090202 +0200
++++ gcc/ada/libgnarl/s-osinte__netbsd.adb	2021-10-08 11:29:30.472274837 +0200
+@@ -0,0 +1,140 @@
++------------------------------------------------------------------------------
++--                                                                          --
++--                  GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                --
++--                                                                          --
++--                   S Y S T E M . O S _ I N T E R F A C E                  --
++--                                                                          --
++--                                   B o d y                                --
++--                                                                          --
++--          Copyright (C) 1991-2015, Free Software Foundation, Inc.         --
++--                                                                          --
++-- GNARL is free software; you can  redistribute it  and/or modify it under --
++-- terms of the  GNU General Public License as published  by the Free Soft- --
++-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
++-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
++-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
++-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
++--                                                                          --
++-- As a special exception under Section 7 of GPL version 3, you are granted --
++-- additional permissions described in the GCC Runtime Library Exception,   --
++-- version 3.1, as published by the Free Software Foundation.               --
++--                                                                          --
++-- You should have received a copy of the GNU General Public License and    --
++-- a copy of the GCC Runtime Library Exception along with this program;     --
++-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
++-- <http://www.gnu.org/licenses/>.                                          --
++--                                                                          --
++-- GNARL was developed by the GNARL team at Florida State University. It is --
++-- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
++-- State University (http://www.gnat.com).                                  --
++--                                                                          --
++------------------------------------------------------------------------------
++
++--  This is the NetBSD THREADS version of this package
++
++with Interfaces.C; use Interfaces.C;
++
++package body System.OS_Interface is
++
++   -----------
++   -- Errno --
++   -----------
++
++   function Errno return int is
++      type int_ptr is access all int;
++
++      function internal_errno return int_ptr;
++      pragma Import (C, internal_errno, "__errno");
++
++   begin
++      return (internal_errno.all);
++   end Errno;
++
++   --------------------
++   -- Get_Stack_Base --
++   --------------------
++
++   function Get_Stack_Base (thread : pthread_t) return Address is
++      pragma Unreferenced (thread);
++   begin
++      return Null_Address;
++   end Get_Stack_Base;
++
++   ------------------
++   -- pthread_init --
++   ------------------
++
++   procedure pthread_init is
++   begin
++      null;
++   end pthread_init;
++
++   -----------------------------------
++   -- pthread_mutexattr_setprotocol --
++   -----------------------------------
++
++   function pthread_mutexattr_setprotocol
++     (attr     : access pthread_mutexattr_t;
++      protocol : int) return int is
++      pragma Unreferenced (attr, protocol);
++   begin
++      return 0;
++   end pthread_mutexattr_setprotocol;
++
++   --------------------------------------
++   -- pthread_mutexattr_setprioceiling --
++   --------------------------------------
++
++   function pthread_mutexattr_setprioceiling
++     (attr     : access pthread_mutexattr_t;
++      prioceiling : int) return int is
++      pragma Unreferenced (attr, prioceiling);
++   begin
++      return 0;
++   end pthread_mutexattr_setprioceiling;
++
++   -----------------
++   -- To_Duration --
++   -----------------
++
++   function To_Duration (TS : timespec) return Duration is
++   begin
++      return Duration (TS.ts_sec) + Duration (TS.ts_nsec) / 10#1#E9;
++   end To_Duration;
++
++   ------------------------
++   -- To_Target_Priority --
++   ------------------------
++
++   function To_Target_Priority
++     (Prio : System.Any_Priority) return Interfaces.C.int
++   is
++   begin
++      return Interfaces.C.int (Prio);
++   end To_Target_Priority;
++
++   -----------------
++   -- To_Timespec --
++   -----------------
++
++   function To_Timespec (D : Duration) return timespec is
++      S : time_t;
++      F : Duration;
++
++   begin
++      S := time_t (Long_Long_Integer (D));
++      F := D - Duration (S);
++
++      --  If F has negative value due to a round-up, adjust for positive F
++      --  value.
++
++      if F < 0.0 then
++         S := S - 1;
++         F := F + 1.0;
++      end if;
++
++      return timespec'(ts_sec => S,
++                       ts_nsec => long (Long_Long_Integer (F * 10#1#E9)));
++   end To_Timespec;
++
++end System.OS_Interface;
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-osinte____netbsd.ads b/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-osinte____netbsd.ads
new file mode 100644
index 0000000000..457dbd4db5
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-osinte____netbsd.ads
@@ -0,0 +1,670 @@
+$NetBSD: patch-gcc_ada_libgnarl_s-osinte____netbsd.ads,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Add NetBSD interface.
+
+--- gcc/ada/libgnarl/s-osinte__netbsd.ads.orig	2021-10-08 11:29:30.503927461 +0200
++++ gcc/ada/libgnarl/s-osinte__netbsd.ads	2021-10-09 18:31:14.947869872 +0200
+@@ -0,0 +1,663 @@
++------------------------------------------------------------------------------
++--                                                                          --
++--                  GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                --
++--                                                                          --
++--                   S Y S T E M . O S _ I N T E R F A C E                  --
++--                                                                          --
++--                                   S p e c                                --
++--                                                                          --
++--             Copyright (C) 1991-1994, Florida State University            --
++--          Copyright (C) 1995-2015, Free Software Foundation, Inc.         --
++--                                                                          --
++-- GNAT is free software;  you can  redistribute it  and/or modify it under --
++-- terms of the  GNU General Public License as published  by the Free Soft- --
++-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
++-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
++-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
++-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
++--                                                                          --
++-- As a special exception under Section 7 of GPL version 3, you are granted --
++-- additional permissions described in the GCC Runtime Library Exception,   --
++-- version 3.1, as published by the Free Software Foundation.               --
++--                                                                          --
++-- You should have received a copy of the GNU General Public License and    --
++-- a copy of the GCC Runtime Library Exception along with this program;     --
++-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
++-- <http://www.gnu.org/licenses/>.                                          --
++--                                                                          --
++-- GNARL was developed by the GNARL team at Florida State University. It is --
++-- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
++-- State University (http://www.gnat.com).                                  --
++--                                                                          --
++------------------------------------------------------------------------------
++
++--  This is the NetBSD PTHREADS version of this package.
++
++--  This package encapsulates all direct interfaces to OS services
++--  that are needed by the tasking run-time (libgnarl).
++
++--  PLEASE DO NOT add any with-clauses to this package or remove the pragma
++--  Preelaborate. This package is designed to be a bottom-level (leaf) package.
++
++with Ada.Unchecked_Conversion;
++
++with Interfaces.C;
++with System.OS_Constants;
++
++package System.OS_Interface is
++   pragma Preelaborate;
++
++   pragma Linker_Options ("-pthread");
++
++   subtype int            is Interfaces.C.int;
++   subtype short          is Interfaces.C.short;
++   subtype long           is Interfaces.C.long;
++   subtype unsigned       is Interfaces.C.unsigned;
++   subtype unsigned_short is Interfaces.C.unsigned_short;
++   subtype unsigned_long  is Interfaces.C.unsigned_long;
++   subtype unsigned_char  is Interfaces.C.unsigned_char;
++   subtype plain_char     is Interfaces.C.plain_char;
++   subtype size_t         is Interfaces.C.size_t;
++   subtype char_array     is Interfaces.C.char_array;
++   subtype int64          is Interfaces.Integer_64;
++
++   -----------
++   -- Errno --
++   -----------
++
++   function Errno return int;
++   pragma Inline (Errno);
++
++   EAGAIN    : constant := 35;
++   EINTR     : constant := 4;
++   EINVAL    : constant := 22;
++   ENOMEM    : constant := 12;
++   ETIMEDOUT : constant := 60;
++
++   -------------
++   -- Signals --
++   -------------
++
++   Max_Interrupt : constant := 31;
++   type Signal is new int range 0 .. Max_Interrupt;
++   for Signal'Size use int'Size;
++
++   SIGHUP     : constant := 1; --  hangup
++   SIGINT     : constant := 2; --  interrupt (rubout)
++   SIGQUIT    : constant := 3; --  quit (ASCD FS)
++   SIGILL     : constant := 4; --  illegal instruction (not reset)
++   SIGTRAP    : constant := 5; --  trace trap (not reset)
++   SIGIOT     : constant := 6; --  IOT instruction
++   SIGABRT    : constant := 6; --  used by abort, replace SIGIOT in the  future
++   SIGEMT     : constant := 7; --  EMT instruction
++   SIGFPE     : constant := 8; --  floating point exception
++   SIGKILL    : constant := 9; --  kill (cannot be caught or ignored)
++   SIGBUS     : constant := 10; --  bus error
++   SIGSEGV    : constant := 11; --  segmentation violation
++   SIGSYS     : constant := 12; --  bad argument to system call
++   SIGPIPE    : constant := 13; --  write on a pipe with no one to read it
++   SIGALRM    : constant := 14; --  alarm clock
++   SIGTERM    : constant := 15; --  software termination signal from kill
++   SIGURG     : constant := 16; --  urgent condition on IO channel
++   SIGSTOP    : constant := 17; --  stop (cannot be caught or ignored)
++   SIGTSTP    : constant := 18; --  user stop requested from tty
++   SIGCONT    : constant := 19; --  stopped process has been continued
++   SIGCLD     : constant := 20; --  alias for SIGCHLD
++   SIGCHLD    : constant := 20; --  child status change
++   SIGTTIN    : constant := 21; --  background tty read attempted
++   SIGTTOU    : constant := 22; --  background tty write attempted
++   SIGIO      : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
++   SIGXCPU    : constant := 24; --  CPU time limit exceeded
++   SIGXFSZ    : constant := 25; --  filesize limit exceeded
++   SIGVTALRM  : constant := 26; --  virtual timer expired
++   SIGPROF    : constant := 27; --  profiling time alarm
++   SIGWINCH   : constant := 28; --  window size change
++   SIGINFO    : constant := 29; --  information request (NetBSD/FreeBSD)
++   SIGUSR1    : constant := 30; --  user defined signal 1
++   SIGUSR2    : constant := 31; --  user defined signal 2
++
++   SIGADAABORT : constant := SIGABRT;
++   --  Change this if you want to use another signal for task abort.
++   --  SIGTERM might be a good one.
++
++   type Signal_Set is array (Natural range <>) of Signal;
++
++   --  Interrupts that must be unmasked at all times.  NetBSD
++   --  pthreads will not allow an application to mask out any
++   --  interrupt needed by the threads library.
++   Unmasked : constant Signal_Set :=
++     (SIGTRAP, SIGBUS, SIGTTIN, SIGTTOU, SIGTSTP);
++
++   --  NetBSD will uses SIGPROF for timing.  Do not allow a
++   --  handler to attach to this signal.
++   Reserved : constant Signal_Set := (0 .. 0 => SIGPROF);
++
++   type sigset_t is private;
++
++   function sigaddset
++     (set : access sigset_t;
++      sig : Signal) return int;
++   pragma Import (C, sigaddset, "__gnat_sigaddset");
++
++   function sigdelset
++     (set : access sigset_t;
++      sig : Signal) return int;
++   pragma Import (C, sigdelset, "__gnat_sigdelset");
++
++   function sigfillset (set : access sigset_t) return int;
++   pragma Import (C, sigfillset, "__gnat_sigfillset");
++
++   function sigismember
++     (set : access sigset_t;
++      sig : Signal) return int;
++   pragma Import (C, sigismember, "__gnat_sigismember");
++
++   function sigemptyset (set : access sigset_t) return int;
++   pragma Import (C, sigemptyset, "__gnat_sigemptyset");
++
++   --  sigcontext is architecture dependent, so define it private
++   type struct_sigcontext is private;
++
++   --  ??? This is the current definition of struct_sigaction
++   --  as of 2021/10/02 in signal.h
++   type old_struct_sigaction is record
++      sa_handler : System.Address;
++      sa_mask    : sigset_t;
++      sa_flags   : int;
++   end record;
++   pragma Convention (C, old_struct_sigaction);
++
++   --  This is an incorrect struct as of 2021/10/02
++   type new_struct_sigaction is record
++      sa_handler : System.Address;
++      sa_flags   : int;
++      sa_mask    : sigset_t;
++   end record;
++   pragma Convention (C, new_struct_sigaction);
++
++   --  Corrected to use old_struct_sigaction 2021/10/02
++   subtype struct_sigaction is old_struct_sigaction;
++   type struct_sigaction_ptr is access all struct_sigaction;
++
++   SIG_BLOCK   : constant := 1;
++   SIG_UNBLOCK : constant := 2;
++   SIG_SETMASK : constant := 3;
++
++   SIG_DFL  : constant := 0;
++   SIG_IGN  : constant := 1;
++   --  Added for completeness
++   SIG_ERR  : constant := -1;
++   SIG_HOLD : constant := 3;
++
++   SA_SIGINFO : constant := 16#0040#;
++   SA_ONSTACK : constant := 16#0001#;
++
++   function sigaction
++     (sig  : Signal;
++      act  : struct_sigaction_ptr;
++      oact : struct_sigaction_ptr) return int;
++   pragma Import (C, sigaction, "__gnat_sigaction");
++
++   ----------
++   -- Time --
++   ----------
++
++   Time_Slice_Supported : constant Boolean := True;
++   --  Indicates whether time slicing is supported (i.e SCHED_RR is supported)
++
++   type timespec is private;
++
++   function nanosleep (rqtp, rmtp : access timespec) return int;
++   pragma Import (C, nanosleep, "__gnat_nanosleep");
++
++   type clockid_t is new unsigned;
++
++   function clock_getres
++     (clock_id : clockid_t;
++      res      : access timespec) return int;
++   pragma Import (C, clock_getres, "__gnat_clock_getres");
++
++   function clock_gettime
++     (clock_id : clockid_t;
++      tp       : access timespec)
++      return int;
++   pragma Import (C, clock_gettime, "__gnat_clock_gettime");
++
++   function To_Duration (TS : timespec) return Duration;
++   pragma Inline (To_Duration);
++
++   function To_Timespec (D : Duration) return timespec;
++   pragma Inline (To_Timespec);
++
++   type struct_timezone is record
++      tz_minuteswest : int;
++      tz_dsttime     : int;
++   end record;
++   pragma Convention (C, struct_timezone);
++
++   -------------------------
++   -- Priority Scheduling --
++   -------------------------
++
++   SCHED_OTHER : constant := 0;
++   SCHED_FIFO  : constant := 1;
++   SCHED_RR    : constant := 2;
++
++   function To_Target_Priority
++     (Prio : System.Any_Priority) return Interfaces.C.int;
++   --  Maps System.Any_Priority to a POSIX priority
++
++   -------------
++   -- Process --
++   -------------
++
++   type pid_t is private;
++
++   function kill (pid : pid_t; sig : Signal) return int;
++   pragma Import (C, kill, "__gnat_kill");
++
++   function getpid return pid_t;
++   pragma Import (C, getpid, "getpid");
++
++   ---------
++   -- LWP --
++   ---------
++
++   function lwp_self return System.Address;
++   --  lwp_self does not exist on this thread library, revert to pthread_self
++   --  which is the closest approximation (with getpid). This function is
++   --  needed to share s-taprop.adb across POSIX-like targets.
++   pragma Import (C, lwp_self, "pthread_self");
++
++   -------------
++   -- Threads --
++   -------------
++
++   type Thread_Body is access
++     function (arg : System.Address) return System.Address;
++   pragma Convention (C, Thread_Body);
++
++   function Thread_Body_Access is new
++     Ada.Unchecked_Conversion (System.Address, Thread_Body);
++
++   type pthread_t           is private;
++   subtype Thread_Id        is pthread_t;
++
++   type pthread_mutex_t      is limited private;
++   type pthread_cond_t       is limited private;
++   type pthread_attr_t       is limited private;
++   type pthread_mutexattr_t  is limited private;
++   type pthread_condattr_t   is limited private;
++   type pthread_rwlock_t     is limited private;
++   type pthread_rwlockattr_t is limited private;
++   type pthread_key_t        is private;
++
++   PTHREAD_CREATE_DETACHED : constant := 1;
++   PTHREAD_CREATE_JOINABLE : constant := 0;
++
++   PTHREAD_SCOPE_PROCESS : constant := 0;
++   PTHREAD_SCOPE_SYSTEM  : constant := 1;
++
++   -----------
++   -- Stack --
++   -----------
++
++   type stack_t is record
++      ss_sp    : System.Address;
++      ss_size  : size_t;
++      ss_flags : int;
++   end record;
++   pragma Convention (C, stack_t);
++
++   function sigaltstack
++     (ss  : not null access stack_t;
++      oss : access stack_t) return int;
++   pragma Import (C, sigaltstack, "__gnat_sigaltstack");
++
++   Alternate_Stack : aliased System.Address;
++   --  This is a dummy definition, never used (Alternate_Stack_Size is null)
++
++   Alternate_Stack_Size : constant := 0;
++   --  No alternate signal stack is used on this platform
++
++   Stack_Base_Available : constant Boolean := False;
++   --  Indicates whether the stack base is available on this target. This
++   --  allows us to share s-osinte.adb between all the FSU run time. Note that
++   --  this value can only be true if pthread_t has a complete definition that
++   --  corresponds exactly to the C header files.
++
++   function Get_Stack_Base (thread : pthread_t) return Address;
++   pragma Inline (Get_Stack_Base);
++   --  returns the stack base of the specified thread. Only call this function
++   --  when Stack_Base_Available is True.
++
++   function Get_Page_Size return int;
++   pragma Import (C, Get_Page_Size, "_getpagesize");
++   --  Returns the size of a page
++
++   PROT_NONE  : constant := 0;
++   PROT_READ  : constant := 1;
++   PROT_WRITE : constant := 2;
++   PROT_EXEC  : constant := 4;
++   PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC;
++   PROT_ON    : constant := PROT_NONE;
++   PROT_OFF   : constant := PROT_ALL;
++
++   function mprotect (addr : Address; len : size_t; prot : int) return int;
++   pragma Import (C, mprotect);
++
++   ---------------------------------------
++   -- Nonstandard Thread Initialization --
++   ---------------------------------------
++
++   --  FSU_THREADS requires pthread_init, which is nonstandard and this should
++   --  be invoked during the elaboration of s-taprop.adb.
++
++   --  NetBSD does not require this so we provide an empty Ada body
++
++   procedure pthread_init;
++
++   -------------------------
++   -- POSIX.1c  Section 3 --
++   -------------------------
++
++   function sigwait
++     (set : access sigset_t;
++      sig : access Signal) return int;
++   pragma Import (C, sigwait, "sigwait");
++
++   function pthread_kill
++     (thread : pthread_t;
++      sig    : Signal) return int;
++   pragma Import (C, pthread_kill, "pthread_kill");
++
++   function pthread_sigmask
++     (how  : int;
++      set  : access sigset_t;
++      oset : access sigset_t) return int;
++   pragma Import (C, pthread_sigmask, "pthread_sigmask");
++
++   --------------------------
++   -- POSIX.1c  Section 11 --
++   --------------------------
++
++   function pthread_mutexattr_init
++     (attr : access pthread_mutexattr_t) return int;
++   pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
++
++   function pthread_mutexattr_destroy
++     (attr : access pthread_mutexattr_t) return int;
++   pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
++
++   function pthread_mutex_init
++     (mutex : access pthread_mutex_t;
++      attr  : access pthread_mutexattr_t) return int;
++   pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
++
++   function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
++   pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
++
++   function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
++   pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
++
++   function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
++   pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
++
++   function pthread_condattr_init
++     (attr : access pthread_condattr_t) return int;
++   pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
++
++   function pthread_condattr_destroy
++     (attr : access pthread_condattr_t) return int;
++   pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
++
++   function pthread_cond_init
++     (cond : access pthread_cond_t;
++      attr : access pthread_condattr_t) return int;
++   pragma Import (C, pthread_cond_init, "pthread_cond_init");
++
++   function pthread_cond_destroy (cond : access pthread_cond_t) return int;
++   pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
++
++   function pthread_cond_signal (cond : access pthread_cond_t) return int;
++   pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
++
++   function pthread_cond_wait
++     (cond  : access pthread_cond_t;
++      mutex : access pthread_mutex_t) return int;
++   pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
++
++   function pthread_cond_timedwait
++     (cond    : access pthread_cond_t;
++      mutex   : access pthread_mutex_t;
++      abstime : access timespec) return int;
++   pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
++
++   Relative_Timed_Wait : constant Boolean := False;
++   --  pthread_cond_timedwait requires an absolute delay time
++
++   --------------------------
++   -- POSIX.1c  Section 13 --
++   --------------------------
++
++   PTHREAD_PRIO_NONE    : constant := 0;
++   PTHREAD_PRIO_INHERIT : constant := 1;
++   PTHREAD_PRIO_PROTECT : constant := 2;
++
++   function pthread_mutexattr_setprotocol
++     (attr     : access pthread_mutexattr_t;
++      protocol : int) return int;
++
++   function pthread_mutexattr_setprioceiling
++     (attr     : access pthread_mutexattr_t;
++      prioceiling : int) return int;
++
++   type struct_sched_param is record
++      sched_priority : int;
++   end record;
++   pragma Convention (C, struct_sched_param);
++
++   function pthread_getschedparam
++     (thread : pthread_t;
++      policy : access int;
++      param  : access struct_sched_param) return int;
++   pragma Import (C, pthread_getschedparam, "pthread_getschedparam");
++
++   function pthread_setschedparam
++     (thread : pthread_t;
++      policy : int;
++      param  : access struct_sched_param) return int;
++   pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
++
++   function pthread_attr_setscope
++     (attr            : access pthread_attr_t;
++      contentionscope : int) return int;
++   pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
++
++   function pthread_attr_getscope
++     (attr            : access pthread_attr_t;
++      contentionscope : access int) return int;
++   pragma Import (C, pthread_attr_getscope, "pthread_attr_getscope");
++
++   function pthread_attr_setinheritsched
++     (attr            : access pthread_attr_t;
++      inheritsched : int) return int;
++   pragma Import
++     (C, pthread_attr_setinheritsched, "pthread_attr_setinheritsched");
++
++   function pthread_attr_getinheritsched
++     (attr         : access pthread_attr_t;
++      inheritsched : access int) return int;
++   pragma Import
++     (C, pthread_attr_getinheritsched, "pthread_attr_getinheritsched");
++
++   function pthread_attr_setschedpolicy
++     (attr   : access pthread_attr_t;
++      policy : int) return int;
++   pragma Import (C, pthread_attr_setschedpolicy,
++     "pthread_attr_setschedpolicy");
++
++   function pthread_attr_getschedpolicy
++     (attr   : access pthread_attr_t;
++      policy : access int) return int;
++   pragma Import (C, pthread_attr_getschedpolicy,
++     "pthread_attr_getschedpolicy");
++
++   function pthread_attr_setschedparam
++     (attr        : access pthread_attr_t;
++      sched_param : int) return int;
++   pragma Import (C, pthread_attr_setschedparam, "pthread_attr_setschedparam");
++
++   function pthread_attr_getschedparam
++     (attr        : access pthread_attr_t;
++      sched_param : access int) return int;
++   pragma Import (C, pthread_attr_getschedparam, "pthread_attr_getschedparam");
++
++   function sched_yield return int;
++   pragma Import (C, sched_yield, "sched_yield");
++
++   --------------------------
++   -- P1003.1c  Section 16 --
++   --------------------------
++
++   function pthread_attr_init (attributes : access pthread_attr_t) return int;
++   pragma Import (C, pthread_attr_init, "pthread_attr_init");
++
++   function pthread_attr_destroy
++     (attributes : access pthread_attr_t) return int;
++   pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
++
++   function pthread_attr_setdetachstate
++     (attr        : access pthread_attr_t;
++      detachstate : int) return int;
++   pragma Import
++     (C, pthread_attr_setdetachstate, "pthread_attr_setdetachstate");
++
++   function pthread_attr_getdetachstate
++     (attr        : access pthread_attr_t;
++      detachstate : access int) return int;
++   pragma Import
++     (C, pthread_attr_getdetachstate, "pthread_attr_getdetachstate");
++
++   function pthread_attr_getstacksize
++     (attr      : access pthread_attr_t;
++      stacksize : access size_t) return int;
++   pragma Import
++     (C, pthread_attr_getstacksize, "pthread_attr_getstacksize");
++
++   function pthread_attr_setstacksize
++     (attr      : access pthread_attr_t;
++      stacksize : size_t) return int;
++   pragma Import
++     (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
++
++   function pthread_create
++     (thread        : access pthread_t;
++      attributes    : access pthread_attr_t;
++      start_routine : Thread_Body;
++      arg           : System.Address) return int;
++   pragma Import (C, pthread_create, "pthread_create");
++
++   function pthread_detach (thread : pthread_t) return int;
++   pragma Import (C, pthread_detach, "pthread_detach");
++
++   procedure pthread_exit (status : System.Address);
++   pragma Import (C, pthread_exit, "pthread_exit");
++
++   function pthread_self return pthread_t;
++   pragma Import (C, pthread_self, "pthread_self");
++
++   --------------------------
++   -- POSIX.1c  Section 17 --
++   --------------------------
++
++   function pthread_setspecific
++     (key   : pthread_key_t;
++      value : System.Address) return  int;
++   pragma Import (C, pthread_setspecific, "pthread_setspecific");
++
++   function pthread_getspecific (key : pthread_key_t) return System.Address;
++   pragma Import (C, pthread_getspecific, "pthread_getspecific");
++
++   type destructor_pointer is access procedure (arg : System.Address);
++   pragma Convention (C, destructor_pointer);
++
++   function pthread_key_create
++     (key        : access pthread_key_t;
++      destructor : destructor_pointer) return int;
++   pragma Import (C, pthread_key_create, "pthread_key_create");
++
++private
++
++   type sigset_t is array (1 .. 4) of unsigned;
++
++   --  In NetBSD the component sa_handler turns out to
++   --  be one a union type, and the selector is a macro:
++   --  #define sa_handler __sigaction_u._handler
++   --  #define sa_sigaction __sigaction_u._sigaction
++
++   --  Should we add a signal_context type here ???
++   --  How could it be done independent of the CPU architecture ???
++   --  sigcontext type is opaque, so it is architecturally neutral.
++   --  It is always passed as an access type, so define it as an empty record
++   --  since the contents are not used anywhere.
++
++   type struct_sigcontext is null record;
++   pragma Convention (C, struct_sigcontext);
++
++   type pid_t is new int;
++
++   type time_t is new int64;
++
++   type timespec is record
++      ts_sec  : time_t;
++      ts_nsec : long;
++   end record;
++   pragma Convention (C, timespec);
++
++   type pthread_t     is new System.Address;
++   type pthread_key_t is new int;
++
++   type pthread_attr_t is record
++      Data : char_array (1 .. System.OS_Constants.PTHREAD_ATTR_SIZE);
++   end record;
++   pragma Convention (C, pthread_attr_t);
++   for pthread_attr_t'Alignment use size_t'Alignment;
++
++   type pthread_mutex_t is record
++      Data : char_array (1 .. System.OS_Constants.PTHREAD_MUTEX_SIZE);
++   end record;
++   pragma Convention (C, pthread_mutex_t);
++   for pthread_mutex_t'Alignment use size_t'Alignment;
++
++   type pthread_mutexattr_t is record
++      Data : char_array (1 .. System.OS_Constants.PTHREAD_MUTEXATTR_SIZE);
++   end record;
++   pragma Convention (C, pthread_mutexattr_t);
++   for pthread_mutexattr_t'Alignment use size_t'Alignment;
++
++   type pthread_cond_t is record
++      Data : char_array (1 .. System.OS_Constants.PTHREAD_COND_SIZE);
++   end record;
++   pragma Convention (C, pthread_cond_t);
++   for pthread_cond_t'Alignment use size_t'Alignment;
++
++   type pthread_condattr_t is record
++      Data : char_array (1 .. System.OS_Constants.PTHREAD_CONDATTR_SIZE);
++   end record;
++   pragma Convention (C, pthread_condattr_t);
++   for pthread_condattr_t'Alignment use size_t'Alignment;
++
++   type pthread_rwlock_t is record
++      Data : char_array (1 .. System.OS_Constants.PTHREAD_RWLOCK_SIZE);
++   end record;
++   pragma Convention (C, pthread_rwlock_t);
++   for pthread_rwlock_t'Alignment use size_t'Alignment;
++
++   type pthread_rwlockattr_t is record
++      Data : char_array (1 .. System.OS_Constants.PTHREAD_RWLOCKATTR_SIZE);
++   end record;
++   pragma Convention (C, pthread_rwlockattr_t);
++   for pthread_rwlockattr_t'Alignment use size_t'Alignment;
++
++end System.OS_Interface;
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-taprop____posix.adb b/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-taprop____posix.adb
new file mode 100644
index 0000000000..af50017808
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_libgnarl_s-taprop____posix.adb
@@ -0,0 +1,27 @@
+$NetBSD: patch-gcc_ada_libgnarl_s-taprop____posix.adb,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+When using SCHED_OTHER, the minimum and maximum in NetBSD is -1.
+In most other OSs it is 0. Change the behaviour to try to set the
+params using the default priority, if that fails, use 0, otherwise
+use -1. If none are valid, the tasking system will fail if assertions
+are on.
+
+--- gcc/ada/libgnarl/s-taprop__posix.adb.orig	2021-09-23 19:55:24.471842046 +0000
++++ gcc/ada/libgnarl/s-taprop__posix.adb	2021-09-23 20:01:31.689253592 +0000
+@@ -654,6 +654,16 @@
+       else
+          Result := pthread_setschedparam
+            (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
++         if Result /= 0 then
++            Param.sched_priority := 0;
++            Result := pthread_setschedparam
++              (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
++            if Result /= 0 then
++               Param.sched_priority := -1;
++               Result := pthread_setschedparam
++                 (T.Common.LL.Thread, SCHED_OTHER, Param'Access);
++            end if;
++         end if;
+       end if;
+ 
+       pragma Assert (Result = 0);
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_libgnat_g-socthi.ads b/gcc-bootstrap/patches/patch-gcc_ada_libgnat_g-socthi.ads
new file mode 100644
index 0000000000..7e3a4bb9dd
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_libgnat_g-socthi.ads
@@ -0,0 +1,15 @@
+$NetBSD: patch-gcc_ada_libgnat_g-socthi.ads,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Fix symbol to make it use the C processed one.
+
+--- gcc/ada/libgnat/g-socthi.ads.orig	2023-07-07 10:08:19.039159092 +0300
++++ gcc/ada/libgnat/g-socthi.ads
+@@ -53,8 +53,6 @@
+ 
+    package C renames Interfaces.C;
+ 
+-   use type System.CRTL.ssize_t;
+-
+    function Socket_Errno return Integer renames GNAT.OS_Lib.Errno;
+    --  Returns last socket error number
+ 
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_libgnat_g-socthi____bsd.adb b/gcc-bootstrap/patches/patch-gcc_ada_libgnat_g-socthi____bsd.adb
new file mode 100644
index 0000000000..c2e895a16b
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_libgnat_g-socthi____bsd.adb
@@ -0,0 +1,363 @@
+$NetBSD: patch-gcc_ada_libgnat_g-socthi____bsd.adb,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Create a g-socthi package that is common to all *BSD systems.
+
+--- /dev/null	2021-10-09 18:50:23.845256363 +0200
++++ gcc/ada/libgnat/g-socthi__bsd.adb	2021-10-09 18:07:08.069557825 +0200
+@@ -0,0 +1,356 @@
++------------------------------------------------------------------------------
++--                                                                          --
++--                         GNAT COMPILER COMPONENTS                         --
++--                                                                          --
++--                    G N A T . S O C K E T S . T H I N                     --
++--                                                                          --
++--                                 B o d y                                  --
++--                                                                          --
++--                     Copyright (C) 2001-2018, AdaCore                     --
++--                                                                          --
++-- GNAT is free software;  you can  redistribute it  and/or modify it under --
++-- terms of the  GNU General Public License as published  by the Free Soft- --
++-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
++-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
++-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
++-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
++--                                                                          --
++-- As a special exception under Section 7 of GPL version 3, you are granted --
++-- additional permissions described in the GCC Runtime Library Exception,   --
++-- version 3.1, as published by the Free Software Foundation.               --
++--                                                                          --
++-- You should have received a copy of the GNU General Public License and    --
++-- a copy of the GCC Runtime Library Exception along with this program;     --
++-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
++-- <http://www.gnu.org/licenses/>.                                          --
++--                                                                          --
++-- GNAT was originally developed  by the GNAT team at  New York University. --
++-- Extensive contributions were provided by Ada Core Technologies Inc.      --
++--                                                                          --
++------------------------------------------------------------------------------
++
++--  This package provides a target dependent thin interface to the sockets
++--  layer for use by the GNAT.Sockets package (g-socket.ads). This package
++--  should not be directly with'ed by an applications program.
++
++--  This is the *BSD version which uses fcntl rather than ioctl
++--  The constant SCON.Thread_Blocking_IO is always true (for all platforms, not
++--  just *BSD), so this binding is significantly simpler than the standard
++--  one it replaces.
++
++with GNAT.OS_Lib; use GNAT.OS_Lib;
++
++with Interfaces.C; use Interfaces.C;
++
++package body GNAT.Sockets.Thin is
++
++   function Syscall_Accept
++     (S       : C.int;
++      Addr    : System.Address;
++      Addrlen : not null access C.int) return C.int;
++   pragma Import (C, Syscall_Accept, "accept");
++   --  The accept() function accepts a connection on a socket.  An incoming
++   --  connection is acknowledged and associated with an immediately created
++   --  socket.  The original socket is returned to the listening state.
++
++   function Syscall_Connect
++     (S       : C.int;
++      Name    : System.Address;
++      Namelen : C.int) return C.int;
++   pragma Import (C, Syscall_Connect, "connect");
++   --  The connect() system call initiates a connection on a socket.  If the
++   --  parameter S is of type SOCK_DGRAM then connect() permanently specifies
++   --  the peer to which datagrams are to be sent.  If S is type SOCK_STREAM
++   --  then connect() attempts to make a connection with another socket, which
++   --  is identified by the parameter Name.
++
++   function Syscall_Recv
++     (S     : C.int;
++      Msg   : System.Address;
++      Len   : C.int;
++      Flags : C.int) return C.int;
++   pragma Import (C, Syscall_Recv, "recv");
++   --  The recv() function receives a message from a socket.  The call can be
++   --  used on a connection mode socket or a bound, connectionless socket.  If
++   --  no messages are available at the socket, the recv() call waits for a
++   --  message to arrive unless the socket is non-blocking.  If a socket is
++   --  non-blocking, the call returns a -1 and ERRNO is set to EWOULDBLOCK.
++
++   function Syscall_Recvfrom
++     (S       : C.int;
++      Msg     : System.Address;
++      Len     : C.int;
++      Flags   : C.int;
++      From    : System.Address;
++      Fromlen : not null access C.int) return C.int;
++   pragma Import (C, Syscall_Recvfrom, "recvfrom");
++   --  The recvfrom() system call receives a message from a socket and captures
++   --  the address from which the data was sent.  It can be used to receive
++   --  data on an unconnected socket as well.  If no messages are available,
++   --  the call waits for a message to arrive on blocking sockets.  For
++   --  non-blocking sockets without messages, -1 is returned and ERRNO is set
++   --  to EAGAIN or EWOULDBLOCK.
++
++   function Syscall_Recvmsg
++     (S     : C.int;
++      Msg   : System.Address;
++      Flags : C.int) return System.CRTL.ssize_t;
++   pragma Import (C, Syscall_Recvmsg, "recvmsg");
++   --  The recvmsg call receives a message from a socket, and can be used to
++   --  receive data on an unconnected socket as well.  If no messages are
++   --  available, the call waits for a message to arrive on blocking sockets.
++   --  For non-blocking sockets without messages, -1 is returned and ERRNO is
++   --  set to EAGAIN or EWOULDBLOCK.
++
++   function Syscall_Sendmsg
++     (S     : C.int;
++      Msg   : System.Address;
++      Flags : C.int) return System.CRTL.ssize_t;
++   pragma Import (C, Syscall_Sendmsg, "sendmsg");
++   --  The sendmsg() function sends a message to a socket, and can be used with
++   --  unconnected sockets as well (the msg is ignored in this case).  The
++   --  function returns the number of bytes sent when successful, otherwise it
++   --  returns -1 and ERRNO is set (many possible values).
++
++   function Syscall_Sendto
++     (S     : C.int;
++      Msg   : System.Address;
++      Len   : C.int;
++      Flags : C.int;
++      To    : System.Address;
++      Tolen : C.int) return C.int;
++   pragma Import (C, Syscall_Sendto, "sendto");
++   --  The sendto() function only works for connected sockets and it initiates
++   --  the transmission of a message.  A successful call returns the numbers of
++   --  bytes sent, and a failure returns a -1 and ERRNO is set.
++
++   function Syscall_Socket
++     (Domain   : C.int;
++      Typ      : C.int;
++      Protocol : C.int) return C.int;
++   pragma Import (C, Syscall_Socket, "socket");
++   --  The socket() function is used to create an unbound socket and returns a
++   --  file descriptor that can be used with other socket functions.  Upon
++   --  failure, a -1 is returned and ERRNO is set.
++
++   procedure Disable_SIGPIPE (S : C.int);
++   pragma Import (C, Disable_SIGPIPE, "__gnat_disable_sigpipe");
++
++   procedure Disable_All_SIGPIPEs;
++   pragma Import (C, Disable_All_SIGPIPEs, "__gnat_disable_all_sigpipes");
++   --  Sets the process to ignore all SIGPIPE signals on platforms that
++   --  don't support Disable_SIGPIPE for particular streams.
++
++   function C_Fcntl
++     (Fd  : C.int;
++      Cmd : C.int;
++      Val : C.int) return C.int;
++   pragma Import (C, C_Fcntl, "fcntl");
++   --  The ioctl of 64-bit DragonFlyBSD, OpenBSD, and NetBSD does not support
++   --  setting a socket in non-blocking mode.  fcntl must be used instead.
++
++   --------------
++   -- C_Accept --
++   --------------
++
++   function C_Accept
++     (S       : C.int;
++      Addr    : System.Address;
++      Addrlen : not null access C.int) return C.int
++   is
++      R : constant C.int := Syscall_Accept (S, Addr, Addrlen);
++   begin
++
++      Disable_SIGPIPE (R);
++      return R;
++   end C_Accept;
++
++   ---------------
++   -- C_Connect --
++   ---------------
++
++   function C_Connect
++     (S       : C.int;
++      Name    : System.Address;
++      Namelen : C.int) return C.int
++   is
++   begin
++      return Syscall_Connect (S, Name, Namelen);
++   end C_Connect;
++
++   ------------------
++   -- Socket_Ioctl --
++   ------------------
++
++   function Socket_Ioctl
++     (S   : C.int;
++      Req : SOSC.IOCTL_Req_T;
++      Arg : access C.int) return C.int
++   is
++   begin
++      if Req = SOSC.FIONBIO then
++         declare
++            use Interfaces;
++            flags    : constant Unsigned_32 :=
++                                Unsigned_32 (C_Fcntl (S, SOSC.F_GETFL, 0));
++            nonblock : constant Unsigned_32 := Unsigned_32 (SOSC.O_NDELAY);
++            enabled  : constant Boolean := Arg.all = 1;
++            newval   : C.int := C.int (flags);
++         begin
++            if enabled then
++               newval := C.int (flags or nonblock);
++            elsif (flags and nonblock) > 0 then
++               newval := C.int (flags - nonblock);
++            end if;
++            return C_Fcntl (Fd => S, Cmd => SOSC.F_SETFL, Val => newval);
++         end;
++      end if;
++
++      return C_Ioctl (S, Req, Arg);
++   end Socket_Ioctl;
++
++   ------------
++   -- C_Recv --
++   ------------
++
++   function C_Recv
++     (S     : C.int;
++      Msg   : System.Address;
++      Len   : C.int;
++      Flags : C.int) return C.int
++   is
++   begin
++      return Syscall_Recv (S, Msg, Len, Flags);
++   end C_Recv;
++
++   ----------------
++   -- C_Recvfrom --
++   ----------------
++
++   function C_Recvfrom
++     (S       : C.int;
++      Msg     : System.Address;
++      Len     : C.int;
++      Flags   : C.int;
++      From    : System.Address;
++      Fromlen : not null access C.int) return C.int
++   is
++   begin
++      return Syscall_Recvfrom (S, Msg, Len, Flags, From, Fromlen);
++   end C_Recvfrom;
++
++   ---------------
++   -- C_Recvmsg --
++   ---------------
++
++   function C_Recvmsg
++     (S     : C.int;
++      Msg   : System.Address;
++      Flags : C.int) return System.CRTL.ssize_t
++   is
++   begin
++      return Syscall_Recvmsg (S, Msg, Flags);
++   end C_Recvmsg;
++
++   ---------------
++   -- C_Sendmsg --
++   ---------------
++
++   function C_Sendmsg
++     (S     : C.int;
++      Msg   : System.Address;
++      Flags : C.int) return System.CRTL.ssize_t
++   is
++   begin
++      return Syscall_Sendmsg (S, Msg, Flags);
++   end C_Sendmsg;
++
++   --------------
++   -- C_Sendto --
++   --------------
++
++   function C_Sendto
++     (S     : C.int;
++      Msg   : System.Address;
++      Len   : C.int;
++      Flags : C.int;
++      To    : System.Address;
++      Tolen : C.int) return C.int
++   is
++   begin
++      return Syscall_Sendto (S, Msg, Len, Flags, To, Tolen);
++   end C_Sendto;
++
++   --------------
++   -- C_Socket --
++   --------------
++
++   function C_Socket
++     (Domain   : C.int;
++      Typ      : C.int;
++      Protocol : C.int) return C.int
++   is
++      R : constant C.int := Syscall_Socket (Domain, Typ, Protocol);
++   begin
++      Disable_SIGPIPE (R);
++      return R;
++   end C_Socket;
++
++   --------------
++   -- Finalize --
++   --------------
++
++   procedure Finalize is
++   begin
++      null;
++   end Finalize;
++
++   -------------------------
++   -- Host_Error_Messages --
++   -------------------------
++
++   package body Host_Error_Messages is separate;
++
++   ----------------
++   -- Initialize --
++   ----------------
++
++   procedure Initialize is
++   begin
++      Disable_All_SIGPIPEs;
++   end Initialize;
++
++   --------------------
++   -- Signalling_Fds --
++   --------------------
++
++   package body Signalling_Fds is
++
++      --  In this default implementation, we use a C version of these
++      --  subprograms provided by socket.c.
++
++      function C_Create (Fds : not null access Fd_Pair) return C.int;
++      function C_Read (Rsig : C.int) return C.int;
++      function C_Write (Wsig : C.int) return C.int;
++      procedure C_Close (Sig : C.int);
++
++      pragma Import (C, C_Create, "__gnat_create_signalling_fds");
++      pragma Import (C, C_Read,   "__gnat_read_signalling_fd");
++      pragma Import (C, C_Write,  "__gnat_write_signalling_fd");
++      pragma Import (C, C_Close,  "__gnat_close_signalling_fd");
++
++      function Create
++        (Fds : not null access Fd_Pair) return C.int renames C_Create;
++      function Read (Rsig : C.int) return C.int renames C_Read;
++      function Write (Wsig : C.int) return C.int renames C_Write;
++      procedure Close (Sig : C.int) renames C_Close;
++
++   end Signalling_Fds;
++
++   --------------------------
++   -- Socket_Error_Message --
++   --------------------------
++
++   function Socket_Error_Message (Errno : Integer) return String is separate;
++
++end GNAT.Sockets.Thin;
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_s-oscons-tmplt.c b/gcc-bootstrap/patches/patch-gcc_ada_s-oscons-tmplt.c
new file mode 100644
index 0000000000..0f7ba56165
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_s-oscons-tmplt.c
@@ -0,0 +1,94 @@
+$NetBSD: patch-gcc_ada_s-oscons-tmplt.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Add NetBSD to some defined parts and bump the version of
+_XOPEN_SOURCE and add _NETBSD_SOURCE.
+
+--- gcc/ada/s-oscons-tmplt.c.orig	2021-04-08 13:56:27.913738795 +0200
++++ gcc/ada/s-oscons-tmplt.c	2021-10-09 18:26:07.630440685 +0200
+@@ -86,16 +86,25 @@
+  ** a number of non-POSIX but useful/required features.
+  **/
+ 
+-#if defined (__linux__) || defined (__ANDROID__)
++#if defined (__linux__) || defined (__ANDROID__) \
++  || defined (__FreeBSD__) || defined (__NetBSD__) \
++  || defined (__DragonFly__) || defined (__OpenBSD__)
+ 
+ /* Define _XOPEN_SOURCE to get IOV_MAX */
++/* We use 520 since NetBSD does not include getaddrinfo flags with only 500 */
+ # if !defined (_XOPEN_SOURCE)
+-#  define _XOPEN_SOURCE 500
++#  define _XOPEN_SOURCE 520
+ # endif
+ 
+ /* Define _BSD_SOURCE to get CRTSCTS */
+ # define _BSD_SOURCE
+ 
++/* NetBSD requires _NETBSD_SOURCE to be defined in order to include */
++/* NI_MAX{HOST,SERV} correctly */
++# if defined (__NetBSD__)
++#  define _NETBSD_SOURCE
++# endif
++
+ #endif /* defined (__linux__) */
+ 
+ /* Include gsocket.h before any system header so it can redefine FD_SETSIZE */
+@@ -158,7 +167,8 @@
+ #endif
+ 
+ #if defined (__linux__) || defined (__ANDROID__) || defined (__QNX__) \
+-  || defined (__rtems__)
++  || defined (__rtems__) || defined (__FreeBSD__) || defined (__NetBSD__) \
++  || defined (__OpenBSD__) || defined (__DragonFly__)
+ # include <pthread.h>
+ # include <signal.h>
+ #endif
+@@ -406,11 +416,14 @@
+ 
+ */
+ 
+-/* ioctl(2) requests are "int" in UNIX, but "unsigned long" on FreeBSD */
++/* ioctl(2) requests are "int" in UNIX, but "unsigned long" on FreeBSD
++   and NetBSD
++*/
+ 
+-#if defined (__FreeBSD__) || defined (__DragonFly__)
++#if defined (__FreeBSD__) || defined (__DragonFly__) || defined (__NetBSD__) \
++  || defined (__OpenBSD__)
+ # define CNI CNU
+-# define IOCTL_Req_T "Interfaces.C.unsigned"
++# define IOCTL_Req_T "Interfaces.C.unsigned_long"
+ #else
+ # define CNI CND
+ # define IOCTL_Req_T "Interfaces.C.int"
+@@ -1020,7 +1033,8 @@
+ 
+ */
+ 
+-#if defined (__FreeBSD__) || defined (__linux__) || defined (__DragonFly__)
++#if defined (__FreeBSD__) || defined (__linux__) || defined (__DragonFly__) \
++  || defined (__NetBSD__) || defined (__OpenBSD__)
+ # define PTY_Library "-lutil"
+ #else
+ # define PTY_Library ""
+@@ -1833,7 +1847,8 @@
+ 
+ #if defined(__linux__) || defined(__FreeBSD__) \
+  || (defined(_AIX) && defined(_AIXVERSION_530)) \
+- || defined(__DragonFly__) || defined(__QNX__)
++ || defined(__DragonFly__) || defined(__QNX__) \
++ || defined (__NetBSD__) || defined (__OpenBSD__)
+ /** On these platforms use system provided monotonic clock instead of
+  ** the default CLOCK_REALTIME. We then need to set up cond var attributes
+  ** appropriately (see thread.c).
+@@ -1855,7 +1870,9 @@
+ #endif
+ 
+ #if defined (__APPLE__) || defined (__linux__) || defined (__ANDROID__) \
+-  || defined (__QNX__) || defined (__rtems__) || defined (DUMMY)
++  || defined (__QNX__) || defined (__rtems__) || defined (DUMMY) \
++  || defined (__FreeBSD__) || defined (__DragonFly__) \
++  || defined (__NetBSD__) || defined (__OpenBSD__)
+ /*
+ 
+    --  Sizes of pthread data types
diff --git a/gcc-bootstrap/patches/patch-gcc_ada_sysdep.c b/gcc-bootstrap/patches/patch-gcc_ada_sysdep.c
new file mode 100644
index 0000000000..be7663276a
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ada_sysdep.c
@@ -0,0 +1,42 @@
+$NetBSD: patch-gcc_ada_sysdep.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Add NetBSD to some defined sections.
+
+--- gcc/ada/sysdep.c.orig	2021-08-28 13:11:25.681014624 +0000
++++ gcc/ada/sysdep.c	2021-08-28 13:21:14.748176113 +0000
+@@ -320,7 +320,7 @@
+   || (defined (__svr4__) && defined (__i386__)) || defined (__Lynx__) \
+   || defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
+   || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
+-  || defined (__QNX__)
++  || defined (__QNX__) || defined (__NetBSD__)
+ 
+ # ifdef __MINGW32__
+ #  if OLD_MINGW
+@@ -373,7 +373,7 @@
+     || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
+     || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
+     || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
+-    || defined (__QNX__)
++    || defined (__QNX__) || defined (__NetBSD__)
+   char c;
+   int nread;
+   int good_one = 0;
+@@ -394,7 +394,7 @@
+     || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
+     || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
+     || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
+-    || defined (__QNX__)
++    || defined (__QNX__) || defined (__NetBSD__)
+       eof_ch = termios_rec.c_cc[VEOF];
+ 
+       /* If waiting (i.e. Get_Immediate (Char)), set MIN = 1 and wait for
+@@ -831,7 +831,7 @@
+ 
+ #elif defined (__APPLE__) || defined (__FreeBSD__) || defined (__linux__) \
+   || defined (__GLIBC__) || defined (__DragonFly__) || defined (__OpenBSD__) \
+-  || defined (__DJGPP__) || defined (__QNX__)
++  || defined (__DJGPP__) || defined (__QNX__) || defined (__NetBSD__)
+ {
+   localtime_r (timer, &tp);
+   *off = tp.tm_gmtoff;
diff --git a/gcc-bootstrap/patches/patch-gcc_config.gcc b/gcc-bootstrap/patches/patch-gcc_config.gcc
new file mode 100644
index 0000000000..3413dc46d1
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config.gcc
@@ -0,0 +1,250 @@
+$NetBSD: patch-gcc_config.gcc,v 1.5 2024/04/01 14:33:57 js Exp $
+
+Match what is in NetBSD src. Fixes at least aarch64eb, and
+probably several others.
+
+Allow builds on Darwin 21.
+
+Fix build on QNX.
+
+--- gcc/config.gcc.orig	2023-07-07 07:08:19.000000000 +0000
++++ gcc/config.gcc
+@@ -462,6 +462,16 @@ m32r*-*-*)
+         cpu_type=m32r
+ 	extra_options="${extra_options} g.opt"
+         ;;
++m5200-*-*|m5407-*-*)
++	cpu_type=m68k
++	extra_headers=math-68881.h
++	extra_options="${extra_options} m68k/m68k-tables.opt"
++	;;
++m680[012]0-*-*)
++	cpu_type=m68k
++	extra_headers=math-68881.h
++	extra_options="${extra_options} m68k/m68k-tables.opt"
++	;;
+ m68k-*-*)
+ 	extra_headers=math-68881.h
+ 	extra_options="${extra_options} m68k/m68k-tables.opt"
+@@ -891,6 +901,11 @@ case ${target} in
+   case ${enable_threads} in
+     "" | yes | posix) thread_file='posix' ;;
+   esac
++  case ${target} in
++    arm*-* | i[34567]86-* | powerpc*-* | sparc*-* | x86_64-*)
++      default_gnu_indirect_function=yes
++      ;;
++  esac
+   nbsd_tm_file="netbsd.h netbsd-stdint.h netbsd-elf.h"
+   default_use_cxa_atexit=yes
+   target_has_targetdm=yes
+@@ -1125,6 +1140,11 @@ aarch64*-*-netbsd*)
+ 	tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-netbsd.h"
+ 	tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-netbsd"
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
++	case $target in
++	aarch64_be-*)
++		tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
++		;;
++	esac
+ 	;;
+ aarch64*-*-linux*)
+ 	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h"
+@@ -1266,7 +1286,6 @@ arm*-*-freebsd*)                # ARM Fr
+ 	with_tls=${with_tls:-gnu}
+ 	;;
+ arm*-*-netbsdelf*)
+-	target_cpu_cname="strongarm"
+ 	tmake_file="${tmake_file} arm/t-arm"
+ 	tm_file="dbxelf.h elfos.h ${nbsd_tm_file} arm/elf.h"
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+@@ -1275,26 +1294,34 @@ arm*-*-netbsdelf*)
+ 	esac
+ 	case ${target} in
+ 	arm*-*-netbsdelf-*eabi*)
+-	    tm_file="$tm_file arm/bpabi.h arm/netbsd-elf.h arm/netbsd-eabi.h"
+-	    tmake_file="$tmake_file arm/t-bpabi arm/t-netbsdeabi"
++	    tm_file="${tm_file} arm/bpabi.h arm/netbsd-elf.h arm/netbsd-eabi.h"
++	    #tmake_file="$tmake_file arm/t-bpabi"
++	    # The EABI requires the use of __cxa_atexit.
++	    default_use_cxa_atexit=yes
++	    # NetBSD native configuration pulls this in, not sure why this must
++	    # be here explicitly for pkgsrc.
++	    gcc_cv_initfini_array=yes
+ 	    ;;
+ 	*)
+-	    tm_file="$tm_file arm/netbsd-elf.h"
++	    tm_file="$tm_file arm/bpabi.h arm/netbsd-elf.h"
++	    #tmake_file="$tmake_file arm/t-bpabi arm/t-netbsdeabi"
+ 	    tmake_file="$tmake_file arm/t-netbsd"
+ 	    ;;
+ 	esac
+ 	tm_file="${tm_file} arm/aout.h arm/arm.h"
+ 	case ${target} in
+ 	arm*-*-netbsdelf-*eabihf*)
+-	    # Hard-float requires at least Arm v5te
+-	    target_cpu_cname="arm10e"
+ 	    tm_defines="${tm_defines} TARGET_DEFAULT_FLOAT_ABI=ARM_FLOAT_ABI_HARD"
+ 	    ;;
+ 	esac
+ 	case ${target} in
+-	armv6*) target_cpu_cname="arm1176jzf-s";;
+-	armv7*) target_cpu_cname="generic-armv7-a";;
++	armv4*) with_cpu=${with_cpu:-strongarm};;
++	armv6*) with_cpu=${with_cpu:-arm1176jzf-s};;
++	armv7*) with_cpu=${with_cpu:-cortex-a8};;
++	arm*eabihf*) with_cpu=${with_cpu:-arm10e};;
++	arm*) with_cpu=${with_cpu:-arm9e};;
+ 	esac
++	target_cpu_cname="$with_cpu"
+ 	;;
+ arm*-*-linux-* | arm*-*-uclinuxfdpiceabi)
+ 	tm_file="dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h arm/elf.h arm/linux-gas.h arm/linux-elf.h"
+@@ -1942,6 +1969,7 @@ i[34567]86-*-netbsdelf*)
+ 	;;
+ x86_64-*-netbsd*)
+ 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${nbsd_tm_file} i386/x86-64.h i386/netbsd64.h"
++	tmake_file="${tmake_file} i386/t-netbsd64"
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+ 	;;
+ i[34567]86-*-openbsd*)
+@@ -2072,7 +2100,7 @@ i[34567]86-*-lynxos*)
+ 	gnu_ld=yes
+ 	gas=yes
+ 	;;
+-i[34567]86-*-nto-qnx*)
++i[34567]86-*-qnx*)
+ 	tm_file="${tm_file} i386/att.h dbxelf.h tm-dwarf2.h elfos.h i386/unix.h i386/nto.h"
+ 	extra_options="${extra_options} i386/nto.opt"
+ 	gnu_ld=yes
+@@ -2264,6 +2292,16 @@ ia64*-*-elf*)
+ 		target_cpu_default="${target_cpu_default}|MASK_GNU_LD"
+ 	fi
+ 	;;
++ia64*-*-netbsd*)
++	tm_file="${tm_file} dbxelf.h elfos.h ${nbsd_tm_file} ia64/sysv4.h ia64/netbsd.h"
++	target_cpu_default="MASK_GNU_AS|MASK_GNU_LD"
++	tmake_file="${tmake_file} ia64/t-ia64"
++	if test x$with_system_libunwind != xyes ; then
++		tmake_file="${tmake_file} t-libunwind-elf ia64/t-glibc-libunwind"
++	fi
++	extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o crtfastmath.o"
++	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
++	;;
+ ia64*-*-freebsd*)
+ 	tm_file="${tm_file} dbxelf.h elfos.h ${fbsd_tm_file} ia64/sysv4.h ia64/freebsd.h"
+ 	target_cpu_default="MASK_GNU_AS|MASK_GNU_LD"
+@@ -2376,8 +2414,25 @@ m68k-*-elf* | fido-*-elf*)
+ 		;;
+ 	esac
+ 	;;
+-m68k*-*-netbsdelf*)
++m68010-*-netbsdelf* | m68k-*-netbsdelf* | m5407-*-netbsdelf*)
+ 	default_m68k_cpu=68020
++	case ${target} in
++	m5407*)
++		with_arch=${with_arch:-cf}
++		target_cpu_default="mcf5475"
++#	        target="`echo ${target} | sed 's/m68kcf/m68k/'`"
++		;;
++	m68010*)
++		target_cpu_default="m68010"
++		tmake_file="${tmake_file} m68k/t-m68kelf m68k/t-m68010-netbsd"
++		default_m68k_cpu=68010
++		tmake_file="${tmake_file} m68k/t-floatlib"
++		;;
++	*)
++		with_arch=${with_arch:-m68k}
++		tmake_file="${tmake_file} m68k/t-floatlib"
++		;;
++	esac
+ 	default_cf_cpu=5475
+ 	tm_file="${tm_file} dbxelf.h elfos.h ${nbsd_tm_file} m68k/netbsd-elf.h"
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+@@ -2517,6 +2572,26 @@ riscv*-*-freebsd*)
+ 	# automatically detect that GAS supports it, yet we require it.
+ 	gcc_cv_initfini_array=yes
+ 	;;
++riscv*-*-netbsd*)			# NetBSD RISC-V
++	tm_file="elfos.h ${tm_file} ${nbsd_tm_file} riscv/netbsd.h"
++	tm_defines="${tm_defines} CHAR_FAST8=1 SHORT_FAST16=1"
++	case ${target} in
++	  riscv32*) tm_defines="${tm_defines} TARGET_64BIT_DEFAULT=0" ;;
++	  *) tmake_file="${tmake_file} riscv/t-netbsd64" ;;
++	esac
++	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
++	tmake_file="${tmake_file} riscv/t-riscv"
++	gnu_ld=yes
++	gas=yes
++	gcc_cv_initfini_array=yes
++	;;
++mips64*-*-netbsd*)			# NetBSD/mips64, either endian.
++	target_cpu_default="MASK_ABICALLS|MASK_FLOAT64|MASK_SOFT_FLOAT_ABI"
++	tm_file="elfos.h ${tm_file} mips/elf.h ${nbsd_tm_file} mips/netbsd.h mips/netbsd64.h"
++	tmake_file="${tmake_file} mips/t-netbsd64"
++	tm_defines="${tm_defines} MIPS_ABI_DEFAULT=ABI_N32"
++	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
++	;;
+ mips*-*-netbsd*)			# NetBSD/mips, either endian.
+ 	target_cpu_default="MASK_ABICALLS"
+ 	tm_file="elfos.h ${tm_file} mips/elf.h ${nbsd_tm_file} mips/netbsd.h"
+@@ -2932,11 +3007,24 @@ powerpc*-*-freebsd*)
+ 		;;
+ 	esac
+ 	;;
+-powerpc-*-netbsd*)
+-	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h ${nbsd_tm_file} freebsd-spec.h rs6000/sysv4.h rs6000/netbsd.h"
++powerpc*-*-netbsd*)
++	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h ${nbsd_tm_file} freebsd-spec.h"
++	case ${target} in
++	    powerpc64*)
++		tm_file="rs6000/biarch64.h ${tm_file}"
++		tm_file="${tm_file} rs6000/sysv4.h rs6000/default64.h rs6000/netbsd64.h"
++		tmake_file="${tmake_file} rs6000/t-netbsd64"
++		;;
++	    *)
++		tm_file="${tm_file} rs6000/sysv4.h rs6000/netbsd.h"
++		tmake_file="${tmake_file} rs6000/t-netbsd"
++		;;
++	esac
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+-	tmake_file="${tmake_file} rs6000/t-netbsd"
+-	extra_options="${extra_options} rs6000/sysv4.opt"
++	extra_options="${extra_options} rs6000/sysv4.opt rs6000/linux64.opt"
++	if test x${enable_secureplt} != xno; then
++	    tm_file="rs6000/secureplt.h ${tm_file}"
++	fi
+ 	;;
+ powerpc-*-eabisimaltivec*)
+ 	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/eabi.h rs6000/eabisim.h rs6000/eabialtivec.h"
+@@ -3408,9 +3496,11 @@ sparc64-*-freebsd*|ultrasparc-*-freebsd*
+ sparc64-*-netbsd*)
+ 	tm_file="sparc/biarch64.h ${tm_file}"
+ 	tm_file="${tm_file} dbxelf.h elfos.h sparc/sysv4.h ${nbsd_tm_file} sparc/netbsd-elf.h"
++	tm_file="${tm_file} sparc/default64.h"
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+ 	extra_options="${extra_options} sparc/long-double-switch.opt"
+ 	tmake_file="${tmake_file} sparc/t-sparc sparc/t-netbsd64"
++	with_cpu=ultrasparc
+ 	;;
+ sparc64-*-openbsd*)
+ 	tm_file="sparc/openbsd1-64.h ${tm_file} dbxelf.h elfos.h sparc/sysv4.h sparc/sp64-elf.h"
+@@ -3925,6 +4015,9 @@ if test x$with_cpu = x ; then
+     frv550-*-*linux*)
+       with_cpu=fr550
+       ;;
++    m5200-*-*|m5407-*-*)
++      with_cpu=${default_cf_cpu}
++      ;;
+     m68k*-*-*)
+       case "$with_arch" in
+ 	"cf")
+@@ -4435,7 +4528,7 @@ case "${target}" in
+ 		esac
+ 		;;
+ 
+-	fido-*-* | m68k*-*-*)
++	fido-*-* | m68k*-*-* | m5200-*-* | m5407-*-*)
+ 		supported_defaults="arch cpu"
+ 		case "$with_arch" in
+ 		"" | "m68k"| "cf")
diff --git a/gcc-bootstrap/patches/patch-gcc_config.host b/gcc-bootstrap/patches/patch-gcc_config.host
new file mode 100644
index 0000000000..f31cd0b7e4
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config.host
@@ -0,0 +1,15 @@
+$NetBSD: patch-gcc_config.host,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Add aarch64*-*-netbsd*.
+
+--- gcc/config.host.orig	2020-07-23 06:35:17.316384243 +0000
++++ gcc/config.host
+@@ -99,7 +99,7 @@ case ${host} in
+ esac
+ 
+ case ${host} in
+-  aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia*)
++  aarch64*-*-freebsd* | aarch64*-*-netbsd* | aarch64*-*-linux* | aarch64*-*-fuchsia*)
+     case ${target} in
+       aarch64*-*-*)
+ 	host_extra_gcc_objs="driver-aarch64.o"
diff --git a/gcc-bootstrap/patches/patch-gcc_config_aarch64_aarch64-builtins.c b/gcc-bootstrap/patches/patch-gcc_config_aarch64_aarch64-builtins.c
new file mode 100644
index 0000000000..2132f1a857
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_aarch64_aarch64-builtins.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-gcc_config_aarch64_aarch64-builtins.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+initialise subtarget builtins so cabs*() are renamed.
+https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565289.html
+
+--- gcc/config/aarch64/aarch64-builtins.c.orig	2017-01-20 21:03:41.000000000 +0000
++++ gcc/config/aarch64/aarch64-builtins.c	2018-11-10 00:44:41.905576216 +0000
+@@ -1303,6 +1303,10 @@ aarch64_general_init_builtins (void)
+ 
+   if (TARGET_MEMTAG)
+     aarch64_init_memtag_builtins ();
++
++#ifdef SUBTARGET_INIT_BUILTINS
++  SUBTARGET_INIT_BUILTINS;
++#endif
+ }
+ 
+ /* Implement TARGET_BUILTIN_DECL for the AARCH64_BUILTIN_GENERAL group.  */
diff --git a/gcc-bootstrap/patches/patch-gcc_config_aarch64_aarch64-netbsd.h b/gcc-bootstrap/patches/patch-gcc_config_aarch64_aarch64-netbsd.h
new file mode 100644
index 0000000000..83fdd7cdaa
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_aarch64_aarch64-netbsd.h
@@ -0,0 +1,18 @@
+$NetBSD: patch-gcc_config_aarch64_aarch64-netbsd.h,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Match what is in NetBSD src.  Fixes at least aarch64eb, and
+probably several others.
+
+--- gcc/config/aarch64/aarch64-netbsd.h.orig	2021-04-08 04:56:28.033740243 -0700
++++ gcc/config/aarch64/aarch64-netbsd.h	2021-04-24 00:16:41.451665444 -0700
+@@ -20,6 +20,10 @@
+ #ifndef GCC_AARCH64_NETBSD_H
+ #define GCC_AARCH64_NETBSD_H
+ 
++/* NetBSD malloc(3) does 64, not 128 bytes. */
++#undef MALLOC_ABI_ALIGNMENT
++#define MALLOC_ABI_ALIGNMENT  64
++
+ #define TARGET_LINKER_BIG_EMULATION "aarch64nbsdb"
+ #define TARGET_LINKER_LITTLE_EMULATION "aarch64nbsd"
+ 
diff --git a/gcc-bootstrap/patches/patch-gcc_config_aarch64_driver-aarch64.c b/gcc-bootstrap/patches/patch-gcc_config_aarch64_driver-aarch64.c
new file mode 100644
index 0000000000..ffc08c3dc6
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_aarch64_driver-aarch64.c
@@ -0,0 +1,184 @@
+$NetBSD: patch-gcc_config_aarch64_driver-aarch64.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Match what is in NetBSD src.  Fixes at least aarch64eb, and
+probably several others.
+
+--- gcc/config/aarch64/driver-aarch64.c.orig	2021-04-08 04:56:28.041740341 -0700
++++ gcc/config/aarch64/driver-aarch64.c	2021-04-24 00:16:45.471750258 -0700
+@@ -25,6 +25,7 @@
+ #include "system.h"
+ #include "coretypes.h"
+ #include "tm.h"
++#include "diagnostic-core.h"
+ 
+ /* Defined in common/config/aarch64/aarch64-common.c.  */
+ std::string aarch64_get_extension_string_for_isa_flags (uint64_t, uint64_t);
+@@ -244,6 +245,14 @@
+    ARGC and ARGV are set depending on the actual arguments given
+    in the spec.  */
+ 
++#ifdef __NetBSD__
++/* The NetBSD/arm64 platform may not export linux-style /proc/cpuinfo,
++   but the data is available via a sysctl(3) interface.  */
++#include <sys/param.h>
++#include <sys/sysctl.h>
++#include <aarch64/armreg.h>
++#endif
++
+ const char *
+ host_detect_local_cpu (int argc, const char **argv)
+ {
+@@ -282,6 +291,7 @@
+   if (!arch && !tune && !cpu)
+     goto not_found;
+ 
++#ifndef __NetBSD__
+   fcpu_info = getenv ("GCC_CPUINFO");
+   if (fcpu_info)
+     f = fopen (fcpu_info, "r");
+@@ -374,6 +384,145 @@
+ 
+   fclose (f);
+   f = NULL;
++#else
++  unsigned int curcpu;
++  size_t len;
++  char impl_buf[8];
++  int mib[2], ncpu;
++
++  mib[0] = CTL_HW;
++  mib[1] = HW_NCPU; 
++  len = sizeof(ncpu);
++  if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == -1)
++    goto not_found;
++
++  for (curcpu = 0; curcpu < ncpu; curcpu++)
++    {
++      char path[128];
++      struct aarch64_sysctl_cpu_id id;
++
++      len = sizeof id;
++      snprintf(path, sizeof path, "machdep.cpu%d.cpu_id", curcpu);
++      if (sysctlbyname(path, &id, &len, NULL, 0) != 0)
++        goto not_found;
++
++      unsigned cimp = __SHIFTOUT(id.ac_midr, MIDR_EL1_IMPL);
++      if (cimp == INVALID_IMP)
++        goto not_found;
++
++      if (imp == INVALID_IMP)
++        imp = cimp;
++	/* FIXME: BIG.little implementers are always equal. */
++      else if (imp != cimp)
++        goto not_found;
++  
++      unsigned cvariant = __SHIFTOUT(id.ac_midr, MIDR_EL1_VARIANT);
++      if (!contains_core_p (variants, cvariant))
++        {
++          if (n_variants == 2)
++            goto not_found;
++  
++          variants[n_variants++] = cvariant;
++  	}
++
++      unsigned ccore = __SHIFTOUT(id.ac_midr, MIDR_EL1_PARTNUM);
++      if (!contains_core_p (cores, ccore))
++  	{
++  	  if (n_cores == 2)
++  	    goto not_found;
++  
++  	  cores[n_cores++] = ccore;
++  	}
++
++      if (!tune && !processed_exts)
++        {
++          std::string exts;
++
++	  /* These are all the extensions from aarch64-option-extensions.def.  */
++          if (__SHIFTOUT(id.ac_aa64pfr0, ID_AA64PFR0_EL1_FP) == ID_AA64PFR0_EL1_FP_IMPL)
++	    exts += "fp ";
++          if (__SHIFTOUT(id.ac_aa64pfr0, ID_AA64PFR0_EL1_ADVSIMD) == ID_AA64PFR0_EL1_ADV_SIMD_IMPL)
++	    exts += "asimd ";
++#ifdef ID_AA64ISAR0_EL1_RDM
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_RDM) == ID_AA64ISAR0_EL1_RDM_SQRDML)
++	    exts += "asimdrdm ";
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_DP) == ID_AA64ISAR0_EL1_DP_UDOT)
++	    exts += "asimddp ";
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_FHM) == ID_AA64ISAR0_EL1_FHM_FMLAL)
++	    exts += "asimdfml ";
++#endif
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_AES) == ID_AA64ISAR0_EL1_AES_AES)
++	    exts += "aes ";
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_AES) == ID_AA64ISAR0_EL1_AES_PMUL)
++	    exts += "aes pmull ";
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_CRC32) == ID_AA64ISAR0_EL1_CRC32_CRC32X)
++	    exts += "crc32 ";
++#ifdef ID_AA64ISAR0_EL1_ATOMIC
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_ATOMIC) == ID_AA64ISAR0_EL1_ATOMIC_SWP)
++	    exts += "atomics ";
++#endif
++          if ((__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_SHA1) & ID_AA64ISAR0_EL1_SHA1_SHA1CPMHSU) != 0)
++	    exts += "sha1 ";
++          if ((__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_SHA2) & ID_AA64ISAR0_EL1_SHA2_SHA256HSU) != 0)
++	    exts += "sha2 ";
++#ifdef ID_AA64ISAR0_EL1_SHA2_SHA512HSU
++          if ((__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_SHA2) & ID_AA64ISAR0_EL1_SHA2_SHA512HSU) != 0)
++	    exts += "sha512 ";
++          if ((__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_SHA3) & ID_AA64ISAR0_EL1_SHA3_EOR3) != 0)
++	    exts += "sha3 ";
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_SM3) == ID_AA64ISAR0_EL1_SM3_SM3)
++	    exts += "sm3 ";
++          if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_SM4) == ID_AA64ISAR0_EL1_SM4_SM4)
++	    exts += "sm4 ";
++          if (__SHIFTOUT(id.ac_aa64pfr0, ID_AA64PFR0_EL1_SVE) == ID_AA64PFR0_EL1_SVE_IMPL)
++	    exts += "sve ";
++          if (__SHIFTOUT(id.ac_aa64isar1, ID_AA64ISAR1_EL1_LRCPC) == ID_AA64ISAR1_EL1_LRCPC_PR)
++	    exts += "lrcpc ";
++#endif
++
++          for (i = 0; i < num_exts; i++)
++            {
++	      const char *p = aarch64_extensions[i].feat_string;
++
++	      /* If the feature contains no HWCAPS string then ignore it for the
++		 auto detection.  */
++	      if (*p == '\0')
++		continue;
++
++	      bool enabled = true;
++
++	      /* This may be a multi-token feature string.  We need
++		 to match all parts, which could be in any order.  */
++	      size_t len = strlen (exts.c_str());
++	      do
++		{
++		  const char *end = strchr (p, ' ');
++		  if (end == NULL)
++		    end = strchr (p, '\0');
++		  if (memmem (exts.c_str(), len, p, end - p) == NULL)
++		    {
++		      /* Failed to match this token.  Turn off the
++			 features we'd otherwise enable.  */
++		      enabled = false;
++		      break;
++		    }
++		  if (*end == '\0')
++		    break;
++		  p = end + 1;
++		}
++	      while (1);
++
++              if (enabled)
++                extension_flags |= aarch64_extensions[i].flag;
++              else
++                extension_flags &= ~(aarch64_extensions[i].flag);
++            }
++
++          processed_exts = true;
++	}
++    }
++  /* End of NetBSD specific section.  */
++#endif
+ 
+   /* Weird cpuinfo format that we don't know how to handle.  */
+   if (n_cores == 0
diff --git a/gcc-bootstrap/patches/patch-gcc_config_arm_arm.h b/gcc-bootstrap/patches/patch-gcc_config_arm_arm.h
new file mode 100644
index 0000000000..8978522653
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_arm_arm.h
@@ -0,0 +1,45 @@
+$NetBSD: patch-gcc_config_arm_arm.h,v 1.1 2022/02/02 22:07:28 mrg Exp $
+
+--- gcc/config/arm/arm.h.orig	2021-04-08 04:56:28.057740534 -0700
++++ gcc/config/arm/arm.h	2022-01-31 21:11:39.595024008 -0800
+@@ -937,6 +937,11 @@
+ #define ARM_UNWIND_INFO  0
+ #endif
+ 
++/* Overriden by config/arm/netbsd-eabi.h.  */
++#ifndef ARM_DWARF_UNWIND_TABLES
++#define ARM_DWARF_UNWIND_TABLES 0
++#endif
++
+ /* Use r0 and r1 to pass exception handling information.  */
+ #define EH_RETURN_DATA_REGNO(N) (((N) < 2) ? N : INVALID_REGNUM)
+ 
+@@ -948,11 +953,19 @@
+ #define ARM_TARGET2_DWARF_FORMAT DW_EH_PE_pcrel
+ #endif
+ 
++#if ARM_DWARF_UNWIND_TABLES
++/* DWARF unwinding uses the normal indirect/pcrel vs absptr format
++   for 32bit platforms. */
++#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
++  (flag_pic ? (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4) \
++            : DW_EH_PE_absptr)
++#else
+ /* ttype entries (the only interesting data references used)
+    use TARGET2 relocations.  */
+ #define ASM_PREFERRED_EH_DATA_FORMAT(code, data) \
+   (((code) == 0 && (data) == 1 && ARM_UNWIND_INFO) ? ARM_TARGET2_DWARF_FORMAT \
+ 			       : DW_EH_PE_absptr)
++#endif
+ 
+ /* The native (Norcroft) Pascal compiler for the ARM passes the static chain
+    as an invisible last argument (possible since varargs don't exist in
+@@ -2342,7 +2355,7 @@
+ 
+ /* -mcpu=native handling only makes sense with compiler running on
+    an ARM chip.  */
+-#if defined(__arm__)
++#if defined(__arm__) && defined(__linux__)
+ extern const char *host_detect_local_cpu (int argc, const char **argv);
+ #define HAVE_LOCAL_CPU_DETECT
+ # define MCPU_MTUNE_NATIVE_FUNCTIONS			\
diff --git a/gcc-bootstrap/patches/patch-gcc_config_arm_bpabi.h b/gcc-bootstrap/patches/patch-gcc_config_arm_bpabi.h
new file mode 100644
index 0000000000..c06eacf5b9
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_arm_bpabi.h
@@ -0,0 +1,22 @@
+$NetBSD: patch-gcc_config_arm_bpabi.h,v 1.1 2022/02/02 22:07:28 mrg Exp $
+
+--- gcc/config/arm/bpabi.h.orig	2021-04-08 04:56:28.061740583 -0700
++++ gcc/config/arm/bpabi.h	2022-01-31 21:13:16.734263818 -0800
+@@ -24,6 +24,7 @@
+    <http://www.gnu.org/licenses/>.  */
+ 
+ /* Use the AAPCS ABI by default.  */
++#undef ARM_DEFAULT_ABI
+ #define ARM_DEFAULT_ABI ARM_ABI_AAPCS
+ 
+ /* Assume that AAPCS ABIs should adhere to the full BPABI.  */
+@@ -107,7 +108,9 @@
+ /* The BPABI specifies the use of .{init,fini}_array.  Therefore, we
+    do not want GCC to put anything into the .{init,fini} sections.  */
+ #undef INIT_SECTION_ASM_OP
++#define INIT_SECTION_ASM_OP ""
+ #undef FINI_SECTION_ASM_OP
++#define FINI_SECTION_ASM_OP ""
+ #define INIT_ARRAY_SECTION_ASM_OP ARM_EABI_CTORS_SECTION_OP
+ #define FINI_ARRAY_SECTION_ASM_OP ARM_EABI_DTORS_SECTION_OP
+ 
diff --git a/gcc-bootstrap/patches/patch-gcc_config_arm_elf.h b/gcc-bootstrap/patches/patch-gcc_config_arm_elf.h
new file mode 100644
index 0000000000..5ac636464f
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_arm_elf.h
@@ -0,0 +1,14 @@
+$NetBSD: patch-gcc_config_arm_elf.h,v 1.1 2022/02/02 22:07:28 mrg Exp $
+
+--- gcc/config/arm/elf.h.orig	2021-04-08 04:56:28.065740630 -0700
++++ gcc/config/arm/elf.h	2022-01-31 21:14:04.684223580 -0800
+@@ -147,6 +147,8 @@
+ #undef L_floatdidf
+ #undef L_floatdisf
+ #undef L_floatundidf
++/* XXXMRG: don't take this out, we need it! */
++# ifndef __NetBSD__
+ #undef L_floatundisf
++# endif
+ #endif
+-
diff --git a/gcc-bootstrap/patches/patch-gcc_config_arm_netbsd-eabi.h b/gcc-bootstrap/patches/patch-gcc_config_arm_netbsd-eabi.h
new file mode 100644
index 0000000000..3c07c84d32
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_arm_netbsd-eabi.h
@@ -0,0 +1,57 @@
+$NetBSD: patch-gcc_config_arm_netbsd-eabi.h,v 1.1 2022/02/02 22:07:28 mrg Exp $
+
+--- gcc/config/arm/netbsd-eabi.h.orig	2021-04-08 04:56:28.065740630 -0700
++++ gcc/config/arm/netbsd-eabi.h	2022-01-31 21:15:29.555403989 -0800
+@@ -49,8 +49,8 @@
+ 
+ #undef ARM_UNWIND_INFO
+ #define ARM_UNWIND_INFO 0
+-#undef DWARF2_UNWIND_INFO
+-#define DWARF2_UNWIND_INFO 1
++#undef ARM_DWARF_UNWIND_TABLES
++#define ARM_DWARF_UNWIND_TABLES 1
+ 
+ #undef TARGET_OS_CPP_BUILTINS
+ #define TARGET_OS_CPP_BUILTINS()		\
+@@ -59,7 +59,7 @@
+       if (TARGET_AAPCS_BASED)			\
+ 	TARGET_BPABI_CPP_BUILTINS();		\
+       NETBSD_OS_CPP_BUILTINS_ELF();		\
+-      if (DWARF2_UNWIND_INFO)			\
++      if (ARM_DWARF_UNWIND_TABLES)		\
+ 	builtin_define ("__ARM_DWARF_EH__");	\
+     }						\
+   while (0)
+@@ -81,17 +81,25 @@
+ 
+ #undef SUBTARGET_EXTRA_ASM_SPEC
+ #define SUBTARGET_EXTRA_ASM_SPEC		\
+-  "%{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu} "	\
++  "-matpcs %{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu} "	\
+   "%{fpic|fpie:-k} "				\
+   "%{fPIC|fPIE:-k}"
+ 
++/* Default to full VFP if -mhard-float is specified.  */
++#undef SUBTARGET_ASM_FLOAT_SPEC
++#define SUBTARGET_ASM_FLOAT_SPEC	\
++  "%{mhard-float:%{!mfpu=*:-mfpu=vfp}}   \
++   %{mfloat-abi=hard:%{!mfpu=*:-mfpu=vfp}}"
++
+ #undef SUBTARGET_EXTRA_SPECS
+ #define SUBTARGET_EXTRA_SPECS						\
+   { "subtarget_extra_asm_spec",	SUBTARGET_EXTRA_ASM_SPEC },		\
++  { "subtarget_asm_float_spec", SUBTARGET_ASM_FLOAT_SPEC }, 		\
+   { "linker_eabi_suffix",	TARGET_LINKER_EABI_SUFFIX },		\
+   { "linker_emulation",		TARGET_LINKER_EMULATION },		\
+   { "linker_big_emulation",	TARGET_LINKER_BIG_EMULATION },		\
+   { "linker_little_emulation",	TARGET_LINKER_LITTLE_EMULATION },	\
++  { "be8_link_spec",		BE8_LINK_SPEC }, 			\
+   { "target_fix_v4bx_spec",	TARGET_FIX_V4BX_SPEC },			\
+   NETBSD_SUBTARGET_EXTRA_SPECS
+ 
+@@ -102,4 +110,5 @@
+   "-X %{mbig-endian:-EB -m %(linker_big_emulation)} "		\
+   "%{mlittle-endian:-EL -m %(linker_liitle_emulation)} "	\
+   "%{!mbig-endian:%{!mlittle-endian:-m %(linker_emulation)}} "	\
++  "%(be8_link_spec) "						\
+   "%(target_fix_v4bx_spec) %(netbsd_link_spec)"
diff --git a/gcc-bootstrap/patches/patch-gcc_config_arm_netbsd-elf.h b/gcc-bootstrap/patches/patch-gcc_config_arm_netbsd-elf.h
new file mode 100644
index 0000000000..a308e8b317
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_arm_netbsd-elf.h
@@ -0,0 +1,80 @@
+$NetBSD: patch-gcc_config_arm_netbsd-elf.h,v 1.1 2022/02/02 22:07:28 mrg Exp $
+
+--- gcc/config/arm/netbsd-elf.h.orig	2021-04-08 04:56:28.065740630 -0700
++++ gcc/config/arm/netbsd-elf.h	2022-01-31 21:14:32.314234515 -0800
+@@ -27,9 +27,20 @@
+ 
+ /* arm.h defaults to ARM6 CPU.  */
+ 
+-/* This defaults us to little-endian.  */
+-#ifndef TARGET_ENDIAN_DEFAULT
+-#define TARGET_ENDIAN_DEFAULT 0
++/* Default EABI to armv5t so that thumb shared libraries work.
++   The ARM926EH-S core is the default for armv5te, so set
++   SUBTARGET_CPU_DEFAULT to achieve this.  */
++
++#define SUBTARGET_CPU_DEFAULT \
++	(ARM_DEFAULT_ABI != ARM_ABI_APCS && ARM_DEFAULT_ABI != ARM_ABI_ATPCS \
++	    ? TARGET_CPU_arm926ejs : TARGET_CPU_arm6)
++
++/* TARGET_BIG_ENDIAN_DEFAULT is set in
++   config.gcc for big endian configurations.  */
++#if TARGET_BIG_ENDIAN_DEFAULT
++#define TARGET_ENDIAN_DEFAULT    MASK_BIG_END
++#else
++#define TARGET_ENDIAN_DEFAULT    0
+ #endif
+ 
+ #undef MULTILIB_DEFAULTS
+@@ -56,25 +67,28 @@
+ 
+ #undef SUBTARGET_EXTRA_ASM_SPEC
+ #define SUBTARGET_EXTRA_ASM_SPEC	\
++  "-matpcs %{mabi=aapcs*:-meabi=5} "	\
+   "%{" FPIE_OR_FPIC_SPEC ":-k}"
+ 
++#undef SUBTARGET_EXTRA_SPECS
++#define SUBTARGET_EXTRA_SPECS					\
++  { "subtarget_extra_asm_spec",	SUBTARGET_EXTRA_ASM_SPEC },	\
++  { "subtarget_asm_float_spec", SUBTARGET_ASM_FLOAT_SPEC },	\
++  NETBSD_SUBTARGET_EXTRA_SPECS
++
+ /* Default to full VFP if -mfloat-abi=hard is specified.  */
+ #undef SUBTARGET_ASM_FLOAT_SPEC
+-#define SUBTARGET_ASM_FLOAT_SPEC	\
+-  "%{mfloat-abi=hard:{!mfpu=*:-mfpu=vfp}}"
+-
+-#undef SUBTARGET_EXTRA_SPECS
+-#define SUBTARGET_EXTRA_SPECS				\
+-  { "subtarget_extra_asm_spec",	SUBTARGET_EXTRA_ASM_SPEC }, \
+-  { "subtarget_asm_float_spec", SUBTARGET_ASM_FLOAT_SPEC }, \
+-  { "netbsd_link_spec",		NETBSD_LINK_SPEC_ELF },	\
+-  { "netbsd_entry_point",	NETBSD_ENTRY_POINT },
++#define SUBTARGET_ASM_FLOAT_SPEC		\
++  "%{mhard-float:%{!mfpu=*:-mfpu=vfp}}		\
++   %{mfloat-abi=hard:%{!mfpu=*:-mfpu=vfp}}"
+ 
+ #define NETBSD_ENTRY_POINT "__start"
+ 
+ #undef LINK_SPEC
+ #define LINK_SPEC \
+-  "-X %{mbig-endian:-EB} %{mlittle-endian:-EL} \
++  "-X \
++   %{mbig-endian:-EB %{-mabi=aapcs*:-m armelfb_nbsd_eabi}} \
++   %{mlittle-endian:-EL %{-mabi=aapcs*:-m armelf_nbsd_eabi}} \
+    %(netbsd_link_spec)"
+ 
+ /* Make GCC agree with <machine/ansi.h>.  */
+@@ -85,6 +99,12 @@
+ #undef PTRDIFF_TYPE
+ #define PTRDIFF_TYPE "long int"
+ 
++#undef INTPTR_TYPE
++#define INTPTR_TYPE PTRDIFF_TYPE
++
++#undef UINTPTR_TYPE
++#define UINTPTR_TYPE SIZE_TYPE
++
+ /* We don't have any limit on the length as out debugger is GDB.  */
+ #undef DBX_CONTIN_LENGTH
+ 
diff --git a/gcc-bootstrap/patches/patch-gcc_config_sparc_sparc.c b/gcc-bootstrap/patches/patch-gcc_config_sparc_sparc.c
new file mode 100644
index 0000000000..1eacdf2d76
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_config_sparc_sparc.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-gcc_config_sparc_sparc.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Invoke subtarget-specific code for replacing builtin functions.
+Causes "cabsl" to be converted to _c99_cabsl on NetBSD.
+https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565290.html
+
+--- gcc/config/sparc/sparc.c.orig	2020-07-23 06:35:17.480386051 +0000
++++ gcc/config/sparc/sparc.c
+@@ -10993,6 +10993,9 @@ sparc_init_builtins (void)
+ 
+   if (TARGET_VIS)
+     sparc_vis_init_builtins ();
++#ifdef SUBTARGET_INIT_BUILTINS
++  SUBTARGET_INIT_BUILTINS;
++#endif
+ }
+ 
+ /* Create builtin functions for FPU instructions.  */
diff --git a/gcc-bootstrap/patches/patch-gcc_configure b/gcc-bootstrap/patches/patch-gcc_configure
new file mode 100644
index 0000000000..035e8d3f38
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_configure
@@ -0,0 +1,15 @@
+$NetBSD: patch-gcc_configure,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90143
+
+--- gcc/configure.orig	2015-09-30 23:06:11.000000000 +0000
++++ gcc/configure
+@@ -28321,7 +28321,7 @@ case "$target" in
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
+-  *-*-dragonfly* | *-*-freebsd*)
++  *-*-dragonfly* | *-*-freebsd* | *-*-netbsd* )
+     if grep dl_iterate_phdr $target_header_dir/sys/link_elf.h > /dev/null 2>&1; then
+       gcc_cv_target_dl_iterate_phdr=yes
+     else
diff --git a/gcc-bootstrap/patches/patch-gcc_ggc-common.c b/gcc-bootstrap/patches/patch-gcc_ggc-common.c
new file mode 100644
index 0000000000..ca76990c01
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ggc-common.c
@@ -0,0 +1,51 @@
+$NetBSD: patch-gcc_ggc-common.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+--- gcc/ggc-common.c.orig	2014-12-10 03:45:40.000000000 +0000
++++ gcc/ggc-common.c
+@@ -591,6 +591,8 @@ gt_pch_restore (FILE *f)
+   size_t i;
+   struct mmap_info mmi;
+   int result;
++  struct line_maps * old_line_table = line_table;
++  location_t old_input_loc = input_location;
+ 
+   /* Delete any deletable objects.  This makes ggc_pch_read much
+      faster, as it can be sure that no GCable objects remain other
+@@ -603,7 +605,7 @@ gt_pch_restore (FILE *f)
+   for (rt = gt_pch_scalar_rtab; *rt; rt++)
+     for (rti = *rt; rti->base != NULL; rti++)
+       if (fread (rti->base, rti->stride, 1, f) != 1)
+-	fatal_error (input_location, "cannot read PCH file: %m");
++	{ line_table = old_line_table; input_location = old_input_loc; fatal_error (input_location, "cannot read PCH file: %m"); }
+ 
+   /* Read in all the global pointers, in 6 easy loops.  */
+   for (rt = gt_ggc_rtab; *rt; rt++)
+@@ -611,23 +613,23 @@ gt_pch_restore (FILE *f)
+       for (i = 0; i < rti->nelt; i++)
+ 	if (fread ((char *)rti->base + rti->stride * i,
+ 		   sizeof (void *), 1, f) != 1)
+-	  fatal_error (input_location, "cannot read PCH file: %m");
++	  { line_table = old_line_table; input_location = old_input_loc; fatal_error (input_location, "cannot read PCH file: %m"); }
+ 
+   if (fread (&mmi, sizeof (mmi), 1, f) != 1)
+-    fatal_error (input_location, "cannot read PCH file: %m");
++    { line_table = old_line_table; input_location = old_input_loc; fatal_error (input_location, "cannot read PCH file: %m"); }
+ 
+   result = host_hooks.gt_pch_use_address (mmi.preferred_base, mmi.size,
+ 					  fileno (f), mmi.offset);
+   if (result < 0)
+-    fatal_error (input_location, "had to relocate PCH");
++    { line_table = old_line_table; input_location = old_input_loc; fatal_error (input_location, "had to relocate PCH"); }
+   if (result == 0)
+     {
+       if (fseek (f, mmi.offset, SEEK_SET) != 0
+ 	  || fread (mmi.preferred_base, mmi.size, 1, f) != 1)
+-	fatal_error (input_location, "cannot read PCH file: %m");
++	{ line_table = old_line_table; input_location = old_input_loc; fatal_error (input_location, "cannot read PCH file: %m"); }
+     }
+   else if (fseek (f, mmi.offset + mmi.size, SEEK_SET) != 0)
+-    fatal_error (input_location, "cannot read PCH file: %m");
++    { line_table = old_line_table; input_location = old_input_loc; fatal_error (input_location, "cannot read PCH file: %m"); }
+ 
+   ggc_pch_read (f, mmi.preferred_base);
+ 
diff --git a/gcc-bootstrap/patches/patch-gcc_ginclude_stddef.h b/gcc-bootstrap/patches/patch-gcc_ginclude_stddef.h
new file mode 100644
index 0000000000..b60aae536b
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_ginclude_stddef.h
@@ -0,0 +1,18 @@
+$NetBSD: patch-gcc_ginclude_stddef.h,v 1.1 2024/04/01 18:08:48 js Exp $
+
+Include the system <stddef.h> first, as otherwise we'll end up without
+ptrdiff_t and size_t depending on include order.
+
+--- gcc/ginclude/stddef.h.orig	2023-07-07 07:08:19.000000000 +0000
++++ gcc/ginclude/stddef.h
+@@ -21,6 +21,10 @@ a copy of the GCC Runtime Library Except
+ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ <http://www.gnu.org/licenses/>.  */
+ 
++#ifdef __QNX__
++# include_next <stddef.h>
++#endif
++
+ /*
+  * ISO C Standard:  7.17  Common definitions  <stddef.h>
+  */
diff --git a/gcc-bootstrap/patches/patch-gcc_lto_lto.c b/gcc-bootstrap/patches/patch-gcc_lto_lto.c
new file mode 100644
index 0000000000..c4b9174334
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_lto_lto.c
@@ -0,0 +1,19 @@
+$NetBSD: patch-gcc_lto_lto.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Better fallback for netbsd<8 lacking WALLSIG.
+
+--- gcc/lto/lto.c.orig	2018-01-03 21:42:12.000000000 +0000
++++ gcc/lto/lto.c
+@@ -2321,7 +2321,11 @@ wait_for_child ()
+   do
+     {
+ #ifndef WCONTINUED
+-#define WCONTINUED 0
++#  ifdef WALLSIG
++#    define WCONTINUED WALLSIG
++#  else
++#    define WCONTINUED 0
++#  endif
+ #endif
+       int w = waitpid (0, &status, WUNTRACED | WCONTINUED);
+       if (w == -1)
diff --git a/gcc-bootstrap/patches/patch-gcc_opts-common.c b/gcc-bootstrap/patches/patch-gcc_opts-common.c
new file mode 100644
index 0000000000..61fcad648c
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_opts-common.c
@@ -0,0 +1,13 @@
+$NetBSD: patch-gcc_opts-common.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+--- gcc/opts-common.c.orig	2023-07-07 07:08:19.000000000 +0000
++++ gcc/opts-common.c
+@@ -1808,7 +1808,7 @@ void prepend_xassembler_to_collect_as_op
+     }
+ }
+ 
+-jobserver_info::jobserver_info ()
++jobserver_info::jobserver_info () : rfd(-1), wfd(-1), is_active(false)
+ {
+   /* Traditionally, GNU make uses opened pipes for jobserver-auth,
+     e.g. --jobserver-auth=3,4.
diff --git a/gcc-bootstrap/patches/patch-gcc_opts-jobserver.h b/gcc-bootstrap/patches/patch-gcc_opts-jobserver.h
new file mode 100644
index 0000000000..6aaf9c0ea5
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_opts-jobserver.h
@@ -0,0 +1,28 @@
+$NetBSD: patch-gcc_opts-jobserver.h,v 1.1 2024/04/01 14:33:57 js Exp $
+
+--- gcc/opts-jobserver.h.orig	2023-07-07 07:08:19.000000000 +0000
++++ gcc/opts-jobserver.h
+@@ -30,17 +30,17 @@ struct jobserver_info
+   jobserver_info ();
+ 
+   /* Error message if there is a problem.  */
+-  string error_msg = "";
++  string error_msg;
+   /* Skipped MAKEFLAGS where --jobserver-auth is skipped.  */
+-  string skipped_makeflags = "";
++  string skipped_makeflags;
+   /* File descriptor for reading used for jobserver communication.  */
+-  int rfd = -1;
++  int rfd;
+   /* File descriptor for writing used for jobserver communication.  */
+-  int wfd = -1;
++  int wfd;
+   /* Named pipe path.  */
+-  string pipe_path = "";
++  string pipe_path;
+   /* Return true if jobserver is active.  */
+-  bool is_active = false;
++  bool is_active;
+ };
+ 
+ #endif /* GCC_JOBSERVER_H */
diff --git a/gcc-bootstrap/patches/patch-gcc_plugin.c b/gcc-bootstrap/patches/patch-gcc_plugin.c
new file mode 100644
index 0000000000..de7d12c022
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_plugin.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-gcc_plugin.c,v 1.2 2024/04/01 14:33:57 js Exp $
+
+Support dynamic link interface functions.
+
+Needs to come after the other includes as those add some defines that change
+behavior (breaks QNX otherwise).
+
+--- gcc/plugin.c.orig	2023-07-07 07:08:19.000000000 +0000
++++ gcc/plugin.c
+@@ -30,6 +30,8 @@ along with GCC; see the file COPYING3.  
+ #include "intl.h"
+ #include "plugin.h"
+ 
++#include <dlfcn.h>
++
+ #ifdef ENABLE_PLUGIN
+ #include "plugin-version.h"
+ #endif
diff --git a/gcc-bootstrap/patches/patch-gcc_targhooks.c b/gcc-bootstrap/patches/patch-gcc_targhooks.c
new file mode 100644
index 0000000000..c5a34501e7
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gcc_targhooks.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-gcc_targhooks.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+PR pkg/53436
+netbsd can't handle hidden reference to stack_chk_fail_local.
+(note: this code is only happening if targeting i386)
+
+--- gcc/targhooks.c.orig	2018-01-13 18:00:59.000000000 +0000
++++ gcc/targhooks.c
+@@ -919,7 +919,7 @@ default_external_stack_protect_fail (voi
+ tree
+ default_hidden_stack_protect_fail (void)
+ {
+-#ifndef HAVE_GAS_HIDDEN
++#if !defined(HAVE_GAS_HIDDEN) || defined(__NetBSD__) || defined(__sun)
+   return default_external_stack_protect_fail ();
+ #else
+   tree t = stack_chk_fail_decl;
diff --git a/gcc-bootstrap/patches/patch-gmp_gen-sieve.c b/gcc-bootstrap/patches/patch-gmp_gen-sieve.c
new file mode 100644
index 0000000000..d6477b3f9b
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gmp_gen-sieve.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-gmp_gen-sieve.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+Fix compiling with GCC 4.4.2 on QNX.
+
+--- gmp/gen-sieve.c.orig	2023-07-29 13:42:16.000000000 +0000
++++ gmp/gen-sieve.c
+@@ -95,8 +95,9 @@ generate (int limb_bits, int limit)
+ void
+ setmask (mpz_t mask, int a, int b)
+ {
++  unsigned i;
+   mpz_set_ui (mask, 0);
+-  for (unsigned i = 0; i < 2 * a * b; ++i)
++  for (i = 0; i < 2 * a * b; ++i)
+     if ((bit_to_n (i) % a == 0) || (bit_to_n (i) % b == 0))
+       mpz_setbit (mask, i);
+ }
diff --git a/gcc-bootstrap/patches/patch-gmp_mpn_generic_compute_powtab.c b/gcc-bootstrap/patches/patch-gmp_mpn_generic_compute_powtab.c
new file mode 100644
index 0000000000..18c87285c3
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gmp_mpn_generic_compute_powtab.c
@@ -0,0 +1,67 @@
+$NetBSD: patch-gmp_mpn_generic_compute_powtab.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+Fix compiling with GCC 4.4.2 on QNX.
+
+--- gmp/mpn/generic/compute_powtab.c.orig	2023-07-29 13:42:16.000000000 +0000
++++ gmp/mpn/generic/compute_powtab.c
+@@ -70,6 +70,7 @@ mpn_compute_powtab_mul (powers_t *powtab
+   mp_limb_t cy;
+   long start_idx;
+   int c;
++  long pi;
+ 
+   mp_limb_t big_base = mp_bases[base].big_base;
+   int chars_per_limb = mp_bases[base].chars_per_limb;
+@@ -139,7 +140,7 @@ mpn_compute_powtab_mul (powers_t *powtab
+       start_idx = n_pows - 3;
+     }
+ 
+-  for (long pi = start_idx; pi >= 0; pi--)
++  for (pi = start_idx; pi >= 0; pi--)
+     {
+       t = powtab_mem_ptr;
+       powtab_mem_ptr += 2 * n + 2;
+@@ -223,7 +224,8 @@ mpn_compute_powtab_div (powers_t *powtab
+ 
+   mp_size_t n = 1;
+   mp_size_t shift = 0;
+-  for (long pi = n_pows - 1; pi >= 0; pi--)
++  long pi;
++  for (pi = n_pows - 1; pi >= 0; pi--)
+     {
+       t = powtab_mem_ptr;
+       powtab_mem_ptr += 2 * n;
+@@ -271,7 +273,7 @@ mpn_compute_powtab_div (powers_t *powtab
+ 
+   /* Strip any remaining low zero limbs.  */
+   pt -= n_pows + 1;
+-  for (long pi = n_pows; pi >= 0; pi--)
++  for (pi = n_pows; pi >= 0; pi--)
+     {
+       mp_ptr t = pt[pi].p;
+       mp_size_t shift = pt[pi].shift;
+@@ -293,7 +295,8 @@ powtab_decide (size_t *exptab, size_t un
+ {
+   int chars_per_limb = mp_bases[base].chars_per_limb;
+   long n_pows = 0;
+-  for (size_t pn = (un + 1) >> 1; pn != 1; pn = (pn + 1) >> 1)
++  size_t pn;
++  for (pn = (un + 1) >> 1; pn != 1; pn = (pn + 1) >> 1)
+     {
+       exptab[n_pows] = pn * chars_per_limb;
+       n_pows++;
+@@ -301,11 +304,12 @@ powtab_decide (size_t *exptab, size_t un
+   exptab[n_pows] = chars_per_limb;
+ 
+ #if HAVE_mpn_compute_powtab_mul && HAVE_mpn_compute_powtab_div
+-  size_t pn = un - 1;
++  pn = un - 1;
+   size_t xn = (un + 1) >> 1;
+   unsigned mcost = 1;
+   unsigned dcost = 1;
+-  for (long i = n_pows - 2; i >= 0; i--)
++  long i;
++  for (i = n_pows - 2; i >= 0; i--)
+     {
+       size_t pow = (pn >> (i + 1)) + 1;
+ 
diff --git a/gcc-bootstrap/patches/patch-gmp_mpz_millerrabin.c b/gcc-bootstrap/patches/patch-gmp_mpz_millerrabin.c
new file mode 100644
index 0000000000..5de2002cdf
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gmp_mpz_millerrabin.c
@@ -0,0 +1,16 @@
+$NetBSD: patch-gmp_mpz_millerrabin.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+Fix compiling with GCC 4.4.2 on QNX.
+
+--- gmp/mpz/millerrabin.c.orig	2023-07-29 13:42:17.000000000 +0000
++++ gmp/mpz/millerrabin.c
+@@ -206,7 +206,8 @@ millerrabin (mpz_srcptr n, mpz_ptr x, mp
+   if (mpz_cmp_ui (y, 1L) == 0 || mod_eq_m1 (y, n))
+     return 1;
+ 
+-  for (mp_bitcnt_t i = 1; i < k; ++i)
++  mp_bitcnt_t i;
++  for (i = 1; i < k; ++i)
+     {
+       mpz_powm_ui (y, y, 2L, n);
+       if (mod_eq_m1 (y, n))
diff --git a/gcc-bootstrap/patches/patch-gmp_mpz_nextprime.c b/gcc-bootstrap/patches/patch-gmp_mpz_nextprime.c
new file mode 100644
index 0000000000..0dbe925b98
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gmp_mpz_nextprime.c
@@ -0,0 +1,43 @@
+$NetBSD: patch-gmp_mpz_nextprime.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+Fix compiling with GCC 4.4.2 on QNX.
+
+--- gmp/mpz/nextprime.c.orig	2023-07-29 13:42:17.000000000 +0000
++++ gmp/mpz/nextprime.c
+@@ -113,7 +113,8 @@ findnext_small (unsigned t, short diff)
+   for (; ; t += diff)
+     {
+       unsigned prime = 3;
+-      for (int i = 0; ; prime += primegap_small[i++])
++      int i;
++      for (i = 0; ; prime += primegap_small[i++])
+ 	{
+ 	  unsigned q, r;
+ 	  q = t / prime;
+@@ -182,14 +183,18 @@ findnext (mpz_ptr p,
+       i = 0;
+       last_prime = 3;
+       /* THINK: should we get rid of sieve_limit and use (i < prime_limit)? */
+-      for (mp_limb_t j = 4, *sp = sieve; j < sieve_limit; j += GMP_LIMB_BITS * 3)
+-	for (mp_limb_t b = j, x = ~ *(sp++); x != 0; b += 3, x >>= 1)
+-	  if (x & 1)
+-	    {
+-	      mp_limb_t prime = b | 1;
+-	      primegap_tmp[i++] = prime - last_prime;
+-	      last_prime = prime;
+-	    }
++      mp_limb_t j, *sp;
++      for (j = 4, sp = sieve; j < sieve_limit; j += GMP_LIMB_BITS * 3)
++        {
++          mp_limb_t b, x;
++	  for (b = j, x = ~ *(sp++); x != 0; b += 3, x >>= 1)
++	    if (x & 1)
++	      {
++	        mp_limb_t prime = b | 1;
++	        primegap_tmp[i++] = prime - last_prime;
++	        last_prime = prime;
++	      }
++        }
+ 
+       /* Both primesieve and prime_limit ignore the first two primes. */
+       ASSERT(i == prime_limit);
diff --git a/gcc-bootstrap/patches/patch-gmp_mpz_primorial_ui.c b/gcc-bootstrap/patches/patch-gmp_mpz_primorial_ui.c
new file mode 100644
index 0000000000..c12305c30e
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gmp_mpz_primorial_ui.c
@@ -0,0 +1,31 @@
+$NetBSD: patch-gmp_mpz_primorial_ui.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+Fix compiling with GCC 4.4.2 on QNX.
+
+--- gmp/mpz/primorial_ui.c.orig	2023-07-29 13:42:17.000000000 +0000
++++ gmp/mpz/primorial_ui.c
+@@ -106,13 +106,17 @@ mpz_primorial_ui (mpz_ptr res, unsigned 
+ 	max_prod = GMP_NUMB_MAX / n;
+ 
+ 	/* Loop on sieved primes. */
+-	for (mp_limb_t i = 4, *sp = sieve; i < n; i += GMP_LIMB_BITS * 3)
+-	  for (mp_limb_t b = i, x = ~ *(sp++); x != 0; b += 3, x >>= 1)
+-	    if (x & 1)
+-	      {
+-		mp_limb_t prime = b | 1;
+-		FACTOR_LIST_STORE (prime, prod, max_prod, factors, j);
+-	      }
++        mp_limb_t i, *sp;
++	for (i = 4, sp = sieve; i < n; i += GMP_LIMB_BITS * 3)
++          {
++            mp_limb_t b, x;
++	    for (b = i, x = ~ *(sp++); x != 0; b += 3, x >>= 1)
++	      if (x & 1)
++	        {
++		  mp_limb_t prime = b | 1;
++		  FACTOR_LIST_STORE (prime, prod, max_prod, factors, j);
++	        }
++          }
+       }
+ 
+       if (j != 0)
diff --git a/gcc-bootstrap/patches/patch-gmp_primesieve.c b/gcc-bootstrap/patches/patch-gmp_primesieve.c
new file mode 100644
index 0000000000..5ad3dd16b0
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gmp_primesieve.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-gmp_primesieve.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+Fix compiling with GCC 4.4.2 on QNX.
+
+--- gmp/primesieve.c.orig	2023-07-29 13:42:17.000000000 +0000
++++ gmp/primesieve.c
+@@ -288,8 +288,8 @@ gmp_primesieve (mp_ptr bit_array, mp_lim
+   bits = n_fto_bit(n);
+   size = bits / GMP_LIMB_BITS + 1;
+ 
+-  for (mp_size_t j = 0, lim = MIN (size, PRIMESIEVE_NUMBEROF_TABLE);
+-       j < lim; ++j)
++  mp_size_t j, lim;
++  for (j = 0, lim = MIN (size, PRIMESIEVE_NUMBEROF_TABLE); j < lim; ++j)
+     bit_array [j] = presieved [j]; /* memcopy? */
+ 
+   if (size > PRIMESIEVE_NUMBEROF_TABLE) {
diff --git a/gcc-bootstrap/patches/patch-gnattools_configure b/gcc-bootstrap/patches/patch-gnattools_configure
new file mode 100644
index 0000000000..a21803a59a
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-gnattools_configure
@@ -0,0 +1,18 @@
+$NetBSD: patch-gnattools_configure,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Include NetBSD in the gnat tools configure.
+
+--- gnattools/configure.orig	2021-08-28 14:19:25.404806918 +0000
++++ gnattools/configure	2021-08-28 14:25:51.208977452 +0000
+@@ -2079,6 +2079,11 @@
+     mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb \
+     indepsw.adb<indepsw-gnu.adb"
+     ;;
++  *-*-netbsd*)
++    TOOLS_TARGET_PAIRS="\
++    mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb \
++    indepsw.adb<indepsw-gnu.adb"
++    ;;
+   *-*-linux*)
+     TOOLS_TARGET_PAIRS="\
+     mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb \
diff --git a/gcc-bootstrap/patches/patch-include_plugin-api.h b/gcc-bootstrap/patches/patch-include_plugin-api.h
new file mode 100644
index 0000000000..16ea689fe4
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-include_plugin-api.h
@@ -0,0 +1,20 @@
+$NetBSD: patch-include_plugin-api.h,v 1.1 2024/04/01 14:33:57 js Exp $
+
+QNX uses __LITTLEENDIAN__ / __BIGENDIAN__, so detect based on that as well.
+
+--- include/plugin-api.h.orig	2023-07-07 07:08:21.000000000 +0000
++++ include/plugin-api.h
+@@ -89,6 +89,13 @@
+ #ifdef __BIG_ENDIAN__
+ #define PLUGIN_BIG_ENDIAN 1
+ #endif
++/* Detect based on __BIGENDIAN__ and __LITTLEENDIAN__ */
++#ifdef __LITTLEENDIAN__
++#define PLUGIN_LITTLE_ENDIAN 1
++#endif
++#ifdef __BIGENDIAN__
++#define PLUGIN_BIG_ENDIAN 1
++#endif
+ #endif
+ 
+ #ifdef __cplusplus
diff --git a/gcc-bootstrap/patches/patch-isl_configure b/gcc-bootstrap/patches/patch-isl_configure
new file mode 100644
index 0000000000..13df03588d
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-isl_configure
@@ -0,0 +1,26 @@
+$NetBSD: patch-isl_configure,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Make test portable
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90144
+
+--- isl/configure.orig	2016-01-14 17:26:10.000000000 +0000
++++ isl/configure
+@@ -17561,7 +17561,7 @@ else
+ fi
+ 
+ 
+- if test "x$with_int" == "ximath-32"; then
++ if test "x$with_int" = "ximath-32"; then
+   SMALL_INT_OPT_TRUE=
+   SMALL_INT_OPT_FALSE='#'
+ else
+@@ -17569,7 +17569,7 @@ else
+   SMALL_INT_OPT_FALSE=
+ fi
+ 
+-if test "x$with_int" == "ximath-32"; then :
++if test "x$with_int" = "ximath-32"; then :
+ 
+ 
+ $as_echo "#define USE_SMALL_INT_OPT /**/" >>confdefs.h
diff --git a/gcc-bootstrap/patches/patch-libffi_configure b/gcc-bootstrap/patches/patch-libffi_configure
new file mode 100644
index 0000000000..c03dbbb59f
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libffi_configure
@@ -0,0 +1,16 @@
+$NetBSD: patch-libffi_configure,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90146
+https://github.com/libffi/libffi/issues/485
+
+--- libffi/configure.orig	2013-06-01 17:03:49.000000000 +0000
++++ libffi/configure
+@@ -12689,7 +12689,7 @@ case "$target" in
+ $as_echo "#define FFI_EXEC_TRAMPOLINE_TABLE 1" >>confdefs.h
+ 
+      ;;
+-     *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
++     *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-netbsd* | *-*-openbsd* | *-pc-solaris*)
+ 
+ $as_echo "#define FFI_MMAP_EXEC_WRIT 1" >>confdefs.h
+ 
diff --git a/gcc-bootstrap/patches/patch-libffi_testsuite_libffi.call_float2.c b/gcc-bootstrap/patches/patch-libffi_testsuite_libffi.call_float2.c
new file mode 100644
index 0000000000..1b35cf135b
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libffi_testsuite_libffi.call_float2.c
@@ -0,0 +1,15 @@
+$NetBSD: patch-libffi_testsuite_libffi.call_float2.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90146
+
+--- libffi/testsuite/libffi.call/float2.c.orig	2013-06-01 17:08:18.000000000 +0000
++++ libffi/testsuite/libffi.call/float2.c
+@@ -45,7 +45,7 @@ int main (void)
+   /* This is ifdef'd out for now. long double support under SunOS/gcc
+      is pretty much non-existent.  You'll get the odd bus error in library
+      routines like printf().  */
+-  printf ("%Lf, %Lf, %Lf, %Lf\n", ld, ldblit(f), ld - ldblit(f), LDBL_EPSILON);
++  printf ("%Lf, %Lf, %Lf, %Lf\n", (long double)ld, (long double)ldblit(f), (long double)(ld - ldblit(f)), (long double)LDBL_EPSILON);
+ #endif
+ 
+   /* These are not always the same!! Check for a reasonable delta */
diff --git a/gcc-bootstrap/patches/patch-libgcc_config.host b/gcc-bootstrap/patches/patch-libgcc_config.host
new file mode 100644
index 0000000000..b139908713
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgcc_config.host
@@ -0,0 +1,36 @@
+$NetBSD: patch-libgcc_config.host,v 1.3 2024/04/01 14:33:57 js Exp $
+
+This is needed for arm64 to get Out-of-line LSE atomics linked into libgcc.
+libsupc++ fails to link without this, and for arm to build.
+
+Fix build on QNX.
+
+--- libgcc/config.host.orig	2023-07-07 07:08:21.000000000 +0000
++++ libgcc/config.host
+@@ -405,6 +405,7 @@ aarch64*-*-freebsd*)
+ aarch64*-*-netbsd*)
+ 	extra_parts="$extra_parts crtfastmath.o"
+ 	tmake_file="${tmake_file} ${cpu_type}/t-aarch64"
++	tmake_file="${tmake_file} ${cpu_type}/t-lse"
+ 	tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm"
+ 	md_unwind_header=aarch64/aarch64-unwind.h
+ 	;;
+@@ -491,7 +492,8 @@ arm*-*-netbsdelf*)
+ 	case ${host} in
+ 	  arm*-*-netbsdelf-*eabi*)
+ 	    tmake_file="${tmake_file} arm/t-netbsd-eabi"
+-	    unwind_header=config/arm/unwind-arm.h
++	    # GCC 7 vs NetBSD/eabi -> avoid arm unwinder
++	    #unwind_header=config/arm/unwind-arm.h
+ 	    ;;
+ 	  *)
+ 	    tmake_file="${tmake_file} arm/t-netbsd t-slibgcc-gld-nover"
+@@ -797,7 +799,7 @@ i[34567]86-pc-msdosdjgpp*)
+ 	;;
+ i[34567]86-*-lynxos*)
+ 	;;
+-i[34567]86-*-nto-qnx*)
++i[34567]86-*-qnx*)
+ 	tmake_file="$tmake_file i386/t-nto t-libgcc-pic"
+ 	extra_parts=crtbegin.o
+ 	;;
diff --git a/gcc-bootstrap/patches/patch-libgcc_crtstuff.c b/gcc-bootstrap/patches/patch-libgcc_crtstuff.c
new file mode 100644
index 0000000000..a1b8b053dc
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgcc_crtstuff.c
@@ -0,0 +1,27 @@
+$NetBSD: patch-libgcc_crtstuff.c,v 1.2 2024/04/01 14:33:57 js Exp $
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90147
+
+Disable TM clone registry on QNX, as the linker does not support it.
+
+--- libgcc/crtstuff.c.orig	2023-07-07 07:08:21.000000000 +0000
++++ libgcc/crtstuff.c
+@@ -81,7 +81,7 @@ call_ ## FUNC (void)					\
+ #endif
+ 
+ #if defined(TARGET_DL_ITERATE_PHDR) && \
+-   (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__))
++   (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__))
+ #define BSD_DL_ITERATE_PHDR_AVAILABLE
+ #endif
+  
+@@ -151,7 +151,8 @@ call_ ## FUNC (void)					\
+ # define HIDDEN_DTOR_LIST_END
+ #endif
+ 
+-#if !defined(USE_TM_CLONE_REGISTRY) && defined(OBJECT_FORMAT_ELF)
++#if !defined(USE_TM_CLONE_REGISTRY) && defined(OBJECT_FORMAT_ELF) \
++    && !defined(__QNX__)
+ # define USE_TM_CLONE_REGISTRY 1
+ #elif !defined(USE_TM_CLONE_REGISTRY)
+ # define USE_TM_CLONE_REGISTRY 0
diff --git a/gcc-bootstrap/patches/patch-libgfortran_intrinsics_execute_command_line.c b/gcc-bootstrap/patches/patch-libgfortran_intrinsics_execute_command_line.c
new file mode 100644
index 0000000000..d9ad06cae6
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgfortran_intrinsics_execute_command_line.c
@@ -0,0 +1,15 @@
+$NetBSD: patch-libgfortran_intrinsics_execute_command_line.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+--- libgfortran/intrinsics/execute_command_line.c.orig	2023-07-07 07:08:21.000000000 +0000
++++ libgfortran/intrinsics/execute_command_line.c
+@@ -45,6 +45,10 @@ extern char **environ;
+ #include <signal.h>
+ #endif
+ 
++#ifndef SA_RESTART
++#define SA_RESTART 0
++#endif
++
+ enum { EXEC_SYNCHRONOUS = -2, EXEC_NOERROR = 0, EXEC_SYSTEMFAILED,
+        EXEC_CHILDFAILED, EXEC_INVALIDCOMMAND };
+ static const char *cmdmsg_values[] =
diff --git a/gcc-bootstrap/patches/patch-libgfortran_intrinsics_string_intrinsics_inc.c b/gcc-bootstrap/patches/patch-libgfortran_intrinsics_string_intrinsics_inc.c
new file mode 100644
index 0000000000..7fc5ab2d86
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgfortran_intrinsics_string_intrinsics_inc.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-libgfortran_intrinsics_string_intrinsics_inc.c,v 1.1 2024/04/01 14:33:57 js Exp $
+
+--- libgfortran/intrinsics/string_intrinsics_inc.c.orig	2023-07-07 07:08:21.000000000 +0000
++++ libgfortran/intrinsics/string_intrinsics_inc.c
+@@ -203,11 +203,7 @@ string_len_trim (gfc_charlen_type len, c
+       /* Handle the first characters until we're aligned on a long word
+ 	 boundary.  Actually, s + i + 1 must be properly aligned, because
+ 	 s + i will be the last byte of a long word read.  */
+-      starting = (
+-#ifdef __INTPTR_TYPE__
+-		  (__INTPTR_TYPE__)
+-#endif
+-		  (s + i + 1)) % long_len;
++      starting = ((intptr_t)(s + i + 1)) % long_len;
+       i -= starting;
+       for (; starting > 0; --starting)
+ 	if (s[i + starting] != ' ')
diff --git a/gcc-bootstrap/patches/patch-libgfortran_io_format.c b/gcc-bootstrap/patches/patch-libgfortran_io_format.c
new file mode 100644
index 0000000000..5970fbd5ea
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgfortran_io_format.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-libgfortran_io_format.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Fix -Werror=char-subscripts.
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95177
+
+--- libgfortran/io/format.c.orig	2020-05-07 10:50:02.000000000 +0000
++++ libgfortran/io/format.c
+@@ -193,7 +193,7 @@ next_char (format_data *fmt, int literal
+ 	return -1;
+ 
+       fmt->format_string_len--;
+-      c = toupper (*fmt->format_string++);
++      c = toupper ((unsigned char) *fmt->format_string++);
+       fmt->error_element = c;
+     }
+   while ((c == ' ' || c == '\t') && !literal);
diff --git a/gcc-bootstrap/patches/patch-libgfortran_io_io.h b/gcc-bootstrap/patches/patch-libgfortran_io_io.h
new file mode 100644
index 0000000000..788b0c2078
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgfortran_io_io.h
@@ -0,0 +1,18 @@
+$NetBSD: patch-libgfortran_io_io.h,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Don't declare old_locale* an internal_proto to avoid linking problems
+
+--- libgfortran/io/io.h.orig	2018-01-07 10:17:52.000000000 +0000
++++ libgfortran/io/io.h
+@@ -57,11 +57,8 @@ extern locale_t c_locale;
+ internal_proto(c_locale);
+ #else
+ extern char* old_locale;
+-internal_proto(old_locale);
+ extern int old_locale_ctr;
+-internal_proto(old_locale_ctr);
+ extern __gthread_mutex_t old_locale_lock;
+-internal_proto(old_locale_lock);
+ #endif
+ 
+ 
diff --git a/gcc-bootstrap/patches/patch-libgfortran_io_list__read.c b/gcc-bootstrap/patches/patch-libgfortran_io_list__read.c
new file mode 100644
index 0000000000..16537d08ac
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgfortran_io_list__read.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-libgfortran_io_list__read.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Fix -Werror=char-subscripts.
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95177
+
+--- libgfortran/io/list_read.c.orig	2020-05-07 10:50:02.000000000 +0000
++++ libgfortran/io/list_read.c
+@@ -2757,7 +2757,7 @@ nml_match_name (st_parameter_dt *dtp, co
+   for (i = 0; i < len; i++)
+     {
+       c = next_char (dtp);
+-      if (c == EOF || (tolower (c) != tolower (name[i])))
++      if (c == EOF || (tolower (c) != tolower ((unsigned char) name[i])))
+ 	{
+ 	  dtp->u.p.nml_read_error = 1;
+ 	  break;
diff --git a/gcc-bootstrap/patches/patch-libgfortran_io_read.c b/gcc-bootstrap/patches/patch-libgfortran_io_read.c
new file mode 100644
index 0000000000..94a400d644
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgfortran_io_read.c
@@ -0,0 +1,44 @@
+$NetBSD: patch-libgfortran_io_read.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Fix -Werror=char-subscripts.
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95177
+
+--- libgfortran/io/read.c.orig	2020-05-07 10:50:02.000000000 +0000
++++ libgfortran/io/read.c
+@@ -959,7 +959,7 @@ read_f (st_parameter_dt *dtp, const fnod
+ 	 between "NaN" and the optional perenthesis is not permitted.  */
+       while (w > 0)
+ 	{
+-	  *out = tolower (*p);
++	  *out = tolower ((unsigned char) *p);
+ 	  switch (*p)
+ 	    {
+ 	    case ' ':
+@@ -981,7 +981,7 @@ read_f (st_parameter_dt *dtp, const fnod
+ 		goto bad_float;
+ 	      break;
+ 	    default:
+-	      if (!isalnum (*out))
++	      if (!isalnum ((unsigned char) *out))
+ 		goto bad_float;
+ 	    }
+ 	  --w;
+@@ -1109,7 +1109,7 @@ exponent:
+ 
+   if (dtp->u.p.blank_status == BLANK_UNSPECIFIED)
+     {
+-      while (w > 0 && isdigit (*p))
++      while (w > 0 && isdigit ((unsigned char) *p))
+ 	{
+ 	  exponent *= 10;
+ 	  exponent += *p - '0';
+@@ -1137,7 +1137,7 @@ exponent:
+ 	      else
+ 		assert (dtp->u.p.blank_status == BLANK_NULL);
+ 	    }
+-	  else if (!isdigit (*p))
++	  else if (!isdigit ((unsigned char) *p))
+ 	    goto bad_float;
+ 	  else
+ 	    {
diff --git a/gcc-bootstrap/patches/patch-libgfortran_runtime_environ.c b/gcc-bootstrap/patches/patch-libgfortran_runtime_environ.c
new file mode 100644
index 0000000000..5cf4a84329
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libgfortran_runtime_environ.c
@@ -0,0 +1,26 @@
+$NetBSD: patch-libgfortran_runtime_environ.c,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Fix -Werror=char-subscripts.
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95177
+
+--- libgfortran/runtime/environ.c.orig	2020-05-07 10:50:02.000000000 +0000
++++ libgfortran/runtime/environ.c
+@@ -91,7 +91,7 @@ init_integer (variable * v)
+     return;
+ 
+   for (q = p; *q; q++)
+-    if (!isdigit (*q) && (p != q || *q != '-'))
++    if (!isdigit ((unsigned char) *q) && (p != q || *q != '-'))
+       return;
+ 
+   *v->var = atoi (p);
+@@ -344,7 +344,7 @@ static int
+ match_integer (void)
+ {
+   unit_num = 0;
+-  while (isdigit (*p))
++  while (isdigit ((unsigned char) *p))
+     unit_num = unit_num * 10 + (*p++ - '0');
+   return INTEGER;
+ }
diff --git a/gcc-bootstrap/patches/patch-libiberty_pex-unix.c b/gcc-bootstrap/patches/patch-libiberty_pex-unix.c
new file mode 100644
index 0000000000..10740cd041
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libiberty_pex-unix.c
@@ -0,0 +1,16 @@
+$NetBSD: patch-libiberty_pex-unix.c,v 1.1 2024/04/01 14:33:58 js Exp $
+
+QNX has spawnve and spawnvpe, which makes configure assume it's the same
+spawnve / spawnvpe that exists on Windows.
+
+--- libiberty/pex-unix.c.orig	2023-07-07 07:08:21.000000000 +0000
++++ libiberty/pex-unix.c
+@@ -366,7 +366,7 @@ pex_unix_close (struct pex_obj *obj ATTR
+ 
+ /* Execute a child.  */
+ 
+-#if defined(HAVE_SPAWNVE) && defined(HAVE_SPAWNVPE)
++#if defined(HAVE_SPAWNVE) && defined(HAVE_SPAWNVPE) && !defined(__QNX__)
+ /* Implementation of pex->exec_child using the Cygwin spawn operation.  */
+ 
+ /* Subroutine of pex_unix_exec_child.  Move OLD_FD to a new file descriptor
diff --git a/gcc-bootstrap/patches/patch-libquadmath_printf_printf_fphex.c b/gcc-bootstrap/patches/patch-libquadmath_printf_printf_fphex.c
new file mode 100644
index 0000000000..f7211ca55f
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libquadmath_printf_printf_fphex.c
@@ -0,0 +1,12 @@
+$NetBSD: patch-libquadmath_printf_printf_fphex.c,v 1.1 2024/04/01 14:33:58 js Exp $
+
+--- libquadmath/printf/printf_fphex.c.orig	2023-07-07 07:08:21.000000000 +0000
++++ libquadmath/printf/printf_fphex.c
+@@ -23,6 +23,7 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdbool.h>
++#include <unistd.h>
+ #define NDEBUG
+ #include <assert.h>
+ #include "quadmath-rounding-mode.h"
diff --git a/gcc-bootstrap/patches/patch-libquadmath_printf_quadmath-printf.c b/gcc-bootstrap/patches/patch-libquadmath_printf_quadmath-printf.c
new file mode 100644
index 0000000000..f68ddd5d7e
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libquadmath_printf_quadmath-printf.c
@@ -0,0 +1,34 @@
+$NetBSD: patch-libquadmath_printf_quadmath-printf.c,v 1.2 2024/04/01 14:33:58 js Exp $
+
+Fix -Werror=char-subscripts.
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95178
+
+--- libquadmath/printf/quadmath-printf.c.orig	2023-07-07 07:08:21.000000000 +0000
++++ libquadmath/printf/quadmath-printf.c
+@@ -22,6 +22,7 @@ Boston, MA 02110-1301, USA.  */
+ #include <stdarg.h>
+ #include <string.h>
+ #include <stdio.h>
++#include <unistd.h>
+ #include "quadmath-printf.h"
+ 
+ /* Read a simple integer from a string and update the string pointer.
+@@ -189,7 +190,7 @@ quadmath_snprintf (char *str, size_t siz
+       ++format;
+       info.width = va_arg (ap, int);
+     }
+-  else if (isdigit (*format))
++  else if (isdigit ((unsigned char) *format))
+     /* Constant width specification.  */
+     info.width = read_int (&format);
+ 
+@@ -206,7 +207,7 @@ quadmath_snprintf (char *str, size_t siz
+ 
+ 	  info.prec = va_arg (ap, int);
+ 	}
+-      else if (isdigit (*format))
++      else if (isdigit ((unsigned char) *format))
+ 	info.prec = read_int (&format);
+       else
+ 	/* "%.?" is treated like "%.0?".  */
diff --git a/gcc-bootstrap/patches/patch-libquadmath_strtod_strtod__l.c b/gcc-bootstrap/patches/patch-libquadmath_strtod_strtod__l.c
new file mode 100644
index 0000000000..8cf27a0c8e
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libquadmath_strtod_strtod__l.c
@@ -0,0 +1,39 @@
+$NetBSD: patch-libquadmath_strtod_strtod__l.c,v 1.2 2024/04/01 14:33:58 js Exp $
+
+Fix -Werror=char-subscripts.
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95178
+
+Fix _MAX and _MIN being defined on QNX and breaking the concatenation.
+
+--- libquadmath/strtod/strtod_l.c.orig	2023-07-07 07:08:21.000000000 +0000
++++ libquadmath/strtod/strtod_l.c
+@@ -57,10 +57,10 @@
+ # define STRING_TYPE char
+ # define CHAR_TYPE char
+ # define L_(Ch) Ch
+-# define ISSPACE(Ch) isspace (Ch)
+-# define ISDIGIT(Ch) isdigit (Ch)
+-# define ISXDIGIT(Ch) isxdigit (Ch)
+-# define TOLOWER(Ch) tolower (Ch)
++# define ISSPACE(Ch) isspace ((unsigned char) Ch)
++# define ISDIGIT(Ch) isdigit ((unsigned char) Ch)
++# define ISXDIGIT(Ch) isxdigit ((unsigned char) Ch)
++# define TOLOWER(Ch) tolower ((unsigned char) Ch)
+ # define TOLOWER_C(Ch) \
+   ({__typeof(Ch) __tlc = (Ch); \
+     (__tlc >= 'A' && __tlc <= 'Z') ? __tlc - 'A' + 'a' : __tlc; })
+@@ -89,6 +89,13 @@ __quadmath_strncasecmp_c (const char *s1
+ #endif
+ 
+ 
++#ifdef _MAX
++#undef _MAX
++#endif
++#ifdef _MIN
++#undef _MIN
++#endif
++
+ /* Constants we need from float.h; select the set for the FLOAT precision.  */
+ #define MANT_DIG	PASTE(FLT,_MANT_DIG)
+ #define	DIG		PASTE(FLT,_DIG)
diff --git a/gcc-bootstrap/patches/patch-libstdc++-v3_include_bits_std_abs.h b/gcc-bootstrap/patches/patch-libstdc++-v3_include_bits_std_abs.h
new file mode 100644
index 0000000000..ce1f8a5398
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libstdc++-v3_include_bits_std_abs.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-libstdc++-v3_include_bits_std_abs.h,v 1.1 2024/04/01 14:33:58 js Exp $
+
+--- libstdc++-v3/include/bits/std_abs.h.orig	2023-07-07 07:08:22.000000000 +0000
++++ libstdc++-v3/include/bits/std_abs.h
+@@ -41,6 +41,10 @@
+ #endif
+ #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+ 
++#ifdef __QNX__
++#define __CORRECT_ISO_CPP_MATH_H_PROTO
++#endif
++
+ #undef abs
+ 
+ extern "C++"
diff --git a/gcc-bootstrap/patches/patch-libstdc++-v3_include_bits_stl_function.h b/gcc-bootstrap/patches/patch-libstdc++-v3_include_bits_stl_function.h
new file mode 100644
index 0000000000..7e23f99616
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libstdc++-v3_include_bits_stl_function.h
@@ -0,0 +1,49 @@
+$NetBSD: patch-libstdc++-v3_include_bits_stl_function.h,v 1.1 2024/04/01 14:33:58 js Exp $
+
+--- libstdc++-v3/include/bits/stl_function.h.orig	2023-07-07 07:08:22.000000000 +0000
++++ libstdc++-v3/include/bits/stl_function.h
+@@ -60,6 +60,8 @@
+ #include <bits/move.h>
+ #endif
+ 
++#include <stdint.h>
++
+ namespace std _GLIBCXX_VISIBILITY(default)
+ {
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+@@ -421,7 +423,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ #endif
+ 	  return __x > __y;
+ #endif
+-	return (__UINTPTR_TYPE__)__x > (__UINTPTR_TYPE__)__y;
++	return (uintptr_t)__x > (uintptr_t)__y;
+       }
+     };
+ 
+@@ -440,7 +442,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ #endif
+ 	  return __x < __y;
+ #endif
+-	return (__UINTPTR_TYPE__)__x < (__UINTPTR_TYPE__)__y;
++	return (uintptr_t)__x < (uintptr_t)__y;
+       }
+     };
+ 
+@@ -459,7 +461,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ #endif
+ 	  return __x >= __y;
+ #endif
+-	return (__UINTPTR_TYPE__)__x >= (__UINTPTR_TYPE__)__y;
++	return (uintptr_t)__x >= (uintptr_t)__y;
+       }
+     };
+ 
+@@ -478,7 +480,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ #endif
+ 	  return __x <= __y;
+ #endif
+-	return (__UINTPTR_TYPE__)__x <= (__UINTPTR_TYPE__)__y;
++	return (uintptr_t)__x <= (uintptr_t)__y;
+       }
+     };
+ 
diff --git a/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cmath b/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cmath
new file mode 100644
index 0000000000..5869cce0ed
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cmath
@@ -0,0 +1,15 @@
+$NetBSD: patch-libstdc++-v3_include_c_global_cmath,v 1.1 2024/04/01 14:33:58 js Exp $
+
+--- libstdc++-v3/include/c_global/cmath.orig	2023-07-07 07:08:22.000000000 +0000
++++ libstdc++-v3/include/c_global/cmath
+@@ -49,6 +49,10 @@
+ #ifndef _GLIBCXX_CMATH
+ #define _GLIBCXX_CMATH 1
+ 
++#ifdef __QNX__
++#define __CORRECT_ISO_CPP_MATH_H_PROTO
++#endif
++
+ // Get rid of those macros defined in <math.h> in lieu of real functions.
+ #undef div
+ #undef acos
diff --git a/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cstring b/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cstring
new file mode 100644
index 0000000000..a16af35fdd
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cstring
@@ -0,0 +1,15 @@
+$NetBSD: patch-libstdc++-v3_include_c_global_cstring,v 1.1 2024/04/01 14:33:58 js Exp $
+
+--- libstdc++-v3/include/c_global/cstring.orig	2023-07-07 07:08:22.000000000 +0000
++++ libstdc++-v3/include/c_global/cstring
+@@ -44,6 +44,10 @@
+ #ifndef _GLIBCXX_CSTRING
+ #define _GLIBCXX_CSTRING 1
+ 
++#ifdef __QNX__
++#define __CORRECT_ISO_CPP_STRING_H_PROTO
++#endif
++
+ // Get rid of those macros defined in <string.h> in lieu of real functions.
+ #undef memchr
+ #undef memcmp
diff --git a/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cwchar b/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cwchar
new file mode 100644
index 0000000000..f28cf6bbe6
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libstdc++-v3_include_c_global_cwchar
@@ -0,0 +1,15 @@
+$NetBSD: patch-libstdc++-v3_include_c_global_cwchar,v 1.1 2024/04/01 14:33:58 js Exp $
+
+--- libstdc++-v3/include/c_global/cwchar.orig	2023-07-07 07:08:22.000000000 +0000
++++ libstdc++-v3/include/c_global/cwchar
+@@ -47,6 +47,10 @@
+ #ifndef _GLIBCXX_CWCHAR
+ #define _GLIBCXX_CWCHAR 1
+ 
++#ifdef __QNX__
++#define __CORRECT_ISO_CPP_WCHAR_H_PROTO
++#endif
++
+ // Need to do a bit of trickery here with mbstate_t as char_traits
+ // assumes it is in wchar.h, regardless of wchar_t specializations.
+ #ifndef _GLIBCXX_HAVE_MBSTATE_T
diff --git a/gcc-bootstrap/patches/patch-libstdc++-v3_libsupc++_new__opa.cc b/gcc-bootstrap/patches/patch-libstdc++-v3_libsupc++_new__opa.cc
new file mode 100644
index 0000000000..959bfdafb5
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libstdc++-v3_libsupc++_new__opa.cc
@@ -0,0 +1,17 @@
+$NetBSD: patch-libstdc++-v3_libsupc++_new__opa.cc,v 1.1 2022/03/13 08:34:04 nia Exp $
+
+Ensure we can find SunOS std::aligned_alloc if using it.
+
+--- libstdc++-v3/libsupc++/new_opa.cc.orig	2020-03-04 08:30:03.000000000 +0000
++++ libstdc++-v3/libsupc++/new_opa.cc
+@@ -57,6 +57,10 @@ extern "C"
+ }
+ #endif
+ 
++#if defined(__sun) && _GLIBCXX_HAVE_ALIGNED_ALLOC
++using std::aligned_alloc;
++#endif
++
+ namespace __gnu_cxx {
+ #if _GLIBCXX_HAVE_ALIGNED_ALLOC
+ using ::aligned_alloc;
diff --git a/gcc-bootstrap/patches/patch-libstdc++-v3_src_c++11_system_error.cc b/gcc-bootstrap/patches/patch-libstdc++-v3_src_c++11_system_error.cc
new file mode 100644
index 0000000000..21aaefcddf
--- /dev/null
+++ b/gcc-bootstrap/patches/patch-libstdc++-v3_src_c++11_system_error.cc
@@ -0,0 +1,15 @@
+$NetBSD: patch-libstdc++-v3_src_c++11_system_error.cc,v 1.1 2024/04/01 14:33:58 js Exp $
+
+EALREADY and EBUSY are the same on QNX.
+
+--- libstdc++-v3/src/c++11/system_error.cc.orig	2023-07-07 07:08:22.000000000 +0000
++++ libstdc++-v3/src/c++11/system_error.cc
+@@ -100,7 +100,7 @@ namespace
+ #ifdef EAGAIN
+       case EAGAIN:
+ #endif
+-#ifdef EALREADY
++#if defined(EALREADY) && (!defined(EBUSY) || EALREADY != EBUSY)
+       case EALREADY:
+ #endif
+ #ifdef EBADF


Home | Main Index | Thread Index | Old Index