steleman / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 0 forks source link

Uninstrumented linked-only executables fail to initialize ASan before main #357

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
On OS X 10.10, when you have an uninstrumented executable that only links to 
the ASan dylib, ASan doesn't get initialized before main(). This means that 
calling __asan_region_is_poisoned will crash because there is no shadow memory. 
See the attached test case, which currently fails on OS X.

I noticed that the Posix/start-deactivated.cc testcase occasionally randomly 
fails with a segfault, see 
http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_checkall/85
/console , and I reduced the bug into this.

When there is any instrumented module, __asan_init will get called from the 
module constructor, but when we only link to the dylib, it doesn't get called 
before main. We should probably explicitly invoke __asan_init in a constructor 
within ASan runtime.

Original issue reported on code.google.com by kuba.brecka@gmail.com on 13 Nov 2014 at 5:12

Attachments:

GoogleCodeExporter commented 9 years ago
Right, good catch. On Linux we use a static runtime with an initializer in 
.preinit_array. On Android, we use a shared runtime, but one of our 
interceptors gets called early during libc initialization. Neither happens on 
OSX.

We should add a constructor calling AsanInitFromRtl when building a shared 
runtime.

Original comment by euge...@google.com on 13 Nov 2014 at 9:44

GoogleCodeExporter commented 9 years ago
> On Android, we use a shared runtime,
> but one of our interceptors gets called early during libc initialization.

Same for Linux with Asan DSO.

Original comment by tetra20...@gmail.com on 13 Nov 2014 at 12:27

GoogleCodeExporter commented 9 years ago
Proposed a fix in http://reviews.llvm.org/D7117.

Original comment by kuba.brecka@gmail.com on 22 Jan 2015 at 4:17

GoogleCodeExporter commented 9 years ago
Committed in r226929.

Original comment by kuba.brecka@gmail.com on 23 Jan 2015 at 9:53