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

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


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

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.

>From abaf75b9c52b5a7f15ede526acbbc6739e2cada0 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Thu, 21 Aug 2025 10:07:03 +0200
Subject: [PATCH] [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 #149444.

Pass the flag to explicitly request enough alignment.
---
 compiler-rt/lib/asan/CMakeLists.txt | 8 ++++++++
 1 file changed, 8 insertions(+)

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 "")



More information about the llvm-commits mailing list