cmd/compile: do not use content addressable symbol for generic iface method names

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>
This commit is contained in:
Cherry Mui 2022-08-09 17:10:22 -04:00
parent 3c2a3ce6d9
commit 8dc7710fae
1 changed files with 9 additions and 3 deletions

View 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
}