]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: do not use content addressable symbol for generic iface method names
authorCherry Mui <cherryyz@google.com>
Tue, 9 Aug 2022 21:10:22 +0000 (17:10 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 10 Aug 2022 00:51:41 +0000 (00:51 +0000)
When a generic interface method is used, we use a special
relocation R_USEGENERICIFACEMETHOD to tell the linker the name of
the generic interface method, so it can keep methods with that
name live. The relocation references a symbol whose content is the
name. Currently this is a string symbol, which is content
addessable and may have trailing zero bytes (for better
deduplication). The trailing bytes can cause confusion for the
linker. This symbol doesn't need to be in the final binary and
doesn't need to be deduplicated with other symbol. So we don't use
content addressable symbol but make an (unnamed) symbol
specifically for this.

May fix #54346.

Change-Id: If0c34f7844c3553a7be3846b66cf1c103bc231c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/422300
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/reflectdata/reflect.go

index 83d66eab421f5f5b62229bde28bb1f80c45c5079..cfdf2af849a71c89591c00710685099d29cd5dd1 100644 (file)
@@ -19,7 +19,6 @@ import (
        "cmd/compile/internal/inline"
        "cmd/compile/internal/ir"
        "cmd/compile/internal/objw"
-       "cmd/compile/internal/staticdata"
        "cmd/compile/internal/typebits"
        "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
@@ -2057,8 +2056,15 @@ func MarkUsedIfaceMethod(n *ir.CallExpr) {
                // of the method for matching.
                r := obj.Addrel(ir.CurFunc.LSym)
                // We use a separate symbol just to tell the linker the method name.
-               // (The symbol itself is not needed in the final binary.)
-               r.Sym = staticdata.StringSym(src.NoXPos, dot.Sel.Name)
+               // (The symbol itself is not needed in the final binary. Do not use
+               // staticdata.StringSym, which creates a content addessable symbol,
+               // which may have trailing zero bytes. This symbol doesn't need to
+               // be deduplicated anyway.)
+               name := dot.Sel.Name
+               var nameSym obj.LSym
+               nameSym.WriteString(base.Ctxt, 0, len(name), name)
+               objw.Global(&nameSym, int32(len(name)), obj.RODATA)
+               r.Sym = &nameSym
                r.Type = objabi.R_USEGENERICIFACEMETHOD
                return
        }