Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocmPackages.llvm.clang: remove -nostdlibinc flag #370180

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

collares
Copy link
Member

@collares collares commented Jan 2, 2025

As reported in #368672, rocmPackages.llvm.libc fails to build. The proximate cause is #356162, but I think it just revealed a problem with the rocm package. More specifically, there seems to be something fishy in

I think libcxx-cxxflags only gets populated in the wrapper if libcxx is null or lib.isLLVM is true...

+ optionalString (libcxx == null && isClang && (useGccForLibs && gccForLibs.langCC or false)) ''
for dir in ${gccForLibs}/include/c++/*; do
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
done
for dir in ${gccForLibs}/include/c++/*/${targetPlatform.config}; do
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
done
''
+ optionalString (libcxx.isLLVM or false) ''
echo "-isystem ${getDev libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags
''

...but runtimes is neither:

{
lib,
stdenv,
callPackage,
rocmUpdateScript,
llvm,
}:
callPackage ../base.nix rec {
inherit stdenv rocmUpdateScript;
buildDocs = false;
buildMan = false;
buildTests = false;
targetName = "runtimes";
targetDir = targetName;
targetRuntimes = [
"libunwind"
"libcxxabi"
"libcxx"
"compiler-rt"
];
extraBuildInputs = [ llvm ];
extraCMakeFlags = [
"-DLIBCXX_INCLUDE_BENCHMARKS=OFF"
"-DLIBCXX_CXX_ABI=libcxxabi"
];
extraLicenses = [ lib.licenses.mit ];
}

Since nothing ROCm-related builds at the moment, this PR adds a minimal workaround, namely hackily removing -nostdlibinc from nix-support/cc-cflags. Turns out the gcc 14 update also caused a different libstdc++ version to be used in ROCm's wrapped Clang, so we now also pass gccForLibs explicitly.

