From 368f14b5011a5f19415b7cb2814be0d2c636a8bd Mon Sep 17 00:00:00 2001 From: Luna Nova Date: Sat, 1 Nov 2025 13:14:41 -0700 Subject: [PATCH 1/2] rocmPackages.llvm: remove workaround for LLVMgold-path.patch Prior to overrideScope support for llvmPackages, LLVMgold-path.patch would point at a non-overridden LLVM and needed replaced. Now that we use overrideScope we can drop this patch. --- pkgs/development/rocm-modules/6/llvm/default.nix | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pkgs/development/rocm-modules/6/llvm/default.nix b/pkgs/development/rocm-modules/6/llvm/default.nix index 3b03a66574c2f..cd788383b96fd 100644 --- a/pkgs/development/rocm-modules/6/llvm/default.nix +++ b/pkgs/development/rocm-modules/6/llvm/default.nix @@ -213,12 +213,7 @@ let echo 'export CXX=clang++' >> $out/nix-support/setup-hook ''; # Removes patches which either aren't desired, or don't apply against ROCm LLVM - removeInapplicablePatches = - x: - ( - (lib.strings.hasSuffix "add-nostdlibinc-flag.patch" (baseNameOf x)) - || (lib.strings.hasSuffix "clang-at-least-16-LLVMgold-path.patch" (baseNameOf x)) - ); + removeInapplicablePatches = x: (lib.strings.hasSuffix "add-nostdlibinc-flag.patch" (baseNameOf x)); tablegenUsage = x: !(lib.strings.hasInfix "llvm-tblgen" x); llvmTargetsFlag = "-DLLVM_TARGETS_TO_BUILD=AMDGPU;${ { @@ -387,11 +382,6 @@ overrideLlvmPackagesRocm (s: { url = "https://github.com/GZGavinZhao/rocm-llvm-project/commit/6d296f879b0fed830c54b2a9d26240da86c8bb3a.patch"; relative = "clang"; }) - # FIXME: Temporarily kept for rebuild avoidance - # Should be dropped in followup and we no longer need to filter out the original application - (replaceVars ./../../../compilers/llvm/common/clang/clang-at-least-16-LLVMgold-path.patch { - libllvmLibdir = "${s.final.libllvm.lib}/lib"; - }) ]; hardeningDisable = [ "all" ]; nativeBuildInputs = old.nativeBuildInputs ++ [ From 6ff66dc257d70572bad647126cec5785495ce0f1 Mon Sep 17 00:00:00 2001 From: Luna Nova Date: Sat, 1 Nov 2025 19:00:46 -0700 Subject: [PATCH 2/2] rocmPackages.llvm: remove unnecessary filtering of nostdlibinc patch add-nostdlibinc-flag.patch is no longer needed as it was moved to the cc-wrapper --- .../rocm-modules/6/llvm/default.nix | 148 +++++++++--------- 1 file changed, 70 insertions(+), 78 deletions(-) diff --git a/pkgs/development/rocm-modules/6/llvm/default.nix b/pkgs/development/rocm-modules/6/llvm/default.nix index cd788383b96fd..63da17d84e4d2 100644 --- a/pkgs/development/rocm-modules/6/llvm/default.nix +++ b/pkgs/development/rocm-modules/6/llvm/default.nix @@ -212,8 +212,6 @@ let echo 'export CC=clang' >> $out/nix-support/setup-hook echo 'export CXX=clang++' >> $out/nix-support/setup-hook ''; - # Removes patches which either aren't desired, or don't apply against ROCm LLVM - removeInapplicablePatches = x: (lib.strings.hasSuffix "add-nostdlibinc-flag.patch" (baseNameOf x)); tablegenUsage = x: !(lib.strings.hasInfix "llvm-tblgen" x); llvmTargetsFlag = "-DLLVM_TARGETS_TO_BUILD=AMDGPU;${ { @@ -349,83 +347,77 @@ overrideLlvmPackagesRocm (s: { (s.prev.clang-unwrapped.override { enableClangToolsExtra = false; }).overrideAttrs - ( - old: - let - filteredPatches = builtins.filter (x: !(removeInapplicablePatches x)) old.patches; - in - { - passthru = old.passthru // { - inherit gcc-prefix; - }; - patches = [ - (fetchpatch { - # [PATCH] [clang] Install scan-build-py into plain "lib" directory - # Backported so 19/clang/gnu-install-dirs patch applies to AMD's LLVM fork - hash = "sha256-bOqAjBwRKcERpQkiBpuojGs6ddd5Ht3zL5l3TuJK2w8="; - url = "https://github.com/llvm/llvm-project/commit/816fde1cbb700ebcc8b3df81fb93d675c04c12cd.patch"; - relative = "clang"; - }) - ] - ++ filteredPatches - ++ [ - # Never add FHS include paths - ./clang-bodge-ignore-systemwide-incls.diff - # Prevents builds timing out if a single compiler invocation is very slow but - # per-arch jobs are completing by ensuring there's terminal output - ./clang-log-jobs.diff - ./opt-offload-compress-on-by-default.patch - ./perf-shorten-gcclib-include-paths.patch - (fetchpatch { - # [ClangOffloadBundler]: Add GetBundleIDsInFile to OffloadBundler - sha256 = "sha256-G/mzUdFfrJ2bLJgo4+mBcR6Ox7xGhWu5X+XxT4kH2c8="; - url = "https://github.com/GZGavinZhao/rocm-llvm-project/commit/6d296f879b0fed830c54b2a9d26240da86c8bb3a.patch"; - relative = "clang"; - }) - ]; - hardeningDisable = [ "all" ]; - nativeBuildInputs = old.nativeBuildInputs ++ [ - removeReferencesTo - ]; - buildInputs = old.buildInputs ++ [ - zstd - zlib + (old: { + passthru = old.passthru // { + inherit gcc-prefix; + }; + patches = [ + (fetchpatch { + # [PATCH] [clang] Install scan-build-py into plain "lib" directory + # Backported so 19/clang/gnu-install-dirs patch applies to AMD's LLVM fork + hash = "sha256-bOqAjBwRKcERpQkiBpuojGs6ddd5Ht3zL5l3TuJK2w8="; + url = "https://github.com/llvm/llvm-project/commit/816fde1cbb700ebcc8b3df81fb93d675c04c12cd.patch"; + relative = "clang"; + }) + ] + ++ old.patches + ++ [ + # Never add FHS include paths + ./clang-bodge-ignore-systemwide-incls.diff + # Prevents builds timing out if a single compiler invocation is very slow but + # per-arch jobs are completing by ensuring there's terminal output + ./clang-log-jobs.diff + ./opt-offload-compress-on-by-default.patch + ./perf-shorten-gcclib-include-paths.patch + (fetchpatch { + # [ClangOffloadBundler]: Add GetBundleIDsInFile to OffloadBundler + sha256 = "sha256-G/mzUdFfrJ2bLJgo4+mBcR6Ox7xGhWu5X+XxT4kH2c8="; + url = "https://github.com/GZGavinZhao/rocm-llvm-project/commit/6d296f879b0fed830c54b2a9d26240da86c8bb3a.patch"; + relative = "clang"; + }) + ]; + hardeningDisable = [ "all" ]; + nativeBuildInputs = old.nativeBuildInputs ++ [ + removeReferencesTo + ]; + buildInputs = old.buildInputs ++ [ + zstd + zlib + ]; + env = (old.env or { }) // { + NIX_CFLAGS_COMPILE = "${(old.env or { }).NIX_CFLAGS_COMPILE or ""} ${llvmExtraCflags}"; + }; + dontStrip = profilableStdenv; + # Ensure we don't leak refs to compiler that was used to bootstrap this LLVM + disallowedReferences = (old.disallowedReferences or [ ]) ++ disallowedRefsForToolchain; + # Enable structured attrs for separateDebugInfo, because it is required with disallowedReferences set + __structuredAttrs = true; + # https://github.com/llvm/llvm-project/blob/6976deebafa8e7de993ce159aa6b82c0e7089313/clang/cmake/caches/DistributionExample-stage2.cmake#L9-L11 + cmakeFlags = + # TODO: Remove in followup, tblgen now works correctly but would rebuild + (builtins.filter tablegenUsage old.cmakeFlags) + ++ commonCmakeFlags + ++ lib.optionals (!withLibcxx) [ + # FIXME: Config file in rocm-toolchain instead of GCC_INSTALL_PREFIX? + # Expected to be fully removed eventually + "-DUSE_DEPRECATED_GCC_INSTALL_PREFIX=ON" + "-DGCC_INSTALL_PREFIX=${gcc-prefix}" ]; - env = (old.env or { }) // { - NIX_CFLAGS_COMPILE = "${(old.env or { }).NIX_CFLAGS_COMPILE or ""} ${llvmExtraCflags}"; - }; - dontStrip = profilableStdenv; - # Ensure we don't leak refs to compiler that was used to bootstrap this LLVM - disallowedReferences = (old.disallowedReferences or [ ]) ++ disallowedRefsForToolchain; - # Enable structured attrs for separateDebugInfo, because it is required with disallowedReferences set - __structuredAttrs = true; - # https://github.com/llvm/llvm-project/blob/6976deebafa8e7de993ce159aa6b82c0e7089313/clang/cmake/caches/DistributionExample-stage2.cmake#L9-L11 - cmakeFlags = - # TODO: Remove in followup, tblgen now works correctly but would rebuild - (builtins.filter tablegenUsage old.cmakeFlags) - ++ commonCmakeFlags - ++ lib.optionals (!withLibcxx) [ - # FIXME: Config file in rocm-toolchain instead of GCC_INSTALL_PREFIX? - # Expected to be fully removed eventually - "-DUSE_DEPRECATED_GCC_INSTALL_PREFIX=ON" - "-DGCC_INSTALL_PREFIX=${gcc-prefix}" - ]; - preFixup = '' - ${toString old.preFixup or ""} - moveToOutput "lib/lib*.a" "$dev" - moveToOutput "lib/cmake" "$dev" - mkdir -p $dev/lib/clang/ - ln -s $lib/lib/clang/${llvmMajorVersion} $dev/lib/clang/ - sed -Ei "s|$lib/lib/(lib[^/]*)\.a|$dev/lib/\1.a|g" $dev/lib/cmake/clang/*.cmake - ''; - postFixup = '' - ${toString old.postFixup or ""} - find $lib -type f -exec remove-references-to -t ${refsToRemove} {} + - find $dev -type f -exec remove-references-to -t ${refsToRemove} {} + - ''; - meta = old.meta // llvmMeta; - } - ) + preFixup = '' + ${toString old.preFixup or ""} + moveToOutput "lib/lib*.a" "$dev" + moveToOutput "lib/cmake" "$dev" + mkdir -p $dev/lib/clang/ + ln -s $lib/lib/clang/${llvmMajorVersion} $dev/lib/clang/ + sed -Ei "s|$lib/lib/(lib[^/]*)\.a|$dev/lib/\1.a|g" $dev/lib/cmake/clang/*.cmake + ''; + postFixup = '' + ${toString old.postFixup or ""} + find $lib -type f -exec remove-references-to -t ${refsToRemove} {} + + find $dev -type f -exec remove-references-to -t ${refsToRemove} {} + + ''; + meta = old.meta // llvmMeta; + }) ); # A clang that understands standard include searching in a GNU sysroot and will put GPU libs in include path # in the right order