[llvm] r270273 - Create a sigaltstack when we register our signal handlers. Otherwise we'd very

Hahnfeld, Jonas via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 7 07:35:51 PDT 2016


> -----Original Message-----
> From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On Behalf
> Of Richard Smith via llvm-commits
> Sent: Friday, May 20, 2016 11:08 PM
> To: llvm-commits at lists.llvm.org
> Subject: [llvm] r270273 - Create a sigaltstack when we register our signal
> handlers. Otherwise we'd very
>
> Author: rsmith
> Date: Fri May 20 16:07:41 2016
> New Revision: 270273
>
> URL: http://llvm.org/viewvc/llvm-project?rev=270273&view=rev
> Log:
> Create a sigaltstack when we register our signal handlers. Otherwise we'd
> very likely fail to produce a backtrace if we crash due to stack overflow.
>
> Modified:
>     llvm/trunk/lib/Support/Unix/Signals.inc
>
> Modified: llvm/trunk/lib/Support/Unix/Signals.inc
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/lib/Support/Unix/Signals.inc?rev=270273&r1=270272&r2=
> 270273&view=diff
> ==========================================================
> ====================
> --- llvm/trunk/lib/Support/Unix/Signals.inc (original)
> +++ llvm/trunk/lib/Support/Unix/Signals.inc Fri May 20 16:07:41 2016
> @@ -28,6 +28,8 @@
>  # include <execinfo.h>         // For backtrace().
>  #endif
>  #if HAVE_SIGNAL_H
> +// FIXME: We unconditionally use symbols from this header below. Do we
> +really // need a configure-time check for a POSIX-mandated header in
> lib/Support/Unix?
>  #include <signal.h>
>  #endif
>  #if HAVE_SYS_STAT_H
> @@ -106,6 +108,31 @@ static void RegisterHandler(int Signal)
>    ++NumRegisteredSignals;
>  }
>
> +// Hold onto the old alternate signal stack so that it's not reported as a 
> leak.
> +// We don't make any attempt to remove our alt signal stack if we
> +remove our // signal handlers; that can't be done reliably if someone
> +else is also trying // to do the same thing.
> +static struct sigaltstack OldAltStack;
> +
> +static void CreateSigAltStack() {
> +  const size_t AltStackSize = MINSIGSTKSZ + 8192;

Hi Richard,

8192 is based on SIGSTKSZ, right?

I think this may not be enough for our cases, eg when running a complete 
printSymbolizedStackTrace(...). Stack then "grows" into heap and corrupts some 
structures there that are accessed from within the signal handlers.
I was able to reproduce this with libc++ and when linking against libLLVM.so 
which caused bugpoint to enter an infinite loop somewhere in 
std::vector::clear()...

I don't really know how much we actually need - any ideas on how to measure 
our needs?

Thanks,
Jonas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5868 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160607/5f76f98a/attachment.bin>


More information about the llvm-commits mailing list