]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: check consistency of all module data objects
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Wed, 6 May 2015 02:30:28 +0000 (14:30 +1200)
committerIan Lance Taylor <iant@golang.org>
Thu, 7 May 2015 15:06:08 +0000 (15:06 +0000)
Current code just checks the consistency (that the functab is correctly
sorted by PC, etc) of the moduledata object that the runtime belongs to.
Change to check all of them.

Change-Id: I544a44c5de7445fff87d3cdb4840ff04c5e2bf75
Reviewed-on: https://go-review.googlesource.com/9773
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/proc1.go
src/runtime/symtab.go

index 753a3a5058e8abd3b46b2e0d43990a75561e2bb6..00535da77d16d981c1ae66077dfdbe0d1238efad 100644 (file)
@@ -51,7 +51,7 @@ func schedinit() {
        framepointer_enabled = haveexperiment("framepointer")
 
        tracebackinit()
-       symtabverify()
+       moduledataverify()
        stackinit()
        mallocinit()
        mcommoninit(_g_.m)
index e55c357900bc3d10ece40c06c5d7438ff7e0bb59..25f5bf46fb9a968318c1561dc4665f354d0c4e5e 100644 (file)
@@ -84,38 +84,44 @@ type findfuncbucket struct {
        subbuckets [16]byte
 }
 
-func symtabverify() {
+func moduledataverify() {
+       for datap := &firstmoduledata; datap != nil; datap = datap.next {
+               moduledataverify1(datap)
+       }
+}
+
+func moduledataverify1(datap *moduledata) {
        // See golang.org/s/go12symtab for header: 0xfffffffb,
        // two zero bytes, a byte giving the PC quantum,
        // and a byte giving the pointer width in bytes.
-       pcln := *(**[8]byte)(unsafe.Pointer(&firstmoduledata.pclntable))
-       pcln32 := *(**[2]uint32)(unsafe.Pointer(&firstmoduledata.pclntable))
+       pcln := *(**[8]byte)(unsafe.Pointer(&datap.pclntable))
+       pcln32 := *(**[2]uint32)(unsafe.Pointer(&datap.pclntable))
        if pcln32[0] != 0xfffffffb || pcln[4] != 0 || pcln[5] != 0 || pcln[6] != _PCQuantum || pcln[7] != ptrSize {
                println("runtime: function symbol table header:", hex(pcln32[0]), hex(pcln[4]), hex(pcln[5]), hex(pcln[6]), hex(pcln[7]))
                throw("invalid function symbol table\n")
        }
 
        // ftab is lookup table for function by program counter.
-       nftab := len(firstmoduledata.ftab) - 1
+       nftab := len(datap.ftab) - 1
        for i := 0; i < nftab; i++ {
                // NOTE: ftab[nftab].entry is legal; it is the address beyond the final function.
-               if firstmoduledata.ftab[i].entry > firstmoduledata.ftab[i+1].entry {
-                       f1 := (*_func)(unsafe.Pointer(&firstmoduledata.pclntable[firstmoduledata.ftab[i].funcoff]))
-                       f2 := (*_func)(unsafe.Pointer(&firstmoduledata.pclntable[firstmoduledata.ftab[i+1].funcoff]))
+               if datap.ftab[i].entry > datap.ftab[i+1].entry {
+                       f1 := (*_func)(unsafe.Pointer(&datap.pclntable[datap.ftab[i].funcoff]))
+                       f2 := (*_func)(unsafe.Pointer(&datap.pclntable[datap.ftab[i+1].funcoff]))
                        f2name := "end"
                        if i+1 < nftab {
                                f2name = funcname(f2)
                        }
-                       println("function symbol table not sorted by program counter:", hex(firstmoduledata.ftab[i].entry), funcname(f1), ">", hex(firstmoduledata.ftab[i+1].entry), f2name)
+                       println("function symbol table not sorted by program counter:", hex(datap.ftab[i].entry), funcname(f1), ">", hex(datap.ftab[i+1].entry), f2name)
                        for j := 0; j <= i; j++ {
-                               print("\t", hex(firstmoduledata.ftab[j].entry), " ", funcname((*_func)(unsafe.Pointer(&firstmoduledata.pclntable[firstmoduledata.ftab[j].funcoff]))), "\n")
+                               print("\t", hex(datap.ftab[j].entry), " ", funcname((*_func)(unsafe.Pointer(&datap.pclntable[datap.ftab[j].funcoff]))), "\n")
                        }
                        throw("invalid runtime symbol table")
                }
        }
 
-       if firstmoduledata.minpc != firstmoduledata.ftab[0].entry ||
-               firstmoduledata.maxpc != firstmoduledata.ftab[nftab].entry {
+       if datap.minpc != datap.ftab[0].entry ||
+               datap.maxpc != datap.ftab[nftab].entry {
                throw("minpc or maxpc invalid")
        }
 }