Files
clang-p2996/compiler-rt/test/asan/TestCases/Windows/free_hook_realloc.cpp
Charlie Barto 53a81d4d26 Reland [asan][windows] Eliminate the static asan runtime on windows (#107899)
This reapplies 8fa66c6ca7 ([asan][windows]
Eliminate the static asan runtime on windows) for a second time.

That PR bounced off the tests because it caused failures in the other
sanitizer runtimes, these have been fixed by only building interception,
sanitizer_common, and asan with /MD, and continuing to build the rest of
the runtimes with /MT. This does mean that any usage of the static
ubsan/fuzzer/etc runtimes will mean you're mixing different runtime
library linkages in the same app, the interception, sanitizer_common,
and asan runtimes are designed for this, however it does result in some
linker warnings.

Additionally, it turns out when building in release-mode with
LLVM_ENABLE_PDBs the build system forced /OPT:ICF. This totally breaks
asan's "new" method of doing "weak" functions on windows, and so
/OPT:NOICF was explicitly added to asan's link flags.

---------

Co-authored-by: Amy Wishnousky <amyw@microsoft.com>
2024-09-09 13:41:08 -07:00

38 lines
828 B
C++

// Check that free hook doesn't conflict with Realloc.
// RUN: %clangxx_asan -O2 %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s
// FIXME: merge this with the common free_hook_realloc test when we can run
// common tests on Windows.
#include <stdlib.h>
#include <io.h>
#include <sanitizer/allocator_interface.h>
static void *glob_ptr;
extern "C" {
void __sanitizer_free_hook(const volatile void *ptr) {
if (ptr == glob_ptr) {
*(int*)ptr = 0;
write(1, "FreeHook\n", sizeof("FreeHook\n"));
}
}
}
int main() {
int *x = (int*)malloc(100);
x[0] = 42;
glob_ptr = x;
int *y = (int*)realloc(x, 200);
// Verify that free hook was called and didn't spoil the memory.
if (y[0] != 42) {
_exit(1);
}
write(1, "Passed\n", sizeof("Passed\n"));
free(y);
// CHECK: FreeHook
// CHECK: Passed
return 0;
}