I was wondering how exactly .cfi_remember_state is implemented. I know it is a pseudo-op, so I suppose it is converted into a couple of instructions when assembling. I am interested what exact instructions are used to implement it. I tried many ways to figure it out. Namely:
- Read GAS source code. But failed to find anything useful enough.
- Read GAS documentation. But the
.cfi_remember_stateentry is just a simple joke (literally). - Tried to find a gcc switch that would make gcc generate asm from C code with pseudo-ops “expanded”. Failed to find such a switch for x86 / x86-64. (Would be nice if someone could point me to such a switch, assuming it exists, BTW.)
- Google-fu && searching on SO did not yield anything useful.
The only other solution in my mind would be to read the binary of an assembled executable file and try to deduce the instructions. Yet I would like to avoid such a daunting task.
Could any of You, who knows, enlighten me, how exactly it is implemented on x86 and/or x86-64? Maybe along with sharing how / where that information was acquired, so I could check other pseudo-ops, if I ever have the need to?
This directive is a part of DWARF information (really all it does is emit DW_CFA_remember_state directive). Excerpt from DWARF3 standard:
You may play with DWARF information using objdump. Lets begin with simple void assembler file:
Compile it with
gcc cfirem.s -c -o cfirem.oNow disassemble generated DWARF section with
objdump --dwarf cfirem.oYou will get:
If you will uncomment .cfi_remember_state, you will see instead:
So it is not really converting in assembler instructions (try
objdump -dto see that there are no assembler instructions in our sample at all). It is converted in DWARF pseudo-instructions, that are used when debugger like GDB processes your variable locations, stack information and so on.