pkgsrc-WIP-changes archive

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

i686-elf-gcc: fix the build on macOS



Module Name:	pkgsrc-wip
Committed By:	Pierre Pronchery <khorben%defora.org@localhost>
Pushed By:	khorben
Date:		Fri Feb 28 03:07:40 2025 +0100
Changeset:	fb2e1416ea9c35822f7cb23e5cfd4e49aa21668f

Modified Files:
	i686-elf-gcc/Makefile
	i686-elf-gcc/distinfo
Added Files:
	i686-elf-gcc/patches/patch-contrib_download__prerequisites
	i686-elf-gcc/patches/patch-fixincludes_fixincl.x
	i686-elf-gcc/patches/patch-fixincludes_inclhack.def
	i686-elf-gcc/patches/patch-gcc_Makefile.in
	i686-elf-gcc/patches/patch-gcc_config.gcc
	i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64-builtins.c
	i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64-netbsd.h
	i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64.h
	i686-elf-gcc/patches/patch-gcc_config_aarch64_t-aarch64-netbsd
	i686-elf-gcc/patches/patch-gcc_config_arm_arm.h
	i686-elf-gcc/patches/patch-gcc_config_netbsd-elf.h
	i686-elf-gcc/patches/patch-gcc_config_netbsd-protos.h
	i686-elf-gcc/patches/patch-gcc_config_sparc_sparc.c
	i686-elf-gcc/patches/patch-gcc_config_t-netbsd
	i686-elf-gcc/patches/patch-gcc_config_x-netbsd
	i686-elf-gcc/patches/patch-gcc_configure
	i686-elf-gcc/patches/patch-gcc_ggc-common.c
	i686-elf-gcc/patches/patch-gcc_ginclude_stddef.h
	i686-elf-gcc/patches/patch-gcc_lto_lto.c
	i686-elf-gcc/patches/patch-gcc_plugin.c
	i686-elf-gcc/patches/patch-gcc_system.h
	i686-elf-gcc/patches/patch-gcc_targhooks.c
	i686-elf-gcc/patches/patch-libffi_configure
	i686-elf-gcc/patches/patch-libffi_testsuite_libffi.call_float2.c
	i686-elf-gcc/patches/patch-libgcc_config.host
	i686-elf-gcc/patches/patch-libgcc_crtstuff.c
	i686-elf-gcc/patches/patch-libgfortran_io_io.h
	i686-elf-gcc/patches/patch-libsanitizer_configure.tgt
	i686-elf-gcc/patches/patch-libsanitizer_sanitizer__common_Makefile.am
	i686-elf-gcc/patches/patch-libsanitizer_sanitizer__common_Makefile.in
	i686-elf-gcc/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__base.h
	i686-elf-gcc/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__configure__char.cc
	i686-elf-gcc/patches/patch-libstdc++-v3_libsupc++_new__opa.cc

Log Message:
i686-elf-gcc: fix the build on macOS

This duplicates the patch directory from lang/gcc8, in order to add the
missing patch for clang. (From 9e38ac6f9dafe61fdab858e8cb713ec9e5d3eb00)

Tested on macOS Sequoia 15.3.1 (amd64)

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

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

diffstat:
 i686-elf-gcc/Makefile                              |   1 -
 i686-elf-gcc/distinfo                              |   1 +
 .../patches/patch-contrib_download__prerequisites  |  17 ++++
 i686-elf-gcc/patches/patch-fixincludes_fixincl.x   | 111 +++++++++++++++++++++
 .../patches/patch-fixincludes_inclhack.def         |  36 +++++++
 i686-elf-gcc/patches/patch-gcc_Makefile.in         |  16 +++
 i686-elf-gcc/patches/patch-gcc_config.gcc          |  47 +++++++++
 .../patch-gcc_config_aarch64_aarch64-builtins.c    |  17 ++++
 .../patch-gcc_config_aarch64_aarch64-netbsd.h      | 104 +++++++++++++++++++
 .../patches/patch-gcc_config_aarch64_aarch64.h     |  15 +++
 .../patch-gcc_config_aarch64_t-aarch64-netbsd      |  28 ++++++
 i686-elf-gcc/patches/patch-gcc_config_arm_arm.h    |  20 ++++
 i686-elf-gcc/patches/patch-gcc_config_netbsd-elf.h |  63 ++++++++++++
 .../patches/patch-gcc_config_netbsd-protos.h       |  38 +++++++
 .../patches/patch-gcc_config_sparc_sparc.c         |  18 ++++
 i686-elf-gcc/patches/patch-gcc_config_t-netbsd     |  31 ++++++
 i686-elf-gcc/patches/patch-gcc_config_x-netbsd     |  12 +++
 i686-elf-gcc/patches/patch-gcc_configure           |  15 +++
 i686-elf-gcc/patches/patch-gcc_ggc-common.c        |  71 +++++++++++++
 i686-elf-gcc/patches/patch-gcc_ginclude_stddef.h   |  64 ++++++++++++
 i686-elf-gcc/patches/patch-gcc_lto_lto.c           |  19 ++++
 i686-elf-gcc/patches/patch-gcc_plugin.c            |  15 +++
 i686-elf-gcc/patches/patch-gcc_system.h            |  80 +++++++++++++++
 i686-elf-gcc/patches/patch-gcc_targhooks.c         |  17 ++++
 i686-elf-gcc/patches/patch-libffi_configure        |  16 +++
 .../patch-libffi_testsuite_libffi.call_float2.c    |  15 +++
 i686-elf-gcc/patches/patch-libgcc_config.host      |  32 ++++++
 i686-elf-gcc/patches/patch-libgcc_crtstuff.c       |  15 +++
 i686-elf-gcc/patches/patch-libgfortran_io_io.h     |  18 ++++
 .../patches/patch-libsanitizer_configure.tgt       |  19 ++++
 ...atch-libsanitizer_sanitizer__common_Makefile.am |  17 ++++
 ...atch-libsanitizer_sanitizer__common_Makefile.in |  28 ++++++
 ...libstdc++-v3_config_os_bsd_netbsd_ctype__base.h |  54 ++++++++++
 ..._config_os_bsd_netbsd_ctype__configure__char.cc |  81 +++++++++++++++
 .../patch-libstdc++-v3_libsupc++_new__opa.cc       |  17 ++++
 35 files changed, 1167 insertions(+), 1 deletion(-)

diffs:
diff --git a/i686-elf-gcc/Makefile b/i686-elf-gcc/Makefile
index b6a5cb1c05..a8908cb92c 100644
--- a/i686-elf-gcc/Makefile
+++ b/i686-elf-gcc/Makefile
@@ -9,7 +9,6 @@ PKGNAME=	cross-${GCC_TARGET}-${DISTNAME}
 CATEGORIES=	cross
 MASTER_SITES=	${MASTER_SITE_GNU:=gcc/gcc-${GCC8_DIST_VERSION}/}
 EXTRACT_USING=	bsdtar
-PATCHDIR=	${.CURDIR}/../../lang/gcc8/patches
 EXTRACT_SUFX=	.tar.xz
 
 MAINTAINER=	port-i386%NetBSD.org@localhost
diff --git a/i686-elf-gcc/distinfo b/i686-elf-gcc/distinfo
index 92d0bbf6b2..b7995cc828 100644
--- a/i686-elf-gcc/distinfo
+++ b/i686-elf-gcc/distinfo
@@ -23,6 +23,7 @@ SHA1 (patch-gcc_ggc-common.c) = a5d2dba635859f5d680c3f80d7c30b42461c752b
 SHA1 (patch-gcc_ginclude_stddef.h) = fb1f83801e0f5bcec110667dc868c47ff2d10343
 SHA1 (patch-gcc_lto_lto.c) = 7bd85ac8ade76a28c394f6fbe5d495f91824f79f
 SHA1 (patch-gcc_plugin.c) = 7a7ebc6650fe327fa7be1f7a4d26e8edc7597fcf
