[dev.link] cmd/link: escape package path in objByPkg map

The package references recorded in the object file, which are
obtained from the compiler, are escaped. We should also use the
escaped package paths in the linker for resolving package
references.

Change-Id: I42eb12df6ff24330e6dc7bed1dc8224bb3b8a106
Reviewed-on: https://go-review.googlesource.com/c/go/+/200158
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2019-10-09 15:37:46 -04:00
parent 0108b54a3d
commit e44dfa1f2b

View file

@ -103,6 +103,7 @@ func (l *Loader) AddObj(pkg string, r *oReader) Sym {
if _, ok := l.start[r]; ok {
panic("already added")
}
pkg = objabi.PathToPrefix(pkg) // the object file contains escaped package path
if _, ok := l.objByPkg[pkg]; !ok {
l.objByPkg[pkg] = r
}
@ -189,7 +190,11 @@ func (l *Loader) Resolve(r *oReader, s goobj2.SymRef) Sym {
rr = r
default:
pkg := r.Pkg(int(p))
rr = l.objByPkg[pkg]
var ok bool
rr, ok = l.objByPkg[pkg]
if !ok {
log.Fatalf("reference of nonexisted package %s, from %v", pkg, r.unit.Lib)
}
}
return l.ToGlobal(rr, int(s.SymIdx))
}