From 34489eb2af3bbb7be101bc838615cf4a4dc6828d Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 25 Oct 2018 22:18:08 +0000 Subject: 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 From-SVN: r265510 --- gcc/go/gofrontend/gogo.h | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'gcc/go/gofrontend/gogo.h') diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h index 9c469ca..48359eb 100644 --- a/gcc/go/gofrontend/gogo.h +++ b/gcc/go/gofrontend/gogo.h @@ -199,26 +199,10 @@ class Gogo return name.substr(1, name.rfind('.') - 1); } - // Given a name which may or may not have been hidden, return the - // name to use within a mangled symbol name. - static std::string - mangle_possibly_hidden_name(const std::string& name) - { - // FIXME: This adds in pkgpath twice for hidden symbols, which is - // less than ideal. - std::string n; - if (!Gogo::is_hidden_name(name)) - n = name; - else - { - n = "."; - std::string pkgpath = Gogo::hidden_name_pkgpath(name); - n.append(Gogo::pkgpath_for_symbol(pkgpath)); - n.append(1, '.'); - n.append(Gogo::unpack_hidden_name(name)); - } - return n; - } + // Given a name which may or may not have been hidden, append the + // appropriate version of the name to the result string. + static void + append_possibly_hidden_name(std::string *result, const std::string& name); // Given a name which may or may not have been hidden, return the // name to use in an error message. -- cgit v1.1