I hacked the UBSan runtime locally to use the fast unwinder. I thought this 
"worked", but it seems to only print one frame. This explains why:


 67 void BufferedStackTrace::FastUnwindStack(uptr pc, uptr bp, uptr stack_top,  
                                                                                
                                                                                
                                                                              
 68                                          uptr stack_bottom, u32 max_depth) 
{                                                                               
                                                                                
                                                                               
 69   const uptr kPageSize = GetPageSizeCached();                               
                                                                                
                                                                                
                                                                             
 70   CHECK_GE(max_depth, 2);                                                   
                                                                                
                                                                                
                                                                             
 71   trace_buffer[0] = pc;                                                     
                                                                                
                                                                                
                                                                             
 72   size = 1;                                                                 
                                                                                
                                                                                
                                                                             
 73   if (stack_top < 4096) return;  // Sanity check for stack top.  


There is a comment by Alexey Samsonov giving a warning about this:
                                                                                
                                                                                
                                                                                
                                                           
 34   // We can only use slow unwind, as we don't have any information about 
stack                                                                           
                                                                                
                                                                                
 
 35   // top/bottom.                                                            
                                                                                
                                                                                
                                                                              
 36   // FIXME: It's better to respect "fast_unwind_on_fatal" runtime flag and  
                                                                                
                                                                                
                                                                              
 37   // fetch stack top/bottom information if we have it (e.g. if we're 
running                                                                         
                                                                                
                                                                                
     
 38   // under ASan).                                                           
                                                                                
                                                                                
                                                                             
 39   if (StackTrace::WillUseFastUnwind(false))                                 
                                                                                
                                                                                
                                                                             
 40     return;  

So, in the absence of stack top/bottom info, we'd need to add support for the 
slow unwinder.

vedant


> On Apr 14, 2017, at 10:19 AM, Kuba Mracek <mra...@apple.com> wrote:
> 
> What exactly is wrong with the fast unwinder?  It's used in ASan and TSan and 
> besides not knowing about inlined frames, it works great.  But we're almost 
> always dealing with code that has frame pointers (and the sanitizer runtimes 
> themselves are built with frame pointers).
> 
> Kuba
> 
>> On 13 Apr 2017, at 19:18, Vedant Kumar via cfe-commits 
>> <cfe-commits@lists.llvm.org> wrote:
>> 
>> Does anyone know what it would take to get the slow unwinder to work on 
>> Darwin?
>> 
>> thanks,
>> vedant
>> 
>>> On Apr 13, 2017, at 6:59 PM, Vedant Kumar via cfe-commits 
>>> <cfe-commits@lists.llvm.org> wrote:
>>> 
>>> Author: vedantk
>>> Date: Thu Apr 13 20:59:44 2017
>>> New Revision: 300295
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=300295&view=rev
>>> Log:
>>> [docs] UBSan: Mention that print_stacktrace=1 is unsupported on Darwin
>>> 
>>> Printing out stack traces along with UBSan diagnostics is unsupported on
>>> Darwin. That's because it isn't possible to use the fast unwinder or the
>>> slow unwinder.
>>> 
>>> Apparently, it's inappropriate to use the fast unwinder for UBSan
>>> issues. I'm not exactly sure why (see the comment in ubsan_diag.cc).
>>> Forcing use of the fast unwinder produces decent results, AFAICT.
>>> 
>>> Darwin also does not appear to have a slow unwinder suitable for use
>>> with the sanitizers. Apparently that's because of PR20800 [1][2]. But
>>> that bug has been fixed. I'm not sure if there is anything preventing
>>> use of the slow unwinder now.
>>> 
>>> Currently, passing UBSAN_OPTIONS=print_stacktrace=1 does nothing on
>>> Darwin. This isn't good, but it might be a while before we can fix the
>>> situation, so we should at least document it.
>>> 
>>> [1] https://github.com/google/sanitizers/issues/137
>>> "We can't use the slow unwinder on OSX now, because Clang produces
>>> incorrect unwind info for the ASan runtime functions on OSX
>>> (http://llvm.org/PR20800)."
>>> 
>>> [2] https://bugs.llvm.org/show_bug.cgi?id=20800
>>> Bug 20800 - Invalid compact unwind info generated for a function without
>>> frame pointers on OSX
>>> 
>>> Modified:
>>>  cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
>>> 
>>> Modified: cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UndefinedBehaviorSanitizer.rst?rev=300295&r1=300294&r2=300295&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/docs/UndefinedBehaviorSanitizer.rst (original)
>>> +++ cfe/trunk/docs/UndefinedBehaviorSanitizer.rst Thu Apr 13 20:59:44 2017
>>> @@ -157,6 +157,8 @@ will need to:
>>>  ``UBSAN_OPTIONS=print_stacktrace=1``.
>>> #. Make sure ``llvm-symbolizer`` binary is in ``PATH``.
>>> 
>>> +Stacktrace printing for UBSan issues is currently not supported on Darwin.
>>> +
>>> Issue Suppression
>>> =================
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> 

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to