Skip to content

Conversation

@fabled
Copy link
Contributor

@fabled fabled commented Jan 19, 2026

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_address function to bare minimum. Based on my observation in comment #876 (comment)

Additional refactor the code so that unwind_register_address gets simplified when the "dereference flag" is not possible/supported.

On x86-64 the net reduction is -1209 instructions.

 support/ebpf/tracer.ebpf.amd64                     | Bin 3550560 -> 3527104 bytes
 support/ebpf/tracer.ebpf.arm64                     | Bin 3523920 -> 3493624 bytes

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.)

@fabled fabled force-pushed the tt-simplify-native-unwind branch 7 times, most recently from f2d9746 to 5117aa9 Compare January 20, 2026 14:00
@fabled fabled force-pushed the tt-simplify-native-unwind branch from 5117aa9 to 79257c1 Compare January 20, 2026 17:34
@fabled fabled marked this pull request as ready for review January 20, 2026 17:39
@fabled fabled requested review from a team as code owners January 20, 2026 17:39
Comment on lines +611 to +617
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;
Copy link
Contributor Author

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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant