-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check inlining and optimization when init mockey
Change-Id: I3a362d2160ce4db55f9b4574f8fcf9e0cfb170f8
- Loading branch information
Showing
4 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package tool | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
func init() { | ||
// set MOCKEY_CHECK_GCFLAGS=false to disable this check | ||
checkGCflags() | ||
} | ||
|
||
func checkGCflags() int { | ||
if flag := os.Getenv("MOCKEY_CHECK_GCFLAGS"); flag != "false" && !IsGCFlagsSet() { | ||
panic(` | ||
Mockey init failed, did you forget to add -gcflags="all=-N -l" ? | ||
(Set env MOCKEY_CHECK_GCFLAGS=false to disable gcflags check) | ||
`) | ||
} | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package tool | ||
|
||
import ( | ||
"reflect" | ||
"unsafe" | ||
|
||
"golang.org/x/arch/x86/x86asm" | ||
) | ||
|
||
func fn() { | ||
} | ||
func fn2() { | ||
fn() | ||
} | ||
func IsGCFlagsSet() bool { | ||
var asm []byte | ||
header := (*reflect.SliceHeader)(unsafe.Pointer(&asm)) | ||
header.Data = reflect.ValueOf(fn2).Pointer() | ||
header.Len = 1000 | ||
header.Cap = 1000 | ||
|
||
flag := false | ||
pos := 0 | ||
for pos < len(asm) { | ||
inst, _ := x86asm.Decode(asm[pos:], 64) | ||
if inst.Op == x86asm.RET { | ||
break | ||
} | ||
if inst.Op == x86asm.CALL { | ||
flag = true | ||
break | ||
} | ||
pos += int(inst.Len) | ||
} | ||
return flag | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package tool | ||
|
||
import ( | ||
"reflect" | ||
"unsafe" | ||
|
||
"golang.org/x/arch/arm64/arm64asm" | ||
) | ||
|
||
func fn() { | ||
} | ||
func fn2() { | ||
fn() | ||
} | ||
func IsGCFlagsSet() bool { | ||
var asm []byte | ||
header := (*reflect.SliceHeader)(unsafe.Pointer(&asm)) | ||
header.Data = reflect.ValueOf(fn2).Pointer() | ||
header.Len = 1000 | ||
header.Cap = 1000 | ||
|
||
flag := false | ||
pos := 0 | ||
for pos < len(asm) { | ||
inst, _ := arm64asm.Decode(asm[pos:]) | ||
if inst.Op == arm64asm.RET { | ||
break | ||
} | ||
if inst.Op == arm64asm.BL { | ||
flag = true | ||
break | ||
} | ||
pos += int(unsafe.Sizeof(inst.Enc)) | ||
} | ||
return flag | ||
} |