compiler: improve name mangling for packpaths
commit2b77d4ca5daff95c781bf279b4aa1c98c1bbfbce
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 25 Oct 2018 22:18:08 +0000 (25 22:18 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 25 Oct 2018 22:18:08 +0000 (25 22:18 +0000)
tree0dbda78980d4553fdaeee92ca666d72a2ab95213
parent35f422fade21ce39c17cb7df2af68e854edc3ed7
compiler: improve name mangling for packpaths

    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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265510 138bc75d-0d04-0410-961f-82ee72b054a4
34 files changed:
gcc/go/gofrontend/MERGE
gcc/go/gofrontend/go-encode-id.cc
gcc/go/gofrontend/go-encode-id.h
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/gogo.h
gcc/go/gofrontend/lex.h
gcc/go/gofrontend/names.cc
libgo/go/cmd/cgo/main.go
libgo/go/cmd/cgo/out.go
libgo/go/internal/bytealg/bytealg.c
libgo/go/internal/cpu/cpu_gccgo.c
libgo/go/runtime/atomic_pointer.go
libgo/go/runtime/cpuprof.go
libgo/go/runtime/debug/stack_test.go
libgo/go/runtime/heapdump.go
libgo/go/runtime/internal/atomic/atomic.c
libgo/go/runtime/mgc.go
libgo/go/runtime/mheap.go
libgo/go/runtime/mstats.go
libgo/go/runtime/net_plan9.go
libgo/go/runtime/netpoll.go
libgo/go/runtime/pprof/mprof_test.go
libgo/go/runtime/proc.go
libgo/go/runtime/proflabel.go
libgo/go/runtime/rdebug.go
libgo/go/runtime/runtime1.go
libgo/go/runtime/sema.go
libgo/go/runtime/sigqueue.go
libgo/go/runtime/symtab.go
libgo/go/runtime/time.go
libgo/go/runtime/trace.go
libgo/go/runtime/traceback_gccgo.go
libgo/go/sync/atomic/atomic.c
libgo/testsuite/gotest