[cfe-dev] Clang-Cl assembly output - .seh_ pseudo code

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Mon Jan 20 13:29:48 PST 2020


I can say a bit about them. We inherited these directives from the gnu
assembler, and a similar question was asked about GCC here:
https://stackoverflow.com/questions/20819927/what-are-seh-assembly-commands-that-gcc-outputs/38181874


Basically, these directives do not emit instructions, they record metadata
about the prologue. Later, the .seh_handlerdata directive emits that
metadata into an .xdata section, encoded according to these rules:
https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019


So, truly, these directives describe how to unwind the stack. They do not
describe how __try / __except work. That is controlled by the data after
.seh_handlerdata. Those bytes are typically known as the LSDA,
"language-specific data area".  The personality function
__C_specific_handler interprets the LSDA to handle exceptions.

Hope that helps.

On Mon, Jan 20, 2020 at 12:53 AM Gaier, Bjoern via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hello Clang-Developers,
>
>
>
> I have a question about the assembly output Clang-Cl generated for me,
> when passing /Fa. The code was using a __try and __except statement and I
> wanted to see how the __try statement is represented in the target
> assembly. To my surprise there was no ".cv_loc" for that specific line - so
> I scrolled up a bit.
>
> There I found:
>
>
>
> push      rbp
>
> .seh_pushreg 5
>
> sub        rsp, 48
>
> .seh_stackalloc 48
>
> lea          rbp, [rsp + 48]
>
> .seh_setframe 5, 48
>
> .seh_endprologue
>
>
>
> I looked up those words and only could find out that those are pseudo
> code. I wonder, why am I not allowed to see the content behind those pseudo
> code? Is there a way to find out what will be written there later?
>
> I also found the following lines in a different code which really confused
> me:
>
>
>
> push      rax
>
> .seh_stackalloc 8
>
> .seh_endprologue
>
>
>
> Even though there is written "stackalloc" the rsp is not changed, but in
> the code I posted above it was changed.
>
>
>
> Kind greetings
>
> Björn
> Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816,
> USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert
> Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima.
> Junichi Tajika
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200120/1bb43adb/attachment.html>


More information about the cfe-dev mailing list