[all-commits] [llvm/llvm-project] 481e9b: [asan][win][msvc] override new and delete and sepe...
Charlie Barto via All-commits
all-commits at lists.llvm.org
Fri Dec 1 11:57:06 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 481e9b3e0b9c0a6843261f060822c7a41387e28c
https://github.com/llvm/llvm-project/commit/481e9b3e0b9c0a6843261f060822c7a41387e28c
Author: Charlie Barto <chbarto at microsoft.com>
Date: 2023-12-01 (Fri, 01 Dec 2023)
Changed paths:
M compiler-rt/lib/asan/CMakeLists.txt
M compiler-rt/lib/asan/asan_interface.inc
A compiler-rt/lib/asan/asan_win_delete_array_align_nothrow_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_array_align_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_array_nothrow_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_array_size_align_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_array_size_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_array_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_scalar_align_nothrow_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_scalar_align_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_scalar_nothrow_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_scalar_size_align_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_scalar_size_thunk.cpp
A compiler-rt/lib/asan/asan_win_delete_scalar_thunk.cpp
A compiler-rt/lib/asan/asan_win_new_array_align_nothrow_thunk.cpp
A compiler-rt/lib/asan/asan_win_new_array_align_thunk.cpp
A compiler-rt/lib/asan/asan_win_new_array_nothrow_thunk.cpp
A compiler-rt/lib/asan/asan_win_new_array_thunk.cpp
A compiler-rt/lib/asan/asan_win_new_delete.cpp
A compiler-rt/lib/asan/asan_win_new_delete_thunk_common.h
A compiler-rt/lib/asan/asan_win_new_scalar_align_nothrow_thunk.cpp
A compiler-rt/lib/asan/asan_win_new_scalar_align_thunk.cpp
A compiler-rt/lib/asan/asan_win_new_scalar_nothrow_thunk.cpp
A compiler-rt/lib/asan/asan_win_new_scalar_thunk.cpp
M compiler-rt/test/asan/TestCases/Windows/double_operator_delete.cpp
A compiler-rt/test/asan/TestCases/Windows/new_delete_mfc_already_defined.cpp
A compiler-rt/test/asan/TestCases/Windows/new_delete_mfc_already_defined_dbg.cpp
M compiler-rt/test/asan/TestCases/Windows/operator_array_new_left_oob.cpp
M compiler-rt/test/asan/TestCases/Windows/operator_array_new_right_oob.cpp
M compiler-rt/test/asan/TestCases/Windows/operator_array_new_uaf.cpp
M compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp
A compiler-rt/test/asan/TestCases/Windows/operator_delete_replacement_array.cpp
A compiler-rt/test/asan/TestCases/Windows/operator_delete_replacement_scalar.cpp
M compiler-rt/test/asan/TestCases/Windows/operator_delete_wrong_argument.cpp
A compiler-rt/test/asan/TestCases/Windows/operator_new_delete_replacement_all.cpp
A compiler-rt/test/asan/TestCases/Windows/operator_new_delete_replacement_common.h
A compiler-rt/test/asan/TestCases/Windows/operator_new_delete_replacement_macros.h
M compiler-rt/test/asan/TestCases/Windows/operator_new_left_oob.cpp
A compiler-rt/test/asan/TestCases/Windows/operator_new_replacement_array.cpp
A compiler-rt/test/asan/TestCases/Windows/operator_new_replacement_scalar.cpp
M compiler-rt/test/asan/TestCases/Windows/operator_new_right_oob.cpp
M compiler-rt/test/asan/TestCases/Windows/operator_new_uaf.cpp
M compiler-rt/test/asan/TestCases/Windows/wrong_downcast_on_heap.cpp
M compiler-rt/test/asan/TestCases/large_func_test.cpp
M compiler-rt/test/asan/TestCases/malloc_context_size.cpp
M compiler-rt/test/asan/TestCases/use-after-delete.cpp
Log Message:
-----------
[asan][win][msvc] override new and delete and seperate TUs (#68754)
Migrated from: https://reviews.llvm.org/D155879, with some of the
suggestions applied.
PR Description copied from above:
Currently asan simply exports each overridden new/delete function from
the DLL, this works fine normally, but fails if the user is overriding
some, but not all, of these functions. In this case the non-overridden
functions still come from the asan DLL, but they can't correctly call
the user provided override (for example sized op delete should fall back
to scalar op delete, if a scalar op delete is provided). Things were
also broken in the static build because all the asan overrides were
exported from the same TU, and so if you overrode one but not all of
them then you'd get ODR violations. This PR should fix both of these
cases, but the static case isn't really tested (and indeed one such test
does fail) because linking asan statically basically doesn't work on
windows right now with LLVM's version of asan. In fact, while we did fix
this in our fork, it was a huge mess and we've now made the dynamic
version work in all situations (/MD, /MT, /MDd, /MTd, etc) instead.
The following is the description from the internal PR that implemented
most of this feature.
> Previously, operator new/delete were provided as DLL exports when
linking dynamically and wholearchived when linked statically. Both
scenarios were broken. When linking statically, the user could not
define their own op new/delete, because they were already brought into
the link by ASAN. When dynamically linking, if the user provided some
but not all of the overloads, new and delete would be partially hooked.
For example, if the user defined scalar op delete, but the program then
called sized op delete, the sized op delete would still be the version
provided by ASAN instead of falling back to the user-defined scalar op
delete, like the standard requires.
> The change <internal PR number>: ASAN operator new/delete fallbacks in
the ASAN libraries fixes this moving all operator new/delete definitions
to be statically linked. However, this still won't work if
/InferAsanLibs still whole-archives everything since then all the op
new/deletes would always be provided by ASAN, which is why these changes
are necessary.
> With these changes, we will no longer wholearchive all of ASAN and
will leave the c++ parts (the op new/delete definitions) to be included
as a default library. However, it is also necessary to ensure that the
asan library with op new/delete will be searched before the
corresponding CRT library with the same op new/delete definitions. To
accomplish this, we make sure to add the asan library to the beginning
of the default lib list, or move it explicitly to the front if it's
already in the list. If the C runtime library is explicitly provided, we
make sure to warn the user if the current linker line will result in
operator new/delete not being provided by ASAN.
Note that the rearrangement of defaultlibs is not in this diff.
---------
Co-authored-by: Charlie Barto <Charles.Barto at microsoft.com>
More information about the All-commits
mailing list