diff --git a/CMakeLists.txt b/CMakeLists.txt
index a442408..304f2f9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -97,7 +97,10 @@ if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
   endif()
   test_target_arch(i386 ${TARGET_32_BIT_CFLAGS})
 elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
-  test_target_arch(powerpc64 ${TARGET_64_BIT_CFLAGS})
+  # Explicitly set -m flag on powerpc, because on ppc64 defaults for gcc and
+  # clang are different.
+  test_target_arch(ppc64 ${TARGET_64_BIT_CFLAGS})
+  test_target_arch(ppc ${TARGET_32_BIT_CFLAGS})
 endif()
 
 # We only support running instrumented tests when we're not cross compiling
@@ -136,11 +139,12 @@ if (NOT MSVC)
     -fno-builtin
     -fno-exceptions
     -fomit-frame-pointer
-    -funwind-tables
-    -fno-stack-protector
-    -Wno-gnu  # Variadic macros with 0 arguments for ...
     -fvisibility=hidden
     )
+# master has:
+#  -funwind-tables
+#  -fno-stack-protector
+#  -Wno-gnu  # Variadic macros with 0 arguments for ...
   if (NOT COMPILER_RT_DEBUG)
     list(APPEND SANITIZER_COMMON_CFLAGS -O3)
   endif()
@@ -159,7 +163,8 @@ if (NOT MSVC)
   if(SUPPORTS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
     list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
   else()
-    list(APPEND SANITIZER_COMMON_CFLAGS -g)
+#   only enable -g for stage 1, stage 2 (-no-integrated-as) unable to handle -g
+#    list(APPEND SANITIZER_COMMON_CFLAGS -g)
   endif()
 endif()
 # Warnings suppressions.
@@ -195,22 +200,24 @@ if(APPLE)
   if(COMPILER_RT_USES_LIBCXX)
-    set(SANITIZER_MIN_OSX_VERSION 10.7)
+    set(SANITIZER_MIN_OSX_VERSION ${LLVM_HOST_OSX_VERSION})
   else()
-    set(SANITIZER_MIN_OSX_VERSION 10.6)
+# set target evrsion = host version for now (may be cache-overridden)
+# this works when SDKROOT is blank
+    set(SANITIZER_MIN_OSX_VERSION ${LLVM_HOST_OSX_VERSION})
   endif()
   set(DARWIN_osx_CFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
-  set(DARWIN_iossim_CFLAGS 
-    -mios-simulator-version-min=7.0 -isysroot ${IOSSIM_SDK_DIR})
+#  set(DARWIN_iossim_CFLAGS 
+#    -mios-simulator-version-min=7.0 -isysroot ${IOSSIM_SDK_DIR})
   set(DARWIN_osx_LINKFLAGS)
-  set(DARWIN_iossim_LINKFLAGS
-    -Wl,-ios_simulator_version_min,7.0.0
-    -mios-simulator-version-min=7.0
-    -isysroot ${IOSSIM_SDK_DIR})
+#  set(DARWIN_iossim_LINKFLAGS
+#    -Wl,-ios_simulator_version_min,7.0.0
+#    -mios-simulator-version-min=7.0
+#    -isysroot ${IOSSIM_SDK_DIR})
 endif()
 
 # Architectures supported by Sanitizer runtimes. Specific sanitizers may
 # support only subset of these (e.g. TSan works on x86_64 only).
 filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
-  x86_64 i386 powerpc64)
+  x86_64 i386 ppc64 ppc)
 
 add_subdirectory(include)
 
diff --git a/SDKs/darwin/usr/include/stdio.h b/SDKs/darwin/usr/include/stdio.h
index 006652f..fb18636 100644
--- a/SDKs/darwin/usr/include/stdio.h
+++ b/SDKs/darwin/usr/include/stdio.h
@@ -38,11 +38,14 @@ typedef __SIZE_TYPE__ size_t;
 #    define __FDOPEN_NAME  "_fdopen"
 #    define __FOPEN_NAME "_fopen"
 #    define __FWRITE_NAME "_fwrite"
+#  elif defined(__ppc__)
+#    define __FOPEN_NAME "_fopen"
+#    define __FWRITE_NAME "_fwrite"
 #  else
 #    error "unrecognized architecture for targetting OS X"
 #  endif
 #elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
-#  if defined(__i386) || defined (__x86_64)
+#  if defined(__i386) || defined (__x86_64) || defined(__ppc__)
 #    define __FDOPEN_NAME  "_fdopen"
 #    define __FOPEN_NAME "_fopen"
 #    define __FWRITE_NAME "_fwrite"
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index b620828..1364547 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -195,8 +195,23 @@ set(i386_SOURCES
   i386/umoddi3.S
   ${GENERIC_SOURCES})
 
