Skip to content

Commit 321a220

Browse files
committed
cmd/link: only add dummy XCOFF reference if the symbol exists
On AIX when external linking, for some symbols we need to add dummy references to prevent the external linker from discarding them. Currently we add the reference unconditionally. But if the symbol doesn't exist, the linking fails in a later stage for generating external relocation of a nonexistent symbol. The symbols are special symbols that almost always exist, except that go:buildid may not exist if the linker is invoked without the -buildid flag. The go command invokes the linker with the flag, so this can only happen with manual linker invocation. Specifically, test/run.go does this in some cases. Fix this by checking the symbol existence before adding the reference. Re-enable tests on AIX. Perhaps the linker should always emit a dummy buildid even if the flag is not set... Fixes #54814. Change-Id: I43d81587151595309e189e38960cbda9a1c5ca32 Reviewed-on: https://go-review.googlesource.com/c/go/+/427620 Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
1 parent 202b7e7 commit 321a220

File tree

7 files changed

+11
-7
lines changed

7 files changed

+11
-7
lines changed

src/cmd/link/internal/ld/symtab.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,12 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
684684
// Add R_XCOFFREF relocation to prevent ld's garbage collection of
685685
// the following symbols. They might not be referenced in the program.
686686
addRef := func(name string) {
687+
s := ldr.Lookup(name, 0)
688+
if s == 0 {
689+
return
690+
}
687691
r, _ := moduledata.AddRel(objabi.R_XCOFFREF)
688-
r.SetSym(ldr.Lookup(name, 0))
692+
r.SetSym(s)
689693
r.SetSiz(uint8(ctxt.Arch.PtrSize))
690694
}
691695
addRef("runtime.rodata")

test/fixedbugs/bug514.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

7-
//go:build cgo && !aix
7+
//go:build cgo
88

99
package main
1010

test/fixedbugs/issue40954.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

7-
//go:build cgo && !aix
7+
//go:build cgo
88

99
package main
1010

test/fixedbugs/issue42032.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// source code is governed by a BSD-style license that can be found in
55
// the LICENSE file.
66

7-
//go:build cgo && !aix
7+
//go:build cgo
88

99
package main
1010

test/fixedbugs/issue42076.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// source code is governed by a BSD-style license that can be found in
55
// the LICENSE file.
66

7-
//go:build cgo && !aix
7+
//go:build cgo
88

99
package main
1010

test/fixedbugs/issue46903.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run
2-
//go:build goexperiment.unified && cgo && !aix
2+
//go:build goexperiment.unified && cgo
33

44
// TODO(mdempsky): Enable test unconditionally. This test should pass
55
// for non-unified mode too.

test/fixedbugs/issue51733.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

7-
//go:build cgo && !aix
7+
//go:build cgo
88

99
package main
1010

0 commit comments

Comments
 (0)