Skip to content

Commit c3c686f

Browse files
committedJun 4, 2019
[HWASAN] Make new/delete weak
This allows instrumenting programs which have their own versions of new and delete operators. Differential revision: https://reviews.llvm.org/D62794 llvm-svn: 362478
1 parent 73a15d4 commit c3c686f

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed
 

‎compiler-rt/lib/hwasan/hwasan_new_delete.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ namespace std {
3535
if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\
3636
return res
3737

38-
INTERCEPTOR_ATTRIBUTE
38+
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
3939
void *operator new(size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); }
40-
INTERCEPTOR_ATTRIBUTE
40+
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
4141
void *operator new[](size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); }
42-
INTERCEPTOR_ATTRIBUTE
42+
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
4343
void *operator new(size_t size, std::nothrow_t const&) {
4444
OPERATOR_NEW_BODY(true /*nothrow*/);
4545
}
46-
INTERCEPTOR_ATTRIBUTE
46+
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
4747
void *operator new[](size_t size, std::nothrow_t const&) {
4848
OPERATOR_NEW_BODY(true /*nothrow*/);
4949
}
@@ -52,13 +52,13 @@ void *operator new[](size_t size, std::nothrow_t const&) {
5252
GET_MALLOC_STACK_TRACE; \
5353
if (ptr) hwasan_free(ptr, &stack)
5454

55-
INTERCEPTOR_ATTRIBUTE
55+
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
5656
void operator delete(void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
57-
INTERCEPTOR_ATTRIBUTE
57+
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
5858
void operator delete[](void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
59-
INTERCEPTOR_ATTRIBUTE
59+
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
6060
void operator delete(void *ptr, std::nothrow_t const&) { OPERATOR_DELETE_BODY; }
61-
INTERCEPTOR_ATTRIBUTE
61+
INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
6262
void operator delete[](void *ptr, std::nothrow_t const&) {
6363
OPERATOR_DELETE_BODY;
6464
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clangxx_hwasan %s
2+
#include <stddef.h>
3+
#include <new>
4+
5+
char *__dummy;
6+
7+
void *operator new(size_t size) { return __dummy; }
8+
void *operator new[](size_t size) { return __dummy; }
9+
void *operator new(size_t size, std::nothrow_t const&) noexcept {
10+
return __dummy;
11+
}
12+
void *operator new[](size_t size, std::nothrow_t const&) noexcept {
13+
return __dummy;
14+
}
15+
16+
void operator delete(void *ptr) noexcept {}
17+
void operator delete[](void *ptr) noexcept {}
18+
void operator delete(void *ptr, std::nothrow_t const&) noexcept {}
19+
void operator delete[](void *ptr, std::nothrow_t const&) noexcept {}
20+
21+
int main() {
22+
return 0;
23+
}

0 commit comments

Comments
 (0)