aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/type.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2020-09-24 16:54:31 -0400
committerCherry Zhang <cherryyz@google.com>2020-09-29 15:20:13 +0000
commit0ab72ed020d0c320b5007987abdf40677db34cfc (patch)
treeadfacfc78e174b0aa3e477a191b7b956a5b6f26f /src/runtime/type.go
parent0163bdae685c1b060f8108ac5af13ea6374555b1 (diff)
downloadgo-0ab72ed020d0c320b5007987abdf40677db34cfc.tar.gz
go-0ab72ed020d0c320b5007987abdf40677db34cfc.zip
cmd/link, runtime: use a sentinel value for unreachable method
In the method table, the method's code pointer is stored as an offset from the start of the text section. Currently, for an unreachable method, the offset is left as 0, which resolves to the start of the text section at run time. It is possible that there is valid code there. If an unreachable method is ever reached (due to a compiler or linker bug), the execution will jump to a wrong location but may continue to run for a while, until it fails with a seemingly unrelated error. This CL changes it to use -1 for unreachable method instead. At run time this will resolve to an invalid address, which makes it fail immediately if it is ever reached. Change-Id: Ied6ed7f1833c4f3b991fdf55d8810d70d307b2e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/257203 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/runtime/type.go')
-rw-r--r--src/runtime/type.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/runtime/type.go b/src/runtime/type.go
index 52b6cb30b4..81455f3532 100644
--- a/src/runtime/type.go
+++ b/src/runtime/type.go
@@ -217,7 +217,9 @@ func (t *_type) nameOff(off nameOff) name {
}
func resolveTypeOff(ptrInModule unsafe.Pointer, off typeOff) *_type {
- if off == 0 {
+ if off == 0 || off == -1 {
+ // -1 is the sentinel value for unreachable code.
+ // See cmd/link/internal/ld/data.go:relocsym.
return nil
}
base := uintptr(ptrInModule)
@@ -257,6 +259,11 @@ func (t *_type) typeOff(off typeOff) *_type {
}
func (t *_type) textOff(off textOff) unsafe.Pointer {
+ if off == -1 {
+ // -1 is the sentinel value for unreachable code.
+ // See cmd/link/internal/ld/data.go:relocsym.
+ return unsafe.Pointer(^uintptr(0))
+ }
base := uintptr(unsafe.Pointer(t))
var md *moduledata
for next := &firstmoduledata; next != nil; next = next.next {