diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go index 02b384ba9dfeff..5074ffa8c9e743 100644 --- a/src/cmd/link/internal/ld/symtab.go +++ b/src/cmd/link/internal/ld/symtab.go @@ -684,8 +684,12 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind { // Add R_XCOFFREF relocation to prevent ld's garbage collection of // the following symbols. They might not be referenced in the program. addRef := func(name string) { + s := ldr.Lookup(name, 0) + if s == 0 { + return + } r, _ := moduledata.AddRel(objabi.R_XCOFFREF) - r.SetSym(ldr.Lookup(name, 0)) + r.SetSym(s) r.SetSiz(uint8(ctxt.Arch.PtrSize)) } addRef("runtime.rodata") diff --git a/test/fixedbugs/bug514.go b/test/fixedbugs/bug514.go index 1a6c7f14dd784a..9b231853378258 100644 --- a/test/fixedbugs/bug514.go +++ b/test/fixedbugs/bug514.go @@ -4,7 +4,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build cgo && !aix +//go:build cgo package main diff --git a/test/fixedbugs/issue40954.go b/test/fixedbugs/issue40954.go index e268b808ca1423..0beaabb7439755 100644 --- a/test/fixedbugs/issue40954.go +++ b/test/fixedbugs/issue40954.go @@ -4,7 +4,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build cgo && !aix +//go:build cgo package main diff --git a/test/fixedbugs/issue42032.go b/test/fixedbugs/issue42032.go index 68fbc890458cf7..eb118591019e73 100644 --- a/test/fixedbugs/issue42032.go +++ b/test/fixedbugs/issue42032.go @@ -4,7 +4,7 @@ // source code is governed by a BSD-style license that can be found in // the LICENSE file. -//go:build cgo && !aix +//go:build cgo package main diff --git a/test/fixedbugs/issue42076.go b/test/fixedbugs/issue42076.go index b958d0eeb50b50..ef8db2da30d685 100644 --- a/test/fixedbugs/issue42076.go +++ b/test/fixedbugs/issue42076.go @@ -4,7 +4,7 @@ // source code is governed by a BSD-style license that can be found in // the LICENSE file. -//go:build cgo && !aix +//go:build cgo package main diff --git a/test/fixedbugs/issue46903.go b/test/fixedbugs/issue46903.go index 90ceb9a86c2e65..28cb43df3bab44 100644 --- a/test/fixedbugs/issue46903.go +++ b/test/fixedbugs/issue46903.go @@ -1,5 +1,5 @@ // run -//go:build goexperiment.unified && cgo && !aix +//go:build goexperiment.unified && cgo // TODO(mdempsky): Enable test unconditionally. This test should pass // for non-unified mode too. diff --git a/test/fixedbugs/issue51733.go b/test/fixedbugs/issue51733.go index 757ef733c3fff8..933c3e868c0545 100644 --- a/test/fixedbugs/issue51733.go +++ b/test/fixedbugs/issue51733.go @@ -4,7 +4,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build cgo && !aix +//go:build cgo package main