An elf file contains multiple sections (.eh_frame, .eh_frame_shr) to store precise information about how stack unwdinging has to be done. This is also the basis for throwing exceptions (.gcc_except_table). Inserting inline assembly would certainly mess with these tables.
How is the compiler dealing with that? Is it parsing back the inline assembly and then update the tables or will stack unwinding (and therefore also exception handling) just break when inline assembly messes up the stack?
Inserting inline assembly would certainly mess with these tables.
True, and it very often does (though not with certainty, see below).
How is the compiler dealing with that?
It doesn't.
Instead, it's up to the assembly writer to either not modify the frame register (which could be either RSP or RBP on x86_64
) and not execute any PUSH
, POP
, CALL
or RET
instructions, or alternatively to provide correct .cfi
descriptors in the inline assembly (which is generally pretty difficult to do, because you don't know what the compiler will do in the rest of the function).