compiler: improve name mangling for packpaths

Programming / Compilers / GCC - ian [138bc75d-0d04-0410-961f-82ee72b054a4] - 25 October 2018 22:18 EDT

The current implementation of Gogo::pkgpath_for_symbol was written in a way that allowed two distinct package paths to map to the same symbol, which could cause collisions at link- time or compile-time.

Switch to a better mangling scheme to insure that we get a unique packagepath symbol for each package. In the new scheme instead of having separate mangling schemes for identifiers and package paths, the main identifier mangler ("go_encode_id") now handles mangling of both packagepath characters and identifier characters.

The new mangling scheme is more intrusive: "foo/bar.Baz" is mangled as "foo..z2fbar.Baz" instead of "foo_bar.Baz". To mitigate this, this patch also adds a demangling capability so that function names returned from runtime.CallersFrames are converted back to their original unmangled form.

Changing the pkgpath_for_symbol scheme requires updating a number of //go:linkname directives and C "__asm__" directives to match the new scheme, as well as updating the 'gotest' driver (which makes assumptions about the correct mapping from pkgpath symbol to package name).

Fixes golang/go#27534.

Reviewed-on: https://go-review.googlesource.com/c/135455

2b77d4ca5da compiler: improve name mangling for packpaths
gcc/go/gofrontend/MERGE | 2 +-
gcc/go/gofrontend/go-encode-id.cc | 93 ++++++++++++++++++++++---
gcc/go/gofrontend/go-encode-id.h | 5 ++
gcc/go/gofrontend/gogo.cc | 45 +++++++-----
gcc/go/gofrontend/gogo.h | 24 ++-----
gcc/go/gofrontend/lex.h | 7 +-
gcc/go/gofrontend/names.cc | 53 +++++++-------
libgo/go/cmd/cgo/main.go | 2 +
libgo/go/cmd/cgo/out.go | 111 ++++++++++++++++++++++++++++--
libgo/go/internal/bytealg/bytealg.c | 12 ++--
libgo/go/internal/cpu/cpu_gccgo.c | 4 +-
libgo/go/runtime/atomic_pointer.go | 12 ++--
libgo/go/runtime/cpuprof.go | 4 +-
libgo/go/runtime/debug/stack_test.go | 4 +-
libgo/go/runtime/heapdump.go | 2 +-
libgo/go/runtime/internal/atomic/atomic.c | 46 ++++++-------
libgo/go/runtime/mgc.go | 2 +-
libgo/go/runtime/mheap.go | 2 +-
libgo/go/runtime/mstats.go | 2 +-
libgo/go/runtime/net_plan9.go | 4 +-
libgo/go/runtime/netpoll.go | 18 ++---
libgo/go/runtime/pprof/mprof_test.go | 6 +-
libgo/go/runtime/proc.go | 6 +-
libgo/go/runtime/proflabel.go | 4 +-
libgo/go/runtime/rdebug.go | 4 +-
libgo/go/runtime/runtime1.go | 2 +-
libgo/go/runtime/sema.go | 4 +-
libgo/go/runtime/sigqueue.go | 12 ++--
libgo/go/runtime/symtab.go | 74 ++++++++++++++++++++
libgo/go/runtime/time.go | 2 +-
libgo/go/runtime/trace.go | 8 +--
libgo/go/runtime/traceback_gccgo.go | 7 +-
libgo/go/sync/atomic/atomic.c | 52 +++++++-------
libgo/testsuite/gotest | 40 +++++++++--
34 files changed, 481 insertions(+), 194 deletions(-)

Upstream: gcc.gnu.org


  • Share