[compiler-rt] [ASan][cmake] Exclude .so build when building for WASI by default (PR #139042)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 00:59:07 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Yuta Saito (kateinoigakukun)

<details>
<summary>Changes</summary>

`libclang_rt.asan.so` depends on `libc.so` and `libc++.so` but they are not always available 
are still not shipped as a part of Swift WebAssembly SDK because it's still in a very early stage. Let's make shared library build optional for now and revisit after https://github.com/llvm/llvm-project/issues/103592 is solved and the shared library will be 1st citizen on WASI

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


1 Files Affected:

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


``````````diff
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index e2f39f224df9c..5616a40164bd1 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -1,5 +1,12 @@
 # Build for the AddressSanitizer runtime support library.
 
+set(COMPILER_RT_ASAN_BUILD_SHARED_LIBS_default ON)
+if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
+  set(COMPILER_RT_ASAN_BUILD_SHARED_LIBS_default OFF)
+endif()
+option(COMPILER_RT_ASAN_BUILD_SHARED_LIBS
+	"Build AddressSanitizer shared libraries" ${COMPILER_RT_ASAN_BUILD_SHARED_LIBS_default})
+
 set(ASAN_SOURCES
   asan_allocator.cpp
   asan_activation.cpp
@@ -307,25 +314,27 @@ else()
     endif()
 
     set(ASAN_DYNAMIC_WEAK_INTERCEPTION)
-    add_compiler_rt_runtime(clang_rt.asan
-      SHARED
-      ARCHS ${arch}
-      OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
-              RTAsan_dynamic
-              # The only purpose of RTAsan_dynamic_version_script_dummy is to
-              # carry a dependency of the shared runtime on the version script.
-              # Replacing it with a straightforward
-              # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
-              # generates an order-only dependency in ninja.
-              RTAsan_dynamic_version_script_dummy
-              RTUbsan_cxx
-              ${ASAN_DYNAMIC_WEAK_INTERCEPTION}
-      CFLAGS ${ASAN_DYNAMIC_CFLAGS}
-      LINK_FLAGS ${ASAN_DYNAMIC_LINK_FLAGS}
-                ${VERSION_SCRIPT_FLAG}
-      LINK_LIBS ${ASAN_DYNAMIC_LIBS}
-      DEFS ${ASAN_DYNAMIC_DEFINITIONS}
-      PARENT_TARGET asan)
+    if (COMPILER_RT_ASAN_BUILD_SHARED_LIBS)
+      add_compiler_rt_runtime(clang_rt.asan
+        SHARED
+        ARCHS ${arch}
+        OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
+                RTAsan_dynamic
+                # The only purpose of RTAsan_dynamic_version_script_dummy is to
+                # carry a dependency of the shared runtime on the version script.
+                # Replacing it with a straightforward
+                # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
+                # generates an order-only dependency in ninja.
+                RTAsan_dynamic_version_script_dummy
+                RTUbsan_cxx
+                ${ASAN_DYNAMIC_WEAK_INTERCEPTION}
+        CFLAGS ${ASAN_DYNAMIC_CFLAGS}
+        LINK_FLAGS ${ASAN_DYNAMIC_LINK_FLAGS}
+                  ${VERSION_SCRIPT_FLAG}
+        LINK_LIBS ${ASAN_DYNAMIC_LIBS}
+        DEFS ${ASAN_DYNAMIC_DEFINITIONS}
+        PARENT_TARGET asan)
+    endif()
 
     if (SANITIZER_USE_SYMBOLS AND NOT ${arch} STREQUAL "i386")
       add_sanitizer_rt_symbols(clang_rt.asan_cxx

``````````

</details>


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


More information about the llvm-commits mailing list