[compiler-rt] [asan][win][msvc] override new and delete and seperate TUs (PR #68754)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 18 05:52:50 PST 2023
================
@@ -0,0 +1,47 @@
+//===-- asan_win_new_array_nothrow_thunk.cc -------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// Windows-specific user-provided new/delete operator detection and fallback.
+//===----------------------------------------------------------------------===//
+#include "asan_win_new_delete_thunk_common.h"
+
+////////////////////////////////////
+// clang-format off
+// new() Fallback Ordering
+//
+// +----------+
+// |new_scalar<---------------+
+// +----^-----+ |
+// | |
+// +----+-------------+ +----+----+
+// |new_scalar_nothrow| |new_array|
+// +------------------+ +----^----+
+// |
+// +------------+----+
+// |NEW_ARRAY_NOTHROW|
+// +-----------------+
+// clang-format on
+
+extern "C" void* __cdecl __asan_new_array_nothrow(size_t size);
+
+// Avoid tailcall optimization to preserve stack frame.
+#pragma optimize("", off)
+void* operator new[](size_t size, std::nothrow_t const&) noexcept {
+ if (__asan_InitDefine<op_new_scalar>::defined &&
+ __asan_InitDefine<op_new_array>::defined) {
+ return __asan_new_array_nothrow(size);
+ }
+
+ try {
+ return operator new[](size);
----------------
mstorsjo wrote:
FYI (somewhat offtopic) I just checked and saw that this implementation here does fall back on the right operator - vcruntime seems to be getting this bit wrong, see https://developercommunity.visualstudio.com/t/vcruntime-nothrow-array-operator-new-fal/10373274 - where it seems that vcruntime's implementation of nothrowing array new falls back on nothrowing scalar new, instead of throwing array new like it's supposed to.
https://github.com/llvm/llvm-project/pull/68754
More information about the llvm-commits
mailing list