diff --git a/pkgs/development/compilers/llvm/7/clang/HIP-use-PATH-7.patch b/pkgs/development/compilers/llvm/7/clang/HIP-use-PATH-7.patch new file mode 100644 index 00000000000..764dddd966c --- /dev/null +++ b/pkgs/development/compilers/llvm/7/clang/HIP-use-PATH-7.patch @@ -0,0 +1,68 @@ +From 8412cba68835f8f4cc527d02194b181faa5944d4 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Holger=20W=C3=BCnsche?= +Date: Tue, 21 Jan 2020 19:46:09 +0100 +Subject: [PATCH] [HIP] use GetProgramPath for executable discovery + +This change replaces the manual building of executable paths +using llvm::sys::path::append with GetProgramPath. +This enables adding other paths in case executables reside +in different directories and makes the code easier to read. + +Differential Revision: https://reviews.llvm.org/D72903 +--- + clang/lib/Driver/ToolChains/HIP.cpp | 18 ++++++------------ + 1 file changed, 6 insertions(+), 12 deletions(-) + +diff --git a/lib/Driver/ToolChains/HIP.cpp b/lib/Driver/ToolChains/HIP.cpp +index 03acf45a9b3..75fd3226c75 100644 +--- a/lib/Driver/ToolChains/HIP.cpp ++++ b/lib/Driver/ToolChains/HIP.cpp +@@ -98,9 +98,8 @@ const char *AMDGCN::Linker::constructLLVMLinkCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpName)); + CmdArgs.push_back(OutputFileName); +- SmallString<128> ExecPath(C.getDriver().Dir); +- llvm::sys::path::append(ExecPath, "llvm-link"); +- const char *Exec = Args.MakeArgString(ExecPath); ++ const char *Exec = ++ Args.MakeArgString(getToolChain().GetProgramPath("llvm-link")); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); + return OutputFileName; + } +@@ -141,9 +140,8 @@ const char *AMDGCN::Linker::constructOptCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpFileName)); + OptArgs.push_back(OutputFileName); +- SmallString<128> OptPath(C.getDriver().Dir); +- llvm::sys::path::append(OptPath, "opt"); +- const char *OptExec = Args.MakeArgString(OptPath); ++ const char *OptExec = ++ Args.MakeArgString(getToolChain().GetProgramPath("opt")); + C.addCommand(llvm::make_unique(JA, *this, OptExec, OptArgs, Inputs)); + return OutputFileName; + } +@@ -161,9 +159,7 @@ const char *AMDGCN::Linker::constructLlcCommand( + const char *LlcOutputFile = + C.addTempFile(C.getArgs().MakeArgString(LlcOutputFileName)); + LlcArgs.push_back(LlcOutputFile); +- SmallString<128> LlcPath(C.getDriver().Dir); +- llvm::sys::path::append(LlcPath, "llc"); +- const char *Llc = Args.MakeArgString(LlcPath); ++ const char *Llc = Args.MakeArgString(getToolChain().GetProgramPath("llc")); + C.addCommand(llvm::make_unique(JA, *this, Llc, LlcArgs, Inputs)); + return LlcOutputFile; + } +@@ -178,9 +174,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA, + ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", + "-shared", "-o", Output.getFilename(), + InputFileName}; +- SmallString<128> LldPath(C.getDriver().Dir); +- llvm::sys::path::append(LldPath, "lld"); +- const char *Lld = Args.MakeArgString(LldPath); ++ const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); + C.addCommand(llvm::make_unique(JA, *this, Lld, LldArgs, Inputs)); + } + +-- +2.23.1 + diff --git a/pkgs/development/compilers/llvm/7/clang/default.nix b/pkgs/development/compilers/llvm/7/clang/default.nix index cc5dcfc160b..6e01f4259ee 100644 --- a/pkgs/development/compilers/llvm/7/clang/default.nix +++ b/pkgs/development/compilers/llvm/7/clang/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3 +{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3, lld , fixDarwinDylibNames , enableManpages ? false , enablePolly ? false # TODO: get this info from llvm (passthru?) @@ -22,7 +22,7 @@ let nativeBuildInputs = [ cmake python3 ] ++ stdenv.lib.optional enableManpages python3.pkgs.sphinx; - buildInputs = [ libxml2 llvm ] + buildInputs = [ libxml2 llvm lld ] ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames; cmakeFlags = [ @@ -38,7 +38,11 @@ let "-DLINK_POLLY_INTO_TOOLS=ON" ]; - patches = [ ./purity.patch ]; + patches = [ + ./purity.patch + # make clang -xhip use $PATH to find executables + ./HIP-use-PATH-7.patch + ]; postPatch = '' sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ diff --git a/pkgs/development/compilers/llvm/7/default.nix b/pkgs/development/compilers/llvm/7/default.nix index f5dbea58a7d..04e1610fb79 100644 --- a/pkgs/development/compilers/llvm/7/default.nix +++ b/pkgs/development/compilers/llvm/7/default.nix @@ -32,6 +32,7 @@ let llvm-polly = callPackage ./llvm.nix { enablePolly = true; }; clang-unwrapped = callPackage ./clang { + inherit (tools) lld; inherit clang-tools-extra_src; }; clang-polly-unwrapped = callPackage ./clang { diff --git a/pkgs/development/compilers/llvm/8/clang/HIP-use-PATH-8.patch b/pkgs/development/compilers/llvm/8/clang/HIP-use-PATH-8.patch new file mode 100644 index 00000000000..f4be100d1ab --- /dev/null +++ b/pkgs/development/compilers/llvm/8/clang/HIP-use-PATH-8.patch @@ -0,0 +1,80 @@ +From d9f1b7d7571b252e0ba2359ae6cfa93a9903c0e7 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Holger=20W=C3=BCnsche?= +Date: Tue, 21 Jan 2020 19:49:44 +0100 +Subject: [PATCH] [HIP] use GetProgramPath for executable discovery + +This change replaces the manual building of executable paths +using llvm::sys::path::append with GetProgramPath. +This enables adding other paths in case executables reside +in different directories and makes the code easier to read. + +Differential Revision: https://reviews.llvm.org/D72903 +--- + clang/lib/Driver/ToolChains/HIP.cpp | 23 ++++++++--------------- + 1 file changed, 8 insertions(+), 15 deletions(-) + +diff --git a/lib/Driver/ToolChains/HIP.cpp b/lang/lib/Driver/ToolChains/HIP.cpp +index 868765cf88e..31f2d68ec6c 100644 +--- a/lib/Driver/ToolChains/HIP.cpp ++++ b/lib/Driver/ToolChains/HIP.cpp +@@ -104,9 +104,8 @@ const char *AMDGCN::Linker::constructLLVMLinkCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpName)); + CmdArgs.push_back(OutputFileName); +- SmallString<128> ExecPath(C.getDriver().Dir); +- llvm::sys::path::append(ExecPath, "llvm-link"); +- const char *Exec = Args.MakeArgString(ExecPath); ++ const char *Exec = ++ Args.MakeArgString(getToolChain().GetProgramPath("llvm-link")); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); + return OutputFileName; + } +@@ -147,9 +146,8 @@ const char *AMDGCN::Linker::constructOptCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpFileName)); + OptArgs.push_back(OutputFileName); +- SmallString<128> OptPath(C.getDriver().Dir); +- llvm::sys::path::append(OptPath, "opt"); +- const char *OptExec = Args.MakeArgString(OptPath); ++ const char *OptExec = ++ Args.MakeArgString(getToolChain().GetProgramPath("opt")); + C.addCommand(llvm::make_unique(JA, *this, OptExec, OptArgs, Inputs)); + return OutputFileName; + } +@@ -167,9 +165,7 @@ const char *AMDGCN::Linker::constructLlcCommand( + const char *LlcOutputFile = + C.addTempFile(C.getArgs().MakeArgString(LlcOutputFileName)); + LlcArgs.push_back(LlcOutputFile); +- SmallString<128> LlcPath(C.getDriver().Dir); +- llvm::sys::path::append(LlcPath, "llc"); +- const char *Llc = Args.MakeArgString(LlcPath); ++ const char *Llc = Args.MakeArgString(getToolChain().GetProgramPath("llc")); + C.addCommand(llvm::make_unique(JA, *this, Llc, LlcArgs, Inputs)); + return LlcOutputFile; + } +@@ -184,9 +180,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA, + ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", + "-shared", "-o", Output.getFilename(), + InputFileName}; +- SmallString<128> LldPath(C.getDriver().Dir); +- llvm::sys::path::append(LldPath, "lld"); +- const char *Lld = Args.MakeArgString(LldPath); ++ const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); + C.addCommand(llvm::make_unique(JA, *this, Lld, LldArgs, Inputs)); + } + +@@ -218,9 +212,8 @@ void AMDGCN::constructHIPFatbinCommand(Compilation &C, const JobAction &JA, + Args.MakeArgString(std::string("-outputs=").append(OutputFileName)); + BundlerArgs.push_back(BundlerOutputArg); + +- SmallString<128> BundlerPath(C.getDriver().Dir); +- llvm::sys::path::append(BundlerPath, "clang-offload-bundler"); +- const char *Bundler = Args.MakeArgString(BundlerPath); ++ const char *Bundler = Args.MakeArgString( ++ T.getToolChain().GetProgramPath("clang-offload-bundler")); + C.addCommand(llvm::make_unique(JA, T, Bundler, BundlerArgs, Inputs)); + } + +-- +2.23.1 + diff --git a/pkgs/development/compilers/llvm/8/clang/default.nix b/pkgs/development/compilers/llvm/8/clang/default.nix index 8601f6d0680..81a069e6c01 100644 --- a/pkgs/development/compilers/llvm/8/clang/default.nix +++ b/pkgs/development/compilers/llvm/8/clang/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3 +{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3, lld , fixDarwinDylibNames , enableManpages ? false , enablePolly ? false # TODO: get this info from llvm (passthru?) @@ -22,7 +22,7 @@ let nativeBuildInputs = [ cmake python3 ] ++ stdenv.lib.optional enableManpages python3.pkgs.sphinx; - buildInputs = [ libxml2 llvm ] + buildInputs = [ libxml2 llvm lld ] ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames; cmakeFlags = [ @@ -50,6 +50,8 @@ let ./unwindlib.patch # https://reviews.llvm.org/D51899 ./compiler-rt-baremetal.patch + # make clang -xhip use $PATH to find executables + ./HIP-use-PATH-8.patch ]; postPatch = '' diff --git a/pkgs/development/compilers/llvm/8/default.nix b/pkgs/development/compilers/llvm/8/default.nix index 8b916e1cda7..d604dda5fe5 100644 --- a/pkgs/development/compilers/llvm/8/default.nix +++ b/pkgs/development/compilers/llvm/8/default.nix @@ -32,6 +32,7 @@ let llvm-polly = callPackage ./llvm.nix { enablePolly = true; }; clang-unwrapped = callPackage ./clang { + inherit (tools) lld; inherit clang-tools-extra_src; }; clang-polly-unwrapped = callPackage ./clang { diff --git a/pkgs/development/compilers/llvm/9/clang/HIP-use-PATH-9.patch b/pkgs/development/compilers/llvm/9/clang/HIP-use-PATH-9.patch new file mode 100644 index 00000000000..102d810ff68 --- /dev/null +++ b/pkgs/development/compilers/llvm/9/clang/HIP-use-PATH-9.patch @@ -0,0 +1,80 @@ +From 7147e9774c74abcd1d6db24e24d0fd989c2b97dd Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Holger=20W=C3=BCnsche?= +Date: Tue, 21 Jan 2020 19:52:04 +0100 +Subject: [PATCH] [HIP] use GetProgramPath for executable discovery + +This change replaces the manual building of executable paths +using llvm::sys::path::append with GetProgramPath. +This enables adding other paths in case executables reside +in different directories and makes the code easier to read. + +Differential Revision: https://reviews.llvm.org/D72903 +--- + clang/lib/Driver/ToolChains/HIP.cpp | 23 ++++++++--------------- + 1 file changed, 8 insertions(+), 15 deletions(-) + +diff --git a/lib/Driver/ToolChains/HIP.cpp b/lib/Driver/ToolChains/HIP.cpp +index 2ec97e798fd..735c302debb 100644 +--- a/lib/Driver/ToolChains/HIP.cpp ++++ b/lib/Driver/ToolChains/HIP.cpp +@@ -66,9 +66,8 @@ const char *AMDGCN::Linker::constructLLVMLinkCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpName)); + CmdArgs.push_back(OutputFileName); +- SmallString<128> ExecPath(C.getDriver().Dir); +- llvm::sys::path::append(ExecPath, "llvm-link"); +- const char *Exec = Args.MakeArgString(ExecPath); ++ const char *Exec = ++ Args.MakeArgString(getToolChain().GetProgramPath("llvm-link")); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); + return OutputFileName; + } +@@ -114,9 +113,8 @@ const char *AMDGCN::Linker::constructOptCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpFileName)); + OptArgs.push_back(OutputFileName); +- SmallString<128> OptPath(C.getDriver().Dir); +- llvm::sys::path::append(OptPath, "opt"); +- const char *OptExec = Args.MakeArgString(OptPath); ++ const char *OptExec = ++ Args.MakeArgString(getToolChain().GetProgramPath("opt")); + C.addCommand(llvm::make_unique(JA, *this, OptExec, OptArgs, Inputs)); + return OutputFileName; + } +@@ -156,9 +154,7 @@ const char *AMDGCN::Linker::constructLlcCommand( + const char *LlcOutputFile = + C.addTempFile(C.getArgs().MakeArgString(LlcOutputFileName)); + LlcArgs.push_back(LlcOutputFile); +- SmallString<128> LlcPath(C.getDriver().Dir); +- llvm::sys::path::append(LlcPath, "llc"); +- const char *Llc = Args.MakeArgString(LlcPath); ++ const char *Llc = Args.MakeArgString(getToolChain().GetProgramPath("llc")); + C.addCommand(llvm::make_unique(JA, *this, Llc, LlcArgs, Inputs)); + return LlcOutputFile; + } +@@ -172,9 +168,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA, + // The output from ld.lld is an HSA code object file. + ArgStringList LldArgs{ + "-flavor", "gnu", "-shared", "-o", Output.getFilename(), InputFileName}; +- SmallString<128> LldPath(C.getDriver().Dir); +- llvm::sys::path::append(LldPath, "lld"); +- const char *Lld = Args.MakeArgString(LldPath); ++ const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); + C.addCommand(llvm::make_unique(JA, *this, Lld, LldArgs, Inputs)); + } + +@@ -206,9 +200,8 @@ void AMDGCN::constructHIPFatbinCommand(Compilation &C, const JobAction &JA, + Args.MakeArgString(std::string("-outputs=").append(OutputFileName)); + BundlerArgs.push_back(BundlerOutputArg); + +- SmallString<128> BundlerPath(C.getDriver().Dir); +- llvm::sys::path::append(BundlerPath, "clang-offload-bundler"); +- const char *Bundler = Args.MakeArgString(BundlerPath); ++ const char *Bundler = Args.MakeArgString( ++ T.getToolChain().GetProgramPath("clang-offload-bundler")); + C.addCommand(llvm::make_unique(JA, T, Bundler, BundlerArgs, Inputs)); + } + +-- +2.23.1 + diff --git a/pkgs/development/compilers/llvm/9/clang/default.nix b/pkgs/development/compilers/llvm/9/clang/default.nix index 5f89c3dc3b7..d8df52df553 100644 --- a/pkgs/development/compilers/llvm/9/clang/default.nix +++ b/pkgs/development/compilers/llvm/9/clang/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3 +{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3, lld , fixDarwinDylibNames , enableManpages ? false , enablePolly ? false # TODO: get this info from llvm (passthru?) @@ -22,7 +22,7 @@ let nativeBuildInputs = [ cmake python3 ] ++ stdenv.lib.optional enableManpages python3.pkgs.sphinx; - buildInputs = [ libxml2 llvm ] + buildInputs = [ libxml2 llvm lld ] ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames; cmakeFlags = [ @@ -43,6 +43,8 @@ let ./purity.patch # https://reviews.llvm.org/D51899 ./compiler-rt-baremetal.patch + # make clang -xhip use $PATH to find executables + ./HIP-use-PATH-9.patch ]; postPatch = '' diff --git a/pkgs/development/compilers/llvm/9/default.nix b/pkgs/development/compilers/llvm/9/default.nix index 38ab7794018..11e44b8bdfa 100644 --- a/pkgs/development/compilers/llvm/9/default.nix +++ b/pkgs/development/compilers/llvm/9/default.nix @@ -32,6 +32,7 @@ let llvm-polly = callPackage ./llvm.nix { enablePolly = true; }; clang-unwrapped = callPackage ./clang { + inherit (tools) lld; inherit clang-tools-extra_src; }; clang-polly-unwrapped = callPackage ./clang {