cmd/go: update -DGOPKGPATH to use current pkgpath encoding
authorIan Lance Taylor <iant@golang.org>
Tue, 18 Feb 2020 02:16:41 +0000 (18:16 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 18 Feb 2020 20:03:13 +0000 (12:03 -0800)
This will need to be done in the gc version too, probably more cleverly.
This version will ensure that the next GCC release works correctly
when using the GCC version of the go tool.

Updates golang/go#37272

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/219817

gcc/go/gofrontend/MERGE
libgo/go/cmd/go/internal/work/gccgo.go

index 47dd5fbb9083fcf76b6a3dac040b21f5cbed69d0..ce10ee1d8d466b160c2646af2b8a1c39a59d5045 100644 (file)
@@ -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.
index f6fa17da85cfd2720a382ebb53339914d6342411..63d5c624f79c5989cfde098a8ad67283282e3e5d 100644 (file)
@@ -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)
 }