Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Go 调用泛型函数时会先执行 LEA 指令,再执行 CALL 指令。我在上次提交
1f9d72d
中基于此特点跳过了跟 struct 传值产生的 CALL 指令,修复了 struct 传值导致
泛型打桩卡住的问题。
判断的依据是看 CALL 指令前面是否还有 LEA 指令且第一个参数为 RAX。
根据 Ruomenger 的调查,Go1.20 在执行 LEA 指令时,其目的寄存器由 RAX
改为 RBX,从而导致泛型 mock 出错。我还没找到对应的改动以及改动的原因。
Ruomenger 提议在检查 LEA 指令时同时支持 RAX 和 RBX 两种情况。但我认为
这样做不能根除问题,以后 Go 编译器改版可能还会引出新问题。
经过一番研究,我感觉使用函数名来判断可能是一个比较稳定的的办法。
getFirstCallFunc 最终找到泛型底层函数的地址。该地址对应的函数名包含
[...]
:以此为基准来确定函数指针应该没问题。而且 Go 语言提供 runtime.FuncForPC 非常方便。
Fix #12