This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Ensure AsanInitFromRtl is called from a static initializer on OS X by using ASAN_DYNAMIC=1
ClosedPublic

Authored by kubamracek on Jan 21 2015, 8:17 PM.

Details

Reviewers
glider
Summary

Hi everyone,

this is an OS X specific patch that adds a dyld initializer (marked with __attribute__((constructor))) which just calls AsanInitFromRtl. The idea is to ensure that the ASan runtime gets initialized early (i.e. before other initializers/constructors) even when DYLD_INSERT_LIBRARIES is not used. In that case, the interceptors are not installed (on OS X, DYLD_INSERT_LIBRARIES is required for interceptors to work), and therefore ASan gets currently initialized quite late -- from the main executable's module initializer. The following issues are a consequence of this:

Both of them are fixed with this patch.

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 18580.Jan 21 2015, 8:17 PM
kubamracek retitled this revision from to [compiler-rt] Add a __attribute__((constructor)) AsanInitFromRtl initializer for OS X.
kubamracek updated this object.
kubamracek edited the test plan for this revision. (Show Details)
kubamracek added subscribers: Unknown Object (MLST), glider, samsonov, kcc.

There is already code which does precisely this for ASAN_DYNAMIC case in asan_rtl.cc. Could you use it instead? IMHO ASAN_DYNAMIC should be defined on all platforms which use dynamic ASan runtime.

glider added inline comments.Jan 22 2015, 7:06 AM
lib/asan/asan_mac.cc
70 ↗(On Diff #18580)

Can you please remind me why do we want to launch without DYLD_INSERT_LIBRARIES?

kubamracek retitled this revision from [compiler-rt] Add a __attribute__((constructor)) AsanInitFromRtl initializer for OS X to [compiler-rt] Ensure AsanInitFromRtl is called from a static initializer on OS X by using ASAN_DYNAMIC=1.

Changing the patch to use ASAN_DYNAMIC=1 on OS X instead. Changing the title of the

Can you please remind me why do we want to launch without DYLD_INSERT_LIBRARIES?

We don't want to launch without DYLD_INSERT_LIBRARIES. Whenever we detect that, we relaunch or abort(). But the cases/issues that this patch solves are crashes that happen even *before* we can detect the missing DYLD_INSERT_LIBRARIES. I'm just trying to initialize ASan even sooner, so we can detect the missing env var sooner.

Can you implement AsanCheckDynamicRTPrereqs on Mac? This function is supposed to check that dynamic runtime is loaded properly. On Linux this boils down to ensuring that it comes first in dynamic library list. I guess on Darwin we simply need to check DYLD_INSERT_LIBRARIES?

Can you implement AsanCheckDynamicRTPrereqs on Mac? This function is supposed to check that dynamic runtime is loaded properly. On Linux this boils down to ensuring that it comes first in dynamic library list. I guess on Darwin we simply need to check DYLD_INSERT_LIBRARIES?

This is already done in asan_mac.cc in MaybeReexec. We could probably get rid of it and move the code to AsanCheckDynamicRTPrereqs instead, but I'd rather do that as a separate patch, since that would be a NFC refactoring, whereas this patch actually changes behavior.

glider accepted this revision.Jan 23 2015, 8:41 AM
glider added a reviewer: glider.
glider added inline comments.
test/asan/TestCases/Darwin/mixing-global-constructors.cc
25

This test case has weird indentation. Can you run clang-format just to make sure?

This revision is now accepted and ready to land.Jan 23 2015, 8:41 AM
kubamracek closed this revision.Jan 23 2015, 11:37 AM

Landed in r226929.