Skip to content

Commit d5d00d3

Browse files
cmd/go: update -DGOPKGPATH to use current pkgpath encoding
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 Change-Id: I5636bec7268bcd41994c2e2262f8293cb95c0cd4 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/219817 Reviewed-by: Than McIntosh <[email protected]>
1 parent 8505def commit d5d00d3

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

libgo/go/cmd/go/internal/work/gccgo.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,28 @@ func gccgoPkgpath(p *load.Package) string {
596596
return p.ImportPath
597597
}
598598

599+
// gccgoCleanPkgpath returns the form of p's pkgpath that gccgo uses
600+
// for symbol names. This is like gccgoPkgpathToSymbolNew in cmd/cgo/out.go.
599601
func gccgoCleanPkgpath(p *load.Package) string {
600-
clean := func(r rune) rune {
602+
ppath := gccgoPkgpath(p)
603+
bsl := []byte{}
604+
changed := false
605+
for _, c := range []byte(ppath) {
601606
switch {
602-
case 'A' <= r && r <= 'Z', 'a' <= r && r <= 'z',
603-
'0' <= r && r <= '9':
604-
return r
607+
case 'A' <= c && c <= 'Z', 'a' <= c && c <= 'z',
608+
'0' <= c && c <= '9', c == '_':
609+
bsl = append(bsl, c)
610+
case c == '.':
611+
bsl = append(bsl, ".x2e"...)
612+
changed = true
613+
default:
614+
encbytes := []byte(fmt.Sprintf("..z%02x", c))
615+
bsl = append(bsl, encbytes...)
616+
changed = true
605617
}
606-
return '_'
607618
}
608-
return strings.Map(clean, gccgoPkgpath(p))
619+
if !changed {
620+
return ppath
621+
}
622+
return string(bsl)
609623
}

0 commit comments

Comments
 (0)