}
}
if ok && !*flags.SymABIs {
- obj.WriteObjFile(ctxt, buf)
+ obj.WriteObjFile(ctxt, buf, "")
}
if !ok || diag {
if failedFile != "" {
addGCLocals()
- obj.WriteObjFile(Ctxt, bout.Writer)
+ obj.WriteObjFile(Ctxt, bout.Writer, myimportpath)
}
func addptabs() {
return p.ImportPath
}
h := sha1.New()
- fmt.Fprintf(h, "build ID: %s\n", a.buildID)
+ buildID := a.buildID
+ if a.Mode == "link" {
+ // For linking, use the main package's build ID instead of
+ // the binary's build ID, so it is the same hash used in
+ // compiling and linking.
+ // When compiling, we use actionID/actionID (instead of
+ // actionID/contentID) as a temporary build ID to compute
+ // the hash. Do the same here. (See buildid.go:useCache)
+ // The build ID matters because it affects the overall hash
+ // in the plugin's pseudo-import path returned below.
+ // We need to use the same import path when compiling and linking.
+ id := strings.Split(buildID, buildIDSeparator)
+ buildID = id[1] + buildIDSeparator + id[1]
+ }
+ fmt.Fprintf(h, "build ID: %s\n", buildID)
for _, file := range str.StringList(p.GoFiles, p.CgoFiles, p.SFiles) {
data, err := ioutil.ReadFile(filepath.Join(p.Dir, file))
if err != nil {
"log"
"path/filepath"
"sort"
+ "strings"
"sync"
)
nAutom int
nFuncdata int
nFile int
+
+ pkgpath string // the package import path (escaped), "" if unknown
}
func (w *objWriter) addLengths(s *LSym) {
w.writeInt(int64(w.nFile))
}
-func newObjWriter(ctxt *Link, b *bufio.Writer) *objWriter {
+func newObjWriter(ctxt *Link, b *bufio.Writer, pkgpath string) *objWriter {
return &objWriter{
- ctxt: ctxt,
- wr: b,
+ ctxt: ctxt,
+ wr: b,
+ pkgpath: objabi.PathToPrefix(pkgpath),
}
}
-func WriteObjFile(ctxt *Link, b *bufio.Writer) {
- w := newObjWriter(ctxt, b)
+func WriteObjFile(ctxt *Link, b *bufio.Writer, pkgpath string) {
+ w := newObjWriter(ctxt, b, pkgpath)
// Magic header
w.wr.WriteString("\x00go112ld")
w.wr.WriteByte(symPrefix)
if isPath {
w.writeString(filepath.ToSlash(s.Name))
+ } else if w.pkgpath != "" {
+ // w.pkgpath is already escaped.
+ n := strings.Replace(s.Name, "\"\".", w.pkgpath+".", -1)
+ w.writeString(n)
} else {
w.writeString(s.Name)
}
Found bool
}
var syms = []symType{
- {"B", "%22%22.Testdata", false, false},
- {"T", "%22%22.Testfunc", false, false},
+ {"B", "mylib.Testdata", false, false},
+ {"T", "mylib.Testfunc", false, false},
}
if iscgo {
- syms = append(syms, symType{"B", "%22%22.TestCgodata", false, false})
- syms = append(syms, symType{"T", "%22%22.TestCgofunc", false, false})
+ syms = append(syms, symType{"B", "mylib.TestCgodata", false, false})
+ syms = append(syms, symType{"T", "mylib.TestCgofunc", false, false})
if runtime.GOOS == "darwin" || (runtime.GOOS == "windows" && runtime.GOARCH == "386") {
syms = append(syms, symType{"D", "_cgodata", true, false})
syms = append(syms, symType{"T", "_cgofunc", true, false})