public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Will Hawkins <whh8b@virginia.edu>
Cc: Yubin Ruan <ablacktshirt@gmail.com>,
	"libc-help@sourceware.org" <libc-help@sourceware.org>
Subject: Re: determine whether code is running in a signal handler context
Date: Thu, 19 Oct 2017 03:12:00 -0000	[thread overview]
Message-ID: <2b3c5128-50c8-889c-a645-360355d491b7@redhat.com> (raw)
In-Reply-To: <CAE+MWFuGn=Ryp9GyMYYg=6O=7WtmsL1GezyE4KTV9KU6NCjucw@mail.gmail.com>

On 10/18/2017 07:39 PM, Will Hawkins wrote:
>> This is not true. It is architecture dependent. For examples on how complex
>> it is to get this 100% right you have to go read gdb sources to see how
>> they do this. It is non-trivial. It might be easier to use a library like
>> libunwind to determine this for you (if it even can).
> 
> This is a fascinating thread. The downside to using libunwind is that,
> iirc, it requires debugging information in the binary to work. In other
> words, it would not work on a stripped binary. Please correct me if I am
> wrong.

No. libunwind only needs .eh_frame/.debug_frame, not debug information.

Some unwinders can operate without debug information, but only if the
architecture, and ABI layout of the frame allow unwinding with a frame
pointer. On 32-bit ARM, at least for a while, the frame pointer was
synthesized by the compiler to avoid using a fixed frame pointer and
free up such a pointer for the compiler to use. The side effect is that
you always need the DWARF unwind information to unwind a frame, but you
do *not* need debug information. One should be careful not to confuse
the two. The generic term "debug information" can mean a lot more,
including all the DWARF required to debug the program. You don't need
this to unwind, you only need .eh_frame/.debug_frame. As you see 32-bit
ARM was leading the charge here to free up a register for compiler use,
and now it's common practice on x86_64 and x86 to compile without the
frame pointer, and so you must have auxiliary information to unwind,
and you can't write a by-hand unwinder that follows the frame pointer.

The complex part is that to unwind from an asynchronously delivered signal
you need asynchronous unwind tables which describe how to unwind from
any point in the program, because when the signal arrives you may attempt
an unwind from any point to an outer frame. Usually the unwind information
can be elided to the point at which function calls are made, or try/catch
blocks.

But you need not unwind from the signal handler, you need only detect
that you are *in* a signal handler, and libunwind might have enough
heuristics for the machines you care about that it might work. I have
not tried it though, so YMMV.

-- 
Cheers,
Carlos.

  reply	other threads:[~2017-10-19  3:12 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18 14:18 Yubin Ruan
2017-10-18 18:34 ` Carlos O'Donell
2017-10-19  1:52   ` Yubin Ruan
2017-10-19  2:19     ` Carlos O'Donell
2017-10-19  2:39       ` Will Hawkins
2017-10-19  3:12         ` Carlos O'Donell [this message]
2017-10-19  4:07           ` Yubin Ruan
2017-10-19  4:56             ` Carlos O'Donell
2017-10-19  4:19           ` Will Hawkins
2017-10-19  4:01       ` Yubin Ruan
2017-10-19  2:59 ` Sean Conner
2017-10-19  3:12 ` Sean Conner
2017-10-19  3:51   ` Yubin Ruan
2017-10-19  7:10     ` Jeffrey Walton
2017-10-20 10:32 ` Szabolcs Nagy
2017-10-20 11:23   ` Yubin Ruan
2017-10-20 11:31     ` Szabolcs Nagy
2017-10-20 17:19       ` Carlos O'Donell
2017-10-20 17:48         ` Szabolcs Nagy
2017-10-22  6:09           ` Carlos O'Donell
2017-10-22 23:39             ` where is the definition of idtype_t supposed to live? John Lumby
2017-10-23 13:57               ` Florian Weimer
     [not found]                 ` <BN6PR22MB16662DE3DFB590B3D6006F81A3460@BN6PR22MB1666.namprd22.prod.outlook.com>
2017-10-23 14:20                   ` Florian Weimer
2017-10-23 10:01             ` determine whether code is running in a signal handler context Szabolcs Nagy
2017-10-23 14:30               ` Carlos O'Donell
2017-10-24  1:00                 ` Yubin Ruan
2017-11-27  8:43 ` Yubin Ruan
2017-11-27 11:55   ` Florian Weimer
2017-11-27 12:50     ` Yubin Ruan
2017-11-27 12:51       ` Florian Weimer
2017-11-27 12:58         ` Adhemerval Zanella

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=2b3c5128-50c8-889c-a645-360355d491b7@redhat.com \
    --to=carlos@redhat.com \
    --cc=ablacktshirt@gmail.com \
    --cc=libc-help@sourceware.org \
    --cc=whh8b@virginia.edu \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).