-
Notifications
You must be signed in to change notification settings - Fork 364
ebpf: simplify native unwinder opcodes #1092
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
base: main
Are you sure you want to change the base?
Conversation
f2d9746 to
5117aa9
Compare
5117aa9 to
79257c1
Compare
| union { | ||
| // regs is for the native unwinder to index the registers | ||
| u64 regs[16]; | ||
| // And the anonymous struct offers readable ebpf code access. | ||
| // stackdeltatypes.h must have corresponding indexes to these names. | ||
| struct { | ||
| u64 inval, cfa, pc, sp, fp, lr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically using union here, and then the code to use alternatively both u64 regs[] and struct members to access the same data might be "invalid". But in practice this works.
If it is preferred to not have this kind of potentially invalid code, I can refactor and add perhaps #define reg_pc regs[UNWIND_REG_PC] and other similar accessors, and do the replace on all such instances.
| #define UNWIND_OPCODE_BASE_CFA_FRAME 0x06 | ||
| // An opcode flag to indicate that the value should be dereferenced | ||
| #define UNWIND_OPCODEF_DEREF 0x80 | ||
| #define UNWIND_REG_INVALID 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if all these #defines should be moved to types.h next to the places to where they apply, and just delete this file?
| u8 fpOpcode; // opcode to unwind FP | ||
| u8 flags; // flags | ||
| u8 baseReg; // base register to calculate CFA from | ||
| u8 auxBaseReg; // base register to calculate FP (x86-64) or RA[+FP] (aarch64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chose aux because the meaning depends on arch; could be also baseReg2 and param2 if preferred?
Instead of having a custom set of unwinder opcoder and large switches, make the unwinder just use index to register state. This allows simplifying the
unwind_register_addressfunction to bare minimum. Based on my observation in comment #876 (comment)Additional refactor the code so that
unwind_register_addressgets simplified when the "dereference flag" is not possible/supported.On x86-64 the net reduction is -1209 instructions.
This also paves way for easier support of additional registers. One use case being the issue referenced above which triggered this work.
(This PR also includes some other PRs to avoid needing a rebasing the code in near future. Will rebase the PR as the included other commits get merged in to main.)