cmd/internal: remove duplicate pathToPrefix function

goobj.importPathToPrefix is 3x faster than gc.pathToPrefix so rename and
move it to cmd/internal/objabi which is already imported by both goobj and
gc.

Change-Id: I10eda5bce95ef6d5d888818c5c47258c2833ea45
Reviewed-on: https://go-review.googlesource.com/40875
Run-TryBot: Todd Neal <todd@tneal.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Todd Neal 2017-04-17 18:46:09 -05:00
parent eb40f0621f
commit dc444418d9
9 changed files with 84 additions and 135 deletions

View file

@ -651,7 +651,7 @@ func (ctxt *Link) loadlib() {
// first containing package that the linker loads). canonicalize
// it here to the package with which it will be laid down
// in text.
s.File = pathtoprefix(lib.Pkg)
s.File = objabi.PathToPrefix(lib.Pkg)
}
}
}
@ -752,7 +752,7 @@ func genhash(ctxt *Link, lib *Library) {
}
func objfile(ctxt *Link, lib *Library) {
pkg := pathtoprefix(lib.Pkg)
pkg := objabi.PathToPrefix(lib.Pkg)
if ctxt.Debugvlog > 1 {
ctxt.Logf("%5.2f ldobj: %s (%s)\n", Cputime(), lib.File, pkg)
@ -1312,7 +1312,7 @@ func hostlinkArchArgs() []string {
// compiled by a non-Go compiler) it returns the Hostobj pointer. If
// it is a Go object, it returns nil.
func ldobj(ctxt *Link, f *bio.Reader, lib *Library, length int64, pn string, file string, whence int) *Hostobj {
pkg := pathtoprefix(lib.Pkg)
pkg := objabi.PathToPrefix(lib.Pkg)
eof := f.Offset() + length
start := f.Offset()
@ -1572,35 +1572,6 @@ func ldshlibsyms(ctxt *Link, shlib string) {
ctxt.Shlibs = append(ctxt.Shlibs, Shlib{Path: libpath, Hash: hash, Deps: deps, File: f, gcdataAddresses: gcdataAddresses})
}
// Copied from ../gc/subr.c:/^pathtoprefix; must stay in sync.
/*
* Convert raw string to the prefix that will be used in the symbol table.
* Invalid bytes turn into %xx. Right now the only bytes that need
* escaping are %, ., and ", but we escape all control characters too.
*
* If you edit this, edit ../gc/subr.c:/^pathtoprefix too.
* If you edit this, edit ../../debug/goobj/read.go:/importPathToPrefix too.
*/
func pathtoprefix(s string) string {
slash := strings.LastIndex(s, "/")
for i := 0; i < len(s); i++ {
c := s[i]
if c <= ' ' || i >= slash && c == '.' || c == '%' || c == '"' || c >= 0x7F {
var buf bytes.Buffer
for i := 0; i < len(s); i++ {
c := s[i]
if c <= ' ' || i >= slash && c == '.' || c == '%' || c == '"' || c >= 0x7F {
fmt.Fprintf(&buf, "%%%02x", c)
continue
}
buf.WriteByte(c)
}
return buf.String()
}
}
return s
}
func addsection(seg *Segment, name string, rwx int) *Section {
sect := new(Section)
sect.Rwx = uint8(rwx)