]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: only add dummy XCOFF reference if the symbol exists
authorCherry Mui <cherryyz@google.com>
Thu, 1 Sep 2022 23:31:04 +0000 (19:31 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 2 Sep 2022 15:27:18 +0000 (15:27 +0000)
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>
src/cmd/link/internal/ld/symtab.go
test/fixedbugs/bug514.go
test/fixedbugs/issue40954.go
test/fixedbugs/issue42032.go
test/fixedbugs/issue42076.go
test/fixedbugs/issue46903.go
test/fixedbugs/issue51733.go

index 02b384ba9dfeffa139f791e2a3eba31000a10dee..5074ffa8c9e743da544e9c1c01fcf266a8a55937 100644 (file)
@@ -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")
index 1a6c7f14dd784a8c5ca174694b720a8a49c1ad6d..9b2318533782588ed1cc9ea3b764615e2819c2b6 100644 (file)
@@ -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
 
index e268b808ca14235596b837c29ae45c398891d34c..0beaabb7439755853d0f4d247e423b3b40bf11a1 100644 (file)
@@ -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
 
index 68fbc890458cf76daec42d2f1288ff8a8c2b9478..eb118591019e7322d7dc30e232c0fc0d35225afe 100644 (file)
@@ -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
 
index b958d0eeb50b50c9f8e7fac9ad022e34911559b8..ef8db2da30d68556ea8e38d1ed9344d130a61258 100644 (file)
@@ -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
 
index 90ceb9a86c2e6579610800701712627a2e6f2583..28cb43df3bab447283dd740000df438055de80dc 100644 (file)
@@ -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.
index 757ef733c3fff86d7879c14b44d9b6d37c84c9af..933c3e868c0545c81635ed438352ae571b359976 100644 (file)
@@ -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