[compiler-rt] [asan] Pass -falign-functions=16 when building on Windows (PR #154694)
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 22 01:24:42 PDT 2025
https://github.com/zmodem updated https://github.com/llvm/llvm-project/pull/154694
>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 1/2] [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 "")
>From 0b10da1b6eed6c39120dead66a39b401648fd33f Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans at chromium.org>
Date: Fri, 22 Aug 2025 10:24:17 +0200
Subject: [PATCH 2/2] use /hotpatch instead
---
compiler-rt/lib/asan/CMakeLists.txt | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index 3850d3ce8a9d7..7d07ec765c005 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -106,12 +106,10 @@ 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()
+# Win/ASan relies on the runtime functions being hotpatchable. See
+# https://github.com/llvm/llvm-project/pull/149444
+if(MSVC)
+ list(APPEND ASAN_CFLAGS /hotpatch)
endif()
append_list_if(MSVC /Zl ASAN_CFLAGS)
More information about the llvm-commits
mailing list