libgo patch committed: Update -DGOPKGPATH to current pkgpath encoding

Message ID CAOyqgcXjiPCgbbiDQf_HeLUeT259w-FTsXxWbAU6vVQ4gzcCDw@mail.gmail.com
State New
Headers show
Series
  • libgo patch committed: Update -DGOPKGPATH to current pkgpath encoding
Related show

Commit Message

Ian Lance Taylor Feb. 18, 2020, 8:03 p.m.
This libgo patch changes the go tool to use the current pkgpath
encoding when invoking the C compiler or assembler with -DGOPKGPATH.
The GOPKGPATH macro is used to select the right exported name for a
function called from Go code, so the pkgpath encoding needs to match.
This change will need to be done in the gc version too, probably more
cleverly to work with different versions of gccgo.  This libgo patch
will ensure that the next GCC release works correctly when using the
GCC version of the go tool.  This is for
https://golang.org/issue/37272.  Bootstrapped and ran Go tests on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
855b4aaeabdcddce04ff9295c4b0e6c7aa6db96b

Patch

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 47dd5fbb908..ce10ee1d8d4 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@ 
-8505defaa91ecc5b42afd02eb335981e8b02b288
+d5d00d310ec33aeb18f33f807956ec0c4eeea6bb
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/cmd/go/internal/work/gccgo.go b/libgo/go/cmd/go/internal/work/gccgo.go
index f6fa17da85c..63d5c624f79 100644
--- a/libgo/go/cmd/go/internal/work/gccgo.go
+++ b/libgo/go/cmd/go/internal/work/gccgo.go
@@ -596,14 +596,28 @@  func gccgoPkgpath(p *load.Package) string {
 	return p.ImportPath
 }
 
+// gccgoCleanPkgpath returns the form of p's pkgpath that gccgo uses
+// for symbol names. This is like gccgoPkgpathToSymbolNew in cmd/cgo/out.go.
 func gccgoCleanPkgpath(p *load.Package) string {
-	clean := func(r rune) rune {
+	ppath := gccgoPkgpath(p)
+	bsl := []byte{}
+	changed := false
+	for _, c := range []byte(ppath) {
 		switch {
-		case 'A' <= r && r <= 'Z', 'a' <= r && r <= 'z',
-			'0' <= r && r <= '9':
-			return r
+		case 'A' <= c && c <= 'Z', 'a' <= c && c <= 'z',
+			'0' <= c && c <= '9', c == '_':
+			bsl = append(bsl, c)
+		case c == '.':
+			bsl = append(bsl, ".x2e"...)
+			changed = true
+		default:
+			encbytes := []byte(fmt.Sprintf("..z%02x", c))
+			bsl = append(bsl, encbytes...)
+			changed = true
 		}
-		return '_'
 	}
-	return strings.Map(clean, gccgoPkgpath(p))
+	if !changed {
+		return ppath
+	}
+	return string(bsl)
 }