Skip to content

Commit b3f7f60

Browse files
shawndxcherrymui
authored andcommitted
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 <[email protected]> Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Emmanuel Odeke <[email protected]>
1 parent 3c55aea commit b3f7f60

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/cmd/dist/test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,12 @@ func (t *tester) cgoTest(dt *distTest) error {
10811081
cmd := t.addCmd(dt, "misc/cgo/test", t.goTest())
10821082
cmd.Env = append(os.Environ(), "GOFLAGS=-ldflags=-linkmode=auto")
10831083

1084-
if t.internalLink() {
1084+
// Skip internal linking cases on arm64 to support GCC-9.4 and above,
1085+
// only for linux, conservatively.
1086+
// See issue #39466.
1087+
skipInternalLink := goarch == "arm64" && goos == "linux"
1088+
1089+
if t.internalLink() && !skipInternalLink {
10851090
cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-tags=internal")
10861091
cmd.Env = append(os.Environ(), "GOFLAGS=-ldflags=-linkmode=internal")
10871092
}
@@ -1157,7 +1162,7 @@ func (t *tester) cgoTest(dt *distTest) error {
11571162

11581163
if t.supportedBuildmode("pie") {
11591164
t.addCmd(dt, "misc/cgo/test", t.goTest(), "-buildmode=pie")
1160-
if t.internalLink() && t.internalLinkPIE() {
1165+
if t.internalLink() && t.internalLinkPIE() && !skipInternalLink {
11611166
t.addCmd(dt, "misc/cgo/test", t.goTest(), "-buildmode=pie", "-ldflags=-linkmode=internal", "-tags=internal,internal_pie")
11621167
}
11631168
t.addCmd(dt, "misc/cgo/testtls", t.goTest(), "-buildmode=pie")

0 commit comments

Comments
 (0)