Use lld linker for clangOmpss2 for LTO

This commit is contained in:
Rodrigo Arias 2023-03-06 11:47:01 +01:00
parent 5753f0c312
commit 84623ea9d0
4 changed files with 69 additions and 2 deletions

View File

@ -67,7 +67,7 @@ stdenv.mkDerivation rec {
"-DCMAKE_CXX_FLAGS_DEBUG=-g -ggnu-pubnames" "-DCMAKE_CXX_FLAGS_DEBUG=-g -ggnu-pubnames"
"-DCMAKE_EXE_LINKER_FLAGS_DEBUG=-Wl,-gdb-index" "-DCMAKE_EXE_LINKER_FLAGS_DEBUG=-Wl,-gdb-index"
"-DLLVM_LIT_ARGS=-sv --xunit-xml-output=xunit.xml" "-DLLVM_LIT_ARGS=-sv --xunit-xml-output=xunit.xml"
"-DLLVM_ENABLE_PROJECTS=clang;openmp;compiler-rt;flang" "-DLLVM_ENABLE_PROJECTS=clang;openmp;compiler-rt;flang;lld"
"-DLLVM_ENABLE_ASSERTIONS=${enableAssertions}" "-DLLVM_ENABLE_ASSERTIONS=${enableAssertions}"
"-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON" "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
"-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_BINDIR=bin"

View File

@ -4,14 +4,27 @@
, nanos6 , nanos6
, clangOmpss2Unwrapped , clangOmpss2Unwrapped
, wrapCCWith , wrapCCWith
, llvmPackages
}: }:
let let
# We need to replace the lld linker from bintools with our linker just built,
# otherwise we run into incompatibility issues when mixing compiler and linker
# versions.
bintools-unwrapped = llvmPackages.tools.bintools-unwrapped.override {
lld = clangOmpss2Unwrapped;
};
bintools = llvmPackages.tools.bintools.override {
bintools = bintools-unwrapped;
};
targetConfig = stdenv.targetPlatform.config; targetConfig = stdenv.targetPlatform.config;
inherit gcc nanos6; inherit gcc nanos6;
in wrapCCWith rec {
cc = clangOmpss2Unwrapped; cc = clangOmpss2Unwrapped;
in wrapCCWith {
inherit cc bintools;
extraBuildCommands = '' extraBuildCommands = ''
echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags

View File

@ -105,6 +105,7 @@ let
clangOmpss2 = appendPasstru ( clangOmpss2 = appendPasstru (
callPackage ./bsc/llvm-ompss2/default.nix { callPackage ./bsc/llvm-ompss2/default.nix {
llvmPackages = self.llvmPackages_latest;
clangOmpss2Unwrapped = bsc.clangOmpss2Unwrapped; clangOmpss2Unwrapped = bsc.clangOmpss2Unwrapped;
}) { CC = "clang"; CXX = "clang++"; }; }) { CC = "clang"; CXX = "clang++"; };
@ -113,6 +114,11 @@ let
clangOmpss2Unwrapped = bsc.clangOmpss2UnwrappedGit; clangOmpss2Unwrapped = bsc.clangOmpss2UnwrappedGit;
}) { CC = "clang"; CXX = "clang++"; }; }) { CC = "clang"; CXX = "clang++"; };
stdenvClangOmpss2 = self.stdenv.override {
cc = bsc.clangOmpss2;
allowedRequisites = null;
};
mcxx = bsc.mcxxRelease; mcxx = bsc.mcxxRelease;
mcxxRelease = callPackage ./bsc/mcxx/default.nix { }; mcxxRelease = callPackage ./bsc/mcxx/default.nix { };
mcxxGit = callPackage ./bsc/mcxx/git.nix { }; mcxxGit = callPackage ./bsc/mcxx/git.nix { };
@ -302,6 +308,7 @@ let
compilers.hello-c = callPackage ./test/compilers/hello-c.nix { }; compilers.hello-c = callPackage ./test/compilers/hello-c.nix { };
compilers.hello-cpp = callPackage ./test/compilers/hello-cpp.nix { }; compilers.hello-cpp = callPackage ./test/compilers/hello-cpp.nix { };
compilers.hello-f = callPackage ./test/compilers/hello-f.nix { }; compilers.hello-f = callPackage ./test/compilers/hello-f.nix { };
compilers.lto = callPackage ./test/compilers/lto.nix { };
compilers.intel2023.icx.c = compilers.hello-c.override { compilers.intel2023.icx.c = compilers.hello-c.override {
stdenv = bsc.intel2023.stdenv; stdenv = bsc.intel2023.stdenv;
}; };
@ -317,6 +324,9 @@ let
compilers.intel2023.ifort = compilers.hello-f.override { compilers.intel2023.ifort = compilers.hello-f.override {
stdenv = bsc.intel2023.stdenv-ifort; stdenv = bsc.intel2023.stdenv-ifort;
}; };
compilers.clangOmpss2.lto = compilers.lto.override {
stdenv = bsc.stdenvClangOmpss2;
};
}; };
testAll = with bsc.test; [ testAll = with bsc.test; [
@ -325,6 +335,7 @@ let
compilers.intel2023.icx.cpp compilers.intel2023.icx.cpp
compilers.intel2023.icc.cpp compilers.intel2023.icc.cpp
compilers.intel2023.ifort compilers.intel2023.ifort
compilers.clangOmpss2.lto
]; ];
ci = import ./test/ci.nix { ci = import ./test/ci.nix {

43
test/compilers/lto.nix Normal file
View File

@ -0,0 +1,43 @@
{ stdenv, writeText, which, strace }:
let
hello_c = writeText "hello.c" ''
#include <stdio.h>
#include <limits.h>
#include <xmmintrin.h>
int main()
{
printf("Hello world!\n");
return 0;
}
'';
in
stdenv.mkDerivation rec {
version = "0.0.1";
name = "lto-c";
buildInputs = [ stdenv which strace ];
src = hello_c;
dontUnpack = true;
dontConfigure = true;
NIX_DEBUG = 0;
buildPhase = ''
set -x
echo CC=$CC
echo LD=$LD
echo -------------------------------------------
env
echo -------------------------------------------
cp ${hello_c} hello.c
$CC -v -flto hello.c -o hello
./hello
set +x
'';
installPhase = ''
touch $out
'';
}