[PATCH] D26150: [libc++abi] Fix test_exception_storage_nodynmem on MacOS
Shoaib Meenai via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 31 08:01:48 PDT 2016
smeenai created this revision.
smeenai added reviewers: compnerd, EricWF, howard.hinnant, ikudrin, mclow.lists.
smeenai added a subscriber: cfe-commits.
Mach-O defaults to two-level namespaces, so `calloc` cannot be
interpositoned. Override it via the default malloc zone instead.
Note: `DYLD_FORCE_FLAT_NAMESPACE` can be used to enable interpositioning
on Mach-O, but `calloc` is used during library initialization, so
replacing it with a version which always returns NULL causes segfaults.
This could be worked around, but malloc zones are a cleaner solution.
https://reviews.llvm.org/D26150
Files:
test/test_exception_storage_nodynmem.pass.cpp
Index: test/test_exception_storage_nodynmem.pass.cpp
===================================================================
--- test/test_exception_storage_nodynmem.pass.cpp
+++ test/test_exception_storage_nodynmem.pass.cpp
@@ -17,16 +17,28 @@
#include <assert.h>
#include <cstdlib>
+#if defined(__APPLE__)
+#include <malloc/malloc.h>
+#endif
static bool OverwrittenCallocCalled = false;
// Override calloc to simulate exhaustion of dynamic memory
+#if !defined(__APPLE__)
void *calloc(size_t, size_t) {
+#else
+void *calloc(malloc_zone_t *, size_t, size_t) {
+#endif
OverwrittenCallocCalled = true;
return 0;
}
int main(int argc, char *argv[]) {
+#if defined(__APPLE__)
+ malloc_zone_t *default_zone = malloc_default_zone();
+ default_zone->calloc = calloc;
+#endif
+
// Run the test a couple of times
// to ensure that fallback memory doesn't leak.
for (int I = 0; I < 1000; ++I)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26150.76409.patch
Type: text/x-patch
Size: 925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161031/e15f69ad/attachment.bin>
More information about the cfe-commits
mailing list