-
Notifications
You must be signed in to change notification settings - Fork 335
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
feat: refactor asm2asm #393
Conversation
67dae90
to
6ce8eeb
Compare
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## main #393 +/- ##
=======================================
Coverage ? 78.01%
=======================================
Files ? 62
Lines ? 10419
Branches ? 0
=======================================
Hits ? 8128
Misses ? 1943
Partials ? 348 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
What this PR for
Refactor
asm2asm
tool and golang-importing templates. We do this to mainly achieve two goals:Support traceback when native C functions get panic or profiled
In the past, we generated Plan 9 assembly codes by
asm2asm
(https://github.com/chenzhuoyu/asm2asm) tools. But since Go ASM can't recognize many 'SP-writing' instructions likeaddq $xx, %rsp
generated fromclang
, the imported c functions have incorrectpcsp
funcdata and will fatally crash once panic or profiling happens inside C codes (even if it is recoverable). Thus, we need to calculate correctpcsp
funcdata and import them into go runtime -- which is merely possible under the mechanism of Go ASM.Better performance
On the other hand, Go ASM doesn't support register-based ABI yet (although it has been supported by pure go functions), which causes obviously performance decline of imported C functions (estimated about 5%~20%). If we can drop the denpency of Go ASM and import C functions in the form of pure machines, dynamically, we can gain a lot of flexibility and improvement on ABI conversion.
How doest it work
In compiling time, we refactor
asm2asm
to calculate and generate all the function information we need:pcsp
、max stack size, and text size.In initial time, we implement ABI convertor (
loader/WrapGoC()
) to generate conversion codes:stackguard
is large enough for specific C functionred zone + max stack size
-- If it is not, callruntime.morstack()
;movq + call
)and register both C function and Go stub function. At present, we register every C functions as NoPreempt trait and reserve 32B
red-zone
for them, to avoid unexpected problems caused by different ABIBenchmark