Index: lib/asan/asan_mac.cc =================================================================== --- lib/asan/asan_mac.cc +++ lib/asan/asan_mac.cc @@ -66,6 +66,14 @@ extern "C" void __asan_init(); +// This explicit initializer will be called by dyld early in the process start, +// which is important when launching without DYLD_INSERT_LIBRARIES (i.e. when +// interceptors are not installed). +__attribute__((constructor)) +void PlatformInitializer() { + AsanInitFromRtl(); +} + static const char kDyldInsertLibraries[] = "DYLD_INSERT_LIBRARIES"; LowLevelAllocator allocator_for_env; Index: test/asan/TestCases/Darwin/linked-only.cc =================================================================== --- test/asan/TestCases/Darwin/linked-only.cc +++ test/asan/TestCases/Darwin/linked-only.cc @@ -0,0 +1,33 @@ +// Main executable is uninstrumented, but linked to ASan runtime. +// Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=357. + +// RUN: %clangxx -g -O0 %s -c -o %t.o +// RUN: %clangxx_asan -g -O0 %t.o -o %t +// RUN: %run %t 2>&1 | FileCheck %s + +#include +#include +#include + +#include "sanitizer/asan_interface.h" + +void test_shadow(char *p, size_t size) { + fprintf(stderr, "p = %p\n", p); + char *q = (char *)__asan_region_is_poisoned(p, size); + fprintf(stderr, "=%zd=\n", q ? q - p : -1); +} + +int main(int argc, char *argv[]) { + char *p = (char *)malloc(10000); + test_shadow(p, 100); + free(p); + // CHECK: =-1= + + test_shadow((char *)&main, 1); + // CHECK: =-1= + + test_shadow((char *)&p, 1); + // CHECK: =-1= + + return 0; +} Index: test/asan/TestCases/Darwin/mixing-global-constructors.cc =================================================================== --- test/asan/TestCases/Darwin/mixing-global-constructors.cc +++ test/asan/TestCases/Darwin/mixing-global-constructors.cc @@ -0,0 +1,42 @@ +// A global constructor from a non-instrumented part calls a function +// in an instrumented part. +// Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=363. + +// RUN: %clangxx -DINSTRUMENTED_PART=0 -c %s -o %t-uninst.o +// RUN: %clangxx_asan -DINSTRUMENTED_PART=1 -c %s -o %t-inst.o +// RUN: %clangxx_asan %t-uninst.o %t-inst.o -o %t + +// RUN: %run %t 2>&1 | FileCheck %s + +#include +#include +#include + +void func(char *ptr); + +#if INSTRUMENTED_PART == 1 + +void func(char *ptr) { + *ptr = 'X'; +} + +#else // INSTRUMENTED_PART == 1 + +struct C1 { + C1() { + printf("Hello "); + char buffer[10] = "world"; + func(buffer); + printf("%s\n", buffer); + } +}; + +C1 *obj = new C1(); + +int main(int argc, const char * argv[]) { + return 0; +} + +#endif // INSTRUMENTED_PART == 1 + +// CHECK: Hello Xorld