[compiler-rt] [compiler-rt] Allow building builtins.a without a libc (PR #86737)

Jon Chesterfield via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 13:55:31 PDT 2024


https://github.com/JonChesterfield created https://github.com/llvm/llvm-project/pull/86737

compiler-rt may depend on libc (memset, pthread_mutex_lock etc). Likewise a libc built by clang may depend on compiler-rt builtins.

This circular dependency doesn't matter much once they're both compiled. The easy compilation order to build both from source is:

1. install libc headers somewhere
2. build compiler-rt builtins against those headers
3. build libc against compiler-rt builtins

This patch relaxes the cmake sanity check to pass when libc headers are present, without requiring a libc library. That allows the above sequence to work. Otherwise one needs to build a static libc, then use that to pass the compiler-rt cmake check, then build a normal libc. 




>From 62fa1a4ab1c244ed78cea9fd4d13197896bd47f5 Mon Sep 17 00:00:00 2001
From: Jon Chesterfield <jonathanchesterfield at gmail.com>
Date: Tue, 26 Mar 2024 20:46:58 +0000
Subject: [PATCH] [compiler-rt] Allow building builtins.a without a libc

---
 compiler-rt/cmake/config-ix.cmake | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 2ca18ebb4ad489..9bac923a544ea6 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -235,9 +235,10 @@ set(COMPILER_RT_SUPPORTED_ARCH)
 # Try to compile a very simple source file to ensure we can target the given
 # platform. We use the results of these tests to build only the various target
 # runtime libraries supported by our current compilers cross-compiling
-# abilities.
+# abilities. Checks a libc header (possibly provided by clang) is available
+# and does not need to link against an existing libc to run.
 set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
-file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <stdio.h>\nint main(void) { printf(\"hello, world\"); }\n")
+file(WRITE ${SIMPLE_SOURCE} "#include <stdint.h>\nint main(void) { return 0; }\n")
 
 # Detect whether the current target platform is 32-bit or 64-bit, and setup
 # the correct commandline flags needed to attempt to target 32-bit and 64-bit.



More information about the llvm-commits mailing list