aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/symtab.go
diff options
context:
space:
mode:
authorMichael Hudson-Doyle <michael.hudson@canonical.com>2015-04-11 12:05:21 +0800
committerIan Lance Taylor <iant@golang.org>2015-05-12 01:30:40 +0000
commit77fc03f4cd7f6ea0b142bd17ea172205d5f45cff (patch)
tree06f33fb755d5d5224028dfdcecbe59128f57c73e /src/runtime/symtab.go
parentbe0cb9224b68d5be4e03fd35396d2c2f0755adad (diff)
downloadgo-77fc03f4cd7f6ea0b142bd17ea172205d5f45cff.tar.xz
cmd/internal/ld, runtime: abort on shared library ABI mismatch
This: 1) Defines the ABI hash of a package (as the SHA1 of the __.PKGDEF) 2) Defines the ABI hash of a shared library (sort the packages by import path, concatenate the hashes of the packages and SHA1 that) 3) When building a shared library, compute the above value and define a global symbol that points to a go string that has the hash as its value. 4) When linking against a shared library, read the abi hash from the library and put both the value seen at link time and a reference to the global symbol into the moduledata. 5) During runtime initialization, check that the hash seen at link time still matches the hash the global symbol points to. Change-Id: Iaa54c783790e6dde3057a2feadc35473d49614a5 Reviewed-on: https://go-review.googlesource.com/8773 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
Diffstat (limited to 'src/runtime/symtab.go')
-rw-r--r--src/runtime/symtab.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go
index bbf00bf134..9afa954259 100644
--- a/src/runtime/symtab.go
+++ b/src/runtime/symtab.go
@@ -48,11 +48,24 @@ type moduledata struct {
typelinks []*_type
+ modulename string
+ modulehashes []modulehash
+
gcdatamask, gcbssmask bitvector
next *moduledata
}
+// For each shared library a module links against, the linker creates an entry in the
+// moduledata.modulehashes slice containing the name of the module, the abi hash seen
+// at link time and a pointer to the runtime abi hash. These are checked in
+// moduledataverify1 below.
+type modulehash struct {
+ modulename string
+ linktimehash string
+ runtimehash *string
+}
+
var firstmoduledata moduledata // linker symbol
var lastmoduledatap *moduledata // linker symbol
@@ -117,6 +130,13 @@ func moduledataverify1(datap *moduledata) {
datap.maxpc != datap.ftab[nftab].entry {
throw("minpc or maxpc invalid")
}
+
+ for _, modulehash := range datap.modulehashes {
+ if modulehash.linktimehash != *modulehash.runtimehash {
+ println("abi mismatch detected between", datap.modulename, "and", modulehash.modulename)
+ throw("abi mismatch")
+ }
+ }
}
// FuncForPC returns a *Func describing the function that contains the