]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: don't include deadcoded function symbols in shared build mode
authorCherry Mui <cherryyz@google.com>
Fri, 24 May 2024 22:04:11 +0000 (18:04 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 7 Jun 2024 14:52:41 +0000 (14:52 +0000)
In shared build mode, we include all symbols. This includes
function symbols that are deadcoded by the compiler. They don't
really get compiled, and their metadata may be missing, causing
linker failures. Skip them.

Fixes #67635.

Change-Id: Ic0e64bd032be499cca26da5e9e3ffbe9998bac05
Reviewed-on: https://go-review.googlesource.com/c/go/+/588316
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/cgo/internal/testshared/testdata/depBase/dep.go
src/cmd/link/internal/ld/deadcode.go

index a143fe2ff1604599bf2568f4b1914647969ae50d..6a8bf49c58a51a0f6f8b719a58da6b965bc719bf 100644 (file)
@@ -51,3 +51,8 @@ func F() int {
        defer func() {}()
        return V
 }
+
+func H() {
+       // Issue 67635: deadcoded closures causes linker crash.
+       func() { F() }()
+}
index 241cf603dbd7661d1e34a21d9f8f5ba541a51b90..20609ed7bfc6a33cc738bcbf971507ddc5a05700 100644 (file)
@@ -50,6 +50,12 @@ func (d *deadcodePass) init() {
                n := d.ldr.NDef()
                for i := 1; i < n; i++ {
                        s := loader.Sym(i)
+                       if d.ldr.SymType(s) == sym.STEXT && d.ldr.SymSize(s) == 0 {
+                               // Zero-sized text symbol is a function deadcoded by the
+                               // compiler. It doesn't really get compiled, and its
+                               // metadata may be missing.
+                               continue
+                       }
                        d.mark(s, 0)
                }
                d.mark(d.ctxt.mainInittasks, 0)