[llvm-commits] [compiler-rt] r159821 - in /compiler-rt/trunk/lib/asan: asan_mac.cc asan_mac.h asan_malloc_mac.cc
Alexander Potapenko
glider at google.com
Fri Jul 6 06:04:13 PDT 2012
Author: glider
Date: Fri Jul 6 08:04:12 2012
New Revision: 159821
URL: http://llvm.org/viewvc/llvm-project?rev=159821&view=rev
Log:
A portable way to check whether __CFInitialize has been called: compare kCFAllocatorSystemDefault._base._cfisa to 0.
This should fix http://code.google.com/p/address-sanitizer/issues/detail?id=87 on both Lion and Snow Leopard.
Modified:
compiler-rt/trunk/lib/asan/asan_mac.cc
compiler-rt/trunk/lib/asan/asan_mac.h
compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=159821&r1=159820&r2=159821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Fri Jul 6 08:04:12 2012
@@ -379,28 +379,6 @@
gencountp);
}
-// CF_RC_BITS, the layout of CFRuntimeBase and __CFStrIsConstant are internal
-// and subject to change in further CoreFoundation versions. Apple does not
-// guarantee any binary compatibility from release to release.
-
-// See http://opensource.apple.com/source/CF/CF-635.15/CFInternal.h
-#if defined(__BIG_ENDIAN__)
-#define CF_RC_BITS 0
-#endif
-
-#if defined(__LITTLE_ENDIAN__)
-#define CF_RC_BITS 3
-#endif
-
-// See http://opensource.apple.com/source/CF/CF-635.15/CFRuntime.h
-typedef struct __CFRuntimeBase {
- uptr _cfisa;
- u8 _cfinfo[4];
-#if __LP64__
- u32 _rc;
-#endif
-} CFRuntimeBase;
-
// See http://opensource.apple.com/source/CF/CF-635.15/CFString.c
int __CFStrIsConstant(CFStringRef str) {
CFRuntimeBase *base = (CFRuntimeBase*)str;
Modified: compiler-rt/trunk/lib/asan/asan_mac.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.h?rev=159821&r1=159820&r2=159821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.h (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.h Fri Jul 6 08:04:12 2012
@@ -14,6 +14,28 @@
#ifndef ASAN_MAC_H
#define ASAN_MAC_H
+// CF_RC_BITS, the layout of CFRuntimeBase and __CFStrIsConstant are internal
+// and subject to change in further CoreFoundation versions. Apple does not
+// guarantee any binary compatibility from release to release.
+
+// See http://opensource.apple.com/source/CF/CF-635.15/CFInternal.h
+#if defined(__BIG_ENDIAN__)
+#define CF_RC_BITS 0
+#endif
+
+#if defined(__LITTLE_ENDIAN__)
+#define CF_RC_BITS 3
+#endif
+
+// See http://opensource.apple.com/source/CF/CF-635.15/CFRuntime.h
+typedef struct __CFRuntimeBase {
+ uptr _cfisa;
+ u8 _cfinfo[4];
+#if __LP64__
+ u32 _rc;
+#endif
+} CFRuntimeBase;
+
enum {
MACOS_VERSION_UNKNOWN = 0,
MACOS_VERSION_LEOPARD,
Modified: compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_mac.cc?rev=159821&r1=159820&r2=159821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_mac.cc Fri Jul 6 08:04:12 2012
@@ -397,13 +397,10 @@
// If __CFInitialize() hasn't been called yet, cf_asan will be installed
// as the default allocator after __CFInitialize() finishes (see the
// interceptor for __CFInitialize() above). Otherwise install cf_asan right
- // now. On Snow Leopard we can check for __CFRuntimeClassTableSize, but on
- // Lion it is private, so we can't.
- if (GetMacosVersion() == MACOS_VERSION_SNOW_LEOPARD) {
- int *cf_rcts = (int*)dlsym(RTLD_SELF, "__CFRuntimeClassTableSize");
- if (cf_rcts && *cf_rcts) CFAllocatorSetDefault(cf_asan);
- } else {
- // FIXME: how can we check __CFInitialize() has been called already?
+ // now. On both Snow Leopard and Lion __CFInitialize() calls
+ // __CFAllocatorInitialize(), which initializes the _base._cfisa field of
+ // the default allocators we check here.
+ if (((CFRuntimeBase*)kCFAllocatorSystemDefault)->_cfisa) {
CFAllocatorSetDefault(cf_asan);
}
}
More information about the llvm-commits
mailing list