Mitch Phillips 4f029d1be4 [GWP-ASan] Split the unwinder into segv/non-segv.
Note: Resubmission with frame pointers force-enabled to fix builds with
-DCOMPILER_RT_BUILD_BUILTINS=False

Summary:
Splits the unwinder into a non-segv (for allocation/deallocation traces) and a
segv unwinder. This ensures that implementations can select an accurate, slower
unwinder in the segv handler (if they choose to use the GWP-ASan provided one).
This is important as fast frame-pointer unwinders (like the sanitizer unwinder)
don't like unwinding through signal handlers.

Reviewers: morehouse, cryptoad

Reviewed By: morehouse, cryptoad

Subscribers: cryptoad, mgorny, eugenis, pcc, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D83994
2020-07-21 08:25:37 -07:00

30 lines
650 B
C

// REQUIRES: gwp_asan
// RUN: %clang_gwp_asan %s -g -o %t
// RUN: %expect_crash %t 2>&1 | FileCheck %s
#include <stdlib.h>
__attribute__((noinline)) void *allocate_mem() { return malloc(1); }
__attribute__((noinline)) void free_mem(void *ptr) { free(ptr); }
__attribute__((noinline)) void touch_mem(void *ptr) {
volatile char sink = *((volatile char *)ptr);
}
// CHECK: Use After Free
// CHECK: touch_mem
// CHECK: was deallocated
// CHECK: free_mem
// CHECK: was allocated
// CHECK: allocate_mem
int main() {
for (unsigned i = 0; i < 0x10000; ++i) {
void *ptr = allocate_mem();
free_mem(ptr);
touch_mem(ptr);
}
return 0;
}