These are the changes to the ASAN runtime library that are needed for D16737: Support for dead code stripping on Mach-O platforms.
Diff Detail
Event Timeline
Please update ASan ABI version in lib/asan/asan_init_version.h. See the comment about test you might want to add in http://reviews.llvm.org/D16737
Thanks for reviewing. It does need the LLVM change first. So I will wait to commit until after D16737: Support for dead code stripping on Mach-O platforms is approved.
I discovered that this change was incomplete due to duplicate registration of globals. I've changed this to use a per-library flag that indicates whether globals have been registered already, and ignores duplicate calls.
In the future I'd like to investigate simply eliding the unnecessary ctors, but this fix basically makes them harmless, in the same way that multiple calls to __asan_init do not cause problems.
This also happens to resolve the expected failure of the initialization-bug.cc test case. I do not know if a pathological binary could still execute a ctor that accesses globals before they are registered.
lib/asan/asan_globals.cc | ||
---|---|---|
292 | Let's just make two functions instead of passing one or the other callback here. WDYT? |
lib/asan/asan_globals.cc | ||
---|---|---|
292 | I have no preference, other than that it is already written as-is :) I'm not sure about calling it register_module_globals since module seems to mean translation unit and not shared object—unless I'm mistaken. |
lib/asan/asan_globals.cc | ||
---|---|---|
292 | Yes, "module" has way too many meanings :), "library"? |
Split into two functions per @samsonov's request. Just went with asan_register_module_globals and we can decide to rename it later if we care to.
lib/asan/asan_init_version.h | ||
---|---|---|
32 | Please fix a comment | |
lib/asan/asan_internal.h | ||
77 | It's not really a flag, it's a library/executable marker. You may clarify the way it's used here. E.g. why is it uptr*, not void*? | |
test/asan/TestCases/Darwin/dead-strip.c | ||
22 | So, is it possible to make this test pragma-less? In this way we will also ensure that this invalid load will not be optimized away by the compiler (i.e. run this test with -O3 in addition to -O0). |
Let's just make two functions instead of passing one or the other callback here.
I agree that you can use the same "flag" here: first function will set it from false to true, another one - from true to false.
WDYT?