github.com/tencent/goom@v1.0.1/internal/bytecode/inline_check_amd64.go (about) 1 package bytecode 2 3 import ( 4 "reflect" 5 6 "github.com/tencent/goom/internal/arch/x86asm" 7 "github.com/tencent/goom/internal/bytecode/memory" 8 "github.com/tencent/goom/internal/logger" 9 ) 10 11 func init() { 12 // call fake 13 _ = callFakeFunc() 14 // check call asm code 15 checkInlineDisable() 16 } 17 18 // checkInlineDisable 检测是否关闭 inline 19 func checkInlineDisable() { 20 addr := reflect.ValueOf(callFakeFunc).Pointer() 21 bytes := memory.RawRead(addr, 100) 22 23 existsCallIns := false 24 for pos := 0; pos < len(bytes); { 25 ins, _, err := ParseIns(pos, bytes) 26 if err != nil { 27 logger.Warningf("goom resolve inline err: %v", err) 28 break 29 } 30 31 if ins.Op == x86asm.CALL { 32 existsCallIns = true 33 break 34 } 35 if ins.Op == x86asm.INT && ins.Args[0].String() == "0x3" { 36 break 37 } 38 pos = pos + ins.Len 39 } 40 41 if !existsCallIns { 42 logger.Warningf("go inline is not disable, please use the build param: -gcflags=all=-l") 43 logger.Consolef(logger.WarningLevel, "go inline is not disable, please use the build param: -gcflags=all=-l") 44 } 45 } 46 47 // callFakeFunc 内联测试函数 48 func callFakeFunc() int { 49 return checkTarget(1) 50 } 51 52 // checkTarget 测试目标 mock 函数 53 func checkTarget(i int) int { 54 // example short code 55 return i + 1 56 }