From 3f231047f4a2f3e6d4cb7f2a2b4aaffd72f558d9 Mon Sep 17 00:00:00 2001 From: Liwei Ge Date: Tue, 23 Mar 2021 18:09:29 +0800 Subject: [PATCH] fix build failure of misc/cgo/test on arm64 this change has given better compatible with both gcc8 and gcc10 toolchain, should be maintained util upstream fixes misc/cgo/test fails in 'dist test' on arm64 if the C compiler is of GCC-9.4 or above and its 'outline atomics' feature is enabled, since the internal linking hasn't yet supported "__attribute__((constructor))" and also mis-handles hidden visibility. This change addresses the problem by skipping the internal linking cases of misc/cgo/test on linux/arm64. It fixes 'dist test' failure only, user is expected to pass a GCC option '-mno-outline-atomics' via CGO_CFLAGS if running into the same problem when building cgo programs using internal linking. upstream commit github.com/golang/go/commit/b3f7f60129b822978115717912f4d477a46e8467 Signed-off-by: Liwei Ge Signed-off-by: weitao zhou --- 1001-golang-fix-build-failure-on-arm64.patch | 54 ++++++++++++++++++++ golang.spec | 11 +++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 1001-golang-fix-build-failure-on-arm64.patch diff --git a/1001-golang-fix-build-failure-on-arm64.patch b/1001-golang-fix-build-failure-on-arm64.patch new file mode 100644 index 0000000..e07a426 --- /dev/null +++ b/1001-golang-fix-build-failure-on-arm64.patch @@ -0,0 +1,54 @@ +From b3f7f60129b822978115717912f4d477a46e8467 Mon Sep 17 00:00:00 2001 +From: xd +Date: Wed, 14 Oct 2020 11:02:49 -0700 +Subject: [PATCH] cmd/dist: fix build failure of misc/cgo/test on arm64 + +misc/cgo/test fails in 'dist test' on arm64 if the C compiler is of GCC-9.4 or +above and its 'outline atomics' feature is enabled, since the internal linking +hasn't yet supported "__attribute__((constructor))" and also mis-handles hidden +visibility. + +This change addresses the problem by skipping the internal linking cases of +misc/cgo/test on linux/arm64. It fixes 'dist test' failure only, user is expected to +pass a GCC option '-mno-outline-atomics' via CGO_CFLAGS if running into the same +problem when building cgo programs using internal linking. + +Updates #39466 + +Change-Id: I57f9e85fca881e5fd2dae6c1b4446bce9e0c1975 +Reviewed-on: https://go-review.googlesource.com/c/go/+/262357 +Reviewed-by: Cherry Zhang +Run-TryBot: Cherry Zhang +TryBot-Result: Go Bot +Trust: Emmanuel Odeke +--- + src/cmd/dist/test.go | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go +index 622d0cee8342..3cf49dc8ad2e 100644 +--- a/src/cmd/dist/test.go ++++ b/src/cmd/dist/test.go +@@ -1081,7 +1081,12 @@ func (t *tester) cgoTest(dt *distTest) error { + cmd := t.addCmd(dt, "misc/cgo/test", t.goTest()) + cmd.Env = append(os.Environ(), "GOFLAGS=-ldflags=-linkmode=auto") + +- if t.internalLink() { ++ // Skip internal linking cases on arm64 to support GCC-9.4 and above, ++ // only for linux, conservatively. ++ // See issue #39466. ++ skipInternalLink := goarch == "arm64" && goos == "linux" ++ ++ if t.internalLink() && !skipInternalLink { + cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-tags=internal") + cmd.Env = append(os.Environ(), "GOFLAGS=-ldflags=-linkmode=internal") + } +@@ -1157,7 +1162,7 @@ func (t *tester) cgoTest(dt *distTest) error { + + if t.supportedBuildmode("pie") { + t.addCmd(dt, "misc/cgo/test", t.goTest(), "-buildmode=pie") +- if t.internalLink() && t.internalLinkPIE() { ++ if t.internalLink() && t.internalLinkPIE() && !skipInternalLink { + t.addCmd(dt, "misc/cgo/test", t.goTest(), "-buildmode=pie", "-ldflags=-linkmode=internal") + } + t.addCmd(dt, "misc/cgo/testtls", t.goTest(), "-buildmode=pie") diff --git a/golang.spec b/golang.spec index 8d271f7..cf060b6 100644 --- a/golang.spec +++ b/golang.spec @@ -1,3 +1,4 @@ +%define anolis_release .0.1 %undefine _missing_build_ids_terminate_build %global bcond_with strict_fips @@ -101,7 +102,7 @@ Name: golang Version: %{go_version} -Release: 1%{?dist} +Release: 1%{anolis_release}%{?dist} Summary: The Go Programming Language # source tree includes several copies of Mark.Twain-Tom.Sawyer.txt under Public Domain License: BSD and Public Domain @@ -155,6 +156,10 @@ Patch1939923: skip_test_rhbz1939923.patch # Fix FIPS mode memory leaks Patch1951877: fix-crypto-memory-leaks.patch +# Begin: Anolis customized patches +Patch1001: 1001-golang-fix-build-failure-on-arm64.patch +# End: Anolis customized patches + # Having documentation separate was broken Obsoletes: %{name}-docs < 1.1-4 @@ -256,6 +261,7 @@ Requires: %{name} = %{version}-%{release} %patch1951877 -p1 +%patch1001 -p1 cp %{SOURCE1} ./src/runtime/ @@ -523,6 +529,9 @@ cd .. %endif %changelog +* Thu Jan 20 2022 Weitao Zhou 1.16.12-1.0.1 +- Fix build failure on arm64 with gcc10 + * Fri Dec 10 2021 David Benoit - 1.16.12-1 - Rebase to Go 1.16.12 - Resolves: rhbz#2031125 -- Gitee