[PATCH] D62794: [HWASAN] Make new/delete weak
Eugene Leviant via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 2 10:18:02 PDT 2019
evgeny777 created this revision.
evgeny777 added reviewers: kcc, eugenis.
Herald added a subscriber: kubamracek.
This allows instrumenting executables with overridden new/delete. The approach was discussed in D54905 <https://reviews.llvm.org/D54905>
https://reviews.llvm.org/D62794
Files:
lib/hwasan/hwasan_new_delete.cpp
test/hwasan/TestCases/override-new-delete.cpp
Index: test/hwasan/TestCases/override-new-delete.cpp
===================================================================
--- test/hwasan/TestCases/override-new-delete.cpp
+++ test/hwasan/TestCases/override-new-delete.cpp
@@ -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;
+}
Index: lib/hwasan/hwasan_new_delete.cpp
===================================================================
--- lib/hwasan/hwasan_new_delete.cpp
+++ lib/hwasan/hwasan_new_delete.cpp
@@ -35,15 +35,15 @@
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 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62794.202609.patch
Type: text/x-patch
Size: 2488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190602/ea6d7478/attachment.bin>
More information about the llvm-commits
mailing list