From 8dc7710faeda33b03fe32d4e7c800f0dcf27c698 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Tue, 9 Aug 2022 17:10:22 -0400 Subject: [PATCH] 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 Run-TryBot: Cherry Mui Reviewed-by: Cuong Manh Le TryBot-Result: Gopher Robot --- src/cmd/compile/internal/reflectdata/reflect.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 83d66eab42..cfdf2af849 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -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 } -- 2.50.0