Compare commits

...

4 Commits

Author SHA1 Message Date
Lluís Batlle i Rossell
0872290b7f Change llvm packages for gcc offload 2024-12-22 14:47:55 +01:00
Lluís Batlle i Rossell
60a3981b26 Finally gcc_offload built
But it cannot target gfx1103 - that probably requires the
rocmPackages.llvm that is broken.
2024-12-22 14:47:55 +01:00
Lluís Batlle i Rossell
98338f45a4 More gcc 2024-12-22 14:47:55 +01:00
Lluís Batlle i Rossell
b8bc6fcd24 Middle work for getting gcc to offload to amd 2024-12-22 14:47:55 +01:00
12 changed files with 97 additions and 21 deletions

View File

@@ -167,6 +167,11 @@ rec {
config = "avr"; config = "avr";
}; };
amdgcn = {
config = "amdgcn-amdhsa";
libc = "newlib";
};
vc4 = { vc4 = {
config = "vc4-elf"; config = "vc4-elf";
libc = "newlib"; libc = "newlib";

View File

@@ -163,6 +163,8 @@ rec {
msp430 = { bits = 16; significantByte = littleEndian; family = "msp430"; }; msp430 = { bits = 16; significantByte = littleEndian; family = "msp430"; };
avr = { bits = 8; family = "avr"; }; avr = { bits = 8; family = "avr"; };
amdgcn = { bits = 64; significantByte = littleEndian; family = "amdgcn"; };
vc4 = { bits = 32; significantByte = littleEndian; family = "vc4"; }; vc4 = { bits = 32; significantByte = littleEndian; family = "vc4"; };
or1k = { bits = 32; significantByte = bigEndian; family = "or1k"; }; or1k = { bits = 32; significantByte = bigEndian; family = "or1k"; };
@@ -338,6 +340,7 @@ rec {
ghcjs = { execFormat = unknown; families = { }; }; ghcjs = { execFormat = unknown; families = { }; };
genode = { execFormat = elf; families = { }; }; genode = { execFormat = elf; families = { }; };
mmixware = { execFormat = unknown; families = { }; }; mmixware = { execFormat = unknown; families = { }; };
amdhsa = { execFormat = unknown; families = { }; };
} // { # aliases } // { # aliases
# 'darwin' is the kernel for all of them. We choose macOS by default. # 'darwin' is the kernel for all of them. We choose macOS by default.
darwin = kernels.macos; darwin = kernels.macos;

View File

@@ -21,6 +21,7 @@
, gnugrep ? null , gnugrep ? null
, expand-response-params , expand-response-params
, libcxx ? null , libcxx ? null
, extraCompilerB ? []
# Whether or not to add `-B` and `-L` to `nix-support/cc-{c,ld}flags` # Whether or not to add `-B` and `-L` to `nix-support/cc-{c,ld}flags`
, useCcForLibs ? , useCcForLibs ?
@@ -614,7 +615,12 @@ stdenvNoCC.mkDerivation {
ccLDFlags+=" -L${cc_solib}/lib" ccLDFlags+=" -L${cc_solib}/lib"
ccCFlags+=" -B${cc_solib}/lib" ccCFlags+=" -B${cc_solib}/lib"
'' + optionalString (cc.langAda or false && !isArocc) '' '' + (concatMapStrings (p: ''
ccCFlags+=" -B${p}/libexec/gcc/${stdenvNoCC.buildPlatform.config}/${p.version}"
ccCFlags+=" -B${p}/bin"
ccCFlags+=" -foffload-options=-Wl,-L${p}/${p.stdenv.targetPlatform.config}/lib"
'') extraCompilerB)
+ optionalString (cc.langAda or false && !isArocc) ''
touch "$out/nix-support/gnat-cflags" touch "$out/nix-support/gnat-cflags"
touch "$out/nix-support/gnat-ldflags" touch "$out/nix-support/gnat-ldflags"
basePath=$(echo $cc/lib/*/*/*) basePath=$(echo $cc/lib/*/*/*)

View File

@@ -3,6 +3,7 @@
stdenv, stdenv,
enableMultilib, enableMultilib,
targetConfig, targetConfig,
version,
}: }:
let let
@@ -169,6 +170,10 @@ originalAttrs:
fi fi
eval "$oldOpts" eval "$oldOpts"
'' + lib.optionalString (targetConfig == "amdgcn-amdhsa") ''
makeFlagsArray=''${makeFlagsArray[@]/CFLAGS_FOR_TARGET=*}
makeFlagsArray=''${makeFlagsArray[@]/CXXFLAGS_FOR_TARGET=*}
makeFlagsArray=''${makeFlagsArray[@]/FLAGS_FOR_TARGET=*}
''; '';
preConfigure = preConfigure =
@@ -219,7 +224,7 @@ originalAttrs:
# symlink), this ensures that in every case we can assume that # symlink), this ensures that in every case we can assume that
# $lib/lib contains the .so files # $lib/lib contains the .so files
lib.optionalString (with stdenv; targetPlatform.config != hostPlatform.config) '' lib.optionalString (with stdenv; targetPlatform.config != hostPlatform.config) ''
ln -Ts "''${!outputLib}/''${targetConfig}/lib" $lib/lib ln -Ts "''${!outputLib}/''${targetConfig}/lib" "''${!outputLib}/lib"
'' ''
+ +
# Make `lib64` symlinks to `lib`. # Make `lib64` symlinks to `lib`.
@@ -312,6 +317,11 @@ originalAttrs:
ln -sf "$man_prefix"gcc.1 "$i" ln -sf "$man_prefix"gcc.1 "$i"
fi fi
done done
'' + lib.optionalString (targetConfig == "amdgcn-amdhsa") ''
for a in ld as ar nm runlib; do
ln -s $(type -P amdgcn-amdhsa-$a) \
$out/lib/gcc/x86_64-unknown-linux-gnu/${version}/accel/amdgcn-amdhsa/$a
done
''; '';
} }
)) ))

