Skip to content
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

frametypes should also describe registers and callee-save stack slots #93

Open
stephenrkell opened this issue Jun 13, 2024 · 0 comments

Comments

@stephenrkell
Copy link
Owner

stephenrkell commented Jun 13, 2024

We currently postprocess local variables' DWARF in the frametypes tool, which computes a collection of stack frame layouts for each function. We can think of these as stack maps, each covering a particular range of program counters. However, they currently describe only things that are (1) local variables and (2) literally on the stack, i.e. in memory.

Internally, frametypes is building a map from stack offsets to the DWARF entry (DIE) that resides at that offset.

set<pair< 
		Dwarf_Signed, // frame offset
		iterator_df< with_dynamic_location_die >
	>,
	compare_first_signed_second_offset 
>

(and aggregating these in a boost::icl::interval_map, since each is valid over a particular range of addresses).

There are two small generalisations of this tool that would give us a more complete view of the stack and registers.

  1. Instead of just a frame offset (Dwarf_Signed), allow the 'where' to be a register, and include register-allocated local variables. (Tricky: what to do when a variable is split between a register and memory? This does happen, and can be described by DW_OP_piece.)
  2. Instead of just local variables, allow the 'what' to be "our saved copy of the caller's [some callee-save register]". The DWARF .debug_info section does not tell us this, but the .debug_frame or .eh_frame information does (see also Stack walking should use eh_elfs from frdwarf #83). This is important because the saved value might be a pointer -- though we'd have to look at the caller's type information to know that, since to the callee that does the saving it is just an opaque word-sized value.

This might also tie in with rethinking how we represent stack frames at the uniqtype level (#85).

If we had this information, we could get closer to precise stack-scanning for garbage collection (no doubt some gaps and other ambiguities would still remain, but we could measure the reduction!), other applications that can require us to rewrite pointers (stack reconstruction for dynamic software update, on-stack replacement, etc), and general debug-time features ("what is this stack slot representing?" / dumping memory in a more abstract or more explained form).

@stephenrkell stephenrkell changed the title frametypes should also describe registers and caller-save stack slots frametypes should also describe registers and callee-save stack slots Jun 13, 2024
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

No branches or pull requests

1 participant