"crypto/sha1"
"encoding/binary"
"encoding/hex"
+ "io"
"path/filepath"
"sort"
"strings"
sort.Sort(byPkg(ctxt.Library))
h := sha1.New()
for _, l := range ctxt.Library {
- h.Write(l.hash)
+ io.WriteString(h, l.hash)
}
addgonote(ctxt, ".note.go.abihash", ELF_NOTE_GOABIHASH_TAG, h.Sum([]byte{}))
addgonote(ctxt, ".note.go.pkg-list", ELF_NOTE_GOPKGLIST_TAG, pkglistfornote)
"crypto/sha1"
"debug/elf"
"encoding/binary"
+ "encoding/hex"
"fmt"
"io"
"io/ioutil"
}
}
+ // If package versioning is required, generate a hash of the
+ // the packages used in the link.
+ if Buildmode == BuildmodeShared || Buildmode == BuildmodePlugin || ctxt.Syms.ROLookup("plugin.Open", 0) != nil {
+ for i = 0; i < len(ctxt.Library); i++ {
+ if ctxt.Library[i].Shlib == "" {
+ genhash(ctxt, ctxt.Library[i])
+ }
+ }
+ }
+
if SysArch == sys.Arch386 {
if (Buildmode == BuildmodeCArchive && Iself) || Buildmode == BuildmodeCShared || Buildmode == BuildmodePIE || ctxt.DynlinkingGo() {
got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0)
return arsize + SAR_HDR
}
+func genhash(ctxt *Link, lib *Library) {
+ f, err := bio.Open(lib.File)
+ if err != nil {
+ Errorf(nil, "cannot open file %s for hash generation: %v", lib.File, err)
+ return
+ }
+ defer f.Close()
+
+ var arhdr ArHdr
+ l := nextar(f, int64(len(ARMAG)), &arhdr)
+ if l <= 0 {
+ Errorf(nil, "%s: short read on archive file symbol header", lib.File)
+ return
+ }
+
+ h := sha1.New()
+ if _, err := io.CopyN(h, f, atolwhex(arhdr.size)); err != nil {
+ Errorf(nil, "bad read of %s for hash generation: %v", lib.File, err)
+ return
+ }
+ lib.hash = hex.EncodeToString(h.Sum(nil))
+}
+
func objfile(ctxt *Link, lib *Library) {
pkg := pathtoprefix(lib.Pkg)
goto out
}
- if Buildmode == BuildmodeShared || Buildmode == BuildmodePlugin || ctxt.Syms.ROLookup("plugin.Open", 0) != nil {
- before := f.Offset()
- pkgdefBytes := make([]byte, atolwhex(arhdr.size))
- if _, err := io.ReadFull(f, pkgdefBytes); err != nil {
- Errorf(nil, "%s: short read on archive file symbol header: %v", lib.File, err)
- }
- hash := sha1.Sum(pkgdefBytes)
- lib.hash = hash[:]
- f.Seek(before, 0)
- }
-
off += l
ldpkg(ctxt, f, pkg, atolwhex(arhdr.size), lib.File, Pkgdef)