1

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?

Fee
  • 719
  • 9
  • 24
  • I imagine it is assuming that your claim 'inserting inline assembly would certainly mess with these tables' is false. What makes you think it is true? – user207421 Apr 16 '23 at 09:42
  • 4
    You are not throwing exceptions from the inline assembly, right? Or create objects that need their destructor called? So probably pretty neutral. – BoP Apr 16 '23 at 11:31
  • 2
    There is no inline assembly in standard C++. If your compiler supports it then it's a compiler specific extension and you should consult your compilers documentation for details. – Jesper Juhl Apr 16 '23 at 11:53
  • 2
    The compiler assumes you know what you are doing. If your inline assembly messes up the stack, your problem. Make sure it doesn't. – n. m. could be an AI Apr 21 '23 at 06:20

1 Answers1

1

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

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • doesn't this make basically any non trivial inline assembly practically impossible? – Fee Apr 23 '23 at 06:53
  • Basically any inline assembly that changes the stack is very likely to be a bug at this point? – Fee Apr 23 '23 at 07:04