Apple's dynamic linker won't weak-def_coalesce from a file unless there is at least one weak symbol in the compilation unit so local __ubsan_on_report never has the chance to override the weak one even though the dynamic linker may see it first. This works around the issue by adding an unused weak symbol. (Amended: Remove excessive clang-format artifacts) rdar://95244261 Differential Revision: https://reviews.llvm.org/D127929
25 lines
478 B
C++
25 lines
478 B
C++
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
|
|
|
|
// FIXME: Doesn't work with DLLs
|
|
// XFAIL: win32-dynamic-asan
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
// Required for dyld macOS 12.0+
|
|
#if (__APPLE__)
|
|
__attribute__((weak))
|
|
#endif
|
|
extern "C" void
|
|
__asan_on_error() {
|
|
fprintf(stderr, "__asan_on_error called\n");
|
|
fflush(stderr);
|
|
}
|
|
|
|
int main() {
|
|
char *x = (char*)malloc(10 * sizeof(char));
|
|
free(x);
|
|
return x[5];
|
|
// CHECK: __asan_on_error called
|
|
}
|