+set(ppc_SOURCES
+	ppc/divtc3.c
+	ppc/fixtfdi.c
+	ppc/floatditf.c
+	ppc/floatunditf.c
+	ppc/fixunstfdi.c
+	ppc/gcc_qadd.c
+	ppc/gcc_qdiv.c
+	ppc/gcc_qmul.c
+	ppc/gcc_qsub.c
+	ppc/multc3.c
+	ppc/restFP.S
+	ppc/saveFP.S
+	${GENERIC_SOURCES})
+
 if (NOT WIN32)
-  foreach(arch x86_64 i386)
+  foreach(arch x86_64 i386 ppc)
     if(CAN_TARGET_${arch})
       add_compiler_rt_static_runtime(clang_rt.${arch} ${arch}
         SOURCES ${${arch}_SOURCES}
diff --git a/lib/OSCacheControl.h b/lib/OSCacheControl.h
new file mode 100644
index 0000000..a9955f4
--- /dev/null
+++ b/lib/OSCacheControl.h
@@ -0,0 +1,51 @@
+/* ===-- OSCacheControl.h - Interface cache flush functions ----------------===
+ *
+ *                     The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#ifndef	__OS_CACHHE_CONTROL_H__
+#define	__OS_CACHHE_CONTROL_H__
+
+#include <stddef.h>		/* size_t */
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+/* we will provide assembly from darwin9 sources */
+/* perform one of the above cache functions: */
+
+/** Prepare memory for execution.  This should be called
+ * after writing machine instructions to memory, before
+ * executing them.  It syncs the dcache and icache.
+ * On IA32 processors this function is a NOP, because
+ * no synchronization is required.
+ */
+#define kCacheFunctionPrepareForExecution       1
+
+/* Flush data cache(s).  This ensures that cached data 
+ * makes it all the way out to DRAM, and then removes
+ * copies of the data from all processor caches.
+ * It can be useful when dealing with cache incoherent
+ * devices or DMA.
+ */
+#define kCacheFunctionFlushDcache       2
+
+extern
+int     sys_cache_control( int function, void *start, size_t len);
+
+/* equivalent to sys_cache_control(kCacheFunctionPrepareForExecution): */
+extern
+void    sys_icache_invalidate( void *start, size_t len);
+
+/* equivalent to sys_cache_control(kCacheFunctionFlushDcache): */
+extern
+void    sys_dcache_flush( void *start, size_t len);
+
+__END_DECLS
+
+#endif	/* __OS_CACHHE_CONTROL_H__ */
diff --git a/lib/apple_versioning.c b/lib/apple_versioning.c
index 3797a1a..2b1f1eb 100644
--- a/lib/apple_versioning.c
+++ b/lib/apple_versioning.c
@@ -10,7 +10,7 @@
 
 
 #if __APPLE__
-  #include <Availability.h>
+  #include <AvailabilityMacros.h>
   
   #if __IPHONE_OS_VERSION_MIN_REQUIRED
     #define NOT_HERE_BEFORE_10_6(sym) 
@@ -23,6 +23,15 @@
             __attribute__((visibility("default"))) const char sym##_tmp51 = 0; \
         extern const char sym##_tmp50 __asm("$ld$hide$os5.0$_" #sym ); \
             __attribute__((visibility("default"))) const char sym##_tmp50 = 0; 
+  #elif __ppc__
+    #define NOT_HERE_BEFORE_10_6(sym) \
+        extern const char sym##_tmp3 __asm("$ld$hide$os10.3$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp3 = 0; \
+        extern const char sym##_tmp4 __asm("$ld$hide$os10.4$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \
+        extern const char sym##_tmp5 __asm("$ld$hide$os10.5$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp5 = 0; 
+    #define NOT_HERE_IN_10_8_AND_EARLIER(sym) 
   #else
     #define NOT_HERE_BEFORE_10_6(sym) \
          extern const char sym##_tmp4 __asm("$ld$hide$os10.4$_" #sym ); \
diff --git a/lib/asan/CMakeLists.txt b/lib/asan/CMakeLists.txt
index ad3f054..1e8f1ef 100644
--- a/lib/asan/CMakeLists.txt
+++ b/lib/asan/CMakeLists.txt
@@ -53,7 +53,7 @@ endif()
 
 # Architectures supported by ASan.
 filter_available_targets(ASAN_SUPPORTED_ARCH
-  x86_64 i386 powerpc64)
+  x86_64 i386 ppc64 ppc)
 
 # Compile ASan sources into an object library.
 if(APPLE)
diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc
index a25827b..e75346f 100644
--- a/lib/asan/asan_interceptors.cc
+++ b/lib/asan/asan_interceptors.cc
@@ -102,6 +102,7 @@ int OnExit() {
 }  // namespace __asan
 
 // ---------------------- Wrappers ---------------- {{{1
