Index: lib/asan/CMakeLists.txt =================================================================== --- lib/asan/CMakeLists.txt +++ lib/asan/CMakeLists.txt @@ -65,8 +65,8 @@ add_compiler_rt_darwin_object_library(RTAsan ${os} ARCH ${ASAN_SUPPORTED_ARCH} SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES} - CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) + CFLAGS ${ASAN_DYNAMIC_CFLAGS} + DEFS ${ASAN_DYNAMIC_DEFINITIONS}) endforeach() else() foreach(arch ${ASAN_SUPPORTED_ARCH}) @@ -96,8 +96,8 @@ $ $ $ - CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) + CFLAGS ${ASAN_DYNAMIC_CFLAGS} + DEFS ${ASAN_DYNAMIC_DEFINITIONS}) add_dependencies(asan clang_rt.asan_${os}_dynamic) endforeach() else() Index: make/platform/clang_darwin.mk =================================================================== --- make/platform/clang_darwin.mk +++ make/platform/clang_darwin.mk @@ -173,14 +173,16 @@ -isysroot $(OSX_SDK) \ -fno-builtin \ -gline-tables-only \ - -DMAC_INTERPOSE_FUNCTIONS=1 + -DMAC_INTERPOSE_FUNCTIONS=1 \ + -DASAN_DYNAMIC=1 CFLAGS.asan_iossim_dynamic := \ $(CFLAGS) -mios-simulator-version-min=7.0 \ -isysroot $(IOSSIM_SDK) \ -fno-builtin \ -gline-tables-only \ - -DMAC_INTERPOSE_FUNCTIONS=1 + -DMAC_INTERPOSE_FUNCTIONS=1 \ + -DASAN_DYNAMIC=1 CFLAGS.ubsan_osx := $(CFLAGS) -mmacosx-version-min=10.6 \ -isysroot $(OSX_SDK) \ 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