Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade dependencies & fix generics bug #71

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ Mockey is distributed under the [Apache License](https://github.com/bytedance/mo

## FAQ

### Go 1.23 compile error `"link: github.com/bytedance/mockey/internal/monkey/common: invalid reference to runtime.sysAllocOS"`?
add build flag `-ldflags=-checklinkname=0`

### How to disable inline and compile optimization?
1. Command line:`go test -gcflags="all=-l -N" -v ./...`
2. Goland:fill `-gcflags="all=-l -N"` in the **Run/Debug Configurations > Go tool arguments** dialog box
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/bytedance/mockey
go 1.18

require (
github.com/smartystreets/goconvey v1.6.4
golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff
golang.org/x/sys v0.24.0
github.com/smartystreets/goconvey v1.7.2
golang.org/x/arch v0.11.0
golang.org/x/sys v0.26.0
)

require (
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
github.com/gopherjs/gopherjs v1.12.80 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
)
39 changes: 30 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v1.12.80 h1:aC68NT6VK715WeUapxcPSFq/a3gZdS32HdtghdOIgAo=
github.com/gopherjs/gopherjs v1.12.80/go.mod h1:d55Q4EjGQHeJVms+9LGtXul6ykz5Xzx1E1gaXQXdimY=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff h1:XmKBi9R6duxOB3lfc72wyrwiOY7X2Jl1wuI+RFOyMDE=
golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
github.com/rogpeppe/go-internal v1.0.1-alpha.1/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20180915214035-33ae1944be3f/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20180807104621-f027049dab0a/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20180807162357-acbc56fc7007/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190308142131-b40df0fb21c3/go.mod h1:25r3+/G6/xytQM8iWZKq3Hn0kr0rgFKPUNVEL/dr3z4=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
3 changes: 1 addition & 2 deletions internal/monkey/common/runtime_link/stw/stw_1_21.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func newSTWCtx() ctx {
return &stwCtx{}
}

type stwCtx struct {
}
type stwCtx struct{}

const stwForTestResetDebugLog = 16

Expand Down
1 change: 1 addition & 0 deletions internal/monkey/common/runtime_link/stw/stw_1_22.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const stwForTestResetDebugLog = 16
func (ctx *stwCtx) StopTheWorld() {
ctx.w = stopTheWorld(stwForTestResetDebugLog)
}

func (ctx *stwCtx) StartTheWorld() {
startTheWorld(ctx.w)
}
Expand Down
1 change: 1 addition & 0 deletions internal/monkey/common/runtime_link/stw/stw_above_1_22.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const stwForTestResetDebugLog = 16
func (ctx *stwCtx) StopTheWorld() {
ctx.w = stopTheWorld(stwForTestResetDebugLog)
}

func (ctx *stwCtx) StartTheWorld() {
startTheWorld(ctx.w)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/monkey/common/runtime_link/stw/stw_below_1_21.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func newSTWCtx() ctx {
return &stwCtx{}
}

type stwCtx struct {
}
type stwCtx struct{}

func (ctx *stwCtx) StopTheWorld() {
stopTheWorld("mockey")
Expand Down
3 changes: 1 addition & 2 deletions internal/monkey/common/runtime_link/stw/stw_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func newSTWCtx() ctx {
return &stwCtx{}
}

type stwCtx struct {
}
type stwCtx struct{}

func (ctx *stwCtx) StopTheWorld() {
}
Expand Down
2 changes: 0 additions & 2 deletions internal/monkey/inst/disasm_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ func calcFnAddrRange(name string, fn func()) (uintptr, uintptr) {
for i := range inst.Args {
args = append(args, inst.Args[i])
}
tool.DebugPrintf("init: <%v>\t%v\t%v\t%v\t%v\t%v\t%v\n", args...)

if inst.Op == x86asm.RET {
end = start + uintptr(pos)
tool.DebugPrintf("init: %v(%v,%v)\n", name, start, end)
return start, end
}

Expand Down
26 changes: 6 additions & 20 deletions internal/monkey/inst/disasm_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ func calcFnAddrRange(name string, fn func()) (uintptr, uintptr) {
for i := range inst.Args {
args = append(args, inst.Args[i])
}
tool.DebugPrintf("init: <%v>\t%v\t%v\t%v\t%v\t%v\t%v\n", args...)

if inst.Op == arm64asm.RET {
end = start + uintptr(pos)
tool.DebugPrintf("init: %v(%v,%v)\n", name, start, end)
return start, end
}

Expand Down Expand Up @@ -80,7 +78,7 @@ func GetGenericJumpAddr(addr uintptr, maxScan uint64) uintptr {
}

if inst.Op == arm64asm.BL {
fnAddr := calcAddr(uintptr(unsafe.Pointer(&code[0]))+uintptr(pos), inst.Enc)
fnAddr := calcAddr(uintptr(unsafe.Pointer(&code[0]))+uintptr(pos), inst)
isExtraCall, extraName := isGenericProxyCallExtra(fnAddr)
tool.DebugPrintf("found BL, raw is: %x, fnAddr: %v, isExtraCall: %v, extraName: %v\n", inst.String(), fnAddr, isExtraCall, extraName)
if !isExtraCall {
Expand All @@ -93,23 +91,11 @@ func GetGenericJumpAddr(addr uintptr, maxScan uint64) uintptr {
return allAddrs[0]
}

func calcAddr(from uintptr, bl uint32) uintptr {
tool.DebugPrintf("calc BL addr, from: %x(%v) bl: %x\n", from, from, bl)
offset := bl << 8 >> 8
flag := (offset << 9 >> 9) == offset // 是否小于0

var dest uintptr
if flag {
// L -> H
// (dest - cur) / 4 = offset
// dest = cur + offset * 4
dest = from + uintptr(offset*4)
func calcAddr(from uintptr, bl arm64asm.Inst) uintptr {
distance := int64(bl.Args[0].(arm64asm.PCRel))
if distance < 0 {
return from - uintptr(-distance)
} else {
// H -> L
// (cur - dest) / 4 = (0x00ffffff - offset + 1)
// dest = cur - (0x00ffffff - offset + 1) * 4
dest = from - uintptr((0x00ffffff-offset+1)*4)
return from + uintptr(distance)
}
tool.DebugPrintf("2th complement, L->H:%v offset: %x from: %x(%v) dest: %x(%v), distance: %v\n", flag, offset, from, from, dest, dest, from-dest)
return dest
}
6 changes: 6 additions & 0 deletions internal/monkey/inst/generic_extra_race.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package inst
import (
"reflect"
_ "unsafe"

"github.com/bytedance/mockey/internal/tool"
)

//go:linkname racefuncenter runtime.racefuncenter
Expand Down Expand Up @@ -68,4 +70,8 @@ func init() {
reflect.ValueOf(racewriterangepc1).Pointer(): "racewriterangepc1",
reflect.ValueOf(racecallbackthunk).Pointer(): "racecallbackthunk",
}

for addr, name := range proxyCallRace {
tool.DebugPrintf("race func: %x(%v)\n", addr, name)
}
}
1 change: 1 addition & 0 deletions internal/monkey/mem/write_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func Write(target uintptr, data []byte) error {
if res != 0 {
return fmt.Errorf("write failed, code %v", res)
}
tool.DebugPrintf("Write end(darwin)")
return nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/monkey/mem/write_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func Write(target uintptr, data []byte) error {
if res != 0 {
return fmt.Errorf("write failed, code %v", res)
}
tool.DebugPrintf("Write end(linux)")
return nil
}

Expand Down
Loading