From 0f8dffd0aa71ed996d32e77701ac5ec0bc7cde01 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Sat, 8 May 2021 00:45:06 +0700 Subject: all: use ":" for compiler generated symbols As it can't appear in user package paths. There is a hack for handling "go:buildid" and "type:*" on windows/386. Previously, windows/386 requires underscore prefix on external symbols, but that's only applied for SHOSTOBJ/SUNDEFEXT or cgo export symbols. "go.buildid" is STEXT, "type.*" is STYPE, thus they are not prefixed with underscore. In external linking mode, the external linker can't resolve them as external symbols. But we are lucky that they have "." in their name, so the external linker see them as Forwarder RVA exports. See: - https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#export-address-table - https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/pe-dll.c;h=e7b82ba6ffadf74dc1b9ee71dc13d48336941e51;hb=HEAD#l972) This CL changes "." to ":" in symbols name, so theses symbols can not be found by external linker anymore. So a hacky way is adding the underscore prefix for these 2 symbols. I don't have enough knowledge to verify whether adding the underscore for all STEXT/STYPE symbols are fine, even if it could be, that would be done in future CL. Fixes #37762 Change-Id: I92eaaf24c0820926a36e0530fdb07b07af1fcc35 Reviewed-on: https://go-review.googlesource.com/c/go/+/317917 Reviewed-by: Than McIntosh Run-TryBot: Cuong Manh Le Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- src/cmd/link/internal/ld/lib.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/cmd/link/internal/ld/lib.go') diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index c265d73893..14dc5433fb 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -926,24 +926,24 @@ func (ctxt *Link) mangleTypeSym() { // typeSymbolMangle mangles the given symbol name into something shorter. // -// Keep the type.. prefix, which parts of the linker (like the +// Keep the type:. prefix, which parts of the linker (like the // DWARF generator) know means the symbol is not decodable. -// Leave type.runtime. symbols alone, because other parts of +// Leave type:runtime. symbols alone, because other parts of // the linker manipulates them. func typeSymbolMangle(name string) string { - if !strings.HasPrefix(name, "type.") { + if !strings.HasPrefix(name, "type:") { return name } - if strings.HasPrefix(name, "type.runtime.") { + if strings.HasPrefix(name, "type:runtime.") { return name } if len(name) <= 14 && !strings.Contains(name, "@") { // Issue 19529 return name } hash := notsha256.Sum256([]byte(name)) - prefix := "type." + prefix := "type:" if name[5] == '.' { - prefix = "type.." + prefix = "type:." } return prefix + base64.StdEncoding.EncodeToString(hash[:6]) } @@ -2319,11 +2319,11 @@ func ldshlibsyms(ctxt *Link, shlib string) { continue } - // Symbols whose names start with "type." are compiler - // generated, so make functions with that prefix internal. + // Symbols whose names start with "type:" are compiler generated, + // so make functions with that prefix internal. ver := 0 symname := elfsym.Name // (unmangled) symbol name - if elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC && strings.HasPrefix(elfsym.Name, "type.") { + if elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC && strings.HasPrefix(elfsym.Name, "type:") { ver = abiInternalVer } else if buildcfg.Experiment.RegabiWrappers && elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC { // Demangle the ABI name. Keep in sync with symtab.go:mangleABIName. @@ -2357,7 +2357,7 @@ func ldshlibsyms(ctxt *Link, shlib string) { // The decodetype_* functions in decodetype.go need access to // the type data. sname := l.SymName(s) - if strings.HasPrefix(sname, "type.") && !strings.HasPrefix(sname, "type..") { + if strings.HasPrefix(sname, "type:") && !strings.HasPrefix(sname, "type:.") { su.SetData(readelfsymboldata(ctxt, f, &elfsym)) } } -- cgit v1.3