These are the changes to the ASAN runtime library that are needed for D16737: Support for dead code stripping on Mach-O platforms.
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.
Let's just make two functions instead of passing one or the other callback here.
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.
Yes, "module" has way too many meanings :), "library"?
Please fix a comment
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*?
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).