Index: SDKs/darwin/usr/include/stdio.h
===================================================================
--- SDKs/darwin/usr/include/stdio.h	(revision 167026)
+++ SDKs/darwin/usr/include/stdio.h	(working copy)
@@ -17,6 +17,10 @@
 #ifndef __STDIO_H__
 #define __STDIO_H__
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 typedef struct __sFILE FILE;
 typedef __SIZE_TYPE__ size_t;
 
@@ -63,12 +67,17 @@
 
 int fclose(FILE *);
 int fflush(FILE *);
-FILE *fopen(const char * restrict, const char * restrict) __asm(__FOPEN_NAME);
-int fprintf(FILE * restrict, const char * restrict, ...);
-size_t fwrite(const void * restrict, size_t, size_t, FILE * restrict)
+FILE *fopen(const char * __restrict, const char * __restrict) __asm(__FOPEN_NAME);
+int fprintf(FILE * __restrict, const char * __restrict, ...);
+int	 fputc(int, FILE *);
+size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict)
   __asm(__FWRITE_NAME);
 size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
 long ftell(FILE *);
 int fseek(FILE *, long, int);
 
+#if defined(__cplusplus)
+}
+#endif
+
 #endif /* __STDIO_H__ */
Index: SDKs/darwin/usr/include/stdlib.h
===================================================================
--- SDKs/darwin/usr/include/stdlib.h	(revision 167026)
+++ SDKs/darwin/usr/include/stdlib.h	(working copy)
@@ -17,6 +17,10 @@
 #ifndef __STDLIB_H__
 #define __STDLIB_H__
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 #define NULL ((void *)0)
 
 typedef __SIZE_TYPE__ size_t;
@@ -27,4 +31,8 @@
 char *getenv(const char *);
 void *malloc(size_t);
 
+#if defined(__cplusplus)
+}
+#endif
+
 #endif /* __STDLIB_H__ */
Index: SDKs/darwin/usr/include/string.h
===================================================================
--- SDKs/darwin/usr/include/string.h	(revision 167026)
+++ SDKs/darwin/usr/include/string.h	(working copy)
@@ -17,6 +17,10 @@
 #ifndef __STRING_H__
 #define __STRING_H__
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 typedef __SIZE_TYPE__ size_t;
 
 int memcmp(const void *, const void *, size_t);
@@ -27,4 +31,8 @@
 size_t strlen(const char *);
 char *strncpy(char *, const char *, size_t);
 
+#if defined(__cplusplus)
+}
+#endif
+
 #endif /* __STRING_H__ */
Index: SDKs/darwin/usr/include/unistd.h
===================================================================
--- SDKs/darwin/usr/include/unistd.h	(revision 0)
+++ SDKs/darwin/usr/include/unistd.h	(working copy)
@@ -0,0 +1,34 @@
+/* ===-- unistd.h - stub SDK header for compiler-rt -------------------------===
+ *
+ *                     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.
+ *
+ * ===-----------------------------------------------------------------------===
+ *
+ * This is a stub SDK header file. This file is not part of the interface of
+ * this library nor an official version of the appropriate SDK header. It is
+ * intended only to stub the features of this header required by compiler-rt.
+ *
+ * ===-----------------------------------------------------------------------===
+ */
+
+#ifndef __UNISTD_H__
+#define __UNISTD_H__
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#define	 STDIN_FILENO	0	/* standard input file descriptor */
+#define	STDOUT_FILENO	1	/* standard output file descriptor */
+#define	STDERR_FILENO	2	/* standard error file descriptor */
+
+int	 isatty(int);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __UNISTD_H__ */

Property changes on: SDKs/darwin/usr/include/unistd.h
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain;charset=utf-8
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: lib/Makefile.mk
===================================================================
--- lib/Makefile.mk	(revision 167026)
+++ lib/Makefile.mk	(working copy)
@@ -19,6 +19,7 @@
 SubDirs += profile
 SubDirs += sanitizer_common
 SubDirs += tsan
+SubDirs += ubsan
 
 # FIXME: We don't currently support building an atomic library, and as it must
 # be a separate library from the runtime library, we need to remove its source
Index: lib/ubsan/Makefile.mk
===================================================================
--- lib/ubsan/Makefile.mk	(revision 0)
+++ lib/ubsan/Makefile.mk	(working copy)
@@ -0,0 +1,23 @@
+#===- lib/ubsan/Makefile.mk ---------------------------------*- Makefile -*--===#
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+
+ModuleName := ubsan
+SubDirs :=
+
+Sources := $(foreach file,$(wildcard $(Dir)/*.cc),$(notdir $(file)))
+ObjNames := $(Sources:%.cc=%.o)
+
+Implementation := Generic
+
+# FIXME: use automatic dependencies?
+Dependencies := $(wildcard $(Dir)/*.h)
+Dependencies += $(wildcard $(Dir)/../sanitizer_common/*.h)
+
+# Define a convenience variable for all the ubsan functions.
+UbsanFunctions := $(Sources:%.cc=%)
Index: lib/ubsan/ubsan_value.h
===================================================================
--- lib/ubsan/ubsan_value.h	(revision 167026)
+++ lib/ubsan/ubsan_value.h	(working copy)
@@ -14,9 +14,9 @@
 #ifndef UBSAN_VALUE_H
 #define UBSAN_VALUE_H
 
-// For now, only support linux. Other platforms should be easy to add, and
-// probably work as-is.
-#if !defined(__linux__)
+// For now, only support linux and darwin. Other platforms should be easy to
+// add, and probably work as-is.
+#if !defined(__linux__) && !defined(__APPLE__)
 #error "UBSan not supported for this platform!"
 #endif
 
Index: make/platform/clang_darwin.mk
===================================================================
--- make/platform/clang_darwin.mk	(revision 167026)
+++ make/platform/clang_darwin.mk	(working copy)
@@ -76,6 +76,9 @@
 Configs += asan_osx_dynamic
 UniversalArchs.asan_osx_dynamic := $(call CheckArches,i386 x86_64,asan_osx_dynamic)
 
+Configs += ubsan_osx
+UniversalArchs.ubsan_osx := $(call CheckArches,i386 x86_64,ubsan_osx)
+
 # Darwin 10.6 has a bug in cctools that makes it unable to use ranlib on our ARM
 # object files. If we are on that platform, strip out all ARM archs. We still
 # build the libraries themselves so that Clang can find them where it expects
@@ -131,6 +134,8 @@
 	$(CFLAGS) -mmacosx-version-min=10.5 -fno-builtin \
 	-DMAC_INTERPOSE_FUNCTIONS=1
 
+CFLAGS.ubsan_osx	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
+
 CFLAGS.ios.i386		:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
 CFLAGS.ios.x86_64	:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
 CFLAGS.ios.armv7	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
@@ -183,6 +188,8 @@
                               $(SanitizerCommonFunctions) \
 	                      $(AsanDynamicFunctions)
 
+FUNCTIONS.ubsan_osx := $(UbsanFunctions)
+
 CCKEXT_COMMON_FUNCTIONS := \
 	absvdi2 \
 	absvsi2 \
