[libc-commits] [compiler-rt] [libc] [llvm] [libc][scudo] Use RUNTIMES_USE_LIBC to decide if scudo uses LLVM-libc (PR #239496)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Thu Nov 5 23:23:37 PST 2026


https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/239496

`RUNTIMES_USE_LIBC` CMake flag is now responsible for defining which libc is
used to build compiler-rt runtime libraries. In particular, it provides
`runtimes-libc-headers` interface library, which achieves three important goals
when we're using `llvm-libc`:
* sets up proper include directories to use LLVM-libc headers;
* ensures that LLVM-libc generated headers will be produced;
* Adds `-nostdlibinc` and propagates Linux kernel headers inclusion paths so that
  they match what LLVM-libc itself is using.

Instead of using ad-hoc flag `COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC`
just rely on the value of `RUNTIMES_USE_LIBC=llvm-libc` when we're building Scudo
allocator for use with LLVM-libc. Importantly, this fixes the cross-build of Scudo allocator,
since it will now pick up the correct headers from `-DLIBC_KERNEL_HEADERS` instead
of using host system's kernel headers.

All users of `-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON`
would need to be switched to `-DRUNTIMES_USE_LIBC=llvm-libc`, but thankfully
there are not too many of them. Update the Github workflow that needs it, as well as
LLVM-libc docs (libc++ CI already has the correct `RUNTIMES_USE_LIBC` value).

This change makes `COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC`
flag a no-op, but I leave it as-is for now and delete it in a follow-up change.

>From f046a12e811ff7ba61353ecea1633e982633c351 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Fri, 6 Nov 2026 06:12:02 +0000
Subject: [PATCH] [libc][scudo] Use RUNTIMES_USE_LIBC value to determine if
 scudo uses LLVM-libc.

---
 .github/workflows/libc-fullbuild-tests.yml    |  2 ++
 compiler-rt/cmake/Modules/AddCompilerRT.cmake |  6 +++++-
 .../lib/scudo/standalone/CMakeLists.txt       | 21 ++++++++++---------
 libc/docs/build_and_test.md                   |  2 +-
 libc/docs/full_host_build.md                  |  4 ++--
 libc/docs/getting_started.md                  |  2 +-
 6 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/.github/workflows/libc-fullbuild-tests.yml b/.github/workflows/libc-fullbuild-tests.yml
index dbd14888e99e81..27ad740619a48d 100644
--- a/.github/workflows/libc-fullbuild-tests.yml
+++ b/.github/workflows/libc-fullbuild-tests.yml
@@ -213,6 +213,8 @@ jobs:
 
         if [[ "${{ matrix.include_scudo }}" == "ON" || "${{ matrix.build_fuzzing_tests }}" == "ON" || "${{ matrix.build_builtins }}" == "ON" ]]; then
           export RUNTIMES="$RUNTIMES;compiler-rt"
+          export CMAKE_FLAGS="$CMAKE_FLAGS
+            -DRUNTIMES_USE_LIBC=llvm-libc"
         fi
 
         if [[ "${{ matrix.include_scudo }}" == "ON" ]]; then
diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index bd9aa3a52884f2..9473d673103ff7 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -72,9 +72,10 @@ endfunction()
 #                                  CFLAGS <compile flags>
 #                                  DEFS <compile definitions>
 #                                  DEPS <dependencies>
+#                                  LINK_LIBS <linked libraries>
 #                                  ADDITIONAL_HEADERS <header files>)
 function(add_compiler_rt_object_libraries name)
-  cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS;DEPS;ADDITIONAL_HEADERS"
+  cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS;DEPS;LINK_LIBS;ADDITIONAL_HEADERS"
     ${ARGN})
   set(libnames)
   if(APPLE)
@@ -108,6 +109,9 @@ function(add_compiler_rt_object_libraries name)
     if(LIB_DEPS)
       add_dependencies(${libname} ${LIB_DEPS})
     endif()
+    if(LIB_LINK_LIBS)
+      target_link_libraries(${libname} PRIVATE ${LIB_LINK_LIBS})
+    endif()
 
     # Strip out -msse3 if this isn't macOS.
     set(target_flags ${LIB_CFLAGS})
diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
index 20c59b46006136..84744598fbb45c 100644
--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -156,6 +156,7 @@ set(SCUDO_SOURCES_CXX_WRAPPERS
 
 set(SCUDO_OBJECT_LIBS)
 set(SCUDO_LINK_LIBS)
+set(SCUDO_HEADERS_LIBS)
 
 if (COMPILER_RT_HAS_GWP_ASAN)
   if(COMPILER_RT_USE_LLVM_UNWINDER)
@@ -180,10 +181,11 @@ if (COMPILER_RT_HAS_GWP_ASAN)
 
 endif()
 
-if(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
-  include_directories(${COMPILER_RT_BINARY_DIR}/../libc/include/)
-
-  set(SCUDO_DEPS libc-headers)
+if(RUNTIMES_USE_LIBC STREQUAL "llvm-libc")
+  if(TARGET runtimes-libc-headers)
+    list(APPEND SCUDO_HEADERS_LIBS runtimes-libc-headers)
+    list(APPEND SCUDO_LINK_LIBS runtimes-libc-headers)
+  endif()
 
   list(APPEND SCUDO_CFLAGS "-ffreestanding")
 endif()
@@ -201,19 +203,19 @@ add_compiler_rt_object_libraries(RTScudoStandalone
   SOURCES ${SCUDO_SOURCES}
   ADDITIONAL_HEADERS ${SCUDO_HEADERS}
   CFLAGS ${SCUDO_CFLAGS}
-  DEPS ${SCUDO_DEPS})
+  LINK_LIBS ${SCUDO_HEADERS_LIBS})
 add_compiler_rt_object_libraries(RTScudoStandaloneCWrappers
   ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
   SOURCES ${SCUDO_SOURCES_C_WRAPPERS}
   ADDITIONAL_HEADERS ${SCUDO_HEADERS}
   CFLAGS ${SCUDO_CFLAGS}
-  DEPS ${SCUDO_DEPS})
+  LINK_LIBS ${SCUDO_HEADERS_LIBS})
 add_compiler_rt_object_libraries(RTScudoStandaloneCxxWrappers
   ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
   SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
   ADDITIONAL_HEADERS ${SCUDO_HEADERS}
   CFLAGS ${SCUDO_CFLAGS}
-  DEPS ${SCUDO_DEPS})
+  LINK_LIBS ${SCUDO_HEADERS_LIBS})
 
 add_compiler_rt_runtime(clang_rt.scudo_standalone
   STATIC
@@ -221,7 +223,7 @@ add_compiler_rt_runtime(clang_rt.scudo_standalone
   SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS}
   ADDITIONAL_HEADERS ${SCUDO_HEADERS}
   CFLAGS ${SCUDO_CFLAGS}
-  DEPS ${SCUDO_DEPS}
+  LINK_LIBS ${SCUDO_HEADERS_LIBS}
   OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
   PARENT_TARGET scudo_standalone)
 add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx
@@ -230,7 +232,7 @@ add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx
   SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
   ADDITIONAL_HEADERS ${SCUDO_HEADERS}
   CFLAGS ${SCUDO_CFLAGS}
-  DEPS ${SCUDO_DEPS}
+  LINK_LIBS ${SCUDO_HEADERS_LIBS}
   PARENT_TARGET scudo_standalone)
 
 if(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
@@ -240,7 +242,6 @@ if(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
     SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} ${SCUDO_SOURCES_CXX_WRAPPERS}
     ADDITIONAL_HEADERS ${SCUDO_HEADERS}
     CFLAGS ${SCUDO_CFLAGS}
-    DEPS ${SCUDO_DEPS}
     OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
     LINK_FLAGS ${SCUDO_LINK_FLAGS}
     LINK_LIBS ${SCUDO_LINK_LIBS}
diff --git a/libc/docs/build_and_test.md b/libc/docs/build_and_test.md
index 77824e59cb1f97..7c33fb9a445d28 100644
--- a/libc/docs/build_and_test.md
+++ b/libc/docs/build_and_test.md
@@ -55,7 +55,7 @@ and put the following in your settings.json file:
     "LLVM_ENABLE_SPHINX" : true,
     "LIBC_INCLUDE_DOCS" : true,
     "LLVM_LIBC_INCLUDE_SCUDO" : true,
-    "COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC": true,
+    "RUNTIMES_USE_LIBC" : "llvm-libc",
     "COMPILER_RT_BUILD_GWP_ASAN" : false,
     "COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED" : false,
     "CMAKE_EXPORT_COMPILE_COMMANDS" : true,
diff --git a/libc/docs/full_host_build.md b/libc/docs/full_host_build.md
index f564b03dd57ef0..25cb9cd08cdfe8 100644
--- a/libc/docs/full_host_build.md
+++ b/libc/docs/full_host_build.md
@@ -37,7 +37,7 @@ cmake \
    -DLLVM_LIBC_FULL_BUILD=ON \
    -DCMAKE_BUILD_TYPE=Debug \
    -DLLVM_LIBC_INCLUDE_SCUDO=ON \
-   -DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON \
+   -DRUNTIMES_USE_LIBC=llvm-libc \
    -DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
    -DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF \
    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
@@ -176,7 +176,7 @@ cmake \
    -DLLVM_LIBC_FULL_BUILD=ON \
    -DLIBC_INCLUDE_DOCS=OFF \
    -DLLVM_LIBC_INCLUDE_SCUDO=ON \
-   -DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON \
+   -DRUNTIMES_USE_LIBC=llvm-libc \
    -DCOMPILER_RT_BUILD_GWP_ASAN=OFF                       \
    -DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF        \
    -DCOMPILER_RT_BUILD_BUILTINS:BOOL=TRUE \
diff --git a/libc/docs/getting_started.md b/libc/docs/getting_started.md
index 810ff8095be18b..01fdce0c5f0837 100644
--- a/libc/docs/getting_started.md
+++ b/libc/docs/getting_started.md
@@ -34,7 +34,7 @@ cmake -G Ninja -S runtimes -B build \
   -DCMAKE_C_COMPILER=clang \
   -DCMAKE_CXX_COMPILER=clang++ \
   -DLLVM_LIBC_INCLUDE_SCUDO=ON \
-  -DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON \
+  -DRUNTIMES_USE_LIBC=llvm-libc \
   -DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
   -DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF \
   -DCMAKE_EXPORT_COMPILE_COMMANDS=ON



More information about the libc-commits mailing list