+using __sanitizer::OFF_T;
 using namespace __asan;  // NOLINT
 
 DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr)
diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc
index e27d70a..33ba0c4 100644
--- a/lib/asan/asan_mac.cc
+++ b/lib/asan/asan_mac.cc
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "sanitizer_common/sanitizer_platform.h"
+#include "sanitizer_common/sanitizer_platform_limits_posix.h" // for version info
 #if SANITIZER_MAC
 
 #include "asan_interceptors.h"
@@ -36,23 +37,64 @@
 #include <pthread.h>
 #include <stdlib.h>  // for free()
 #include <unistd.h>
+#ifdef	__APPLE__
 #include <libkern/OSAtomic.h>
+#endif
+
+// The following macros are provided by sanitizer_platform_limits_posix.h
+// MAC_OS_X_VERSION_SELECTED
+// __DARWIN_VERSION__
+#ifndef	__DARWIN_VERSION__
+#define	__DARWIN_VERSION__	0
+#endif
+
+// Looks like blocks/dispatch became available 10.6 and later.
+#if __DARWIN_VERSION__ && (__DARWIN_VERSION__ < 10)
+#define	MISSING_BLOCKS_SUPPORT
+#endif
 
 namespace __asan {
 
+// adjusting for different struct member names on darwin8
+// see /usr/include/i386/_structs.h on darwin9+
+// see /usr/include/i386/ucontext.h on darwin8
+#if	__DARWIN_VERSION__ && (!__DARWIN_UNIX03 || (__DARWIN_VERSION__ < 9))
+#define	STATE_MEM		ss
+#else
+#define	STATE_MEM		__ss
+#endif
+
+// see /usr/include/mach/i386/_structs.h on darwin9+
+// see /usr/include/mach/i386/thread_status.h on darwin8
+#if	defined(__APPLE__) && (!__DARWIN_UNIX03 || (__DARWIN_VERSION__ < 9))
+#define	THREAD_MEM(x)	x
+#else
+#define	THREAD_MEM(x)	__ ## x
+#endif
+
 void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
   ucontext_t *ucontext = (ucontext_t*)context;
+#if defined(__ppc__) || defined(__ppc64__)
+  *pc = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(srr0);
+  *bp = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(r1);		// or r31
+	// powerpc has no dedicated frame pointer
+  *sp = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(r1);
+#else
 # if SANITIZER_WORDSIZE == 64
-  *pc = ucontext->uc_mcontext->__ss.__rip;
-  *bp = ucontext->uc_mcontext->__ss.__rbp;
-  *sp = ucontext->uc_mcontext->__ss.__rsp;
+  *pc = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(rip);
+  *bp = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(rbp);
+  *sp = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(rsp);
 # else
-  *pc = ucontext->uc_mcontext->__ss.__eip;
-  *bp = ucontext->uc_mcontext->__ss.__ebp;
-  *sp = ucontext->uc_mcontext->__ss.__esp;
+  *pc = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(eip);
+  *bp = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(ebp);
+  *sp = ucontext->uc_mcontext->STATE_MEM.THREAD_MEM(esp);
 # endif  // SANITIZER_WORDSIZE
+#endif
 }
 
