This is an archive of the discontinued LLVM Phabricator instance.

Add cmake build support for lsan on OS X
ClosedPublic

Authored by fjricci on Feb 9 2017, 1:01 PM.

Details

Summary

Adds a new cmake flag 'COMPILER_RT_ENABLE_LSAN_OSX', which enables lsan
compilation and is turned off by default. Patches to fix build errors
when this flag is enabled will be uploaded soon.

This is part of an effort to port LSan to OS X, but LSan on OS X does not
currently work or pass tests currently.

Diff Detail

Repository
rL LLVM

Event Timeline

fjricci created this revision.Feb 9 2017, 1:01 PM
kubamracek added inline comments.Feb 10 2017, 2:45 PM
cmake/config-ix.cmake
167–171 ↗(On Diff #87860)

Why exactly do we need this change? Will the 32-bit x86 slice fail to build?

lib/lsan/CMakeLists.txt
19–21 ↗(On Diff #87860)

How about we just unconditionally propagate CAN_SANITIZE_LEAKS (no _MAC) and remove that ugly ifdef in lsan_common.h?

Doesn't this also need to go to lib/asan/CMakeLists.txt?

fjricci added inline comments.Feb 13 2017, 8:05 AM
cmake/config-ix.cmake
167–171 ↗(On Diff #87860)

Yeah, __thread is only supported on 64-bit darwin targets.

lib/lsan/CMakeLists.txt
19–21 ↗(On Diff #87860)

Well, the issue with that is that we build LSanCommon for 32-bit architectures (since asan builds for 32-bit), so we still need the architecture check in lsan_common.h to make sure that it's an empty stub if we're building for 32-bit.

This doesn't need to go into lib/asan/CMakeLists.txt because that just pulls in RTLSanCommon, not the individual sources, and RTLsanCommon will already have the flag.

kubamracek added inline comments.Feb 13 2017, 8:50 AM
cmake/config-ix.cmake
167–171 ↗(On Diff #87860)

Are you sure?

$ uname
Darwin
$ echo "__thread int hello; int main() { hello = 42; }" | clang -x c -arch i386 -
$ ./a.out
$ # works fine
lib/lsan/CMakeLists.txt
19–21 ↗(On Diff #87860)

Ok, can we add a FIXME comment here saying that this will be removed once LSan is fully working on Darwin?

Right, the LSan sources will always have CAN_SANITIZE_LEAKS_MAC. But ASan does include headers from lsan/, and I don't see how they have have CAN_SANITIZE_LEAKS_MAC. Can you verify that ASan files have are able to see CAN_SANITIZE_LEAKS == 1?

fjricci added inline comments.Feb 13 2017, 9:23 AM
cmake/config-ix.cmake
167–171 ↗(On Diff #87860)
$ echo "__thread int hello; int main() { hello = 42; }" | clang -x c -arch i386 -miphoneos-version-min=8.0 -
<stdin>:1:1: error: thread-local storage is not supported for the current target
__thread int hello; int main() { hello = 42; }
^

It looks like i386 support isn't added until -miphoneos-version-min=9.0, and I'm not sure that we want to bump the version that high.

lib/lsan/CMakeLists.txt
19–21 ↗(On Diff #87860)

Ahh I see. You're right, it's not propogated to the asan sources.

fjricci updated this revision to Diff 88244.Feb 13 2017, 12:27 PM

Add CAN_SANITIZE_LEAKS_MAC workaround to asan sources

kubamracek added inline comments.Feb 13 2017, 2:11 PM
cmake/config-ix.cmake
167–171 ↗(On Diff #87860)

Okay, please add a comment explaining this.

fjricci updated this revision to Diff 88257.Feb 13 2017, 2:17 PM

Add comment explaining 32-bit thread local support on ios

kubamracek accepted this revision.Feb 13 2017, 2:35 PM

LGTM.

Could the __thread on 32-bit iOS be solved with the same trick as D29786? No need to do it now, though.

This revision is now accepted and ready to land.Feb 13 2017, 2:35 PM

I'll look into that going forward. My main hesitation would be adding complexity and perhaps a performance hit from using pthreads.

This revision was automatically updated to reflect the committed changes.