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";
};
amdgcn = {
config = "amdgcn-amdhsa";
libc = "newlib";
};
vc4 = {
config = "vc4-elf";
libc = "newlib";

View File

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

View File

@@ -21,6 +21,7 @@
, gnugrep ? null
, expand-response-params
, libcxx ? null
, extraCompilerB ? []
# Whether or not to add `-B` and `-L` to `nix-support/cc-{c,ld}flags`
, useCcForLibs ?
@@ -614,7 +615,12 @@ stdenvNoCC.mkDerivation {
ccLDFlags+=" -L${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-ldflags"
basePath=$(echo $cc/lib/*/*/*)

View File

@@ -3,6 +3,7 @@
stdenv,
enableMultilib,
targetConfig,
version,
}:
let
@@ -169,6 +170,10 @@ originalAttrs:
fi
eval "$oldOpts"
'' + lib.optionalString (targetConfig == "amdgcn-amdhsa") ''
makeFlagsArray=''${makeFlagsArray[@]/CFLAGS_FOR_TARGET=*}
makeFlagsArray=''${makeFlagsArray[@]/CXXFLAGS_FOR_TARGET=*}
makeFlagsArray=''${makeFlagsArray[@]/FLAGS_FOR_TARGET=*}
'';
preConfigure =
@@ -219,7 +224,7 @@ originalAttrs:
# symlink), this ensures that in every case we can assume that
# $lib/lib contains the .so files
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`.
@@ -312,6 +317,11 @@ originalAttrs:
ln -sf "$man_prefix"gcc.1 "$i"
fi
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
, enableMultilib
, enableOffload
, enablePlugin
, disableGdbPlugin ? !enablePlugin
, enableShared
@@ -53,10 +54,10 @@ let
crossConfigureFlags =
# 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-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld"
]
])
++ (if withoutTargetLibc then [
"--disable-libssp"
"--disable-nls"
@@ -84,9 +85,11 @@ let
# See Note [Windows Exception Handling]
"--enable-sjlj-exceptions"
"--with-dwarf2"
] else [
(if crossDarwin then "--with-sysroot=${lib.getLib libcCross}/share/sysroot"
else "--with-headers=${lib.getDev libcCross}${libcCross.incdir or "/include"}")
] else (
lib.optional crossDarwin "--with-sysroot=${lib.getLib libcCross}/share/sysroot"
++ lib.optional (!crossDarwin && targetPlatform.config != "amdgcn-amdhsa")
"--with-sysroot=${lib.getLib libcCross}/share/sysroot"
++ [
"--enable-__cxa_atexit"
"--enable-long-long"
"--enable-threads=${if targetPlatform.isUnix then "posix"
@@ -97,9 +100,10 @@ let
# libsanitizer requires netrom/netrom.h which is not
# available in uclibc.
"--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"
);
));
configureFlags =
# Basic dependencies
@@ -110,7 +114,7 @@ let
"--with-mpfr-lib=${mpfr.out}/lib"
"--with-mpc=${libmpc}"
]
++ lib.optionals (!withoutTargetLibc) [
++ lib.optionals (!withoutTargetLibc && targetPlatform.config != "amdgcn-amdhsa") [
(if libcCross == null
then (
# 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"
"--without-included-gettext"
"--with-system-zlib"
] ++ lib.optionals (targetPlatform.config != "amdgcn-amdhsa") [
"--enable-static"
] ++ lib.optionals (targetPlatform.config == "amdgcn-amdhsa") [
"--disable-sjlj-exceptions"
"--disable-libquadmath"
] ++ [
"--enable-languages=${
lib.concatStringsSep ","
( lib.optional langC "c"
@@ -177,7 +186,7 @@ let
)
}"
]
++ lib.optional enableOffload "--enable-offload-targets=amdgcn-amdhsa"
++ (if (enableMultilib || targetPlatform.isAvr)
then ["--enable-multilib" "--disable-libquadmath"]
else ["--disable-multilib"])
@@ -208,7 +217,9 @@ let
++ import ../common/platform-flags.nix { inherit (stdenv) targetPlatform; inherit lib; }
++ lib.optionals (targetPlatform != hostPlatform) crossConfigureFlags
++ 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
++ lib.optional (targetPlatform == hostPlatform && targetPlatform.isx86_32) "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
++ lib.optional targetPlatform.isNetBSD "--disable-libssp" # Provided by libc.

View File

@@ -31,11 +31,26 @@
let
inherit (lib) optionals;
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
{
# same for all gcc's
depsBuildBuild = [ buildPackages.stdenv.cc ];
depsBuildBuild = [ buildPackages.stdenv.cc ] ++
lib.optional (targetPlatform.config == "amdgcn-amdhsa") llvmAmd;
nativeBuildInputs =
[
@@ -55,7 +70,9 @@ in
# same for all gcc's
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
]
@@ -75,7 +92,7 @@ in
libmpc
]
++ optionals (lib.versionAtLeast version "10") [ libxcrypt ]
++ [
++ optionals (targetPlatform.config != "amdgcn-amdhsa") [
targetPackages.stdenv.cc.bintools # For linking code at run-time
]
++ optionals (isl != null) [ isl ]

View File

@@ -23,7 +23,7 @@ in
[
"-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"}"
]
);

View File

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

View File

@@ -13,9 +13,10 @@
, staticCompiler ? false
, enableShared ? stdenv.targetPlatform.hasSharedLibraries
, enableLTO ? stdenv.hostPlatform.hasSharedLibraries
, enableOffload ? false
, texinfo ? null
, 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.
, zlib ? null
, libucontext ? null
@@ -111,6 +112,7 @@ let
disableBootstrap
disableGdbPlugin
enableLTO
enableOffload
enableMultilib
enablePlugin
enableShared
@@ -152,6 +154,7 @@ let
threadsCross
which
zlib
newlib
;
};
@@ -187,7 +190,7 @@ pipe ((callFile ./common/builder.nix {}) ({
inherit patches;
outputs = [ "out" "man" "info" ] ++ optional (!langJit) "lib";
outputs = [ "out" "man" "info" ] ++ optional (!langJit && targetPlatform.config != "amdgcn-amdhsa") "lib";
setOutputFlags = false;
@@ -356,6 +359,8 @@ pipe ((callFile ./common/builder.nix {}) ({
'';
} // optionalAttrs enableMultilib {
dontMoveLib64 = true;
} // optionalAttrs (targetPlatform.config == "amdgcn-amdhsa") {
newlibSrc = newlib.src;
}
))
([

View File

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

View File

@@ -13,11 +13,11 @@
stdenv.mkDerivation (finalAttrs: {
pname = "newlib";
version = "4.3.0.20230120";
version = "4.4.0.20231231";
src = fetchurl {
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 [

View File

@@ -6080,6 +6080,17 @@ with pkgs;
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
# built with, and use, that cross-compiled libc.
gccWithoutTargetLibc = assert stdenv.targetPlatform != stdenv.hostPlatform; let
@@ -6118,6 +6129,13 @@ with pkgs;
gcc_latest = gcc14;
gcc_offload = wrapCCWith {
cc = gcc_latest.cc.override {
enableOffload = true;
};
extraCompilerB = [ amdgcc ];
};
libgccjit = gcc.cc.override {
name = "libgccjit";
langFortran = false;