cc @emilazy @LunNova (because of #367695) @NixOS/rocm-maintainers

Fixes #368672, fixes #369433

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@collares collares changed the title rocmPackages.llvm: fix build rocmPackages.llvm.libc: fix build Jan 2, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 101-500 labels Jan 2, 2025
@collares collares force-pushed the rocm-fix branch 2 times, most recently from 505011c to b593bd3 Compare January 2, 2025 12:48
@collares
Copy link
Member Author

collares commented Jan 2, 2025

rocm-device-libs fails to build with some errors which look related to libcxx. I'm not sure this PR is correct anymore, since it looks like rocm is supposed to be built with libstdc++ instead of libcxx and that's not currently happening. Suggestions are welcome.

Currently testing just this, which will probably use libstdc++ instead:

diff --git a/pkgs/development/rocm-modules/6/llvm/stage-2/rstdenv.nix b/pkgs/development/rocm-modules/6/llvm/stage-2/rstdenv.nix
index f83abe36cc2e..e44d0689363b 100644
--- a/pkgs/development/rocm-modules/6/llvm/stage-2/rstdenv.nix
+++ b/pkgs/development/rocm-modules/6/llvm/stage-2/rstdenv.nix
@@ -11,13 +11,13 @@
 
 overrideCC stdenv (wrapCCWith rec {
   inherit bintools;
-  libcxx = runtimes;
   cc = clang-unwrapped;
   gccForLibs = stdenv.cc.cc;
 
   extraPackages = [
     llvm
     lld
+    runtimes
   ];
 
   nixSupport.cc-cflags = [

Edit: I updated the PR to use a hackier but more straightforward strategy.

@collares collares marked this pull request as draft January 2, 2025 14:07
@emilazy
Copy link
Member

emilazy commented Jan 2, 2025

I confirm that this definitely seems messed up but sadly don’t understand ROCm enough to know what the correct solution is.

By “built with libstdc++” – do you mean the LLVM tooling itself, or does even GPU‐targeting code use libstdc++? I’d be surprised by the latter; if it has C++ support at all I’d expect it to be libc++.

@collares
Copy link
Member Author

collares commented Jan 3, 2025

@emilazy @GZGavinZhao I've updated the PR. Do you think this hack is an acceptable workaround to fix the build while #370435 is being prepared? This is the minimum change I could think of to unbreak the build.

@collares collares marked this pull request as ready for review January 3, 2025 17:45
@collares collares requested review from LunNova, emilazy and Madouura and removed request for LunNova, emilazy and Madouura January 3, 2025 17:50
@emilazy
Copy link
Member

emilazy commented Jan 3, 2025

So I guess what’s going on here is that the ROCm LLVM never bundled the patch from the main LLVM derivation to add -nostdlibinc, but does use the wrappers? Perhaps the Darwin conditional in the wrappers could just be extended for ROCm as well?

@collares
Copy link
Member Author

collares commented Jan 3, 2025

Yes, exactly, that's most of the issue. The other part is that ROCm wanted to pin GCC 12, but forgot to set gccForLibs in wrapCCWith, so it ended up using GCC 14 libstdc++ which has some incompatibilities (not exactly sure what changed).

@emilazy
Copy link
Member

emilazy commented Jan 3, 2025

Right. So this seems okay for the short term, but it’d be definitely nicer to do it in the wrapper code directly rather than adding it in and then removing it later.

@GZGavinZhao
Copy link
Contributor

As long as the build is fixed, the changes look fine! Thanks for working on this @collares!

And yes, we'll definitely replace this workaround later 😅 by either not building libc at all in #370435 or as @emilazy suggested reuse the existing LLVM code.

@collares collares changed the title rocmPackages.llvm.libc: fix build rocmPackages.llvm.clang: remove -nostdlibinc flag Jan 3, 2025
@emilazy
Copy link
Member

emilazy commented Jan 3, 2025

To be clear, doing this in the wrapper doesn’t involve reusing the entire LLVM derivation. It’s just the ((cc.isClang or false) && !targetPlatform.isDarwin) conditional in pkgs/build-support/cc-wrapper/default.nix that needs adjusting to also exclude ROCm. I’m happy to merge if that change is made.

@collares
Copy link
Member Author

collares commented Jan 3, 2025

But wouldn't changing pkgs/build-support/cc-wrapper/default.nix cause a mass rebuild? I'm not sure if you meant making the change here in this PR or in a follow-up.

@emilazy
Copy link
Member

emilazy commented Jan 3, 2025

No, because builds are based on the derivations produced after evaluation. Since this will only affect the evaluation results when targeting ROCm, there will be no more rebuilds than expected, and we can do it now.

@collares
Copy link
Member Author

collares commented Jan 3, 2025

OK, made the change, but I still have to build it. If you OK the current state of the PR, I can merge it once the build is done.

@nix-owners nix-owners bot requested a review from Ericson2314 January 3, 2025 18:52
@@ -639,7 +639,7 @@ stdenvNoCC.mkDerivation {
# no `/usr/include`, there’s essentially no risk to dropping
# the flag there. See discussion in NixOS/nixpkgs#191152.
#
+ optionalString ((cc.isClang or false) && !targetPlatform.isDarwin) ''
+ optionalString ((cc.isClang or false) && !(cc.isROCm or false) && !targetPlatform.isDarwin) ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be e.g. !targetPlatform.isROCm? Or is ROCm not actually using the proper cross‐compilation machinery?

LGTM as a temporary fix, anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offload code is treated as an auxiliary arch and doesn't fit into the current cross machinery.

eg:

host, target = x86-64
auxiliary-targets = [gfx908, gfx90a, ...]

auxiliary target code objects are embedded in the same output library/bin in a separate section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see; sounds complicated :)

This seems fine for now.

Copy link
Member Author

@collares collares Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell it isn't using the cross-compilation machinery, but to be honest I know nothing about ROCm (I'm just here because Steam broke). Maybe one of the maintainers can chime in (Edit: I hadn't seen the above comments when I wrote this comment, sorry!).

Thanks for the review!

@collares collares merged commit 634ef37 into NixOS:master Jan 3, 2025
22 checks passed
@collares collares deleted the rocm-fix branch January 3, 2025 19:32
@Tjorbenn
Copy link

Tjorbenn commented Jan 4, 2025

The issue still persists for me:

cmake flags: -GNinja -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE
=Release -DCMAKE_INSTALL_LOCALEDIR=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-libc-6.0.2/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/j3yx5caja
6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-libc-6.0.2/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-libc-6.0.2/lib -DCMAKE_INSTALL
_DOCDIR=/nix/store/jqg83sknasfcdjcxrjm8p0wx7bjy461b-rocm-llvm-libc-6.0.2-doc/share/doc/Runtimes -DCMAKE_INSTALL_INFODIR=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86
am4-rocm-llvm-libc-6.0.2/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-libc-6.0.2/share/man -DCMAKE_INSTALL_OLDINCLUDE
DIR=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-libc-6.0.2/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-li
bc-6.0.2/include -DCMAKE_INSTALL_SBINDIR=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-libc-6.0.2/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/j3yx5caja6nzqwc
7fkzi9vqnwcy86am4-rocm-llvm-libc-6.0.2/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-libc-6.0.2/lib -DCMAKE_POLICY_DEFAULT_
CMP0025=NEW -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/g8yj2r057p9ai1c1c5sj321gg2c9smcr-rocm-llvm-binutils-6.0.2/bin/strip -DCMAKE_RANLIB=/nix/store/7
sqn5142gh5asri8aqxvsvib9ii37fyq-rocm-llvm-clang-unwrapped-wrapper-6.0.2/bin/ranlib -DCMAKE_AR=/nix/store/7sqn5142gh5asri8aqxvsvib9ii37fyq-rocm-llvm-clang-unwrap
ped-wrapper-6.0.2/bin/ar -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_INSTALL_PREFIX=/nix/store/j3yx5caja6nzqwc7fkzi9vqnwcy86am4-rocm-llvm-libc
-6.0.2 -DLLVM_TARGETS_TO_BUILD=AMDGPU\;X86 -DLLVM_ENABLE_RUNTIMES=libc -DLLVM_INCLUDE_DOCS=ON -DLLVM_BUILD_DOCS=ON -DLLVM_ENABLE_SPHINX=ON -DSPHINX_OUTPUT_HTML=
ON -DSPHINX_OUTPUT_MAN=ON -DSPHINX_WARNINGS_AS_ERRORS=OFF -DLLVM_INCLUDE_TESTS=ON -DLLVM_BUILD_TESTS=ON -DLLVM_EXTERNAL_LIT=/nix/store/ll40w9mfpybkn17vs148wz472
26i7bbh-python3.12-lit-18.1.8/bin/.lit-wrapped
-- The C compiler identification is Clang 17.0.0
-- The CXX compiler identification is Clang 17.0.0
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /nix/store/7sqn5142gh5asri8aqxvsvib9ii37fyq-rocm-llvm-clang-unwrapped-wrapper-6.0.2/bin/clang
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/7sqn5142gh5asri8aqxvsvib9ii37fyq-rocm-llvm-clang-unwrapped-wrapper-6.0.2/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/7sqn5142gh5asri8aqxvsvib9ii37fyq-rocm-llvm-clang-unwrapped-wrapper-6.0.2/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find LLVM (missing: LLVM_DIR)
-- Could NOT find Clang (missing: Clang_DIR)
1 warning generated.
[7/322] Building CXX object libc/src/ctype/CMakeFiles/libc.src.ctype.isalnum.dir/isalnum.cpp.o
[8/322] Building CXX object libc/utils/testutils/CMakeFiles/libc_test_utils.dir/ExecuteFunctionUnix.cpp.o
FAILED: libc/utils/testutils/CMakeFiles/libc_test_utils.dir/ExecuteFunctionUnix.cpp.o
/nix/store/7sqn5142gh5asri8aqxvsvib9ii37fyq-rocm-llvm-clang-unwrapped-wrapper-6.0.2/bin/clang++ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_M
ACROS  -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissin
g-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring
-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=gnu++17 -MD -MT libc/uti
ls/testutils/CMakeFiles/libc_test_utils.dir/ExecuteFunctionUnix.cpp.o -MF libc/utils/testutils/CMakeFiles/libc_test_utils.dir/ExecuteFunctionUnix.cpp.o.d -o lib
c/utils/testutils/CMakeFiles/libc_test_utils.dir/ExecuteFunctionUnix.cpp.o -c /build/source/libc/utils/testutils/ExecuteFunctionUnix.cpp
/build/source/libc/utils/testutils/ExecuteFunctionUnix.cpp:10:10: fatal error: 'cassert' file not found
#include <cassert>
         ^~~~~~~~~
1 error generated.
[9/322] Building CXX object libc/src/stdio/printf_core/CMakeFiles/libc.src.stdio.printf_core.writer.dir/writer.cpp.o
[10/322] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.math_utils.dir/math_utils.cpp.o
[11/322] Building CXX object libc/src/__support/CPP/CMakeFiles/libc.src.__support.CPP.new.dir/new.cpp.o
[12/322] Building CXX object libc/src/__support/StringUtil/CMakeFiles/libc.src.__support.StringUtil.signal_to_string.dir/signal_to_string.cpp.o
[13/322] Building CXX object libc/src/__support/StringUtil/CMakeFiles/libc.src.__support.StringUtil.error_to_string.dir/error_to_string.cpp.o
[14/322] Building CXX object libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o
[15/322] Building CXX object libc/test/UnitTest/CMakeFiles/LibcUnitTest.dir/LibcTest.cpp.o
FAILED: libc/test/UnitTest/CMakeFiles/LibcUnitTest.dir/LibcTest.cpp.o
/nix/store/7sqn5142gh5asri8aqxvsvib9ii37fyq-rocm-llvm-clang-unwrapped-wrapper-6.0.2/bin/clang++ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_M
ACROS -I/build/source/libc -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings
-Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsugge
st-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=gnu+
+17 -MD -MT libc/test/UnitTest/CMakeFiles/LibcUnitTest.dir/LibcTest.cpp.o -MF libc/test/UnitTest/CMakeFiles/LibcUnitTest.dir/LibcTest.cpp.o.d -o libc/test/UnitT
est/CMakeFiles/LibcUnitTest.dir/LibcTest.cpp.o -c /build/source/libc/test/UnitTest/LibcTest.cpp
/build/source/libc/test/UnitTest/LibcTest.cpp:16:10: fatal error: 'cassert' file not found
#include <cassert>
         ^~~~~~~~~
1 error generated.
[16/322] Building CXX object libc/test/UnitTest/CMakeFiles/TestLogger.dir/TestLogger.cpp.o
ninja: build stopped: subcommand failed.

@collares
Copy link
Member Author

collares commented Jan 4, 2025

@Tjorbenn What nixpkgs commit are you testing, and what command are you using to test it? Thanks!

Edit: If you're using nixos-unstable, you can use https://nixpk.gs/pr-tracker.html?pr=370180 to check if the channel has advanced to include the fix.

@Tjorbenn
Copy link

Tjorbenn commented Jan 4, 2025

@Tjorbenn What nixpkgs commit are you testing, and what command are you using to test it? Thanks!

Edit: If you're using nixos-unstable, you can use https://nixpk.gs/pr-tracker.html?pr=370180 to check if the channel has advanced to include the fix.

Yeah my bad, nevermind. I thought that if it was merged onto the master branch, it was available in nixpkgs unstable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: rocm 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 101-500
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure: rocm-llvm-compiler-rt-6.0.2 Build failure: rocmPackages.llvm.libc
5 participants