+#undef	STATE_MEM
+#undef	THREAD_MEM
+
 MacosVersion cached_macos_version = MACOS_VERSION_UNINITIALIZED;
 
 MacosVersion GetMacosVersionInternal() {
@@ -65,6 +107,7 @@ MacosVersion GetMacosVersionInternal() {
   CHECK_LT(len, maxlen);
   CHECK_NE(sysctl(mib, 2, version, &len, 0, 0), -1);
   switch (version[0]) {
+    case '8': return MACOS_VERSION_TIGER;
     case '9': return MACOS_VERSION_LEOPARD;
     case '1': {
       switch (version[1]) {
@@ -98,6 +141,7 @@ bool PlatformHasDifferentMemcpyAndMemmove() {
   // TODO(glider): need to check dynamically that memcpy() and memmove() are
   // actually the same function.
   return GetMacosVersion() == MACOS_VERSION_SNOW_LEOPARD;
+//  return GetMacosVersion() <= MACOS_VERSION_SNOW_LEOPARD;	// ?
 }
 
 extern "C"
diff --git a/lib/asan/asan_mac.h b/lib/asan/asan_mac.h
index 827b8b0..0baf39e 100644
--- a/lib/asan/asan_mac.h
+++ b/lib/asan/asan_mac.h
@@ -39,6 +39,7 @@ typedef struct __CFRuntimeBase {
 enum MacosVersion {
   MACOS_VERSION_UNINITIALIZED = 0,
   MACOS_VERSION_UNKNOWN,
+  MACOS_VERSION_TIGER,
   MACOS_VERSION_LEOPARD,
   MACOS_VERSION_SNOW_LEOPARD,
   MACOS_VERSION_LION,
diff --git a/lib/clear_cache.c b/lib/clear_cache.c
index b934fd4..5e2c0eb 100644
--- a/lib/clear_cache.c
+++ b/lib/clear_cache.c
@@ -11,7 +11,14 @@
 #include "int_lib.h"
 
 #if __APPLE__
+#include <AvailabilityMacros.h>
+#define	__DARWIN_VERSION__	((MAC_OS_X_VERSION_MIN_REQUIRED - MAC_OS_X_VERSION_10_0)/10 +4)
+#if __DARWIN_VERSION__ >= 9
+/* only appeared in 10.5+ (darwin9) */
   #include <libkern/OSCacheControl.h>
+#else
+  #include "OSCacheControl.h"		/* provided */
+#endif
 #endif
 
 /*
diff --git a/lib/interception/interception.h b/lib/interception/interception.h
index baddd6c..f363165 100644
--- a/lib/interception/interception.h
+++ b/lib/interception/interception.h
@@ -89,6 +89,15 @@ typedef __sanitizer::OFF64_T OFF64_T;
 #if defined(__APPLE__)
 #include <sys/cdefs.h>  // For __DARWIN_ALIAS_C().
 
+// on darwin8 (OS X 10.4), no library symbols were version-suffixed with "$UNIX2003"
+// compare <sys/cdefs.h> across Darwin versions for reference
+#ifndef	__DARWIN_ALIAS
+#define	__DARWIN_ALIAS(sym)
+#endif
+#ifndef	__DARWIN_ALIAS_C
+#define	__DARWIN_ALIAS_C(sym)
+#endif
+
 // Just a pair of pointers.
 struct interpose_substitution {
   const uptr replacement;
diff --git a/lib/interception/interception_type_test.cc b/lib/interception/interception_type_test.cc
index 7b79b78..e3c00d0 100644
--- a/lib/interception/interception_type_test.cc
+++ b/lib/interception/interception_type_test.cc
@@ -33,6 +33,7 @@ COMPILER_CHECK(sizeof(OFF64_T) == sizeof(off64_t));
 // rest (they depend on _FILE_OFFSET_BITS setting when building an application).
 # if defined(__ANDROID__) || !defined _FILE_OFFSET_BITS || \
   _FILE_OFFSET_BITS != 64
+using __sanitizer::OFF_T;	// gcc-4.0 workaround?  shouldn't be needed
 COMPILER_CHECK(sizeof(OFF_T) == sizeof(off_t));
 # endif
 
diff --git a/lib/link-asm-libclang_rt.sh b/lib/link-asm-libclang_rt.sh
new file mode 100755
index 0000000..0122ecb
--- /dev/null
+++ b/lib/link-asm-libclang_rt.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Utility script for linking assembled objects into libclang_rt
+# rationale: cmake build fails to include .S files
+# usage: define the following variables and source this script, call function
+
+# variables needed by the following function
+# CC= compiler that will invoke assembler
+# CCAS_FLAGS= additional assembly-related flags
+# arch={ppc,i386,...}
+# builddir=.../projects/compiler-rt/lib (relative to where function is called)
+# crtsrcdir=.../compiler-rt.git (absolute path)
+# objdir=CMakeFiles/clang_rt.$arch.dir/$arch (relative to builddir)
+# libcrt=$libdir/libclang_rt.$arch.a
+
+assemble_clang_rt() {
+pushd $builddir
+mkdir -p $objdir
+archsrc=$crtsrcdir/lib/$arch
+if test -d "$archsrc"
+then if find "$archsrc" -name '*.S' | grep .
+then for f in $archsrc/*.S
+do      
+        b=`basename $f`
+	echo "Assembling $arch/$b."
+        $CC -arch $arch $CCAS_FLAGS -c $f -o $objdir/$b.o
+done
+echo "Updating static library $libcrt."
+ar cru -b `ar -t $libcrt | grep .c.o -m 1` $libcrt $objdir/*.S.o
+fi
+fi
+popd
+}
diff --git a/lib/sanitizer_common/sanitizer_allocator.h b/lib/sanitizer_common/sanitizer_allocator.h
index 6075cfe..d0f7738 100644
--- a/lib/sanitizer_common/sanitizer_allocator.h
+++ b/lib/sanitizer_common/sanitizer_allocator.h
@@ -1122,6 +1122,7 @@ class LargeMmapAllocator {
   }
 
  private:
+  enum { kMaxNumChunks_e = 1 << FIRST_32_SECOND_64(15, 18) };
   static const int kMaxNumChunks = 1 << FIRST_32_SECOND_64(15, 18);
   struct Header {
     uptr map_beg;
@@ -1148,7 +1149,7 @@ class LargeMmapAllocator {
   }
 
   uptr page_size_;
-  Header *chunks_[kMaxNumChunks];
+  Header *chunks_[kMaxNumChunks_e];
   uptr n_chunks_;
   uptr min_mmap_, max_mmap_;
   bool chunks_sorted_;
diff --git a/lib/sanitizer_common/sanitizer_atomic_clang.h b/lib/sanitizer_common/sanitizer_atomic_clang.h
index c5aa939..9d6649c 100644
--- a/lib/sanitizer_common/sanitizer_atomic_clang.h
+++ b/lib/sanitizer_common/sanitizer_atomic_clang.h
@@ -15,6 +15,52 @@
 #ifndef SANITIZER_ATOMIC_CLANG_H
 #define SANITIZER_ATOMIC_CLANG_H
 
+/**
+	When compiling with gcc-4.0 during stage 1, 
+	these workaround definitions are needed.
+	Stage 2 and beyond should use clang's built-ins.
+	See also workarounds in llvm/lib/Support/Atomic.cpp.
+ */
+#define USE_DARWIN_ATOMICS		(defined(__APPLE__) && defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 2))
+#if USE_DARWIN_ATOMICS
+#include <libkern/OSAtomic.h>
+
+#define	__sync_synchronize		OSMemoryBarrier
+// argument and return types for OSAtomic library functions
+typedef	int32_t		atomic32_t;
+
+template <class T>
+static inline
+T* vcast(volatile T* ptr) { return const_cast<T*>(ptr); }
+
+template <class T, class S>
+static inline
+T as_a(S ptr) {
+//  static_assert(sizeof(S) == sizeof(T));
+//  return static_cast<T>(ptr);
+  return reinterpret_cast<T>(ptr);
+}
+
+template <class T>
+static inline
+T
+__sync_fetch_and_add(volatile T* ptr, const T v) {
+	const T ret = *ptr;
+	OSAtomicAdd32Barrier(v, as_a<atomic32_t*>(vcast(ptr)));
+	return ret;
+}
+
+template <class T>
+static
+inline
+T
+__sync_val_compare_and_swap(volatile T* ptr, const T oldv, const T newv) {
+  const T ret = *ptr;
+  OSAtomicCompareAndSwap32Barrier(oldv, newv, as_a<atomic32_t*>(vcast(ptr)));
+  return ret;
+}
+#endif	// USE_DARWIN_ATOMICS
+
 namespace __sanitizer {
 
 INLINE void atomic_signal_fence(memory_order) {
@@ -100,7 +146,11 @@ INLINE typename T::Type atomic_exchange(volatile T *a,
   DCHECK(!((uptr)a % sizeof(*a)));
   if (mo & (memory_order_release | memory_order_acq_rel | memory_order_seq_cst))
     __sync_synchronize();
+#if USE_DARWIN_ATOMICS
+  v = OSAtomicTestAndSetBarrier(v, vcast(&a->val_dont_use));
+#else
   v = __sync_lock_test_and_set(&a->val_dont_use, v);
+#endif
   if (mo == memory_order_seq_cst)
     __sync_synchronize();
   return v;
diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc
index d1c8976..784e201 100644
--- a/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -2184,10 +2184,12 @@ INTERCEPTOR(int, pthread_mutex_lock, void *m) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, pthread_mutex_lock, m);
   int res = REAL(pthread_mutex_lock)(m);
+#if defined(EOWNERDEAD)
   if (res == errno_EOWNERDEAD)
     COMMON_INTERCEPTOR_MUTEX_REPAIR(ctx, m);
   if (res == 0 || res == errno_EOWNERDEAD)
     COMMON_INTERCEPTOR_MUTEX_LOCK(ctx, m);
+#endif
   return res;
 }
 
diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 78d1f5a..7fb2018 100644
--- a/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -136,6 +136,7 @@
 # define SANITIZER_INTERCEPT_GETMNTENT SI_LINUX
 # define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_STATFS SI_NOT_WINDOWS
+// # define SANITIZER_INTERCEPT_STATFS64 ((SI_MAC || SI_LINUX_NOT_ANDROID) && HAVE_STRUCT_STATFS64)
 # define SANITIZER_INTERCEPT_STATFS64 \
     (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_STATVFS SI_LINUX_NOT_ANDROID
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
index e887751..200ab9b 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -122,7 +122,9 @@ namespace __sanitizer {
   unsigned struct_utsname_sz = sizeof(struct utsname);
   unsigned struct_stat_sz = sizeof(struct stat);
 #if !SANITIZER_IOS
+#ifdef	HAVE_STRUCT_STAT64
   unsigned struct_stat64_sz = sizeof(struct stat64);
+#endif
 #endif // !SANITIZER_IOS
   unsigned struct_rusage_sz = sizeof(struct rusage);
   unsigned struct_tm_sz = sizeof(struct tm);
@@ -144,12 +146,11 @@ namespace __sanitizer {
   unsigned struct_sched_param_sz = sizeof(struct sched_param);
   unsigned struct_statfs_sz = sizeof(struct statfs);
 
-#if SANITIZER_MAC && !SANITIZER_IOS
-  unsigned struct_statfs64_sz = sizeof(struct statfs64);
-#endif // SANITIZER_MAC && !SANITIZER_IOS
-
 #if !SANITIZER_ANDROID
   unsigned ucontext_t_sz = sizeof(ucontext_t);
+#if HAVE_STRUCT_STATFS64
+  unsigned struct_statfs64_sz = sizeof(struct statfs64);
+#endif
 #endif // !SANITIZER_ANDROID
 
 #if SANITIZER_LINUX
@@ -838,7 +839,10 @@ CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
 COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent));
 CHECK_SIZE_AND_OFFSET(dirent, d_ino);
 #if SANITIZER_MAC
+// macro defined in <sys/dirent.h> on darwin10
+#if defined(__DARWIN_64_BIT_INO_T) && __DARWIN_64_BIT_INO_T
 CHECK_SIZE_AND_OFFSET(dirent, d_seekoff);
+#endif
 #else
 CHECK_SIZE_AND_OFFSET(dirent, d_off);
 #endif
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index b9a0fc9..7efcf8a 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -18,6 +18,34 @@
 #include "sanitizer_internal_defs.h"
 #include "sanitizer_platform.h"
 
+// maybe this conditional should be darwin8 or 9 (pre-10)
+#if	SANITIZER_MAC
+#include <sys/cdefs.h>	// just for __DARWIN_64_BIT_INO_T
+
+// version macros don't get defined for ppc64
+#ifndef	MAC_OS_X_VERSION_10_0
+#define	MAC_OS_X_VERSION_10_0	1000
+#endif
+
+#ifdef	MAC_OS_X_VERSION_MAX_ALLOWED
+#define	MAC_OS_X_VERSION_SELECTED		MAC_OS_X_VERSION_MAX_ALLOWED
+#elif	defined(MAC_OS_X_VERSION_MIN_REQUIRED)
+#define	MAC_OS_X_VERSION_SELECTED		MAC_OS_X_VERSION_MIN_REQUIRED
+#elif	defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
+#define	MAC_OS_X_VERSION_SELECTED	__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
+#else
+// default: 10.4
+#define	MAC_OS_X_VERSION_SELECTED	1040
+#endif
+
+#define	__DARWIN_VERSION__	((MAC_OS_X_VERSION_SELECTED - MAC_OS_X_VERSION_10_0)/10 +4)
+#endif
+
+// <sys/mount.h> -- detect __DARWIN_64_BIT_INO_T macro?
+#define	HAVE_STRUCT_STATFS64			(__DARWIN_VERSION__ > 8)
+// EOWNERDEAD appears in darwin11 <errno.h>
+#define	HAVE_EOWNERDEAD				(__DARWIN_VERSION__ > 10)
+
 namespace __sanitizer {
   extern unsigned struct_utsname_sz;
   extern unsigned struct_stat_sz;
@@ -45,6 +73,9 @@ namespace __sanitizer {
 
 #if !SANITIZER_ANDROID
   extern unsigned ucontext_t_sz;
+#if HAVE_STRUCT_STATFS64
+  extern unsigned struct_statfs64_sz;
+#endif
 #endif // !SANITIZER_ANDROID
 
 #if SANITIZER_LINUX
@@ -258,8 +289,12 @@ namespace __sanitizer {
 
 #if SANITIZER_MAC
   struct __sanitizer_dirent {
+#if defined(__DARWIN_64_BIT_INO_T) && __DARWIN_64_BIT_INO_T
     unsigned long long d_ino;
-    unsigned long long d_seekoff;
+    unsigned long long d_seekoff;		// not in darwin8
+#else
+    unsigned int d_ino;			// powerpc-darwin8, i386-darwin10
+#endif
     unsigned short d_reclen;
     // more fields that we don't care about
   };
@@ -475,16 +510,25 @@ namespace __sanitizer {
   extern int shmctl_shm_stat;
 #endif
 
+#if SANITIZER_MAC && (__DARWIN_VERSION__ > 8)
+// not on darwin8 <net/if.h>
+#pragma pack(4)
+#endif
   // ioctl arguments
   struct __sanitizer_ifconf {
     int ifc_len;
     union {
+#if SANITIZER_MAC
+// on darwin8,9,10,11, <net/if.h> also has:
+//    caddr_t ifcu_buf;		// typedef char* caddr_t; // <sys/types.h>
+      char *ifcu_buf;
+#endif
+//    struct  ifreq *ifcu_req;
       void *ifcu_req;
     } ifc_ifcu;
-#if SANITIZER_MAC
-  } __attribute__((packed));
-#else
   };
+#if SANITIZER_MAC && (__DARWIN_VERSION__ > 8)
+#pragma pack()
 #endif
 
 #define IOC_SIZE(nr) (((nr) >> 16) & 0x3fff)
diff --git a/lib/tsan/lit_tests/mutex_robust.cc b/lib/tsan/lit_tests/mutex_robust.cc
index b826616..2f30391 100644
--- a/lib/tsan/lit_tests/mutex_robust.cc
+++ b/lib/tsan/lit_tests/mutex_robust.cc
@@ -13,6 +13,7 @@ void *thr(void *p) {
 }
 
 int main() {
+#ifdef	EOWNERDEAD
   pthread_mutexattr_t a;
   pthread_mutexattr_init(&a);
   pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST);
@@ -26,6 +27,7 @@ int main() {
   }
   pthread_join(th, 0);
   fprintf(stderr, "DONE\n");
+#endif
 }
 
 // This is a correct code, and tsan must not bark.
diff --git a/lib/tsan/lit_tests/mutex_robust2.cc b/lib/tsan/lit_tests/mutex_robust2.cc
index 5bd7ff6..7a5ada6 100644
--- a/lib/tsan/lit_tests/mutex_robust2.cc
+++ b/lib/tsan/lit_tests/mutex_robust2.cc
@@ -15,6 +15,7 @@ void *thr(void *p) {
 }
 
 int main() {
+#ifdef	EOWNERDEAD
   pthread_mutexattr_t a;
   pthread_mutexattr_init(&a);
   pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST);
@@ -29,6 +30,7 @@ int main() {
   x = 43;
   pthread_join(th, 0);
   fprintf(stderr, "DONE\n");
+#endif
 }
 
 // This is a false positive, tsan must not bark at the data race.
diff --git a/make/platform/clang_darwin.mk b/make/platform/clang_darwin.mk
index ddb7029..a1ff024 100644
--- a/make/platform/clang_darwin.mk
+++ b/make/platform/clang_darwin.mk
@@ -148,7 +148,7 @@ CFLAGS.eprintf		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
 CFLAGS.10.4		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
 # FIXME: We can't build ASAN with our stub SDK yet.
 CFLAGS.asan_osx_dynamic := \
-	$(CFLAGS) -mmacosx-version-min=10.6 -fno-builtin \
+	$(CFLAGS) -mmacosx-version-min=10.4 -fno-builtin \
 	-gline-tables-only \
 	-DMAC_INTERPOSE_FUNCTIONS=1 \
   -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
@@ -161,7 +161,7 @@ CFLAGS.asan_iossim_dynamic := \
 	-DMAC_INTERPOSE_FUNCTIONS=1 \
   -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
 
-CFLAGS.ubsan_osx	:= $(CFLAGS) -mmacosx-version-min=10.6 -fno-builtin
+CFLAGS.ubsan_osx	:= $(CFLAGS) -mmacosx-version-min=10.4 -fno-builtin
 
 CFLAGS.ios.i386		:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
 CFLAGS.ios.x86_64	:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
diff --git a/test/Unit/test.mk b/test/Unit/test.mk
new file mode 100644
index 0000000..750a04c
--- /dev/null
+++ b/test/Unit/test.mk
@@ -0,0 +1,101 @@
+# include this Makefile in $(build_dir)/projects/compiler-rt/test and predefine:
+# ARCH - ppc,i386,x86_64
+# OS - darwin
+# CC - compiler
+# CFLAGS - options
+# LLVM_SRCDIR - project root source dir
+# LIBS
+# VERSION - 3.x
+# CXXLIB - link libstdc++ or libc++
+
+COMPILER_RT_SRCDIR = $(LLVM_SRCDIR)/projects/compiler-rt
+VPATH = $(COMPILER_RT_SRCDIR)/test/Unit
+LIBDIR = ../../../lib
+DEFAULT_CFLAGS = -Os -nodefaultlibs
+DEFAULT_CPPFLAGS = -I$(COMPILER_RT_SRCDIR)/lib
+TEST_LIBDIR = $(LIBDIR)/clang/$(VERSION)/lib/$(OS)
+# LDFLAGS = -L$(TEST_LIBDIR)
+TEST_LIB = $(TEST_LIBDIR)/libclang_rt.$(ARCH).a
+LIBUNWIND = /usr/lib/libgcc_s.1.dylib
+CXXLIB ?= -lstdc++
+CXXLINK = $(CXXLIB) $(TEST_LIB) $(LIBUNWIND) $(LIBS)
+
+.SUFFIXES: .c
+
+all:
+
+.c:
+	$(CC) $(DEFAULT_CPPFLAGS) $(DEFAULT_CFLAGS) $(CFLAGS) $< \
+		$(LDFLAGS) $(TEST_LIB) $(LIBS) -o $@
+
+gcc_personality_test: gcc_personality_test.c gcc_personality_test_helper.cxx
+	$(CC) $(DEFAULT_CPPFLAGS) $(DEFAULT_CFLAGS) $(CFLAGS) -fexceptions \
+		$< $(VPATH)/gcc_personality_test_helper.cxx \
+		$(LDFLAGS) $(CXXLINK) -o $@
+
+trampoline_setup_test: trampoline_setup_test.c
+	$(CC) $(DEFAULT_CPPFLAGS) $(DEFAULT_CFLAGS) $(CFLAGS) \
+		-fnested-functions $< $(LDFLAGS) $(TEST_LIB) $(LIBS) -o $@
+
+C_TESTS = absvdi2_test absvsi2_test absvti2_test adddf3vfp_test \
+	addsf3vfp_test addvdi3_test addvsi3_test addvti3_test \
+	ashldi3_test ashlti3_test ashrdi3_test ashrti3_test \
+	bswapdi2_test bswapsi2_test clear_cache_test clzdi2_test \
+	clzsi2_test clzti2_test cmpdi2_test cmpti2_test \
+	comparedf2_test comparesf2_test ctzdi2_test ctzsi2_test \
+	ctzti2_test divdc3_test divdf3vfp_test divdi3_test \
+	divmodsi4_test divsc3_test divsf3vfp_test divsi3_test \
+	divtc3_test divti3_test divxc3_test \
+	enable_execute_stack_test eqdf2vfp_test eqsf2vfp_test \
+	extebdsfdf2vfp_test ffsdi2_test ffsti2_test fixdfdi_test \
+	fixdfsivfp_test fixdfti_test fixsfdi_test fixsfsivfp_test \
+	fixsfti_test fixunsdfdi_test fixunsdfsi_test fixunsdfsivfp_test \
+	fixunsdfti_test fixunssfdi_test fixunssfsi_test \
+	fixunssfsivfp_test fixunssfti_test fixunstfdi_test \
+	fixunsxfdi_test fixunsxfsi_test fixunsxfti_test fixxfdi_test \
+	fixxfti_test floatdidf_test floatdisf_test floatdixf_test \
+	floatsidfvfp_test floatsisfvfp_test floattidf_test \
+	floattisf_test floattixf_test floatundidf_test floatundisf_test \
+	floatundixf_test floatunssidfvfp_test floatunssisfvfp_test \
+	floatuntidf_test floatuntisf_test floatuntixf_test \
+	gcc_personality_test gedf2vfp_test gesf2vfp_test \
+	gtdf2vfp_test gtsf2vfp_test ledf2vfp_test lesf2vfp_test \
+	lshrdi3_test lshrti3_test ltdf2vfp_test ltsf2vfp_test \
+	moddi3_test modsi3_test modti3_test muldc3_test \
+	muldf3vfp_test muldi3_test mulodi4_test mulosi4_test \
+	muloti4_test mulsc3_test mulsf3vfp_test multc3_test \
+	multi3_test mulvdi3_test mulvsi3_test mulvti3_test \
+	mulxc3_test nedf2vfp_test negdf2vfp_test negdi2_test \
+	negsf2vfp_test negti2_test negvdi2_test negvsi2_test \
+	negvti2_test nesf2vfp_test paritydi2_test paritysi2_test \
+	parityti2_test popcountdi2_test popcountsi2_test \
+	popcountti2_test powidf2_test powisf2_test \
+	powitf2_test powixf2_test subdf3vfp_test subsf3vfp_test \
+	subvdi3_test subvsi3_test subvti3_test \
+	trampoline_setup_test truncdfsf2vfp_test ucmpdi2_test \
+	ucmpti2_test udivdi3_test udivmoddi4_test udivmodsi4_test \
+	udivmodti4_test udivsi3_test udivti3_test umoddi3_test \
+	umodsi3_test umodti3_test unorddf2vfp_test unordsf2vfp_test
+
+C_TEST_SOURCES = $(C_TESTS:=.c)
+TESTS = $(C_TESTS)
+
+all: $(TESTS)
+
+check: all
+	pass=0 ; \
+	fail=0 ; \
+	for t in $(TESTS) ; \
+	do if ./$$t ; \
+	then echo "PASS: $$t" ; pass=`expr $$pass + 1` ; \
+	else echo "FAIL: $$t" ; fail=`expr $$fail + 1` ; \
+	fi ; \
+	done ; \
+	echo "===================" ; \
+	echo "$$pass tests passed." ; \
+	echo "$$fail tests failed." ; \
+	test "$$fail" = 0
+
+clean:
+	rm -f $(TESTS)
+
