Skip to content

Commit

Permalink
add offset with data segment to support windows golang1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujhd committed Aug 21, 2020
1 parent 4f35417 commit 89c6548
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ const (
RUNTIME_PREFIX = "runtime."
STKOBJ_SUFFIX = ".stkobj"
INLINETREE_SUFFIX = ".inlinetree"
OS_STDOUT = "os.Stdout"
)
12 changes: 9 additions & 3 deletions register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 89c6548

Please sign in to comment.