[llvm] [Darwin] CMake warning when building sanitized libLTO on Darwin with system sanitizer library (PR #176976)

Andrew Haberlandt via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 20 09:29:28 PST 2026


https://github.com/ndrewh created https://github.com/llvm/llvm-project/pull/176976

Due to a system security policy, libLTO built with `LLVM_USE_SANITIZER` and a toolchain (i.e. Xcode) sanitizer library cannot be loaded into the toolchain `ld`. This only affects Darwin.

This adds a warning when users try to do this, and suggests a workaround (use just-built sanitizer libraries). 

rdar://168502870

>From b4a39395700467393bf15f4361c2cc4f842f3e4a Mon Sep 17 00:00:00 2001
From: Andrew Haberlandt <ahaberlandt at apple.com>
Date: Tue, 20 Jan 2026 09:21:03 -0800
Subject: [PATCH] [Darwin] CMake warning when building sanitized libLTO with
 system sanitizer library

rdar://168502870
---
 llvm/tools/lto/CMakeLists.txt | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/llvm/tools/lto/CMakeLists.txt b/llvm/tools/lto/CMakeLists.txt
index 2c23e4418ac36..bc0952b1980b6 100644
--- a/llvm/tools/lto/CMakeLists.txt
+++ b/llvm/tools/lto/CMakeLists.txt
@@ -48,6 +48,15 @@ if(LLVM_ENABLE_PIC)
     set_property(TARGET LTO APPEND_STRING PROPERTY
                 LINK_FLAGS
                 " -compatibility_version 1 -current_version ${LTO_VERSION}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
+    if(LLVM_USE_SANITIZER)
+      execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=lib
+                      OUTPUT_VARIABLE clang_lib_dir)
+      string(STRIP ${clang_lib_dir} clang_lib_dir)
+      if (clang_lib_dir MATCHES ".*xctoolchain.*")
+        message(WARNING "Sanitized libLTO (with LLVM_USE_SANITIZER) is unsupported on Darwin when compiling "
+                        "with a system sanitizer library. Please use just-built sanitizers.")
+      endif()
+    endif()
   endif()
 
 endif()



More information about the llvm-commits mailing list