From: Tristan Gingold <gingold@adacore.com>
To: Pedro Alves <palves@redhat.com>
Cc: Joel Brobecker <brobecker@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [RFA/commit+doco 2/2] Windows x64 SEH unwinder.
Date: Fri, 11 Jan 2013 08:04:00 -0000 [thread overview]
Message-ID: <EDC4178A-B36D-4B3E-A752-7392E49D2216@adacore.com> (raw)
In-Reply-To: <50EEEB3C.9050202@redhat.com>
On Jan 10, 2013, at 5:24 PM, Pedro Alves wrote:
> On 01/09/2013 08:07 PM, Tristan Gingold wrote:
>
>>>> This is in fact an optimization. If we found a pop, followed by
>>>> an epilog marker, there is not need to decode unwind info.
>>>
>>> I don't understand. pops will always be followed by a marker.
>>> How can that be an optimization?
>>
>> If pop weren't in this list, then if pc points to a pop the unwinder
>> will consider that the pc is in the body and need to decode unwind
>> infos. Now, if pop is in the list, the unwinder will continue to decode
>> until a ret and if a ret is found, it will consider that the pc is in
>> the epilogue, avoiding decoding unwind infos.
>
> (and again for quotability:)
>
>> If pop weren't in this list,
>
> I think you meant, that if pops were not handled in the
> while loop. While I'm saying that the comment implies
> that pop is an epilog marker, and claiming it's not,
> therefore the comment is wrong and misleading. It should
> be clarified/extended.
Ok.
> But let me see if I understood, by trying to rewrite
> and extend your reply into something that I'd find clearer:
>
> We want to detect if the PC points to an epilogue (entry or midway).
> If so, the following epilogue detection+decoding below is
> sufficient. Otherwise, the unwinder will consider that the PC
> is in the body of the function and will need to decode unwind info.
> According to MSDN, an epilogue "must consist of either an
> add RSP,constant or lea RSP,constant[FPReg], followed by a
> series of zero or more 8-byte register pops and a return
> or a jmp".
>
> It confuses me to call this an optimization though,
> because MSDN says:
>
> "This reduces the amount of unwind data required, because no extra
> data is needed to describe each epilog. Instead, the unwind code
> can determine that an epilog is being executed by scanning
> forward through a code stream to identify an epilog."
>
> That reads to me that prologue decoding is not really
> something we can forgo, but something that is _required_,
> because the unwind data describing the epilog will simply
> not be there.
Yes, I now think that this is correct. The unwind data are only for the
prolog, the body don't need any additional data, while the epilog must
be specially handled.
>>> The jump to an epilogue would not be part of the epilogue.
>>
>> Doesn't really matter. The point is that if the current instruction
>> is a jump to the epilogue, there is no need to decode unwind infs.
>
> Okay, that one makes sense to me. Please expand the comments
> in that direction.
>
>>
>>>> But I may miss your point.
>>>
>>> My point is that the docs say the epilogue has this rigid
>>> format that always ends in a marker, and that a marker is
>>> a ret or a jmp (therefore calling "pop" a marker as in the
>>> "I would add" comment seems to me misleading). The code
>>> continues following the jmp, so it makes me believe the code
>>> is erroneously decoding something after the jmp that is
>>> not an epilogue (the caller or perhaps a tailcall).
>>
>> No, it doesn't say that it ends in a marker. The epilogue
>> ends by a ret.
>
> Not by my reading:
>
> http://msdn.microsoft.com/en-us/library/tawsa7cb.aspx
>
> "It must consist of either an add RSP,constant or
> lea RSP,constant[FPReg], followed by a series of zero or
> more 8-byte register pops and a return or a jmp"
> ^^^^^^^^^^^^^^^^^
>
> IOW, I read that as (in pseudo-bnf):
>
> add|lea
> (pop)*
> ret|jmp
>
> This http://blogs.msdn.com/b/freik/archive/2006/01/04/509372.aspx
> confirms my reading.
>
> Hence all this confusion and the asking for an example
> (a disassembly) where jmp appears in the middle
> of an epilogue, and my fear that this prologue detection
> might be following jmps when it should not, and
> therefore not detecting prologue ends correctly.
>
> "All function epilogues must look like this:
>
> (optional) lea rsp, [frame ptr + frame size] or add rsp, frame size
> pop reg (zero or more)
> ret (or jmp)
>
> (...)
> No other instructions may occur betwen the first lea/add and the
> final jmp or ret.
> (...)
> One other note: if the final jmp isn't an ip-relative jmp,
> but an indirect jmp, it must be preceded by the REX prefix,
> to indicate to the OS unwind routines that the jump is headed
> outside of the function, otherwise, the OS assumes it's a jump
> to a different location inside the same function."
Ah, it looks like I missed this note! That really make sense.
> So it looks to me that even if you follow
> jumps to the epilogue as an optimization, the current
> "rex jmp reg" handling is wrong - it should not follow the PC,
> but instead by handling like ret and return 1.
That correct.
> Reading the patch in more detail, I now see that all the other
> jmps handling in the patch's epilogue decoding are relative
> jumps, and those are _not_ considered epilog markers (so it's
> your optimization applying), per RtlVirtualUnwind's docs. But,
> as can be seen in the comment in the patch, immediate jmps
> _are_ epilogue markers, so I do believe they should be handled,
> and terminate the epilog decoding, just like ret.
Yes, I think that's right.
Thanks for digging deeply!
Tristan.
next prev parent reply other threads:[~2013-01-11 8:04 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-09 10:53 Add Windows x64 SEH unwinder (take 2) Joel Brobecker
2013-01-09 10:53 ` [RFA/commit+doco 2/2] Windows x64 SEH unwinder Joel Brobecker
2013-01-09 15:52 ` Pedro Alves
2013-01-09 16:28 ` Tristan Gingold
2013-01-09 17:10 ` Pedro Alves
2013-01-09 17:53 ` Tom Tromey
2013-01-09 19:11 ` Pedro Alves
2013-01-09 20:07 ` Tristan Gingold
2013-01-10 16:24 ` Pedro Alves
2013-01-11 8:04 ` Tristan Gingold [this message]
2013-07-08 10:55 ` [RFA] Windows x64 SEH unwinder (v2) Tristan Gingold
2013-07-26 15:22 ` Pedro Alves
2013-08-19 13:59 ` Tristan Gingold
2013-08-19 14:13 ` Pedro Alves
2013-08-22 9:33 ` [PATCH v3] Windows x64 SEH unwinder Tristan Gingold
2013-08-22 15:10 ` Eli Zaretskii
2013-08-22 15:26 ` Pedro Alves
2013-08-22 15:41 ` Tristan Gingold
2013-08-22 16:15 ` Pedro Alves
2013-08-23 6:54 ` Tristan Gingold
2013-08-27 17:45 ` Pedro Alves
2013-09-02 9:28 ` Tristan Gingold
2013-01-09 16:06 ` [RFA/commit+doco 2/2] " Eli Zaretskii
2013-01-09 16:29 ` Tristan Gingold
2013-01-09 10:53 ` [RFA/commit+NEWS 1/2] Add command set/show debug unwind Joel Brobecker
2013-01-09 12:41 ` Jan Kratochvil
2013-01-09 18:40 ` Joel Brobecker
2013-01-09 15:14 ` Tom Tromey
2013-01-09 16:01 ` Eli Zaretskii
2013-01-09 11:05 ` Add Windows x64 SEH unwinder (take 2) Pedro Alves
2013-01-09 11:11 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EDC4178A-B36D-4B3E-A752-7392E49D2216@adacore.com \
--to=gingold@adacore.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox