The 12/06/2022 11:58, Wilco Dijkstra wrote: > > i don't think how[*RA_STATE] can ever be set to REG_SAVED_OFFSET, > > this pseudo reg is not spilled to the stack, it is reset to 0 in > > each frame and then toggled within a frame. > > It's is just a state, we can use any state we want since it is a pseudo reg. > These registers are global and shared across all functions in an unwind, > so their state or value isn't reset for each frame. So if we want to reset > it in each frame then using a virtual register to hold per-function data > seems like a bad design. I'm surprised nobody has ever tested it...
it was tested (and worked when the frame state was initialized). in principle the CIE can contain instructions to initialize the register state for a frame. the RA_STATE pseudo reg behaves as if the CIE always set its value to 0 at the start of the frame. the design has issues, but this is what we have now. the toggle instruction for RA_STATE does not really fit the dwarf model: the CFI instruction sequence is evaluated with a context that is valid at the end of the sequence so an unwinder only wants to evaluate a register's state at the end, not intermediate values (where the context might not even be valid). so we limited the instructions allowed for RA_STATE: only remember_/restore_state, toggle and val_expression are supported and the latter two cannot be mixed. we still have to use the existing struct for keeping track of this hence reg[RA_STATE].loc.offset. and of course the RA_STATE pseudo reg is only used for computing the return address not propagated to the previous frame so it is special in many ways. so we will need target hooks to fix this and i think the cleanest is to initialize RA_STATE per frame and leave the rest as is.