Skip to content

Commit abaf75b

Browse files
committed
[asan] Pass -falign-functions=16 when building on Windows
Win/ASan relies on the runtime's functions being 16-byte aligned so it can intercept them with hotpatching. This used to be true (but not guaranteed) until llvm#149444. Pass the flag to explicitly request enough alignment.
1 parent ff5767a commit abaf75b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler-rt/lib/asan/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ if(MSVC)
106106
endif()
107107
set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
108108

109+
# Win/ASan relies on the runtime having 16-byte aligned functions for
110+
# hotpatching. See https://github.com/llvm/llvm-project/pull/149444
111+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
112+
if(CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
113+
list(APPEND ASAN_CFLAGS /clang:-falign-functions=16)
114+
endif()
115+
endif()
116+
109117
append_list_if(MSVC /Zl ASAN_CFLAGS)
110118

111119
set(ASAN_COMMON_DEFINITIONS "")

0 commit comments

Comments
 (0)