From 89c654863f3837bf13431eeb1de130743604a926 Mon Sep 17 00:00:00 2001 From: pkujhd Date: Fri, 21 Aug 2020 18:42:01 +0800 Subject: [PATCH] add offset with data segment to support windows golang1.15 --- const.go | 1 + register.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/const.go b/const.go index 5d55d834..00dad5ec 100644 --- a/const.go +++ b/const.go @@ -52,4 +52,5 @@ const ( RUNTIME_PREFIX = "runtime." STKOBJ_SUFFIX = ".stkobj" INLINETREE_SUFFIX = ".inlinetree" + OS_STDOUT = "os.Stdout" ) diff --git a/register.go b/register.go index 2f8d0533..5b2e8314 100644 --- a/register.go +++ b/register.go @@ -54,7 +54,6 @@ func typelinksinit(symPtr map[string]uintptr) { } func RegSymbol(symPtr map[string]uintptr) error { - typelinksinit(symPtr) exe, err := os.Executable() if err != nil { return err @@ -65,14 +64,21 @@ func RegSymbol(symPtr map[string]uintptr) error { } defer f.Close() + typelinksinit(symPtr) syms, err := f.Symbols() + for _, sym := range syms { + if sym.Name == OS_STDOUT { + symPtr[sym.Name] = uintptr(sym.Addr) + } + } + addroff := int64(uintptr(unsafe.Pointer(&os.Stdout))) - int64(symPtr[OS_STDOUT]) for _, sym := range syms { code := strings.ToUpper(string(sym.Code)) if code == "B" || code == "D" { - symPtr[sym.Name] = uintptr(sym.Addr) + symPtr[sym.Name] = uintptr(int64(sym.Addr) + addroff) } if strings.HasPrefix(sym.Name, ITAB_PREFIX) { - symPtr[sym.Name] = uintptr(sym.Addr) + symPtr[sym.Name] = uintptr(int64(sym.Addr) + addroff) } } return nil