From e5ad363fff6e602bf72ce7bf5084297c0d1a2e51 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Thu, 30 Sep 2021 18:09:24 -0400 Subject: [PATCH] cmd/link: correct type..importpath symbol handling The linker specially handles go.importpath symbols. But the compiler doesn't actually generate such symbols. Instead, it generates type..importpath symbols. It is already in the type section as the name starts with "type.". Also set its alignment to 1, as it is string data. Change-Id: I771f5529a0ff41a5bb476b3a02c8cc75729792de Reviewed-on: https://go-review.googlesource.com/c/go/+/353489 Trust: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Go Bot Reviewed-by: Than McIntosh --- src/cmd/link/internal/ld/symtab.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go index 4d099b1133..1e5c73c573 100644 --- a/src/cmd/link/internal/ld/symtab.go +++ b/src/cmd/link/internal/ld/symtab.go @@ -540,11 +540,6 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind { align := int32(1) name := ldr.SymName(s) switch { - case strings.HasPrefix(name, "go.importpath.") && ctxt.UseRelro(): - // Keep go.importpath symbols in the same section as types and - // names, as they can be referred to by a section offset. - symGroupType[s] = sym.STYPERELRO - case strings.HasPrefix(name, "go.string."): symGroupType[s] = sym.SGOSTRING ldr.SetAttrNotInSymbolTable(s, true) @@ -611,7 +606,7 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind { ldr.SetCarrierSym(s, symtype) } } - if strings.HasPrefix(name, "type..namedata.") && ldr.SymAlign(s) == 0 { + if (strings.HasPrefix(name, "type..namedata.") || strings.HasPrefix(name, "type..importpath.")) && ldr.SymAlign(s) == 0 { ldr.SetSymAlign(s, 1) // String data is just bytes, no padding. } } -- 2.48.1