[compiler-rt] r362478 - [HWASAN] Make new/delete weak
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 4 02:20:02 PDT 2019
Author: evgeny777
Date: Tue Jun 4 02:20:02 2019
New Revision: 362478
URL: http://llvm.org/viewvc/llvm-project?rev=362478&view=rev
Log:
[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
Added:
compiler-rt/trunk/test/hwasan/TestCases/override-new-delete.cpp
Modified:
compiler-rt/trunk/lib/hwasan/hwasan_new_delete.cpp
Modified: compiler-rt/trunk/lib/hwasan/hwasan_new_delete.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_new_delete.cpp?rev=362478&r1=362477&r2=362478&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_new_delete.cpp (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_new_delete.cpp Tue Jun 4 02:20:02 2019
@@ -35,15 +35,15 @@ namespace std {
if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\
return res
-INTERCEPTOR_ATTRIBUTE
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void *operator new(size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); }
-INTERCEPTOR_ATTRIBUTE
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void *operator new[](size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); }
-INTERCEPTOR_ATTRIBUTE
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void *operator new(size_t size, std::nothrow_t const&) {
OPERATOR_NEW_BODY(true /*nothrow*/);
}
-INTERCEPTOR_ATTRIBUTE
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void *operator new[](size_t size, std::nothrow_t const&) {
OPERATOR_NEW_BODY(true /*nothrow*/);
}
@@ -52,13 +52,13 @@ void *operator new[](size_t size, std::n
GET_MALLOC_STACK_TRACE; \
if (ptr) hwasan_free(ptr, &stack)
-INTERCEPTOR_ATTRIBUTE
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void operator delete(void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void operator delete[](void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void operator delete(void *ptr, std::nothrow_t const&) { OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
+INTERCEPTOR_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void operator delete[](void *ptr, std::nothrow_t const&) {
OPERATOR_DELETE_BODY;
}
Added: compiler-rt/trunk/test/hwasan/TestCases/override-new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/hwasan/TestCases/override-new-delete.cpp?rev=362478&view=auto
==============================================================================
--- compiler-rt/trunk/test/hwasan/TestCases/override-new-delete.cpp (added)
+++ compiler-rt/trunk/test/hwasan/TestCases/override-new-delete.cpp Tue Jun 4 02:20:02 2019
@@ -0,0 +1,23 @@
+// RUN: %clangxx_hwasan %s
+#include <stddef.h>
+#include <new>
+
+char *__dummy;
+
+void *operator new(size_t size) { return __dummy; }
+void *operator new[](size_t size) { return __dummy; }
+void *operator new(size_t size, std::nothrow_t const&) noexcept {
+ return __dummy;
+}
+void *operator new[](size_t size, std::nothrow_t const&) noexcept {
+ return __dummy;
+}
+
+void operator delete(void *ptr) noexcept {}
+void operator delete[](void *ptr) noexcept {}
+void operator delete(void *ptr, std::nothrow_t const&) noexcept {}
+void operator delete[](void *ptr, std::nothrow_t const&) noexcept {}
+
+int main() {
+ return 0;
+}
More information about the llvm-commits
mailing list