View File

@@ -9,6 +9,7 @@
, enableLTO , enableLTO
, enableMultilib , enableMultilib
, enableOffload
, enablePlugin , enablePlugin
, disableGdbPlugin ? !enablePlugin , disableGdbPlugin ? !enablePlugin
, enableShared , enableShared
@@ -53,10 +54,10 @@ let
crossConfigureFlags = crossConfigureFlags =
# Ensure that -print-prog-name is able to find the correct programs. # Ensure that -print-prog-name is able to find the correct programs.
[ (lib.optionals (targetPlatform.config != "amdgcn-amdhsa") [
"--with-as=${if targetPackages.stdenv.cc.bintools.isLLVM then binutils else targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as" "--with-as=${if targetPackages.stdenv.cc.bintools.isLLVM then binutils else targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
"--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld"
] ])
++ (if withoutTargetLibc then [ ++ (if withoutTargetLibc then [
"--disable-libssp" "--disable-libssp"
"--disable-nls" "--disable-nls"
@@ -84,9 +85,11 @@ let
# See Note [Windows Exception Handling] # See Note [Windows Exception Handling]
"--enable-sjlj-exceptions" "--enable-sjlj-exceptions"
"--with-dwarf2" "--with-dwarf2"
] else [ ] else (
(if crossDarwin then "--with-sysroot=${lib.getLib libcCross}/share/sysroot" lib.optional crossDarwin "--with-sysroot=${lib.getLib libcCross}/share/sysroot"
else "--with-headers=${lib.getDev libcCross}${libcCross.incdir or "/include"}") ++ lib.optional (!crossDarwin && targetPlatform.config != "amdgcn-amdhsa")
"--with-sysroot=${lib.getLib libcCross}/share/sysroot"
++ [
"--enable-__cxa_atexit" "--enable-__cxa_atexit"
"--enable-long-long" "--enable-long-long"
"--enable-threads=${if targetPlatform.isUnix then "posix" "--enable-threads=${if targetPlatform.isUnix then "posix"
@@ -97,9 +100,10 @@ let
# libsanitizer requires netrom/netrom.h which is not # libsanitizer requires netrom/netrom.h which is not
# available in uclibc. # available in uclibc.
"--disable-libsanitizer" "--disable-libsanitizer"
] ++ lib.optional (targetPlatform.libc == "newlib" || targetPlatform.libc == "newlib-nano") "--with-newlib" ] ++ lib.optional ((targetPlatform.libc == "newlib" || targetPlatform.libc == "newlib-nano") &&
targetPlatform.config != "amdgcn-amdhsa") "--with-newlib"
++ lib.optional (targetPlatform.libc == "avrlibc") "--with-avrlibc" ++ lib.optional (targetPlatform.libc == "avrlibc") "--with-avrlibc"
); ));
configureFlags = configureFlags =
# Basic dependencies # Basic dependencies
@@ -110,7 +114,7 @@ let
"--with-mpfr-lib=${mpfr.out}/lib" "--with-mpfr-lib=${mpfr.out}/lib"
"--with-mpc=${libmpc}" "--with-mpc=${libmpc}"
] ]
++ lib.optionals (!withoutTargetLibc) [ ++ lib.optionals (!withoutTargetLibc && targetPlatform.config != "amdgcn-amdhsa") [
(if libcCross == null (if libcCross == null
then ( then (
# GCC will search for the headers relative to SDKROOT on Darwin, so it will find them in the store. # GCC will search for the headers relative to SDKROOT on Darwin, so it will find them in the store.
@@ -160,7 +164,12 @@ let
"--disable-libstdcxx-pch" "--disable-libstdcxx-pch"
"--without-included-gettext" "--without-included-gettext"
"--with-system-zlib" "--with-system-zlib"
] ++ lib.optionals (targetPlatform.config != "amdgcn-amdhsa") [
"--enable-static" "--enable-static"
] ++ lib.optionals (targetPlatform.config == "amdgcn-amdhsa") [
"--disable-sjlj-exceptions"
"--disable-libquadmath"
] ++ [
"--enable-languages=${ "--enable-languages=${
lib.concatStringsSep "," lib.concatStringsSep ","
( lib.optional langC "c" ( lib.optional langC "c"
@@ -177,7 +186,7 @@ let
) )
}" }"
] ]
++ lib.optional enableOffload "--enable-offload-targets=amdgcn-amdhsa"
++ (if (enableMultilib || targetPlatform.isAvr) ++ (if (enableMultilib || targetPlatform.isAvr)
then ["--enable-multilib" "--disable-libquadmath"] then ["--enable-multilib" "--disable-libquadmath"]
else ["--disable-multilib"]) else ["--disable-multilib"])
@@ -208,7 +217,9 @@ let
++ import ../common/platform-flags.nix { inherit (stdenv) targetPlatform; inherit lib; } ++ import ../common/platform-flags.nix { inherit (stdenv) targetPlatform; inherit lib; }
++ lib.optionals (targetPlatform != hostPlatform) crossConfigureFlags ++ lib.optionals (targetPlatform != hostPlatform) crossConfigureFlags
++ lib.optional disableBootstrap' "--disable-bootstrap" ++ lib.optional disableBootstrap' "--disable-bootstrap"
++ lib.optionals (targetPlatform.config == "amdgcn-amdhsa") [
"--target=amdgcn-amdhsa" "--enable-as-accelerator-for=x86_64-unknown-linux-gnu"
]
# Platform-specific flags # Platform-specific flags
++ lib.optional (targetPlatform == hostPlatform && targetPlatform.isx86_32) "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}" ++ lib.optional (targetPlatform == hostPlatform && targetPlatform.isx86_32) "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
++ lib.optional targetPlatform.isNetBSD "--disable-libssp" # Provided by libc. ++ lib.optional targetPlatform.isNetBSD "--disable-libssp" # Provided by libc.

View File

@@ -31,11 +31,26 @@
let let
inherit (lib) optionals; inherit (lib) optionals;
inherit (stdenv) buildPlatform hostPlatform targetPlatform; inherit (stdenv) buildPlatform hostPlatform targetPlatform;
## llvm18 fails with gcc <14
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114419
llvmAmd =
let
llvm = buildPackages.llvmPackages_19;
in buildPackages.runCommand "${llvm.llvm.name}-wrapper" {} ''
mkdir -p $out/bin
for a in ar nm ranlib; do
ln -s ${llvm.llvm}/bin/llvm-$a $out/bin/amdgcn-amdhsa-$a
done
ln -s ${llvm.llvm}/bin/llvm-mc $out/bin/amdgcn-amdhsa-as
ln -s ${llvm.lld}/bin/lld $out/bin/amdgcn-amdhsa-ld
'';
in in
{ {
# same for all gcc's # same for all gcc's
depsBuildBuild = [ buildPackages.stdenv.cc ]; depsBuildBuild = [ buildPackages.stdenv.cc ] ++
lib.optional (targetPlatform.config == "amdgcn-amdhsa") llvmAmd;
nativeBuildInputs = nativeBuildInputs =
[ [
@@ -55,7 +70,9 @@ in
# same for all gcc's # same for all gcc's
depsBuildTarget = depsBuildTarget =
( (
if hostPlatform == buildPlatform then if (targetPlatform.config == "amdgcn-amdhsa") then
[ ]
else if hostPlatform == buildPlatform then
[ [
targetPackages.stdenv.cc.bintools # newly-built gcc will be used targetPackages.stdenv.cc.bintools # newly-built gcc will be used
] ]
@@ -75,7 +92,7 @@ in
libmpc libmpc
] ]
++ optionals (lib.versionAtLeast version "10") [ libxcrypt ] ++ optionals (lib.versionAtLeast version "10") [ libxcrypt ]
++ [ ++ optionals (targetPlatform.config != "amdgcn-amdhsa") [
targetPackages.stdenv.cc.bintools # For linking code at run-time targetPackages.stdenv.cc.bintools # For linking code at run-time
] ]
++ optionals (isl != null) [ isl ] ++ optionals (isl != null) [ isl ]

View File

@@ -23,7 +23,7 @@ in
[ [
"-O2 -idirafter ${lib.getDev dep}${dep.incdir or "/include"}" "-O2 -idirafter ${lib.getDev dep}${dep.incdir or "/include"}"
] ]
++ lib.optionals (!withoutTargetLibc) [ ++ lib.optionals (!withoutTargetLibc && targetPlatform.config != "amdgcn-amdhsa") [
"-B${lib.getLib dep}${dep.libdir or "/lib"}" "-B${lib.getLib dep}${dep.libdir or "/lib"}"
] ]
); );

View File

@@ -57,7 +57,7 @@
) )
popd popd
'' ''
+ lib.optionalString (!langJit) '' + lib.optionalString (!langJit && stdenv.targetPlatform.config != "amdgcn-amdhsa") ''
${ ${
# keep indentation # keep indentation
"" ""

View File

@@ -13,9 +13,10 @@
, staticCompiler ? false , staticCompiler ? false
, enableShared ? stdenv.targetPlatform.hasSharedLibraries , enableShared ? stdenv.targetPlatform.hasSharedLibraries
, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , enableLTO ? stdenv.hostPlatform.hasSharedLibraries
, enableOffload ? false
, texinfo ? null , texinfo ? null
, perl ? null # optional, for texi2pod (then pod2man) , perl ? null # optional, for texi2pod (then pod2man)
, gmp, mpfr, libmpc, gettext, which, patchelf, binutils , gmp, mpfr, libmpc, gettext, which, patchelf, binutils, newlib
, isl ? null # optional, for the Graphite optimization framework. , isl ? null # optional, for the Graphite optimization framework.
, zlib ? null , zlib ? null
, libucontext ? null , libucontext ? null
@@ -111,6 +112,7 @@ let
disableBootstrap disableBootstrap
disableGdbPlugin disableGdbPlugin
enableLTO enableLTO
enableOffload
enableMultilib enableMultilib
enablePlugin enablePlugin
enableShared enableShared
@@ -152,6 +154,7 @@ let
threadsCross threadsCross
which which
zlib zlib
newlib
; ;
}; };
@@ -187,7 +190,7 @@ pipe ((callFile ./common/builder.nix {}) ({
inherit patches; inherit patches;
outputs = [ "out" "man" "info" ] ++ optional (!langJit) "lib"; outputs = [ "out" "man" "info" ] ++ optional (!langJit && targetPlatform.config != "amdgcn-amdhsa") "lib";
setOutputFlags = false; setOutputFlags = false;
@@ -356,6 +359,8 @@ pipe ((callFile ./common/builder.nix {}) ({
''; '';
} // optionalAttrs enableMultilib { } // optionalAttrs enableMultilib {
dontMoveLib64 = true; dontMoveLib64 = true;
} // optionalAttrs (targetPlatform.config == "amdgcn-amdhsa") {
newlibSrc = newlib.src;
} }
)) ))
([ ([

View File

@@ -17,6 +17,7 @@ rec {
# See llvm/cmake/config-ix.cmake. # See llvm/cmake/config-ix.cmake.
platforms = platforms =
["amdgcn-amdhsa" ]++
lib.platforms.aarch64 ++ lib.platforms.aarch64 ++
lib.platforms.arm ++ lib.platforms.arm ++
lib.platforms.mips ++ lib.platforms.mips ++

View File

@@ -13,11 +13,11 @@
stdenv.mkDerivation (finalAttrs: { stdenv.mkDerivation (finalAttrs: {
pname = "newlib"; pname = "newlib";
version = "4.3.0.20230120"; version = "4.4.0.20231231";
src = fetchurl { src = fetchurl {
url = "ftp://sourceware.org/pub/newlib/newlib-${finalAttrs.version}.tar.gz"; url = "ftp://sourceware.org/pub/newlib/newlib-${finalAttrs.version}.tar.gz";
sha256 = "sha256-g6Yqma9Z4465sMWO0JLuJNcA//Q6IsA+QzlVET7zUVA="; sha256 = "sha256-DBZqOeG/CVHfr81olJ/g5LbTZYCB1igvOa7vxjEPLxM=";
}; };
patches = lib.optionals nanoizeNewlib [ patches = lib.optionals nanoizeNewlib [

View File

@@ -6080,6 +6080,17 @@ with pkgs;
gccCrossLibcStdenv = overrideCC stdenvNoCC buildPackages.gccWithoutTargetLibc; gccCrossLibcStdenv = overrideCC stdenvNoCC buildPackages.gccWithoutTargetLibc;
amdgcc = pkgsCross.amdgcn.buildPackages.gcc_latest.cc.override {
langCC = true;
# enableLTO = false;
# enableMultilib = true;
withoutTargetLibc = false;
enableShared = false;
noSysDirs = false;
libcCross = binutilsNoLibc.libc;
targetPackages.stdenv.cc.bintools = binutilsNoLibc;
};
# The GCC used to build libc for the target platform. Normal gccs will be # The GCC used to build libc for the target platform. Normal gccs will be
# built with, and use, that cross-compiled libc. # built with, and use, that cross-compiled libc.
gccWithoutTargetLibc = assert stdenv.targetPlatform != stdenv.hostPlatform; let gccWithoutTargetLibc = assert stdenv.targetPlatform != stdenv.hostPlatform; let
@@ -6118,6 +6129,13 @@ with pkgs;
gcc_latest = gcc14; gcc_latest = gcc14;
gcc_offload = wrapCCWith {
cc = gcc_latest.cc.override {
enableOffload = true;
};
extraCompilerB = [ amdgcc ];
};
libgccjit = gcc.cc.override { libgccjit = gcc.cc.override {
name = "libgccjit"; name = "libgccjit";
langFortran = false; langFortran = false;