llvm-project/compiler-rt
Dan Liew 923cf890d1 Avoid failing a CHECK in `DlAddrSymbolizer::SymbolizePC`.
Summary:
It turns out the `CHECK(addr >= reinterpret_cast<upt>(info.dli_saddr)`
can fail because on armv7s on iOS 9.3 `dladdr()` returns
`info.dli_saddr` with an address larger than the address we provided.

We should avoid crashing here because crashing in the middle of reporting
an issue is very unhelpful. Instead we now try to compute a function offset
if the value we get back from `dladdr()` looks sane, otherwise we don't
set the function offset.

A test case is included. It's basically a slightly modified version of
the existing `test/sanitizer_common/TestCases/Darwin/symbolizer-function-offset-dladdr.cpp`
test case that doesn't run on iOS devices right now.

More details:

In the concrete scenario on armv7s `addr` is `0x2195c870` and the returned
`info.dli_saddr` is `0x2195c871`.

This what LLDB says when disassembling the code.

```
(lldb) dis -a 0x2195c870
libdyld.dylib`<redacted>:
    0x2195c870 <+0>: nop
    0x2195c872 <+2>: blx    0x2195c91c                ; symbol stub for: exit
    0x2195c876 <+6>: trap
```

The value returned by `dladdr()` doesn't make sense because it points
into the middle of a instruction.

There might also be other bugs lurking here because I noticed that the PCs we
gather during stackunwinding (before changing them with
`StackTrace::GetPreviousInstructionPc()`) look a little suspicious (e.g.  the
PC stored for the frame with fail to symbolicate is 0x2195c873) as they don't
look properly aligned. This probably warrants further investigation in the future.

rdar://problem/65621511

Reviewers: kubamracek, yln

Subscribers: kristof.beyls, llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D84262
2020-07-21 12:49:50 -07:00
..
cmake [compiler-rt] Use -nostdinc++ in clang_rt.profile to avoid including C++ headers 2020-07-21 09:14:33 -04:00
docs
include [PGO] Extend the value profile buckets for mem op sizes. 2020-07-15 10:26:15 -07:00
lib Avoid failing a CHECK in `DlAddrSymbolizer::SymbolizePC`. 2020-07-21 12:49:50 -07:00
test Avoid failing a CHECK in `DlAddrSymbolizer::SymbolizePC`. 2020-07-21 12:49:50 -07:00
tools Add GWP-ASan fuzz target to compiler-rt/tools. 2019-08-27 18:28:07 +00:00
unittests [Scudo] [GWP-ASan] Add GWP-ASan to Scudo Standalone. 2019-12-13 09:09:41 -08:00
utils [compiler-rt] Fix build on NetBSD 9.99.44 2020-01-31 14:57:20 +01:00
www [www] Change URLs to HTTPS. 2019-10-24 13:25:15 -07:00
.gitignore
CMakeLists.txt [CMake][compiler-rt] Only set lld as available when it was built 2020-06-29 15:09:05 -07:00
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT Fix typos throughout the license files that somehow I and my reviewers 2019-01-21 09:52:34 +00:00
README.txt

README.txt

Compiler-RT
================================

This directory and its subdirectories contain source code for the compiler
support routines.

Compiler-RT is open source software. You may freely distribute it under the
terms of the license agreement found in LICENSE.txt.

================================