]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: escape package path in objByPkg map
authorCherry Zhang <cherryyz@google.com>
Wed, 9 Oct 2019 19:37:46 +0000 (15:37 -0400)
committerCherry Zhang <cherryyz@google.com>
Thu, 10 Oct 2019 22:06:28 +0000 (22:06 +0000)
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>
src/cmd/link/internal/objfile/objfile2.go

index 2be34b823e0962c4e0eb37d4bc27f084dfba4d03..96d9ad1bd7207a2bdac726bea8dea2c811f4d57a 100644 (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))
 }