+SHA1 (patch-gcc_system.h) = 06d2aa59d1f34321ed7ff97167be193a54f3c81b
 SHA1 (patch-gcc_targhooks.c) = b28d8a9696d07bbfb00b7d8c55193ba99447ff1d
 SHA1 (patch-libffi_configure) = 22006b20d7f655e2455a7ad613d676703b6c1ccc
 SHA1 (patch-libffi_testsuite_libffi.call_float2.c) = 27b84a11378fb648dfaad0c70abedd77a0a1c1a8
diff --git a/i686-elf-gcc/patches/patch-contrib_download__prerequisites b/i686-elf-gcc/patches/patch-contrib_download__prerequisites
new file mode 100644
index 0000000000..0955fe7125
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-contrib_download__prerequisites
@@ -0,0 +1,17 @@
+$NetBSD: patch-contrib_download__prerequisites,v 1.2 2019/04/18 19:18:02 rillig 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/i686-elf-gcc/patches/patch-fixincludes_fixincl.x b/i686-elf-gcc/patches/patch-fixincludes_fixincl.x
new file mode 100644
index 0000000000..7fe3a1dcf6
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-fixincludes_fixincl.x
@@ -0,0 +1,111 @@
+$NetBSD: patch-fixincludes_fixincl.x,v 1.2 2020/04/08 06:39:57 wiz Exp $
+
+A workaround for Catalina SDK bug from
+https://github.com/Homebrew/homebrew-core/pull/44762
+
+--- fixincludes/fixincl.x.orig	2020-03-04 08:29:59.000000000 +0000
++++ fixincludes/fixincl.x
+@@ -2,11 +2,11 @@
+  *
+  * DO NOT EDIT THIS FILE   (fixincl.x)
+  *
+- * It has been AutoGen-ed  January  1, 2020 at 12:04:04 PM by AutoGen 5.18.16
++ * It has been AutoGen-ed  April  8, 2020 at 05:08:04 AM by AutoGen 5.18.10
+  * From the definitions    inclhack.def
+  * and the template file   fixincl
+  */
+-/* DO NOT SVN-MERGE THIS FILE, EITHER Wed Jan  1 12:04:05 EST 2020
++/* DO NOT SVN-MERGE THIS FILE, EITHER Wed Apr  8 05:08:04 GMT 2020
+  *
+  * You must regenerate it.  Use the ./genfixes script.
+  *
+@@ -15,7 +15,7 @@
+  * certain ANSI-incompatible system header files which are fixed to work
+  * correctly with ANSI C and placed in a directory that GNU C will search.
+  *
+- * This file contains 255 fixup descriptions.
++ * This file contains 256 fixup descriptions.
+  *
+  * See README for more information.
+  *
+@@ -2589,6 +2589,48 @@ extern \"C\" {\n\
+ 
+ /* * * * * * * * * * * * * * * * * * * * * * * * * *
+  *
++ *  Description of Darwin_Availability fix
++ */
++tSCC zDarwin_AvailabilityName[] =
++     "darwin_availability";
++
++/*
++ *  File name selection pattern
++ */
++tSCC zDarwin_AvailabilityList[] =
++  "Availability.h\0";
++/*
++ *  Machine/OS name selection pattern
++ */
++tSCC* apzDarwin_AvailabilityMachs[] = {
++        "*-*-darwin*",
++        (const char*)NULL };
++
++/*
++ *  content selection pattern - do fix if pattern found
++ */
++tSCC zDarwin_AvailabilitySelect0[] =
++       "#endif /\\* __OSX_AVAILABLE_STARTING \\*/";
++
++#define    DARWIN_AVAILABILITY_TEST_CT  1
++static tTestDesc aDarwin_AvailabilityTests[] = {
++  { TT_EGREP,    zDarwin_AvailabilitySelect0, (regex_t*)NULL }, };
++
++/*
++ *  Fix Command Arguments for Darwin_Availability
++ */
++static const char* apzDarwin_AvailabilityPatch[] = {
++    "format",
++    "#endif /* __OSX_AVAILABLE_STARTING */\n\
++#ifndef __OSX_AVAILABLE_STARTING\n\
++  #define __OSX_AVAILABLE_STARTING(_osx, _ios)\n\
++  #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep)\n\
++  #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg)\n\
++#endif",
++    (char*)NULL };
++
++/* * * * * * * * * * * * * * * * * * * * * * * * * *
++ *
+  *  Description of Darwin_Availabilityinternal fix
+  */
+ tSCC zDarwin_AvailabilityinternalName[] =
+@@ -10356,9 +10398,9 @@ static const char* apzX11_SprintfPatch[]
+  *
+  *  List of all fixes
+  */
+-#define REGEX_COUNT          294
++#define REGEX_COUNT          295
+ #define MACH_LIST_SIZE_LIMIT 187
+-#define FIX_COUNT            255
++#define FIX_COUNT            256
+ 
+ /*
+  *  Enumerate the fixes
+@@ -10425,6 +10467,7 @@ typedef enum {
+     CTRL_QUOTES_DEF_FIXIDX,
+     CTRL_QUOTES_USE_FIXIDX,
+     CXX_UNREADY_FIXIDX,
++    DARWIN_AVAILABILITY_FIXIDX,
+     DARWIN_AVAILABILITYINTERNAL_FIXIDX,
+     DARWIN_9_LONG_DOUBLE_FUNCS_2_FIXIDX,
+     DARWIN_EXTERNC_FIXIDX,
+@@ -10927,6 +10970,11 @@ tFixDesc fixDescList[ FIX_COUNT ] = {
+      CXX_UNREADY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
+      aCxx_UnreadyTests,   apzCxx_UnreadyPatch, 0 },
+ 
++  {  zDarwin_AvailabilityName,    zDarwin_AvailabilityList,
++     apzDarwin_AvailabilityMachs,
++     DARWIN_AVAILABILITY_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
++     aDarwin_AvailabilityTests,   apzDarwin_AvailabilityPatch, 0 },
++
+   {  zDarwin_AvailabilityinternalName,    zDarwin_AvailabilityinternalList,
+      apzDarwin_AvailabilityinternalMachs,
+      DARWIN_AVAILABILITYINTERNAL_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
diff --git a/i686-elf-gcc/patches/patch-fixincludes_inclhack.def b/i686-elf-gcc/patches/patch-fixincludes_inclhack.def
new file mode 100644
index 0000000000..c6cb3f4dde
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-fixincludes_inclhack.def
@@ -0,0 +1,36 @@
+$NetBSD: patch-fixincludes_inclhack.def,v 1.2 2020/04/08 06:39:57 wiz 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/i686-elf-gcc/patches/patch-gcc_Makefile.in b/i686-elf-gcc/patches/patch-gcc_Makefile.in
new file mode 100644
index 0000000000..0b12d719e3
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_Makefile.in
@@ -0,0 +1,16 @@
+$NetBSD: patch-gcc_Makefile.in,v 1.2 2020/09/17 22:04:15 ryoon Exp $
+
+Ensure libgcc from this GCC is found before others.  Note that there must
+not be a whitespace between $(LINKER_RPATH_FLAG) and the path.  Otherwise
+the flag may be misinterpreted by the linker (e.g. Apple ld).
+
+--- gcc/Makefile.in.orig	2017-05-02 16:12:40.965506000 +0000
++++ gcc/Makefile.in
+@@ -2112,6 +2112,7 @@ prefix.o: $(BASEVER)
+ # Language-independent files.
+ 
+ DRIVER_DEFINES = \
++  -DLINK_LIBGCC_SPEC="\"%D $(LINKER_RPATH_FLAG)$(prefix)/@MACHINE_GNU_PLATFORM@/lib/%M $(LINKER_RPATH_FLAG)$(libdir)/%M \"" \
+   -DSTANDARD_STARTFILE_PREFIX=\"$(unlibsubdir)/\" \
+   -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
+   -DSTANDARD_LIBEXEC_PREFIX=\"$(libexecdir)/gcc/\" \
diff --git a/i686-elf-gcc/patches/patch-gcc_config.gcc b/i686-elf-gcc/patches/patch-gcc_config.gcc
new file mode 100644
index 0000000000..8bc9219c1a
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config.gcc
@@ -0,0 +1,47 @@
+$NetBSD: patch-gcc_config.gcc,v 1.2 2018/11/10 11:45:27 mrg Exp $
+
+add arm64 support
+
+build cabs* rename support
+
+fix x86 crtstuff.
+
+--- gcc/config.gcc.orig	2018-06-25 19:34:01.000000000 +0000
++++ gcc/config.gcc	2018-11-10 00:20:47.655130032 +0000
+@@ -812,6 +812,9 @@
+   gas=yes
+   gnu_ld=yes
+   use_gcc_stdint=wrap
++  # cabs/cabsf are renamed to __c99_cabs/cabsf
++  target_gtfiles="${target_gtfiles} \$(srcdir)/config/netbsd.c"
++  default_gnu_indirect_function=yes
+   case ${enable_threads} in
+     "" | yes | posix) thread_file='posix' ;;
+   esac
+@@ -980,6 +983,13 @@
+ 	tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-freebsd.h"
+ 	tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-freebsd"
+ 	;;
++aarch64*-*-netbsd*)
++	tm_file="${tm_file} dbxelf.h elfos.h ${nbsd_tm_file}"
++	tm_file="${tm_file} aarch64/aarch64-elf.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"
++	# XXX big endian
++	;;
+ aarch64*-*-linux*)
+ 	tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h"
+ 	tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-linux.h"
+@@ -1523,10 +1533,12 @@
+ i[34567]86-*-netbsdelf*)
+ 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${nbsd_tm_file} i386/netbsd-elf.h"
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
++	tmake_file="${tmake_file} i386/t-crtstuff"
+ 	;;
+ 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"
+ 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
++	tmake_file="${tmake_file} i386/t-crtstuff"
+ 	;;
+ i[34567]86-*-openbsd*)
+ 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h"
diff --git a/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64-builtins.c b/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64-builtins.c
new file mode 100644
index 0000000000..e3ff568be1
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64-builtins.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-gcc_config_aarch64_aarch64-builtins.c,v 1.2 2021/02/13 15:56:17 maya 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
+@@ -991,6 +991,9 @@
+      register them.  */
+   if (!TARGET_ILP32)
+     aarch64_init_pauth_hint_builtins ();
++#ifdef SUBTARGET_INIT_BUILTINS
++  SUBTARGET_INIT_BUILTINS;
++#endif
+ }
+ 
+ tree
diff --git a/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64-netbsd.h b/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64-netbsd.h
new file mode 100644
index 0000000000..36c23d142d
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64-netbsd.h
@@ -0,0 +1,104 @@
+$NetBSD: patch-gcc_config_aarch64_aarch64-netbsd.h,v 1.2 2019/04/18 19:18:02 rillig Exp $
+
+AArch64 support for NetBSD.
+
+--- /dev/null	2018-11-09 09:25:57.929086649 +0000
++++ gcc/config/aarch64/aarch64-netbsd.h	2018-11-09 09:23:18.308262443 +0000
+@@ -0,0 +1,97 @@
++/* Definitions for AArch64 running NetBSD
++   Copyright (C) 2016-2017 Free Software Foundation, Inc.
++
++   This file is part of GCC.
++
++   GCC is free software; you can redistribute it and/or modify it
++   under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3, or (at your option)
++   any later version.
++
++   GCC is distributed in the hope that it will be useful, but
++   WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++   General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with GCC; see the file COPYING3.  If not see
++   <http://www.gnu.org/licenses/>.  */
++
++#ifndef GCC_AARCH64_NETBSD_H
++#define GCC_AARCH64_NETBSD_H
++
++#define TARGET_LINKER_BIG_EMULATION "aarch64nbsdb"
++#define TARGET_LINKER_LITTLE_EMULATION "aarch64nbsd"
++
++#if TARGET_BIG_ENDIAN_DEFAULT
++#define TARGET_LINKER_EMULATION  TARGET_LINKER_BIG_EMULATION
++#else
++#define TARGET_LINKER_EMULATION  TARGET_LINKER_LITTLE_EMULATION
++#endif
++
++#undef  SUBTARGET_EXTRA_LINK_SPEC
++#define SUBTARGET_EXTRA_LINK_SPEC " -m" TARGET_LINKER_EMULATION
++
++#define NETBSD_ENTRY_POINT "__start"
++
++#define NETBSD_TARGET_LINK_SPEC  "%{h*}			\
++   -X %{mbig-endian:-EB -m " TARGET_LINKER_BIG_EMULATION "} \
++   %{mlittle-endian:-EL -m " TARGET_LINKER_LITTLE_EMULATION "} \
++   %(netbsd_link_spec)"
++
++#if TARGET_FIX_ERR_A53_835769_DEFAULT
++#define CA53_ERR_835769_SPEC \
++  " %{!mno-fix-cortex-a53-835769:--fix-cortex-a53-835769}"
++#else
++#define CA53_ERR_835769_SPEC \
++  " %{mfix-cortex-a53-835769:--fix-cortex-a53-835769}"
++#endif
++
++#ifdef TARGET_FIX_ERR_A53_843419_DEFAULT
++#define CA53_ERR_843419_SPEC \
++  " %{!mno-fix-cortex-a53-843419:--fix-cortex-a53-843419}"
++#else
++#define CA53_ERR_843419_SPEC \
++  " %{mfix-cortex-a53-843419:--fix-cortex-a53-843419}"
++#endif
++
++#undef  LINK_SPEC
++#define LINK_SPEC NETBSD_LINK_SPEC_ELF 		\
++		  NETBSD_TARGET_LINK_SPEC	\
++                  CA53_ERR_835769_SPEC		\
++                  CA53_ERR_843419_SPEC
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS()		\
++  do						\
++    {						\
++      NETBSD_OS_CPP_BUILTINS_ELF();		\
++    }						\
++  while (0)
++
++#undef SUBTARGET_CPP_SPEC
++#define SUBTARGET_CPP_SPEC NETBSD_CPP_SPEC
++
++#if 0
++#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
++#endif
++
++#if 0
++/* Uninitialized common symbols in non-PIE executables, even with
++   strong definitions in dependent shared libraries, will resolve
++   to COPY relocated symbol in the executable.  See PR65780.  */
++#undef TARGET_BINDS_LOCAL_P
++#define TARGET_BINDS_LOCAL_P default_binds_local_p_2
++#endif
++
++#if 0
++#undef MCOUNT_NAME
++#define MCOUNT_NAME ".mcount"
++#endif
++
++#undef EXTRA_SPECS
++#define EXTRA_SPECS \
++  { "asm_cpu_spec",             ASM_CPU_SPEC }, \
++  NETBSD_SUBTARGET_EXTRA_SPECS
++
++#endif  /* GCC_AARCH64_NETBSD_H */
diff --git a/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64.h b/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64.h
new file mode 100644
index 0000000000..99e7912b1d
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_aarch64_aarch64.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-gcc_config_aarch64_aarch64.h,v 1.2 2019/04/18 19:18:02 rillig Exp $
+
+support AArch64.
+
+--- gcc/config/aarch64/aarch64.h.orig	2018-02-21 14:05:45.000000000 +0000
++++ gcc/config/aarch64/aarch64.h	2018-11-09 12:07:14.375232698 +0000
+@@ -1000,7 +1000,7 @@
+ #define MCPU_TO_MARCH_SPEC_FUNCTIONS \
+   { "rewrite_mcpu", aarch64_rewrite_mcpu },
+ 
+-#if defined(__aarch64__)
++#if defined(__aarch64__) && !defined(__NetBSD__)
+ extern const char *host_detect_local_cpu (int argc, const char **argv);
+ #define HAVE_LOCAL_CPU_DETECT
+ # define EXTRA_SPEC_FUNCTIONS						\
diff --git a/i686-elf-gcc/patches/patch-gcc_config_aarch64_t-aarch64-netbsd b/i686-elf-gcc/patches/patch-gcc_config_aarch64_t-aarch64-netbsd
new file mode 100644
index 0000000000..36ee914f82
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_aarch64_t-aarch64-netbsd
@@ -0,0 +1,28 @@
+$NetBSD: patch-gcc_config_aarch64_t-aarch64-netbsd,v 1.2 2019/04/18 19:18:02 rillig Exp $
+
+AArch64 support for NetBSD.
+
+--- /dev/null	2018-11-09 09:25:57.929086649 +0000
++++ gcc/config/aarch64/t-aarch64-netbsd	2018-11-09 09:23:36.784950907 +0000
+@@ -0,0 +1,21 @@
++# Machine description for AArch64 architecture.
++#  Copyright (C) 2016-2017 Free Software Foundation, Inc.
++#
++#  This file is part of GCC.
++#
++#  GCC is free software; you can redistribute it and/or modify it
++#  under the terms of the GNU General Public License as published by
++#  the Free Software Foundation; either version 3, or (at your option)
++#  any later version.
++#
++#  GCC is distributed in the hope that it will be useful, but
++#  WITHOUT ANY WARRANTY; without even the implied warranty of
++#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++#  General Public License for more details.
++#
++#  You should have received a copy of the GNU General Public License
++#  along with GCC; see the file COPYING3.  If not see
++#  <http://www.gnu.org/licenses/>.
++
++LIB1ASMSRC   = aarch64/lib1funcs.asm
++LIB1ASMFUNCS = _aarch64_sync_cache_range
diff --git a/i686-elf-gcc/patches/patch-gcc_config_arm_arm.h b/i686-elf-gcc/patches/patch-gcc_config_arm_arm.h
new file mode 100644
index 0000000000..15631d83c8
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_arm_arm.h
@@ -0,0 +1,20 @@
+$NetBSD: patch-gcc_config_arm_arm.h,v 1.2 2019/04/18 19:18:02 rillig Exp $
+
+driver-arm.o is only included for freebsd/arm and linux/arm, and
+it is responsible for the definition of host_detect_local_cpu.
+
+Without it, we get an undefined reference.
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77800
+
+--- gcc/config/arm/arm.h.orig	2018-03-22 17:24:41.000000000 +0000
++++ gcc/config/arm/arm.h
+@@ -2195,7 +2195,7 @@ extern const char *arm_target_thumb_only
+ 
+ /* -mcpu=native handling only makes sense with compiler running on
+    an ARM chip.  */
+-#if defined(__arm__)
++#if defined(__arm__) && (defined(__linux__) || defined(__FreeBSD__))
+ 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/i686-elf-gcc/patches/patch-gcc_config_netbsd-elf.h b/i686-elf-gcc/patches/patch-gcc_config_netbsd-elf.h
new file mode 100644
index 0000000000..d1f19cab4a
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_netbsd-elf.h
@@ -0,0 +1,63 @@
+$NetBSD: patch-gcc_config_netbsd-elf.h,v 1.2 2018/11/10 11:45:27 mrg Exp $
+
+Link PIE executables with crtbeginS/crtendS on NetBSD.
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87221
+
+Add NETBSD_SUBTARGET_EXTRA_SPECS and NETBSD_LINK_LD_ELF_SO_SPEC.
+
+--- gcc/config/netbsd-elf.h.orig	2018-01-03 10:03:58.000000000 +0000
++++ gcc/config/netbsd-elf.h	2018-11-10 06:47:49.835868835 +0000
+@@ -40,8 +40,11 @@
+        %{!p:crt0%O%s}}}		\
+    %:if-exists(crti%O%s)	\
+    %{static:%:if-exists-else(crtbeginT%O%s crtbegin%O%s)} \
+-   %{!static: \
+-     %{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
++   %{!static:                   \
++     %{!shared:                 \
++       %{!pie:crtbegin%O%s}     \
++       %{pie:crtbeginS%O%s}}    \
++     %{shared:crtbeginS%O%s}}"
+ 
+ #undef STARTFILE_SPEC
+ #define STARTFILE_SPEC NETBSD_STARTFILE_SPEC
+@@ -52,7 +55,10 @@
+    C++ file-scope static objects deconstructed after exiting "main".  */
+ 
+ #define NETBSD_ENDFILE_SPEC	\
+-  "%{!shared:crtend%O%s} %{shared:crtendS%O%s} \
++  "%{!shared:                   \
++    %{!pie:crtend%O%s}          \
++    %{pie:crtendS%O%s}}         \
++   %{shared:crtendS%O%s}        \
+    %:if-exists(crtn%O%s)"
+ 
+ #undef ENDFILE_SPEC
+@@ -67,6 +73,9 @@
+ 
+    Target-specific code must provide the %(netbsd_entry_point) spec.  */
+ 
++#define NETBSD_LINK_LD_ELF_SO_SPEC \
++  "%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.elf_so}"
++
+ #define NETBSD_LINK_SPEC_ELF \
+   "%{assert*} %{R*} %{rpath*} \
+    %{shared:-shared} \
+@@ -81,6 +90,17 @@
+        -dynamic-linker /usr/libexec/ld.elf_so} \
+      %{static:-static}}"
+ 
++/* Provide the standard list of subtarget extra specs for NetBSD targets.  */
++#define NETBSD_SUBTARGET_EXTRA_SPECS \
++  { "netbsd_link_ld_elf_so",    NETBSD_LINK_LD_ELF_SO_SPEC }, \
++  { "netbsd_cpp_spec",          NETBSD_CPP_SPEC }, \
++  { "netbsd_link_spec",         NETBSD_LINK_SPEC_ELF }, \
++  { "netbsd_entry_point",       NETBSD_ENTRY_POINT }, \
++  { "netbsd_endfile_spec",      NETBSD_ENDFILE_SPEC },
++
++#undef SUBTARGET_EXTRA_SPECS
++#define SUBTARGET_EXTRA_SPECS   NETBSD_SUBTARGET_EXTRA_SPECS
++
+ /* Use --as-needed -lgcc_s for eh support.  */
+ #ifdef HAVE_LD_AS_NEEDED
+ #define USE_LD_AS_NEEDED 1
diff --git a/i686-elf-gcc/patches/patch-gcc_config_netbsd-protos.h b/i686-elf-gcc/patches/patch-gcc_config_netbsd-protos.h
new file mode 100644
index 0000000000..c791b84528
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_netbsd-protos.h
@@ -0,0 +1,38 @@
+$NetBSD: patch-gcc_config_netbsd-protos.h,v 1.2 2020/04/08 06:39:57 wiz Exp $
+
+--- gcc/config/netbsd-protos.h.orig	2020-03-04 08:30:00.000000000 +0000
++++ gcc/config/netbsd-protos.h
+@@ -1,4 +1,33 @@
+ /* Prototypes.
++   Copyright (C) 2001-2014 Free Software Foundation, Inc.
++
++This file is part of GCC.
++
++GCC is free software; you can redistribute it and/or modify
++it under the terms of the GNU General Public License as published by
++the Free Software Foundation; either version 3, or (at your option)
++any later version.
++
++GCC is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++GNU General Public License for more details.
++
++You should have received a copy of the GNU General Public License
++along with GCC; see the file COPYING3.  If not see
++<http://www.gnu.org/licenses/>.  */
++
++#ifndef _NETBSD_PROTOS_H_
++#define _NETBSD_PROTOS_H_
++
++double __c99_cabs (double complex);
++float __c99_cabsf (float complex);
++long double __c99_cabsl (long double complex);
++
++void netbsd_patch_builtins (void);
++
++#endif /* _NETBSD_PROTOS_H_ */
++/* Prototypes.
+    Copyright (C) 2017-2018 Free Software Foundation, Inc.
+ 
+ This file is part of GCC.
diff --git a/i686-elf-gcc/patches/patch-gcc_config_sparc_sparc.c b/i686-elf-gcc/patches/patch-gcc_config_sparc_sparc.c
new file mode 100644
index 0000000000..e10b9ac126
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_sparc_sparc.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-gcc_config_sparc_sparc.c,v 1.1 2021/02/13 15:56:17 maya 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-03-04 08:30:00.000000000 +0000
++++ gcc/config/sparc/sparc.c
+@@ -10943,6 +10943,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/i686-elf-gcc/patches/patch-gcc_config_t-netbsd b/i686-elf-gcc/patches/patch-gcc_config_t-netbsd
new file mode 100644
index 0000000000..8991049df8
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_t-netbsd
@@ -0,0 +1,31 @@
+$NetBSD: patch-gcc_config_t-netbsd,v 1.2 2020/04/08 06:39:57 wiz Exp $
+
+--- gcc/config/t-netbsd.orig	2020-03-04 08:30:00.000000000 +0000
++++ gcc/config/t-netbsd
+@@ -1,3 +1,26 @@
++# Copyright (C) 2002-2014 Free Software Foundation, Inc.
++#
++# This file is part of GCC.
++#
++# GCC is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3, or (at your option)
++# any later version.
++#
++# GCC is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with GCC; see the file COPYING3.  If not see
++# <http://www.gnu.org/licenses/>.
++
++
++netbsd.o: $(srcdir)/config/netbsd.c
++	$(COMPILE) $<
++	$(POSTCOMPILE)
++
+ # Copyright (C) 2017-2018 Free Software Foundation, Inc.
+ #
+ # This file is part of GCC.
diff --git a/i686-elf-gcc/patches/patch-gcc_config_x-netbsd b/i686-elf-gcc/patches/patch-gcc_config_x-netbsd
new file mode 100644
index 0000000000..a54d008a5f
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_config_x-netbsd
@@ -0,0 +1,12 @@
+$NetBSD: patch-gcc_config_x-netbsd,v 1.1 2018/05/05 04:08:36 maya Exp $
+
+Add host hooks for NetBSD - needed for working precompiled headers.
+http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58397
+
+--- /dev/null	2013-09-11 09:12:57.000000000 +0200
++++ gcc/config/x-netbsd	2013-09-10 18:57:27.000000000 +0200
+@@ -0,0 +1,4 @@
++host-netbsd.o : $(srcdir)/config/host-netbsd.c $(CONFIG_H) $(SYSTEM_H) \
++  coretypes.h hosthooks.h hosthooks-def.h $(HOOKS_H)
++	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
++		$(srcdir)/config/host-netbsd.c
diff --git a/i686-elf-gcc/patches/patch-gcc_configure b/i686-elf-gcc/patches/patch-gcc_configure
new file mode 100644
index 0000000000..e244fc74e8
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_configure
@@ -0,0 +1,15 @@
+$NetBSD: patch-gcc_configure,v 1.2 2019/04/18 19:18:02 rillig 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/i686-elf-gcc/patches/patch-gcc_ggc-common.c b/i686-elf-gcc/patches/patch-gcc_ggc-common.c
new file mode 100644
index 0000000000..3ab0bcb2a6
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_ggc-common.c
@@ -0,0 +1,71 @@
+$NetBSD: patch-gcc_ggc-common.c,v 1.1 2018/05/05 04:08:36 maya Exp $
+
+--- gcc/ggc-common.c.orig	2014-12-10 03:45:40.000000000 +0000
++++ gcc/ggc-common.c
+@@ -603,6 +603,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
+@@ -616,32 +618,50 @@ gt_pch_restore (FILE *f)
+   /* Read in all the scalar variables.  */
+   for (rt = gt_pch_scalar_rtab; *rt; rt++)
+     for (rti = *rt; rti->base != NULL; rti++)
+-      if (fread (rti->base, rti->stride, 1, f) != 1)
++      if (fread (rti->base, rti->stride, 1, f) != 1) {
++        line_table = old_line_table;
++        input_location = old_input_loc;
+ 	fatal_error (input_location, "can%'t read PCH file: %m");
++      }
+ 
+   /* Read in all the global pointers, in 6 easy loops.  */
+   for (rt = gt_ggc_rtab; *rt; rt++)
+     for (rti = *rt; rti->base != NULL; rti++)
+       for (i = 0; i < rti->nelt; i++)
+ 	if (fread ((char *)rti->base + rti->stride * i,
+-		   sizeof (void *), 1, f) != 1)
++		   sizeof (void *), 1, f) != 1) {
++          line_table = old_line_table;
++          input_location = old_input_loc;
+ 	  fatal_error (input_location, "can%'t read PCH file: %m");
++        }
+ 
+-  if (fread (&mmi, sizeof (mmi), 1, f) != 1)
++  if (fread (&mmi, sizeof (mmi), 1, f) != 1) {
++    line_table = old_line_table;
++    input_location = old_input_loc;
+     fatal_error (input_location, "can%'t read PCH file: %m");
++  }
+ 
+   result = host_hooks.gt_pch_use_address (mmi.preferred_base, mmi.size,
+ 					  fileno (f), mmi.offset);
+-  if (result < 0)
++  if (result < 0) {
++    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)
++	  || fread (mmi.preferred_base, mmi.size, 1, f) != 1) {
++        line_table = old_line_table;
++        input_location = old_input_loc;
+ 	fatal_error (input_location, "can%'t read PCH file: %m");
++      }
+     }
+-  else if (fseek (f, mmi.offset + mmi.size, SEEK_SET) != 0)
+-    fatal_error (input_location, "can%'t read PCH file: %m");
++  else if (fseek (f, mmi.offset + mmi.size, SEEK_SET) != 0) {
++        line_table = old_line_table;
++        input_location = old_input_loc;
++        fatal_error (input_location, "can%'t read PCH file: %m");
++  }
+ 
+   ggc_pch_read (f, mmi.preferred_base);
+ 
diff --git a/i686-elf-gcc/patches/patch-gcc_ginclude_stddef.h b/i686-elf-gcc/patches/patch-gcc_ginclude_stddef.h
new file mode 100644
index 0000000000..7dc097643d
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_ginclude_stddef.h
@@ -0,0 +1,64 @@
+$NetBSD: patch-gcc_ginclude_stddef.h,v 1.2 2019/08/06 06:16:16 maya Exp $
+
+handle netbsd/arm not using the same include guards for
+ansi.h as other archs
+
+Upstreamed in 2018-06-20 (GCC 9.x)
+
+--- gcc/ginclude/stddef.h.orig	2017-01-01 12:07:43.000000000 +0000
++++ gcc/ginclude/stddef.h
+@@ -46,9 +46,7 @@ see the files COPYING3 and COPYING.RUNTI
+ /* This avoids lossage on SunOS but only if stdtypes.h comes first.
+    There's no way to win with the other order!  Sun lossage.  */
+ 
+-/* On 4.3bsd-net2, make sure ansi.h is included, so we have
+-   one less case to deal with in the following.  */
+-#if defined (__BSD_NET2__) || defined (____386BSD____) || (defined (__FreeBSD__) && (__FreeBSD__ < 5)) || defined(__NetBSD__)
++#if defined(__NetBSD__)
+ #include <machine/ansi.h>
+ #endif
+ /* On FreeBSD 5, machine/ansi.h does not exist anymore... */
+@@ -56,11 +54,7 @@ see the files COPYING3 and COPYING.RUNTI
+ #include <sys/_types.h>
+ #endif
+ 
+-/* In 4.3bsd-net2, machine/ansi.h defines these symbols, which are
+-   defined if the corresponding type is *not* defined.
+-   FreeBSD-2.1 defines _MACHINE_ANSI_H_ instead of _ANSI_H_.
+-   NetBSD defines _I386_ANSI_H_ and _X86_64_ANSI_H_ instead of _ANSI_H_ */
+-#if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_)  || defined(_I386_ANSI_H_)
++#if defined(__NetBSD__)
+ #if !defined(_SIZE_T_) && !defined(_BSD_SIZE_T_)
+ #define _SIZE_T
+ #endif
+@@ -87,7 +81,7 @@ see the files COPYING3 and COPYING.RUNTI
+ #undef _WCHAR_T_
+ #undef _BSD_WCHAR_T_
+ #endif
+-#endif /* defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_) */
++#endif /* defined(__NetBSD__) */
+ 
+ /* Sequent's header files use _PTRDIFF_T_ in some conflicting way.
+    Just ignore it.  */
+@@ -359,11 +353,7 @@ typedef __WINT_TYPE__ wint_t;
+ #undef __need_wint_t
+ #endif
+ 
+-/*  In 4.3bsd-net2, leave these undefined to indicate that size_t, etc.
+-    are already defined.  */
+-/*  BSD/OS 3.1 and FreeBSD [23].x require the MACHINE_ANSI_H check here.  */
+-/*  NetBSD 5 requires the I386_ANSI_H and X86_64_ANSI_H checks here.  */
+-#if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_)
++#if defined(__NetBSD__)
+ /*  The references to _GCC_PTRDIFF_T_, _GCC_SIZE_T_, and _GCC_WCHAR_T_
+     are probably typos and should be removed before 2.8 is released.  */
+ #ifdef _GCC_PTRDIFF_T_
+@@ -391,7 +381,7 @@ typedef __WINT_TYPE__ wint_t;
+ #undef _WCHAR_T_
+ #undef _BSD_WCHAR_T_
+ #endif
+-#endif /* _ANSI_H_ || _MACHINE_ANSI_H_ || _X86_64_ANSI_H_ || _I386_ANSI_H_ */
++#endif /* __NetBSD__ */
+ 
+ #endif /* __sys_stdtypes_h */
+ 
diff --git a/i686-elf-gcc/patches/patch-gcc_lto_lto.c b/i686-elf-gcc/patches/patch-gcc_lto_lto.c
new file mode 100644
index 0000000000..700d61a5e1
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_lto_lto.c
@@ -0,0 +1,19 @@
+$NetBSD: patch-gcc_lto_lto.c,v 1.1 2018/05/05 04:08:36 maya 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/i686-elf-gcc/patches/patch-gcc_plugin.c b/i686-elf-gcc/patches/patch-gcc_plugin.c
new file mode 100644
index 0000000000..58e6525a4a
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_plugin.c
@@ -0,0 +1,15 @@
+$NetBSD: patch-gcc_plugin.c,v 1.1 2023/09/05 16:54:20 vins Exp $
+
+Support dynamic link interface functions.
+
+--- gcc/plugin.c.orig	2022-05-27 07:21:11.335381405 +0000
++++ gcc/plugin.c
+@@ -20,6 +20,8 @@ along with GCC; see the file COPYING3.
+ /* This file contains the support for GCC plugin mechanism based on the
+    APIs described in doc/plugin.texi.  */
+ 
++#include <dlfcn.h>
++
+ #include "config.h"
+ #include "system.h"
+ #include "coretypes.h"
diff --git a/i686-elf-gcc/patches/patch-gcc_system.h b/i686-elf-gcc/patches/patch-gcc_system.h
new file mode 100644
index 0000000000..6cc4a86884
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_system.h
@@ -0,0 +1,80 @@
+$NetBSD: patch-gcc_system.h,v 1.2 2024/12/15 19:31:05 brook Exp $
+
+  Building gcc against libc++, e.g., with clang, poisons the ctype macros
+  due to including safe-ctype.h before including C++ standard headers such
+  as <list>, <map>, etc.
+
+  See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111632
+  
+--- gcc/system.h.orig	2018-02-16 09:05:35.000000000 +0000
++++ gcc/system.h
+@@ -44,6 +44,9 @@ along with GCC; see the file COPYING3.
+ #endif
+ 
+ #include <stdio.h>
++#ifdef __cplusplus
++# include <cstdio>
++#endif
+ 
+ /* Define a generic NULL if one hasn't already been defined.  */
+ #ifndef NULL
+@@ -194,27 +197,8 @@ extern int fprintf_unlocked (FILE *, con
+ #undef fread_unlocked
+ #undef fwrite_unlocked
+ 
+-/* Include <string> before "safe-ctype.h" to avoid GCC poisoning
+-   the ctype macros through safe-ctype.h */
+-
+-#ifdef __cplusplus
+-#ifdef INCLUDE_STRING
+-# include <string>
+-#endif
+-#endif
+-
+-/* There are an extraordinary number of issues with <ctype.h>.
+-   The last straw is that it varies with the locale.  Use libiberty's
+-   replacement instead.  */
+-#include "safe-ctype.h"
+-
+-#include <sys/types.h>
+-
+-#include <errno.h>
+-
+-#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
+-extern int errno;
+-#endif
++/* Include C++ standard headers before "safe-ctype.h" to avoid GCC
++   poisoning the ctype macros through safe-ctype.h */
+ 
+ #ifdef __cplusplus
+ #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY)
+@@ -229,6 +213,9 @@ extern int errno;
+ #ifdef INCLUDE_SET
+ # include <set>
+ #endif
++#ifdef INCLUDE_STRING
++# include <string>
++#endif
+ #ifdef INCLUDE_VECTOR
+ # include <vector>
+ #endif
+@@ -237,6 +224,19 @@ extern int errno;
+ # include <utility>
+ #endif
+ 
++/* There are an extraordinary number of issues with <ctype.h>.
++   The last straw is that it varies with the locale.  Use libiberty's
++   replacement instead.  */
++#include "safe-ctype.h"
++
++#include <sys/types.h>
++
++#include <errno.h>
++
++#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
++extern int errno;
++#endif
++
+ /* Some of glibc's string inlines cause warnings.  Plus we'd rather
+    rely on (and therefore test) GCC's string builtins.  */
+ #define __NO_STRING_INLINES
diff --git a/i686-elf-gcc/patches/patch-gcc_targhooks.c b/i686-elf-gcc/patches/patch-gcc_targhooks.c
new file mode 100644
index 0000000000..dd067b121f
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-gcc_targhooks.c
@@ -0,0 +1,17 @@
+$NetBSD: patch-gcc_targhooks.c,v 1.1 2018/07/18 22:56:22 maya 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/i686-elf-gcc/patches/patch-libffi_configure b/i686-elf-gcc/patches/patch-libffi_configure
new file mode 100644
index 0000000000..79210f396c
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libffi_configure
@@ -0,0 +1,16 @@
+$NetBSD: patch-libffi_configure,v 1.3 2019/04/25 17:07:06 rillig 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/i686-elf-gcc/patches/patch-libffi_testsuite_libffi.call_float2.c b/i686-elf-gcc/patches/patch-libffi_testsuite_libffi.call_float2.c
new file mode 100644
index 0000000000..f2829d199b
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libffi_testsuite_libffi.call_float2.c
@@ -0,0 +1,15 @@
+$NetBSD: patch-libffi_testsuite_libffi.call_float2.c,v 1.2 2019/04/18 19:18:02 rillig 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/i686-elf-gcc/patches/patch-libgcc_config.host b/i686-elf-gcc/patches/patch-libgcc_config.host
new file mode 100644
index 0000000000..14b5a44b81
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libgcc_config.host
@@ -0,0 +1,32 @@
+$NetBSD: patch-libgcc_config.host,v 1.4 2023/01/29 10:47:33 wiz Exp $
+
+Add NetBSD support for aarch64, x86 and x86_64.
+
+--- libgcc/config.host.orig	2021-05-14 08:42:10.000000000 +0000
++++ libgcc/config.host
+@@ -353,6 +353,12 @@ aarch64*-*-fuchsia*)
+ 	tmake_file="${tmake_file} ${cpu_type}/t-lse t-slibgcc-libgcc"
+ 	tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp"
+ 	;;
++aarch64*-*-netbsd*)
++	extra_parts="$extra_parts crtfastmath.o"
++	tmake_file="${tmake_file} ${cpu_type}/t-aarch64"
++	tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm"
++	md_unwind_header=aarch64/aarch64-unwind.h
++	;;
+ aarch64*-*-linux*)
+ 	extra_parts="$extra_parts crtfastmath.o"
+ 	md_unwind_header=aarch64/linux-unwind.h
+@@ -636,10 +642,10 @@ x86_64-*-freebsd*)
+ 	md_unwind_header=i386/freebsd-unwind.h
+ 	;;
+ i[34567]86-*-netbsdelf*)
+-	tmake_file="${tmake_file} i386/t-crtstuff"
++	tmake_file="${tmake_file} i386/t-netbsd i386/t-crtstuff"
+ 	;;
+ x86_64-*-netbsd*)
+-	tmake_file="${tmake_file} i386/t-crtstuff"
++	tmake_file="${tmake_file} i386/t-netbsd i386/t-crtstuff"
+ 	;;
+ i[34567]86-*-openbsd*)
+ 	;;
diff --git a/i686-elf-gcc/patches/patch-libgcc_crtstuff.c b/i686-elf-gcc/patches/patch-libgcc_crtstuff.c
new file mode 100644
index 0000000000..51a27b1fd9
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libgcc_crtstuff.c
@@ -0,0 +1,15 @@
+$NetBSD: patch-libgcc_crtstuff.c,v 1.2 2019/04/18 19:18:02 rillig Exp $
+
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90147
+
+--- libgcc/crtstuff.c.orig	2017-01-01 12:07:43.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
+  
diff --git a/i686-elf-gcc/patches/patch-libgfortran_io_io.h b/i686-elf-gcc/patches/patch-libgfortran_io_io.h
new file mode 100644
index 0000000000..32c8ab48d2
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libgfortran_io_io.h
@@ -0,0 +1,18 @@
+$NetBSD: patch-libgfortran_io_io.h,v 1.1 2018/05/05 04:08:36 maya 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/i686-elf-gcc/patches/patch-libsanitizer_configure.tgt b/i686-elf-gcc/patches/patch-libsanitizer_configure.tgt
new file mode 100644
index 0000000000..04f269a07a
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libsanitizer_configure.tgt
@@ -0,0 +1,19 @@
+$NetBSD: patch-libsanitizer_configure.tgt,v 1.1 2018/05/05 04:08:36 maya Exp $
+
+--- libsanitizer/configure.tgt.orig	2017-10-05 10:39:32.000000000 +0000
++++ libsanitizer/configure.tgt
+@@ -52,9 +52,13 @@ case "${target}" in
+ 		TSAN_TARGET_DEPENDENT_OBJECTS=tsan_rtl_aarch64.lo
+ 	fi
+ 	;;
+-  x86_64-*-darwin[1]* | i?86-*-darwin[1]*)
++  x86_64-*-darwin[1][1-9]* | i?86-*-darwin[1][1-9]*)
+ 	TSAN_SUPPORTED=no
+ 	;;
++  x86_64-*-netbsd*)
++	TSAN_SUPPORTED=no
++	LSAN_SUPPORTED=no
++	;;
+   *)
+ 	UNSUPPORTED=1
+ 	;;
diff --git a/i686-elf-gcc/patches/patch-libsanitizer_sanitizer__common_Makefile.am b/i686-elf-gcc/patches/patch-libsanitizer_sanitizer__common_Makefile.am
new file mode 100644
index 0000000000..3593fbd1e4
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libsanitizer_sanitizer__common_Makefile.am
@@ -0,0 +1,17 @@
+$NetBSD: patch-libsanitizer_sanitizer__common_Makefile.am,v 1.1 2018/05/05 04:08:36 maya Exp $
+
+--- libsanitizer/sanitizer_common/Makefile.am.orig	2017-10-19 11:23:59.000000000 +0000
++++ libsanitizer/sanitizer_common/Makefile.am
+@@ -40,6 +40,7 @@ sanitizer_common_files = \
+ 	sanitizer_mac_libcdep.cc \
+ 	sanitizer_persistent_allocator.cc \
+ 	sanitizer_platform_limits_linux.cc \
++	sanitizer_platform_limits_netbsd.cc \
+ 	sanitizer_platform_limits_posix.cc \
+ 	sanitizer_posix.cc \
+ 	sanitizer_posix_libcdep.cc \
+@@ -114,4 +115,3 @@ AM_MAKEFLAGS = \
+ MAKEOVERRIDES=
+ 
+ ## ################################################################
+-
diff --git a/i686-elf-gcc/patches/patch-libsanitizer_sanitizer__common_Makefile.in b/i686-elf-gcc/patches/patch-libsanitizer_sanitizer__common_Makefile.in
new file mode 100644
index 0000000000..934408d9d0
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libsanitizer_sanitizer__common_Makefile.in
@@ -0,0 +1,28 @@
+$NetBSD: patch-libsanitizer_sanitizer__common_Makefile.in,v 1.1 2018/05/05 04:08:36 maya Exp $
+
+--- libsanitizer/sanitizer_common/Makefile.in.orig	2017-10-22 22:33:06.000000000 +0000
++++ libsanitizer/sanitizer_common/Makefile.in
+@@ -91,6 +91,7 @@ am__objects_1 = sancov_flags.lo sanitize
+ 	sanitizer_mac.lo sanitizer_mac_libcdep.lo \
+ 	sanitizer_persistent_allocator.lo \
+ 	sanitizer_platform_limits_linux.lo \
++	sanitizer_platform_limits_netbsd.lo \
+ 	sanitizer_platform_limits_posix.lo sanitizer_posix.lo \
+ 	sanitizer_posix_libcdep.lo sanitizer_printf.lo \
+ 	sanitizer_procmaps_common.lo sanitizer_procmaps_freebsd.lo \
+@@ -322,6 +323,7 @@ sanitizer_common_files = \
+ 	sanitizer_mac_libcdep.cc \
+ 	sanitizer_persistent_allocator.cc \
+ 	sanitizer_platform_limits_linux.cc \
++	sanitizer_platform_limits_netbsd.cc \
+ 	sanitizer_platform_limits_posix.cc \
+ 	sanitizer_posix.cc \
+ 	sanitizer_posix_libcdep.cc \
+@@ -468,6 +470,7 @@ distclean-compile:
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_mac_libcdep.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_persistent_allocator.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_platform_limits_linux.Plo@am__quote@
++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_platform_limits_netbsd.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_platform_limits_posix.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_posix.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_posix_libcdep.Plo@am__quote@
diff --git a/i686-elf-gcc/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__base.h b/i686-elf-gcc/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__base.h
new file mode 100644
index 0000000000..08bc754fc1
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__base.h
@@ -0,0 +1,54 @@
+$NetBSD: patch-libstdc++-v3_config_os_bsd_netbsd_ctype__base.h,v 1.1 2018/05/05 04:08:36 maya Exp $
+
+Sync with netbsd ctype_base.h
+
+--- libstdc++-v3/config/os/bsd/netbsd/ctype_base.h.orig	2018-01-03 10:03:58.000000000 +0000
++++ libstdc++-v3/config/os/bsd/netbsd/ctype_base.h
+@@ -38,14 +38,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+   /// @brief  Base class for ctype.
+   struct ctype_base
+   {
+-    // Non-standard typedefs.
+-    typedef const unsigned char*	__to_type;
+ 
+     // NB: Offsets into ctype<char>::_M_table force a particular size
+     // on the mask type. Because of this, we don't use an enum.
+-    typedef unsigned char      	mask;
+ 
+ #ifndef _CTYPE_U
++    // Non-standard typedefs.
++    typedef const unsigned char*	__to_type;
++
++    typedef unsigned char      	mask;
++
+     static const mask upper    	= _U;
+     static const mask lower 	= _L;
+     static const mask alpha 	= _U | _L;
+@@ -58,17 +60,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+     static const mask punct 	= _P;
+     static const mask alnum 	= _U | _L | _N;
+ #else
++    typedef const unsigned short*	__to_type;
++
++    typedef unsigned short     	mask;
++
+     static const mask upper    	= _CTYPE_U;
+     static const mask lower 	= _CTYPE_L;
+-    static const mask alpha 	= _CTYPE_U | _CTYPE_L;
+-    static const mask digit 	= _CTYPE_N;
+-    static const mask xdigit 	= _CTYPE_N | _CTYPE_X;
++    static const mask alpha 	= _CTYPE_A;
++    static const mask digit 	= _CTYPE_D;
++    static const mask xdigit 	= _CTYPE_X;
+     static const mask space 	= _CTYPE_S;
+-    static const mask print 	= _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_N | _CTYPE_B;
+-    static const mask graph 	= _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_N;
++    static const mask print 	= _CTYPE_R;
++    static const mask graph 	= _CTYPE_G;
+     static const mask cntrl 	= _CTYPE_C;
+     static const mask punct 	= _CTYPE_P;
+-    static const mask alnum 	= _CTYPE_U | _CTYPE_L | _CTYPE_N;
++    static const mask alnum 	= _CTYPE_A | _CTYPE_D;
+ #endif
+ #if __cplusplus >= 201103L
+     static const mask blank 	= space;
diff --git a/i686-elf-gcc/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__configure__char.cc b/i686-elf-gcc/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__configure__char.cc
new file mode 100644
index 0000000000..2aad4842f5
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__configure__char.cc
@@ -0,0 +1,81 @@
+$NetBSD: patch-libstdc++-v3_config_os_bsd_netbsd_ctype__configure__char.cc,v 1.1 2018/05/05 04:08:36 maya Exp $
+
+Sync with netbsd ctype_configure_char.cc
+
+--- libstdc++-v3/config/os/bsd/netbsd/ctype_configure_char.cc.orig	2018-01-03 10:03:58.000000000 +0000
++++ libstdc++-v3/config/os/bsd/netbsd/ctype_configure_char.cc
+@@ -38,29 +38,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ 
+ // Information as gleaned from /usr/include/ctype.h
+ 
+-  extern "C" const u_int8_t _C_ctype_[];
+-
+   const ctype_base::mask*
+   ctype<char>::classic_table() throw()
+-  { return _C_ctype_ + 1; }
++  { return _C_ctype_tab_ + 1; }
+ 
+-  ctype<char>::ctype(__c_locale, const mask* __table, bool __del,
+-		     size_t __refs)
+-  : facet(__refs), _M_del(__table != 0 && __del),
+-  _M_toupper(NULL), _M_tolower(NULL),
++  ctype<char>::ctype(__c_locale, const mask* __table, bool __del, 
++		     size_t __refs) 
++  : facet(__refs), _M_del(__table != 0 && __del), 
++  _M_toupper(NULL), _M_tolower(NULL), 
+   _M_table(__table ? __table : classic_table())
+-  {
++  { 
+     memset(_M_widen, 0, sizeof(_M_widen));
+     _M_widen_ok = 0;
+     memset(_M_narrow, 0, sizeof(_M_narrow));
+     _M_narrow_ok = 0;
+   }
+ 
+-  ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
+-  : facet(__refs), _M_del(__table != 0 && __del),
+-  _M_toupper(NULL), _M_tolower(NULL),
++  ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
++  : facet(__refs), _M_del(__table != 0 && __del), 
++  _M_toupper(NULL), _M_tolower(NULL), 
+   _M_table(__table ? __table : classic_table())
+-  {
++  { 
+     memset(_M_widen, 0, sizeof(_M_widen));
+     _M_widen_ok = 0;
+     memset(_M_narrow, 0, sizeof(_M_narrow));
+@@ -69,14 +67,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ 
+   char
+   ctype<char>::do_toupper(char __c) const
+-  { return ::toupper((int) __c); }
++  { return ::toupper((int)(unsigned char) __c); }
+ 
+   const char*
+   ctype<char>::do_toupper(char* __low, const char* __high) const
+   {
+     while (__low < __high)
+       {
+-	*__low = ::toupper((int) *__low);
++	*__low = ::toupper((int)(unsigned char) *__low);
+ 	++__low;
+       }
+     return __high;
+@@ -84,14 +82,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ 
+   char
+   ctype<char>::do_tolower(char __c) const
+-  { return ::tolower((int) __c); }
++  { return ::tolower((int)(unsigned char) __c); }
+ 
+-  const char*
++  const char* 
+   ctype<char>::do_tolower(char* __low, const char* __high) const
+   {
+     while (__low < __high)
+       {
+-	*__low = ::tolower((int) *__low);
++	*__low = ::tolower((int)(unsigned char) *__low);
+ 	++__low;
+       }
+     return __high;
diff --git a/i686-elf-gcc/patches/patch-libstdc++-v3_libsupc++_new__opa.cc b/i686-elf-gcc/patches/patch-libstdc++-v3_libsupc++_new__opa.cc
new file mode 100644
index 0000000000..278453115d
--- /dev/null
+++ b/i686-elf-gcc/patches/patch-libstdc++-v3_libsupc++_new__opa.cc
@@ -0,0 +1,17 @@
+$NetBSD: patch-libstdc++-v3_libsupc++_new__opa.cc,v 1.3 2020/04/08 06:39:57 wiz 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;


Home | Main Index | Thread Index | Old Index