diff -pruN 1.17.3-1/debian/changelog 1.17.3-1ubuntu2/debian/changelog
--- 1.17.3-1/debian/changelog	2021-11-07 14:33:32.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/changelog	2022-03-23 13:55:39.000000000 +0000
@@ -1,3 +1,27 @@
+golang-1.17 (1.17.3-1ubuntu2) jammy; urgency=medium
+
+  * No-change rebuild for ppc64el baseline bump.
+
+ -- Łukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com>  Wed, 23 Mar 2022 14:55:39 +0100
+
+golang-1.17 (1.17.3-1ubuntu1) jammy; urgency=low
+
+  * Merge from Debian unstable (LP: #1951125). Remaining changes:
+    - Add support for c-archive and c-shared on RISC-V (LP: #1936664)
+      - Apply patches from https://github.com/4a6f656c/go.git,
+        branch riscv64-c-shared-go1.16:
+        - d/patches/0001-runtime-cgo-save-and-restore-X3-aka-GP-for-crosscall.patch
+        - d/patches/0002-runtime-save-and-restore-X3-aka-GP-for-asmcgocalls-o.patch
+        - d/patches/0003-all-add-support-for-c-archive-and-c-shared-on-linux-.patch
+        - d/patches/0004-runtime-change-riscv64-assembly-to-work-with-Go-1.16.patch
+    - d/patches/0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch:
+      disable internal linking when dynamically linking and CGO_CFLAGS
+      contains flags that might make host object files that the internal
+      linkers ELF reader does not support. This fixes lots of package builds
+      when LTO is enabled by default via dpkg-buildflags.
+
+ -- William 'jawn-smith' Wilson <william.wilson@canonical.com>  Mon, 15 Nov 2021 14:12:56 -0600
+
 golang-1.17 (1.17.3-1) unstable; urgency=medium
 
   * Team upload.
@@ -60,6 +84,29 @@ golang-1.17 (1.17-2) unstable; urgency=m
 
  -- Shengjing Zhu <zhsj@debian.org>  Sun, 29 Aug 2021 01:16:12 +0800
 
+golang-1.17 (1.17-1ubuntu2) impish; urgency=medium
+
+  * Add support for c-archive and c-shared on RISC-V (LP: #1936664)
+    - Apply patches from https://github.com/4a6f656c/go.git,
+      branch riscv64-c-shared-go1.16:
+      - d/patches/0001-runtime-cgo-save-and-restore-X3-aka-GP-for-crosscall.patch
+      - d/patches/0002-runtime-save-and-restore-X3-aka-GP-for-asmcgocalls-o.patch
+      - d/patches/0003-all-add-support-for-c-archive-and-c-shared-on-linux-.patch
+      - d/patches/0004-runtime-change-riscv64-assembly-to-work-with-Go-1.16.patch
+
+ -- William 'jawn-smith' Wilson <william.wilson@canonical.com>  Thu, 16 Sep 2021 13:47:34 -0500
+
+golang-1.17 (1.17-1ubuntu1) impish; urgency=medium
+
+  * Merge from Debian NEW. Remaining changes:
+    - d/patches/0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch:
+      disable internal linking when dynamically linking and CGO_CFLAGS
+      contains flags that might make host object files that the internal
+      linkers ELF reader does not support. This fixes lots of package builds
+      when LTO is enabled by default via dpkg-buildflags.
+
+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com>  Mon, 23 Aug 2021 17:00:57 +1200
+
 golang-1.17 (1.17-1) unstable; urgency=medium
 
   * Team upload.
@@ -73,6 +120,14 @@ golang-1.17 (1.17-1) unstable; urgency=m
 
  -- Michael Hudson-Doyle <mwhudson@debian.org>  Tue, 17 Aug 2021 13:03:28 +1200
 
+golang-1.17 (1.17~rc2-0ubuntu1) impish; urgency=medium
+
+  * New upstream release candidate.
+  * Refresh patches, dropping two that are merged upstream.
+  * Do not include the now-deleted favicon.ico in golang-1.17-doc.
+
+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com>  Tue, 03 Aug 2021 20:46:46 +1200
+
 golang-1.16 (1.16.7-1) unstable; urgency=medium
 
   * Team upload.
@@ -91,6 +146,19 @@ golang-1.16 (1.16.6-1) unstable; urgency
 
  -- Shengjing Zhu <zhsj@debian.org>  Tue, 13 Jul 2021 13:11:46 +0800
 
+golang-1.16 (1.16.5-1ubuntu1) impish; urgency=medium
+
+  * Merge from Debian unstable. Remaning change:
+    - d/patches/0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch:
+      disable internal linking when dynamically linking and CGO_CFLAGS
+      contains flags that might make host object files that the internal
+      linkers ELF reader does not support. This fixes lots of package builds
+      when LTO is enabled by default via dpkg-buildflags.
+  * d/patches/0007-cmd-link-cmd-cgo-support-flto-in-CFLAGS.patch:
+    backport another patch from upstream to fix some failures seen with LTO.
+
+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com>  Wed, 16 Jun 2021 15:56:28 +1200
+
 golang-1.16 (1.16.5-1) unstable; urgency=medium
 
   * Team upload.
@@ -176,6 +244,18 @@ golang-1.16 (1.16.3-1) unstable; urgency
 
  -- Shengjing Zhu <zhsj@debian.org>  Sun, 18 Apr 2021 03:56:41 +0800
 
+golang-1.16 (1.16.2-0ubuntu1) hirsute; urgency=medium
+
+  * New upstream version.
+
+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com>  Tue, 16 Mar 2021 16:34:16 +1300
+
+golang-1.16 (1.16.1-0ubuntu1) hirsute; urgency=medium
+
+  * New upstream version.
+
+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com>  Thu, 11 Mar 2021 11:24:27 +1300
+
 golang-1.16 (1.16-1) unstable; urgency=medium
 
   * New upstream version 1.16
@@ -184,6 +264,17 @@ golang-1.16 (1.16-1) unstable; urgency=m
 
  -- Anthony Fok <foka@debian.org>  Thu, 18 Feb 2021 00:02:53 -0700
 
+golang-1.16 (1.16-0ubuntu1) hirsute; urgency=medium
+
+  * New upstream version.
+  * d/patches/0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch:
+    disable internal linking when dynamically linking and CGO_CFLAGS contains
+    flags that might make host object files that the internal linkers ELF
+    reader does not support. This fixes lots of package builds when LTO is
+    enabled by default via dpkg-buildflags.
+
+ -- Michael Hudson-Doyle <michael.hudson@ubuntu.com>  Wed, 17 Feb 2021 14:15:58 +1300
+
 golang-1.16 (1.16~rc1-1) unstable; urgency=medium
 
   * Team upload.
@@ -1722,3 +1813,4 @@ golang (2011.02.01.1-1) unstable; urgenc
   * Remove codereview directory - some python code to deal with mercurial
 
  -- Ondřej Surý <ondrej@debian.org>  Mon, 14 Feb 2011 17:42:39 +0100
+
diff -pruN 1.17.3-1/debian/control 1.17.3-1ubuntu2/debian/control
--- 1.17.3-1/debian/control	2021-11-07 14:33:32.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/control	2021-11-15 20:12:56.000000000 +0000
@@ -3,7 +3,8 @@
 #
 
 Source: golang-1.17
-Maintainer: Debian Go Compiler Team <team+go-compiler@tracker.debian.org>
+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
+XSBC-Original-Maintainer: Go Compiler Team <team+go-compiler@tracker.debian.org>
 Uploaders: Michael Stapelberg <stapelberg@debian.org>,
            Paul Tagliamonte <paultag@debian.org>,
            Tianon Gravi <tianon@debian.org>,
diff -pruN 1.17.3-1/debian/control.in 1.17.3-1ubuntu2/debian/control.in
--- 1.17.3-1/debian/control.in	2021-11-07 14:33:32.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/control.in	2021-11-15 20:12:56.000000000 +0000
@@ -1,5 +1,6 @@
 Source: golang-X.Y
-Maintainer: Debian Go Compiler Team <team+go-compiler@tracker.debian.org>
+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
+XSBC-Original-Maintainer: Go Compiler Team <team+go-compiler@tracker.debian.org>
 Uploaders: Michael Stapelberg <stapelberg@debian.org>,
            Paul Tagliamonte <paultag@debian.org>,
            Tianon Gravi <tianon@debian.org>,
diff -pruN 1.17.3-1/debian/gbp.conf 1.17.3-1ubuntu2/debian/gbp.conf
--- 1.17.3-1/debian/gbp.conf	2021-11-07 14:33:32.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/gbp.conf	2021-11-15 20:12:56.000000000 +0000
@@ -3,7 +3,7 @@
 #
 
 [DEFAULT]
-debian-branch = golang-1.17
+debian-branch = ubuntu-1.17
 debian-tag = debian/%(version)s
 upstream-branch = upstream-1.17
 upstream-tag = upstream/%(version)s
diff -pruN 1.17.3-1/debian/gbp.conf.in 1.17.3-1ubuntu2/debian/gbp.conf.in
--- 1.17.3-1/debian/gbp.conf.in	2021-11-07 14:33:32.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/gbp.conf.in	2021-11-15 20:12:56.000000000 +0000
@@ -1,5 +1,5 @@
 [DEFAULT]
-debian-branch = golang-X.Y
+debian-branch = ubuntu-X.Y
 debian-tag = debian/%(version)s
 upstream-branch = upstream-X.Y
 upstream-tag = upstream/%(version)s
diff -pruN 1.17.3-1/debian/patches/0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch 1.17.3-1ubuntu2/debian/patches/0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch
--- 1.17.3-1/debian/patches/0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch	1970-01-01 00:00:00.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/patches/0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch	2021-11-15 20:12:56.000000000 +0000
@@ -0,0 +1,75 @@
+From 9842b1f35452eaf8b2ca7252905bc6501a956202 Mon Sep 17 00:00:00 2001
+From: Michael Hudson-Doyle <michael.hudson@canonical.com>
+Date: Wed, 6 Jan 2021 12:18:24 +1300
+Subject: [PATCH] cmd/link: check CGO_CFLAGS for non -g/-I/-O options before
+ internal linking
+
+On Ubuntu we are investigating enabling link-time optimization by
+default, which means the default CFLAGS will contain arguments that
+cause gcc to generate object files cmd/link/internal/loadelf cannot
+process. Rather than failing in this situation, scan CGO_CFLAGS in
+mustLinkExternal and do not link internally if there is a flag that does
+not start with -g, -I, or -O.
+
+CFLAGS can also be injected via #cgo CFLAGS: directives but as use of
+any non-standard library cgo modules disables internal linking anyway,
+we don't have to worry about that here.
+
+Fixes #43505
+
+Change-Id: Ib083f6daf22617e2e5df67e95d3bc178942328cd
+---
+ src/cmd/link/internal/ld/config.go | 28 ++++++++++++++++++++++++++++
+ 1 file changed, 28 insertions(+)
+
+--- a/src/cmd/link/internal/ld/config.go
++++ b/src/cmd/link/internal/ld/config.go
+@@ -8,6 +8,8 @@
+ 	"cmd/internal/sys"
+ 	"fmt"
+ 	"internal/buildcfg"
++	"os"
++	"strings"
+ )
+ 
+ // A BuildMode indicates the sort of object we are building.
+@@ -248,6 +250,29 @@
+ 	return false, ""
+ }
+ 
++// Some arguments in CGO_CFLAGS can cause the host compiler to
++// generate object files that loadelf cannot handle but arguments
++// starting with any of these values are OK.
++var internalOKCflagPrefixes = []string{
++	"-O",
++	"-g",
++	"-I",
++}
++
++func cflagsOKForInternalLinking() bool {
++outer:
++	for _, flag := range strings.Fields(os.Getenv("CGO_CFLAGS")) {
++		for _, okPrefix := range internalOKCflagPrefixes {
++			if strings.HasPrefix(flag, okPrefix) {
++				continue outer
++			}
++		}
++		return false
++	}
++
++	return true
++}
++
+ // determineLinkMode sets ctxt.LinkMode.
+ //
+ // It is called after flags are processed and inputs are processed,
+@@ -272,6 +297,9 @@
+ 		default:
+ 			if extNeeded || (iscgo && externalobj) {
+ 				ctxt.LinkMode = LinkExternal
++			} else if iscgo && !cflagsOKForInternalLinking() {
++				ctxt.LinkMode = LinkExternal
++				extReason = "CGO_CFLAGS contains flag that may inhibit internal linking"
+ 			} else {
+ 				ctxt.LinkMode = LinkInternal
+ 			}
diff -pruN 1.17.3-1/debian/patches/0001-runtime-cgo-save-and-restore-X3-aka-GP-for-crosscall.patch 1.17.3-1ubuntu2/debian/patches/0001-runtime-cgo-save-and-restore-X3-aka-GP-for-crosscall.patch
--- 1.17.3-1/debian/patches/0001-runtime-cgo-save-and-restore-X3-aka-GP-for-crosscall.patch	1970-01-01 00:00:00.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/patches/0001-runtime-cgo-save-and-restore-X3-aka-GP-for-crosscall.patch	2021-11-15 20:12:56.000000000 +0000
@@ -0,0 +1,150 @@
+From 883737f2eacde79d2208e9d756e296d57d292078 Mon Sep 17 00:00:00 2001
+From: Joel Sing <joel@sing.id.au>
+Date: Fri, 16 Jul 2021 02:56:08 +1000
+Subject: [PATCH 1/4] runtime/cgo: save and restore X3 (aka GP) for crosscall1
+ on riscv64
+
+The C code that is calling crosscall1 may depend on the GP register, which Go code
+will currently clobber. Save and restore both X3 (aka GP) and X4 (aka TP) in this
+code path (note that the Go code does not currently clobber X4, however there is
+minimal downside to saving and restoring it here, which then also matches crosscall2).
+
+Updates #47100
+
+Change-Id: Icbb706d7889d5dc59de3efb2b510fa6ea2069496
+---
+ src/runtime/cgo/gcc_riscv64.S | 108 ++++++++++++++++++----------------
+ 1 file changed, 56 insertions(+), 52 deletions(-)
+
+diff --git a/src/runtime/cgo/gcc_riscv64.S b/src/runtime/cgo/gcc_riscv64.S
+index f429dc64ee..fdc77496d9 100644
+--- a/src/runtime/cgo/gcc_riscv64.S
++++ b/src/runtime/cgo/gcc_riscv64.S
+@@ -8,36 +8,38 @@
+  * Calling into the gc tool chain, where all registers are caller save.
+  * Called from standard RISCV ELF psABI, where x8-x9, x18-x27, f8-f9 and
+  * f18-f27 are callee-save, so they must be saved explicitly, along with
+- * x1 (LR).
++ * x1 (LR), x3 (GP) and x4 (TP).
+  */
+ .globl crosscall1
+ crosscall1:
+-	sd	x1, -200(sp)
+-	addi	sp, sp, -200
+-	sd	x8, 8(sp)
+-	sd	x9, 16(sp)
+-	sd	x18, 24(sp)
+-	sd	x19, 32(sp)
+-	sd	x20, 40(sp)
+-	sd	x21, 48(sp)
+-	sd	x22, 56(sp)
+-	sd	x23, 64(sp)
+-	sd	x24, 72(sp)
+-	sd	x25, 80(sp)
+-	sd	x26, 88(sp)
+-	sd	x27, 96(sp)
+-	fsd	f8, 104(sp)
+-	fsd	f9, 112(sp)
+-	fsd	f18, 120(sp)
+-	fsd	f19, 128(sp)
+-	fsd	f20, 136(sp)
+-	fsd	f21, 144(sp)
+-	fsd	f22, 152(sp)
+-	fsd	f23, 160(sp)
+-	fsd	f24, 168(sp)
+-	fsd	f25, 176(sp)
+-	fsd	f26, 184(sp)
+-	fsd	f27, 192(sp)
++	sd	x1, -216(sp)
++	addi	sp, sp, -216
++	sd	x3, 8(sp)
++	sd	x4, 16(sp)
++	sd	x8, 24(sp)
++	sd	x9, 32(sp)
++	sd	x18, 40(sp)
++	sd	x19, 48(sp)
++	sd	x20, 56(sp)
++	sd	x21, 64(sp)
++	sd	x22, 72(sp)
++	sd	x23, 80(sp)
++	sd	x24, 88(sp)
++	sd	x25, 96(sp)
++	sd	x26, 104(sp)
++	sd	x27, 112(sp)
++	fsd	f8, 120(sp)
++	fsd	f9, 128(sp)
++	fsd	f18, 136(sp)
++	fsd	f19, 144(sp)
++	fsd	f20, 152(sp)
++	fsd	f21, 160(sp)
++	fsd	f22, 168(sp)
++	fsd	f23, 176(sp)
++	fsd	f24, 184(sp)
++	fsd	f25, 192(sp)
++	fsd	f26, 200(sp)
++	fsd	f27, 208(sp)
+ 
+ 	// a0 = *fn, a1 = *setg_gcc, a2 = *g
+ 	mv	s1, a0
+@@ -47,31 +49,33 @@ crosscall1:
+ 	jalr	ra, s1	// call fn
+ 
+ 	ld	x1, 0(sp)
+-	ld	x8, 8(sp)
+-	ld	x9, 16(sp)
+-	ld	x18, 24(sp)
+-	ld	x19, 32(sp)
+-	ld	x20, 40(sp)
+-	ld	x21, 48(sp)
+-	ld	x22, 56(sp)
+-	ld	x23, 64(sp)
+-	ld	x24, 72(sp)
+-	ld	x25, 80(sp)
+-	ld	x26, 88(sp)
+-	ld	x27, 96(sp)
+-	fld	f8, 104(sp)
+-	fld	f9, 112(sp)
+-	fld	f18, 120(sp)
+-	fld	f19, 128(sp)
+-	fld	f20, 136(sp)
+-	fld	f21, 144(sp)
+-	fld	f22, 152(sp)
+-	fld	f23, 160(sp)
+-	fld	f24, 168(sp)
+-	fld	f25, 176(sp)
+-	fld	f26, 184(sp)
+-	fld	f27, 192(sp)
+-	addi	sp, sp, 200
++	ld	x3, 8(sp)
++	ld	x4, 16(sp)
++	ld	x8, 24(sp)
++	ld	x9, 32(sp)
++	ld	x18, 40(sp)
++	ld	x19, 48(sp)
++	ld	x20, 56(sp)
++	ld	x21, 64(sp)
++	ld	x22, 72(sp)
++	ld	x23, 80(sp)
++	ld	x24, 88(sp)
++	ld	x25, 96(sp)
++	ld	x26, 104(sp)
++	ld	x27, 112(sp)
++	fld	f8, 120(sp)
++	fld	f9, 128(sp)
++	fld	f18, 136(sp)
++	fld	f19, 144(sp)
++	fld	f20, 152(sp)
++	fld	f21, 160(sp)
++	fld	f22, 168(sp)
++	fld	f23, 176(sp)
++	fld	f24, 184(sp)
++	fld	f25, 192(sp)
++	fld	f26, 200(sp)
++	fld	f27, 208(sp)
++	addi	sp, sp, 216
+ 
+ 	jr	ra
+ 
+-- 
+2.30.2
+
diff -pruN 1.17.3-1/debian/patches/0002-runtime-save-and-restore-X3-aka-GP-for-asmcgocalls-o.patch 1.17.3-1ubuntu2/debian/patches/0002-runtime-save-and-restore-X3-aka-GP-for-asmcgocalls-o.patch
--- 1.17.3-1/debian/patches/0002-runtime-save-and-restore-X3-aka-GP-for-asmcgocalls-o.patch	1970-01-01 00:00:00.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/patches/0002-runtime-save-and-restore-X3-aka-GP-for-asmcgocalls-o.patch	2021-11-15 20:12:56.000000000 +0000
@@ -0,0 +1,47 @@
+From d832860a6b3e9e523c6401e311495a56fd824034 Mon Sep 17 00:00:00 2001
+From: Joel Sing <joel@sing.id.au>
+Date: Fri, 16 Jul 2021 03:00:55 +1000
+Subject: [PATCH 2/4] runtime: save and restore X3 (aka GP) for asmcgocalls on
+ riscv64
+
+The X3 (aka GP) register will potentially be loaded with the __global_pointer$ symbol
+during program start up (usually the dynamic linker). As such, non-Go code may depend
+on the contents of GP, including code called via cgo. Save the original GP value on
+early entry to Go, then restore it in asmcgocall prior to calling non-Go code.
+
+An alternative would be to prevent Go from allocating the X3 register, but this seems
+like a better option.
+
+Updates #47100
+
+Change-Id: I10356886babd958da019a6a0179f609fe90517da
+---
+ src/runtime/asm_riscv64.s       | 3 +++
+ src/runtime/rt0_linux_riscv64.s | 5 +++++
+ 2 files changed, 8 insertions(+)
+
+--- a/src/runtime/asm_riscv64.s
++++ b/src/runtime/asm_riscv64.s
+@@ -345,6 +345,9 @@
+ 	SUB	X8, X9, X8
+ 	MOV	X8, 8(X2)	// save depth in old g stack (can't just save SP, as stack might be copied during a callback)
+ 
++	// Reload GP before calling C code.
++	MOV	$runtime·gp+0(SB), X8
++	MOV	(X8), GP
+ 	JALR	RA, (X5)
+ 
+ 	// Restore g, stack pointer. X10 is return value.
+--- a/src/runtime/rt0_linux_riscv64.s
++++ b/src/runtime/rt0_linux_riscv64.s
+@@ -10,5 +10,10 @@
+ 	JMP	main(SB)
+ 
+ TEXT main(SB),NOSPLIT|NOFRAME,$0
++	MOV	$runtime·gp+0(SB), T0
++	MOV	GP, (T0)
+ 	MOV	$runtime·rt0_go(SB), T0
+ 	JALR	ZERO, T0
++
++DATA	runtime·gp+0(SB)/8,$0
++GLOBL	runtime·gp(SB),NOPTR,$8
diff -pruN 1.17.3-1/debian/patches/0003-all-add-support-for-c-archive-and-c-shared-on-linux-.patch 1.17.3-1ubuntu2/debian/patches/0003-all-add-support-for-c-archive-and-c-shared-on-linux-.patch
--- 1.17.3-1/debian/patches/0003-all-add-support-for-c-archive-and-c-shared-on-linux-.patch	1970-01-01 00:00:00.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/patches/0003-all-add-support-for-c-archive-and-c-shared-on-linux-.patch	2021-11-15 20:12:56.000000000 +0000
@@ -0,0 +1,219 @@
+From 6a9ce43f0871e3c496784221998a2ac42c7f914c Mon Sep 17 00:00:00 2001
+From: Joel Sing <joel@sing.id.au>
+Date: Fri, 16 Jul 2021 03:06:18 +1000
+Subject: [PATCH 3/4] all: add support for c-archive and c-shared on
+ linux/riscv64
+
+This provides the runtime glue (_rt0_riscv64_linux_lib) for c-archive and c-shared
+support, along with enabling both of these buildmodes on linux/riscv64.
+
+Both misc/cgo/testcarchive and misc/cgo/testcshared now pass on this platform.
+
+Fixes #47100
+
+Change-Id: I7ad75b23ae1d592dbac60d15bba557668287711f
+---
+ misc/cgo/testcshared/testdata/libgo2/dup2.go |   2 +-
+ misc/cgo/testcshared/testdata/libgo2/dup3.go |   2 +-
+ src/cmd/compile/internal/ssa/regalloc.go     |   2 +
+ src/cmd/dist/test.go                         |   4 +-
+ src/cmd/internal/sys/supported.go            |   2 +-
+ src/cmd/link/internal/ld/config.go           |   2 +-
+ src/runtime/rt0_linux_riscv64.s              | 111 +++++++++++++++++++
+ 7 files changed, 119 insertions(+), 6 deletions(-)
+
+--- a/misc/cgo/testcshared/testdata/libgo2/dup2.go
++++ b/misc/cgo/testcshared/testdata/libgo2/dup2.go
+@@ -2,7 +2,7 @@
+ // Use of this source code is governed by a BSD-style
+ // license that can be found in the LICENSE file.
+ 
+-// +build darwin dragonfly freebsd linux,!arm64 netbsd openbsd
++// +build darwin dragonfly freebsd linux,!arm64,!riscv64 netbsd openbsd
+ 
+ package main
+ 
+--- a/misc/cgo/testcshared/testdata/libgo2/dup3.go
++++ b/misc/cgo/testcshared/testdata/libgo2/dup3.go
+@@ -2,7 +2,7 @@
+ // Use of this source code is governed by a BSD-style
+ // license that can be found in the LICENSE file.
+ 
+-// +build linux,arm64
++// +build linux,arm64 linux,riscv64
+ 
+ package main
+ 
+--- a/src/cmd/compile/internal/ssa/regalloc.go
++++ b/src/cmd/compile/internal/ssa/regalloc.go
+@@ -634,6 +634,8 @@
+ 			// we do need to be careful, but that carefulness is hidden
+ 			// in the rewrite rules so we always have a free register
+ 			// available for global load/stores. See gen/386.rules (search for Flag_shared).
++		case "riscv64": // X4 (aka TP) already reserved.
++			s.allocatable &^= 1 << 3 // X3 (aka GP)
+ 		case "s390x":
+ 			s.allocatable &^= 1 << 11 // R11
+ 		default:
+--- a/src/cmd/dist/test.go
++++ b/src/cmd/dist/test.go
+@@ -1045,7 +1045,7 @@
+ 		switch pair {
+ 		case "aix-ppc64",
+ 			"darwin-amd64", "darwin-arm64", "ios-arm64",
+-			"linux-amd64", "linux-386", "linux-ppc64le", "linux-s390x",
++			"linux-amd64", "linux-386", "linux-ppc64le", "linux-riscv64", "linux-s390x",
+ 			"freebsd-amd64",
+ 			"windows-amd64", "windows-386":
+ 			return true
+@@ -1053,7 +1053,7 @@
+ 		return false
+ 	case "c-shared":
+ 		switch pair {
+-		case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-s390x",
++		case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x",
+ 			"darwin-amd64", "darwin-arm64",
+ 			"freebsd-amd64",
+ 			"android-arm", "android-arm64", "android-386",
+--- a/src/cmd/internal/sys/supported.go
++++ b/src/cmd/internal/sys/supported.go
+@@ -70,7 +70,7 @@
+ 
+ 	case "c-shared":
+ 		switch platform {
+-		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/s390x",
++		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
+ 			"android/amd64", "android/arm", "android/arm64", "android/386",
+ 			"freebsd/amd64",
+ 			"darwin/amd64", "darwin/arm64",
+--- a/src/cmd/link/internal/ld/config.go
++++ b/src/cmd/link/internal/ld/config.go
+@@ -76,7 +76,7 @@
+ 		*mode = BuildModeCArchive
+ 	case "c-shared":
+ 		switch buildcfg.GOARCH {
+-		case "386", "amd64", "arm", "arm64", "ppc64le", "s390x":
++		case "386", "amd64", "arm", "arm64", "ppc64le", "riscv64", "s390x":
+ 		default:
+ 			return badmode()
+ 		}
+--- a/src/runtime/rt0_linux_riscv64.s
++++ b/src/runtime/rt0_linux_riscv64.s
+@@ -9,6 +9,117 @@
+ 	ADD	$8, X2, A1	// argv
+ 	JMP	main(SB)
+ 
++// When building with -buildmode=c-shared, this symbol is called when the shared
++// library is loaded.
++TEXT _rt0_riscv64_linux_lib(SB),NOSPLIT,$240
++	MOV	$runtime·gp+0(SB), T0
++	MOV	GP, (T0)
++
++	// Preserve callee-save registers, along with X1 (LR), X3 (GP) and X4 (TP).
++	MOV	X1, (8*3)(X2)
++	MOV	X3, (8*4)(X2)
++	MOV	X4, (8*5)(X2)
++	MOV	X8, (8*6)(X2)
++	MOV	X9, (8*7)(X2)
++	MOV	X18, (8*8)(X2)
++	MOV	X19, (8*9)(X2)
++	MOV	X20, (8*10)(X2)
++	MOV	X21, (8*11)(X2)
++	MOV	X22, (8*12)(X2)
++	MOV	X23, (8*13)(X2)
++	MOV	X24, (8*14)(X2)
++	MOV	X25, (8*15)(X2)
++	MOV	X26, (8*16)(X2)
++	MOV	g, (8*17)(X2)
++	MOVD	F8, (8*18)(X2)
++	MOVD	F9, (8*19)(X2)
++	MOVD	F18, (8*20)(X2)
++	MOVD	F19, (8*21)(X2)
++	MOVD	F20, (8*22)(X2)
++	MOVD	F21, (8*23)(X2)
++	MOVD	F22, (8*24)(X2)
++	MOVD	F23, (8*25)(X2)
++	MOVD	F24, (8*26)(X2)
++	MOVD	F25, (8*27)(X2)
++	MOVD	F26, (8*28)(X2)
++	MOVD	F27, (8*29)(X2)
++
++	// Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go
++	MOV	X0, g
++
++	MOV	A0, _rt0_riscv64_linux_lib_argc<>(SB)
++	MOV	A1, _rt0_riscv64_linux_lib_argv<>(SB)
++
++	// Synchronous initialization.
++	MOV	$runtime·libpreinit(SB), T0
++	JALR	RA, T0
++
++	// Reload GP before calling C code, as Go code will have clobbered it.
++	MOV	$runtime·gp+0(SB), T0
++	MOV	(T0), GP
++
++	// Create a new thread to do the runtime initialization and return.
++	MOV	_cgo_sys_thread_create(SB), T0
++	BEQZ	T0, nocgo
++	MOV	$_rt0_riscv64_linux_lib_go(SB), A0
++	MOV	$0, A1
++	ADD	$-16, X2	// Reserve 16 bytes for sp-8 where fp may be saved.
++	JALR	RA, T0
++	ADD	$16, X2
++	JMP	restore
++
++nocgo:
++	MOV	$0x800000, A0                     // stacksize = 8192KB
++	MOV	$_rt0_riscv64_linux_lib_go(SB), A1
++	MOV	A0, 8(X2)
++	MOV	A1, 16(X2)
++	MOV	$runtime·newosproc0(SB), T0
++	JALR	RA, T0
++
++restore:
++	// Restore callee-save registers, along with X1 (LR), X3 (GP) and X4 (TP).
++	MOV	(8*3)(X2), X1
++	MOV	(8*4)(X2), X3
++	MOV	(8*5)(X2), X4
++	MOV	(8*6)(X2), X8
++	MOV	(8*7)(X2), X9
++	MOV	(8*8)(X2), X18
++	MOV	(8*9)(X2), X19
++	MOV	(8*10)(X2), X20
++	MOV	(8*11)(X2), X21
++	MOV	(8*12)(X2), X22
++	MOV	(8*13)(X2), X23
++	MOV	(8*14)(X2), X24
++	MOV	(8*15)(X2), X25
++	MOV	(8*16)(X2), X26
++	MOV	(8*17)(X2), g
++	MOVD	(8*18)(X2), F8
++	MOVD	(8*19)(X2), F9
++	MOVD	(8*20)(X2), F18
++	MOVD	(8*21)(X2), F19
++	MOVD	(8*22)(X2), F20
++	MOVD	(8*23)(X2), F21
++	MOVD	(8*24)(X2), F22
++	MOVD	(8*25)(X2), F23
++	MOVD	(8*26)(X2), F24
++	MOVD	(8*27)(X2), F25
++	MOVD	(8*28)(X2), F26
++	MOVD	(8*29)(X2), F27
++
++	RET
++
++TEXT _rt0_riscv64_linux_lib_go(SB),NOSPLIT,$0
++	MOV	_rt0_riscv64_linux_lib_argc<>(SB), A0
++	MOV	_rt0_riscv64_linux_lib_argv<>(SB), A1
++	MOV	$runtime·rt0_go(SB), T0
++	JALR	ZERO, T0
++
++DATA _rt0_riscv64_linux_lib_argc<>(SB)/8, $0
++GLOBL _rt0_riscv64_linux_lib_argc<>(SB),NOPTR, $8
++DATA _rt0_riscv64_linux_lib_argv<>(SB)/8, $0
++GLOBL _rt0_riscv64_linux_lib_argv<>(SB),NOPTR, $8
++
++
+ TEXT main(SB),NOSPLIT|NOFRAME,$0
+ 	MOV	$runtime·gp+0(SB), T0
+ 	MOV	GP, (T0)
diff -pruN 1.17.3-1/debian/patches/0004-runtime-change-riscv64-assembly-to-work-with-Go-1.16.patch 1.17.3-1ubuntu2/debian/patches/0004-runtime-change-riscv64-assembly-to-work-with-Go-1.16.patch
--- 1.17.3-1/debian/patches/0004-runtime-change-riscv64-assembly-to-work-with-Go-1.16.patch	1970-01-01 00:00:00.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/patches/0004-runtime-change-riscv64-assembly-to-work-with-Go-1.16.patch	2021-11-15 20:12:56.000000000 +0000
@@ -0,0 +1,43 @@
+From 54c3b4b68a1a1f8d44edf8f0b1013cca7396febe Mon Sep 17 00:00:00 2001
+From: Joel Sing <joel@sing.id.au>
+Date: Fri, 16 Jul 2021 04:17:27 +1000
+Subject: [PATCH 4/4] runtime: change riscv64 assembly to work with Go 1.16
+
+Change-Id: I1081d0972f29825ae40dd760d7197062308ddef9
+---
+ src/runtime/rt0_linux_riscv64.s | 12 ++++++++----
+ 1 file changed, 8 insertions(+), 4 deletions(-)
+
+diff --git a/src/runtime/rt0_linux_riscv64.s b/src/runtime/rt0_linux_riscv64.s
+index 41cd878f6d..3fb0f854ec 100644
+--- a/src/runtime/rt0_linux_riscv64.s
++++ b/src/runtime/rt0_linux_riscv64.s
+@@ -47,8 +47,10 @@ TEXT _rt0_riscv64_linux_lib(SB),NOSPLIT,$240
+ 	// Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go
+ 	MOV	X0, g
+ 
+-	MOV	A0, _rt0_riscv64_linux_lib_argc<>(SB)
+-	MOV	A1, _rt0_riscv64_linux_lib_argv<>(SB)
++	MOV	$_rt0_riscv64_linux_lib_argc<>(SB), T0
++	MOV	A0, (T0)
++	MOV	$_rt0_riscv64_linux_lib_argv<>(SB), T0
++	MOV	A1, (T0)
+ 
+ 	// Synchronous initialization.
+ 	MOV	$runtime·libpreinit(SB), T0
+@@ -109,8 +111,10 @@ restore:
+ 	RET
+ 
+ TEXT _rt0_riscv64_linux_lib_go(SB),NOSPLIT,$0
+-	MOV	_rt0_riscv64_linux_lib_argc<>(SB), A0
+-	MOV	_rt0_riscv64_linux_lib_argv<>(SB), A1
++	MOV	$_rt0_riscv64_linux_lib_argc<>(SB), A0
++	MOV	(A0), A0
++	MOV	$_rt0_riscv64_linux_lib_argv<>(SB), A1
++	MOV	(A1), A1
+ 	MOV	$runtime·rt0_go(SB), T0
+ 	JALR	ZERO, T0
+ 
+-- 
+2.30.2
+
diff -pruN 1.17.3-1/debian/patches/series 1.17.3-1ubuntu2/debian/patches/series
--- 1.17.3-1/debian/patches/series	2021-11-07 14:33:32.000000000 +0000
+++ 1.17.3-1ubuntu2/debian/patches/series	2021-11-15 20:12:56.000000000 +0000
@@ -2,3 +2,9 @@
 0002-Fix-Lintian-warnings-about-wrong-interpreter-path.patch
 0005-cmd-dist-increase-default-timeout-scale-for-arm.patch
 0006-skip-userns-test-in-schroot-as-well.patch
+0001-cmd-link-check-CGO_CFLAGS-for-non-g-I-O-options-befo.patch
+
+0001-runtime-cgo-save-and-restore-X3-aka-GP-for-crosscall.patch
+0002-runtime-save-and-restore-X3-aka-GP-for-asmcgocalls-o.patch
+0003-all-add-support-for-c-archive-and-c-shared-on-linux-.patch
+0004-runtime-change-riscv64-assembly-to-work-with-Go-1.16.patch
