From c19c839a57190c7212d7df304a9419da1c499f30 Mon Sep 17 00:00:00 2001 From: sanana Date: Sat, 4 Jan 2025 22:58:33 +0300 Subject: [PATCH] bintools,gcc: introduce mlibc support In gcc, libsanitize is disabled because mlibc doesn't support libsanitize yet but upstream is working on it. Patches needed for gcc to support linux-mlibc targets are pulled from managarm's fork of gcc, patches only needed by managarm are not applied. --- pkgs/build-support/bintools-wrapper/default.nix | 1 + .../compilers/gcc/common/configure-flags.nix | 3 ++- pkgs/development/compilers/gcc/patches/default.nix | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index cb5b5fca22080f..b8c7b34c720924 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -114,6 +114,7 @@ let # shell glob that ought to match it. dynamicLinker = /**/ if sharedLibraryLoader == null then "" + else if targetPlatform.libc == "mlibc" then "${sharedLibraryLoader}/lib/ld.so" else if targetPlatform.libc == "musl" then "${sharedLibraryLoader}/lib/ld-musl-*" else if targetPlatform.libc == "uclibc" then "${sharedLibraryLoader}/lib/ld*-uClibc.so.1" else if (targetPlatform.libc == "bionic" && targetPlatform.is32bit) then "/system/bin/linker" diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix index 25d4f1f53bae9c..2084e965c3a986 100644 --- a/pkgs/development/compilers/gcc/common/configure-flags.nix +++ b/pkgs/development/compilers/gcc/common/configure-flags.nix @@ -93,7 +93,7 @@ let else if targetPlatform.isWindows then (threadsCross.model or "win32") else "single"}" "--enable-nls" - ] ++ lib.optionals (targetPlatform.libc == "uclibc" || targetPlatform.libc == "musl") [ + ] ++ lib.optionals (lib.elem targetPlatform.libc [ "mlibc" "musl" "uclibc" ]) [ # libsanitizer requires netrom/netrom.h which is not # available in uclibc. "--disable-libsanitizer" @@ -217,6 +217,7 @@ let # On Illumos/Solaris GNU as is preferred "--with-gnu-as" "--without-gnu-ld" ] + ++ lib.optional (targetPlatform.libc == "mlibc") "--disable-libsanitizer" ++ lib.optional (targetPlatform.libc == "musl") # musl at least, disable: https://git.buildroot.net/buildroot/commit/?id=873d4019f7fb00f6a80592224236b3ba7d657865 "--disable-libmpx" diff --git a/pkgs/development/compilers/gcc/patches/default.nix b/pkgs/development/compilers/gcc/patches/default.nix index 16e9d6ad195939..53b8dd3fa512da 100644 --- a/pkgs/development/compilers/gcc/patches/default.nix +++ b/pkgs/development/compilers/gcc/patches/default.nix @@ -137,6 +137,18 @@ in }) ] +## mlibc +++ optionals (stdenv.targetPlatform.isMlibc && atLeast14) [ + (fetchpatch { + url = "https://github.com/managarm/gcc/commit/092cb31af8ed12dbecc02327444f030a7c40c344.diff"; + hash = "sha256-Ix95v0UxC73tfW2UliWiRgS0wC1wVUo5waM38qFlRFM="; + }) + (fetchpatch { + url = "https://github.com/managarm/gcc/commit/b5cdfff8afc4a668e65541eec5b512d080116a43.diff"; + hash = "sha256-0xbw/vRbUvsIIhXM8iyAxm2FWXDnYXblAJ1gFEgeOPg="; + }) +] + ## Darwin # Fixes detection of Darwin on x86_64-darwin. Otherwise, GCC uses a deployment target of 10.5, which crashes ld64.