]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix endianness assumption when decoding ftab
authorAustin Clements <austin@google.com>
Mon, 27 Oct 2014 21:12:48 +0000 (17:12 -0400)
committerAustin Clements <austin@google.com>
Mon, 27 Oct 2014 21:12:48 +0000 (17:12 -0400)
The ftab ends with a half functab record consisting only of
the 'entry' field followed by a uint32 giving the offset of
the next table.  Previously, symtabinit assumed it could read
this uint32 as a uintptr.  Since this is unsafe on big endian,
explicitly read the offset as a uint32.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/157660043

src/runtime/symtab.go

index 48d4023b9aa6e1d8bfff3f35fb3dd135c366d016..45d107b777869e1a0cd7e4bcd7c38922e85eeba4 100644 (file)
@@ -84,10 +84,13 @@ func symtabinit() {
                }
        }
 
-       // file table follows ftab.
+       // The ftab ends with a half functab consisting only of
+       // 'entry', followed by a uint32 giving the pcln-relative
+       // offset of the file table.
        sp = (*sliceStruct)(unsafe.Pointer(&filetab))
-       p = unsafe.Pointer(add(unsafe.Pointer(pcln), ftab[nftab].funcoff))
-       sp.array = unsafe.Pointer(add(unsafe.Pointer(pcln), ftab[nftab].funcoff))
+       end := unsafe.Pointer(&ftab[nftab].funcoff) // just beyond ftab
+       fileoffset := *(*uint32)(end)
+       sp.array = unsafe.Pointer(&pclntable[fileoffset])
        // length is in first element of array.
        // set len to 1 so we can get first element.
        sp.len = 1
@@ -224,7 +227,7 @@ func funcline(f *_func, targetpc uintptr, file *string) int32 {
 func funcspdelta(f *_func, targetpc uintptr) int32 {
        x := pcvalue(f, f.pcsp, targetpc, true)
        if x&(ptrSize-1) != 0 {
-               print("invalid spdelta ", f.pcsp, " ", x, "\n")
+               print("invalid spdelta ", hex(f.entry), " ", hex(targetpc), " ", hex(f.pcsp), " ", x, "\n")
        }
        return x
 }