From 14647cefc084282ea02fb4d5c1b896960533962c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 27 Feb 2025 18:21:34 -0800 Subject: [PATCH 1/5] llvmPackages_20.libc-full: fix building --- .../compilers/llvm/common/libc/default.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/libc/default.nix b/pkgs/development/compilers/llvm/common/libc/default.nix index 6ccc7e44ff61..6e54fef55d9b 100644 --- a/pkgs/development/compilers/llvm/common/libc/default.nix +++ b/pkgs/development/compilers/llvm/common/libc/default.nix @@ -46,6 +46,7 @@ stdenv.mkDerivation (finalAttrs: { outputs = [ "out" ] ++ (lib.optional isFullBuild "dev"); postUnpack = lib.optionalString isFullBuild '' + chmod +w $sourceRoot/../$pname/utils/hdrgen patchShebangs $sourceRoot/../$pname/utils/hdrgen/main.py chmod +x $sourceRoot/../$pname/utils/hdrgen/main.py ''; @@ -65,10 +66,20 @@ stdenv.mkDerivation (finalAttrs: { libc = if (!isFullBuild) then stdenv.cc.libc else null; - cmakeFlags = [ - (lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild) - (lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc") - ]; + cmakeFlags = + [ + (lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild) + (lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc") + # Tests requires the host to have a libc. + (lib.cmakeBool "LLVM_INCLUDE_TESTS" (stdenv.cc.libc != null)) + ] + ++ lib.optional (isFullBuild && stdenv.cc.libc == null) [ + # CMake runs a check to see if the compiler works. + # This includes including headers which requires a libc. + # Skip these checks because a libc cannot be used when one doesn't exist. + (lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true) + (lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true) + ]; # For the update script: passthru = { From bf31adf9adef8c165b6d61b33aab495288563001 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Wed, 19 Mar 2025 17:52:07 -0700 Subject: [PATCH 2/5] llvmPackages_20.libc-full: fix infinite recursion with pkgsLLVMLibc in cmake & python3 --- pkgs/development/compilers/llvm/common/default.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 225abc626e42..5cf68c1dd695 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -14,6 +14,7 @@ overrideCC, wrapCCWith, wrapBintoolsWith, + buildPackages, buildLlvmTools, # tools, but from the previous stage, for cross targetLlvmLibraries, # libraries, but from the next stage, for cross targetLlvm, @@ -576,6 +577,13 @@ let # Use clang due to "gnu::naked" not working on aarch64. # Issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77882 stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcNoRt; + cmake = + if stdenv.targetPlatform.libc == "llvm" then buildPackages.cmakeMinimal else buildPackages.cmake; + python3 = + if stdenv.targetPlatform.libc == "llvm" then + buildPackages.python3Minimal + else + buildPackages.python3; }; libc = if stdenv.targetPlatform.libc == "llvm" then libraries.libc-full else libraries.libc-overlay; From 3b56cf6ff8296bd586640f78fa42cdf6709d60ed Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 20 Mar 2025 08:06:42 -0700 Subject: [PATCH 3/5] llvmPackages.clangNoLibcNoRt: drop nostartfiles flag `-nostartfiles` used to be needed for pkgsLLVM, causes problems so don't include it. --- .../compilers/llvm/common/default.nix | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 5cf68c1dd695..e499dfd81c56 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -424,18 +424,14 @@ let libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; - extraBuildCommands = - lib.optionalString (lib.versions.major metadata.release_version == "13") '' - echo "-nostartfiles" >> $out/nix-support/cc-cflags - '' - + mkExtraBuildCommands0 cc; + # "-nostartfiles" used to be needed for pkgsLLVM, causes problems so don't include it. + extraBuildCommands = mkExtraBuildCommands0 cc; } // lib.optionalAttrs (lib.versionAtLeast metadata.release_version "14") { - nixSupport.cc-cflags = - [ "-nostartfiles" ] - ++ lib.optional ( - lib.versionAtLeast metadata.release_version "15" && stdenv.targetPlatform.isWasm - ) "-fno-exceptions"; + # "-nostartfiles" used to be needed for pkgsLLVM, causes problems so don't include it. + nixSupport.cc-cflags = lib.optional ( + lib.versionAtLeast metadata.release_version "15" && stdenv.targetPlatform.isWasm + ) "-fno-exceptions"; } ); From 05219927d04b130cabee3d780606910c2cfd08bd Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 20 Mar 2025 21:59:35 -0700 Subject: [PATCH 4/5] lib.systems: mark LLVM libc as static --- lib/systems/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index ec0106a13dac..3b6840720147 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -200,7 +200,7 @@ let # don't support dynamic linking, but don't get the `staticMarker`. # `pkgsStatic` sets `isStatic=true`, so `pkgsStatic.hostPlatform` always # has the `staticMarker`. - isStatic = final.isWasi || final.isRedox; + isStatic = final.isWasi || final.isRedox || final.isLLVMLibc; # Just a guess, based on `system` inherit From 9f9526053a98e772a123d1015eece437babf1edd Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 20 Mar 2025 22:00:23 -0700 Subject: [PATCH 5/5] llvmPackages_20.libc: enable scudo & link Scrt1 --- .../compilers/llvm/common/libc/default.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/libc/default.nix b/pkgs/development/compilers/llvm/common/libc/default.nix index 6e54fef55d9b..ecb70c783431 100644 --- a/pkgs/development/compilers/llvm/common/libc/default.nix +++ b/pkgs/development/compilers/llvm/common/libc/default.nix @@ -23,6 +23,7 @@ let cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/runtimes "$out" cp -r ${monorepoSrc}/llvm "$out" + cp -r ${monorepoSrc}/compiler-rt "$out" cp -r ${monorepoSrc}/${pname} "$out" ''); in @@ -60,18 +61,28 @@ stdenv.mkDerivation (finalAttrs: { cd ../runtimes ''; - postInstall = lib.optionalString (!isFullBuild) '' - substituteAll ${./libc-shim.tpl} $out/lib/libc.so - ''; + postInstall = + lib.optionalString (!isFullBuild) '' + substituteAll ${./libc-shim.tpl} $out/lib/libc.so + '' + # LLVM libc doesn't recognize static vs dynamic yet. + # Treat LLVM libc as a static libc, requires this symlink until upstream fixes it. + + lib.optionalString (isFullBuild && stdenv.hostPlatform.isLinux) '' + ln $out/lib/crt1.o $out/lib/Scrt1.o + ''; libc = if (!isFullBuild) then stdenv.cc.libc else null; cmakeFlags = [ (lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild) - (lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc") + (lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc;compiler-rt") # Tests requires the host to have a libc. (lib.cmakeBool "LLVM_INCLUDE_TESTS" (stdenv.cc.libc != null)) + (lib.cmakeBool "LLVM_LIBC_INCLUDE_SCUDO" true) + (lib.cmakeBool "COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC" true) + (lib.cmakeBool "COMPILER_RT_BUILD_GWP_ASAN" false) + (lib.cmakeBool "COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED" false) ] ++ lib.optional (isFullBuild && stdenv.cc.libc == null) [ # CMake runs a check to see if the compiler works.