From: Cherry Mui Date: Mon, 11 Apr 2022 22:57:44 +0000 (-0400) Subject: cmd/link: mangle symbol ABI name for linker-generated symbols X-Git-Tag: go1.19beta1~679 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9c7f0b1ccd37b6f41a5326c451c633c92e93870c;p=gostls13.git cmd/link: mangle symbol ABI name for linker-generated symbols The ABI mangling code skips symbols that are not loaded from Go objects. Usually that is fine, as other symbols don't need name mangling. But trampolines are linker generated and have the same symbol version (ABI) as the underlying symbol. We need to avoid symbol name collisions for trampolines, such as a trampoline to f and a trampoline to f. We could explicitly incorportate the ABI into the trampoline name. But as we already have the name mangling scheme we could just use that. The original code excludes external symbols probably because symbols from C object don't need mangling. But a C symbol and a Go symbol shouldn't have same name, and so the condition won't apply. Also exclude static symbols as they don't need mangling. Change-Id: I298eb1d64bc0c3da0154f0146b95c4d26ca2f47a Reviewed-on: https://go-review.googlesource.com/c/go/+/399894 Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh --- diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go index 39066da286..63e140aa71 100644 --- a/src/cmd/link/internal/ld/symtab.go +++ b/src/cmd/link/internal/ld/symtab.go @@ -857,7 +857,7 @@ func mangleABIName(ctxt *Link, ldr *loader.Loader, x loader.Sym, name string) st return name } - if !ldr.IsExternal(x) && ldr.SymType(x) == sym.STEXT && ldr.SymVersion(x) != sym.SymVerABIInternal { + if ldr.SymType(x) == sym.STEXT && ldr.SymVersion(x) != sym.SymVerABIInternal && ldr.SymVersion(x) < sym.SymVerStatic { if s2 := ldr.Lookup(name, sym.SymVerABIInternal); s2 != 0 && ldr.SymType(s2) == sym.STEXT { name = fmt.Sprintf("%s.abi%d", name, ldr.SymVersion(x)) }