-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
clang_9: fix compilation of HIP-code #77476
Conversation
When compiling HIP-code clang executes other llvm binaries, such as llvm-link, llc or opt. Clang expects these binaries in the folder with the clang-executable (...clang/bin/), this is not true for nix, because these binaris are in the llvm/bin folder. It is not possible to simply replace the path of the called library, because then the compilation with gcc fails. While I personally did not encounter a problem with clang failing due to calling lld I added it for completeness, this however means clang also depends on the llvm binutils.
Does this just effect clang 9 or should we do it for other clang versions as well? |
sed -i -e 's|SmallString<128> ExecPath(C.getDriver().Dir);|SmallString<128> ExecPath(C.getDriver().Name.find("clang") != std::string::npos ? "${llvm}/bin" : C.getDriver().Dir);|' \ | ||
-e 's|SmallString<128> OptPath(C.getDriver().Dir);|SmallString<128> OptPath(C.getDriver().Name.find("clang") != std::string::npos ? "${llvm}/bin" : C.getDriver().Dir);|' \ | ||
-e 's|SmallString<128> LlcPath(C.getDriver().Dir);|SmallString<128> LlcPath(C.getDriver().Name.find("clang") != std::string::npos ? "${llvm}/bin" : C.getDriver().Dir);|' \ | ||
-e 's|SmallString<128> LldPath(C.getDriver().Dir);|SmallString<128> LldPath(C.getDriver().Name.find("clang") != std::string::npos ? "${bintools}/bin" : C.getDriver().Dir);|' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
binutils only has lld for clang toolchains. We should use the lld
package here instead.
Clang already has a runtime dependency on llvm, so this is no problem (or at the worst just a few extra wrappers). Ideally we could upstream this to LLVM. I think instead of using |
As far as I found, the commit introducing the code is present since llvm 7.0.0 (and will currently also be present in llvm 10). I haven't tried versions other than 9, because I haven't found good test code for checking. |
I confirmed the problem with clang 8 and 9, for clang7 I would need some more work to get older versions of the device libraries. |
This PR aims to fix the same problem as NixOS/nixpkgs PR NixOS#77476; enabling to compile HIP-code using the packaged clang compiler, by also searching in $PATH for required binaries. The change is committed upstream (https://reviews.llvm.org/D72903), but will not land in the clang versions in nixpkgs (only clang 10+). As such I have created patches for the affected versions. To compile HIP-code lld is needed, so I added it to the clang-package.<Paste>
Motivation for this change
When compiling HIP-code clang executes other llvm binaries, such as
llvm-link, llc or opt. Clang expects these binaries in the folder with
the clang-executable (...clang/bin/), this is not true for nix, because
these binaries are in the llvm/bin folder. It is not possible to simply
replace the path of the called library, because then the compilation
with gcc fails. While I personally did not encounter a problem with
clang failing due to calling lld I added it for completeness, this
however means clang also depends on the llvm binutils.
Maybe older clang versions have the same flaw, I did not check this yet since my test setup only works with clang9 at the moment. Also I am not sure whether this is the most elegant solution, since I don't have too much experience with clang or nix.
Things done
I checked for successful compilation using this this setup. Building this was not possible without this change.
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)