[llvm-commits] [compiler-rt] r159819 - 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 04:58:55 PDT 2012
Author: glider
Date: Fri Jul 6 06:58:54 2012
New Revision: 159819
URL: http://llvm.org/viewvc/llvm-project?rev=159819&view=rev
Log:
Do not check for __CFRuntimeClassTableSize on non-10.6 systems, where this symbol is private.
This change may cause http://code.google.com/p/address-sanitizer/issues/detail?id=87 to re-appear on Lion.
Added:
compiler-rt/trunk/lib/asan/asan_mac.h
Modified:
compiler-rt/trunk/lib/asan/asan_mac.cc
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=159819&r1=159818&r2=159819&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Fri Jul 6 06:58:54 2012
@@ -16,6 +16,7 @@
#include "asan_interceptors.h"
#include "asan_internal.h"
+#include "asan_mac.h"
#include "asan_mapping.h"
#include "asan_stack.h"
#include "asan_thread.h"
@@ -51,14 +52,7 @@
# endif // __WORDSIZE
}
-enum {
- MACOS_VERSION_UNKNOWN = 0,
- MACOS_VERSION_LEOPARD,
- MACOS_VERSION_SNOW_LEOPARD,
- MACOS_VERSION_LION
-};
-
-static int GetMacosVersion() {
+int GetMacosVersion() {
int mib[2] = { CTL_KERN, KERN_OSRELEASE };
char version[100];
uptr len = 0, maxlen = sizeof(version) / sizeof(version[0]);
Added: compiler-rt/trunk/lib/asan/asan_mac.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.h?rev=159819&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.h (added)
+++ compiler-rt/trunk/lib/asan/asan_mac.h Fri Jul 6 06:58:54 2012
@@ -0,0 +1,30 @@
+//===-- asan_mac.h ----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// Mac-specific ASan definitions.
+//===----------------------------------------------------------------------===//
+#ifndef ASAN_MAC_H
+#define ASAN_MAC_H
+
+enum {
+ MACOS_VERSION_UNKNOWN = 0,
+ MACOS_VERSION_LEOPARD,
+ MACOS_VERSION_SNOW_LEOPARD,
+ MACOS_VERSION_LION
+};
+
+namespace __asan {
+
+int GetMacosVersion();
+
+} // namespace __asan
+
+#endif // ASAN_MAC_H
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=159819&r1=159818&r2=159819&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_mac.cc Fri Jul 6 06:58:54 2012
@@ -16,12 +16,14 @@
#include <AvailabilityMacros.h>
#include <CoreFoundation/CFBase.h>
+#include <dlfcn.h>
#include <malloc/malloc.h>
#include <setjmp.h>
#include "asan_allocator.h"
#include "asan_interceptors.h"
#include "asan_internal.h"
+#include "asan_mac.h"
#include "asan_stack.h"
// Similar code is used in Google Perftools,
@@ -394,9 +396,16 @@
cf_asan = CFAllocatorCreate(kCFAllocatorUseContext, &asan_context);
// 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 (if
- // __CFRuntimeClassTableSize is initialized) install cf_asan right now.
- if (__CFRuntimeClassTableSize) CFAllocatorSetDefault(cf_asan);
+ // 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?
+ CFAllocatorSetDefault(cf_asan);
+ }
}
}
} // namespace __asan
More information about the llvm-commits
mailing list