[compiler-rt] [asan] Pass -falign-functions=16 when building on Windows (PR #154694)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 01:11:56 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Hans Wennborg (zmodem)

<details>
<summary>Changes</summary>

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 #<!-- -->149444.

Pass the flag to explicitly request enough alignment.

---
Full diff: https://github.com/llvm/llvm-project/pull/154694.diff


1 Files Affected:

- (modified) compiler-rt/lib/asan/CMakeLists.txt (+8) 


``````````diff
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index d1d229e3e6d40..3850d3ce8a9d7 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -106,6 +106,14 @@ if(MSVC)
 endif()
 set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
 
+# Win/ASan relies on the runtime having 16-byte aligned functions for
+# hotpatching. See https://github.com/llvm/llvm-project/pull/149444
+if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+  if(CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
+    list(APPEND ASAN_CFLAGS /clang:-falign-functions=16)
+  endif()
+endif()
+
 append_list_if(MSVC /Zl ASAN_CFLAGS)
 
 set(ASAN_COMMON_DEFINITIONS "")

``````````

</details>


https://github.com/llvm/llvm-project/pull/154694


More information about the llvm-commits mailing list