]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: mangle symbol ABI name for linker-generated symbols
authorCherry Mui <cherryyz@google.com>
Mon, 11 Apr 2022 22:57:44 +0000 (18:57 -0400)
committerCherry Mui <cherryyz@google.com>
Tue, 12 Apr 2022 23:24:32 +0000 (23:24 +0000)
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<ABI0> and a trampoline to f<ABIInternal>. 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 <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/symtab.go

index 39066da286fba0d32b020217355001b20d1a46c9..63e140aa7181aa85ea3ed4e951cd468e8c3d8283 100644 (file)
@@ -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))
                }