From 4b73e231f9bb41a2fbc7720923715899b26bdb97 Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Mon, 17 Oct 2022 17:27:00 -0700 Subject: linuxHeaders: use elf-header from build packages Splicing does not work correctly here, so elf-header was being pulled from the host packages. It must be pulled from the build packages since it is used by the HOSTCC for build-time tools. Note that using buildPackages here causes infinite recursion. Fixes darwin -> linux-mips cross-compilation of linuxHeaders. --- pkgs/top-level/all-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 93554e795c6cb..1dd4b4b71133b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -24853,7 +24853,7 @@ with pkgs; lkl = callPackage ../applications/virtualization/lkl { }; lklWithFirewall = callPackage ../applications/virtualization/lkl { firewallSupport = true; }; - inherit (callPackages ../os-specific/linux/kernel-headers { }) + inherit (callPackages ../os-specific/linux/kernel-headers { inherit (pkgsBuildBuild) elf-header; }) linuxHeaders makeLinuxHeaders; klibc = callPackage ../os-specific/linux/klibc { }; -- cgit 1.4.1 From b45cf446ea501649bdccef866fb01e5b1042143c Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Mon, 17 Oct 2022 17:26:37 -0700 Subject: linuxHeaders: fix cross-compilation from darwin to mips mips tools require endian headers which are different on darwin. Add stub headers to define the appropriate byte swap functions. Co-authored-by: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com> --- pkgs/os-specific/linux/kernel-headers/default.nix | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkgs/os-specific/linux/kernel-headers/default.nix b/pkgs/os-specific/linux/kernel-headers/default.nix index daa8c1ae2019f..0b38a31fe9566 100644 --- a/pkgs/os-specific/linux/kernel-headers/default.nix +++ b/pkgs/os-specific/linux/kernel-headers/default.nix @@ -1,11 +1,37 @@ { stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header , bison ? null, flex ? null, python ? null, rsync ? null +, writeTextFile }: assert stdenvNoCC.hostPlatform.isAndroid -> (flex != null && bison != null && python != null && rsync != null); let + + # As part of building a hostPlatform=mips kernel, Linux creates and runs a + # tiny utility `arch/mips/boot/tools/relocs_main.c` for the buildPlatform. + # This utility references a glibc-specific header `byteswap.h`. There is a + # compatibility header in gnulib for most BSDs, but not for Darwin, so we + # synthesize one here. + darwin-endian-h = writeTextFile { + name = "endian-h"; + text = '' + #include + ''; + destination = "/include/endian.h"; + }; + darwin-byteswap-h = writeTextFile { + name = "byteswap-h"; + text = '' + #pragma once + #include + #define bswap_16 OSSwapInt16 + #define bswap_32 OSSwapInt32 + #define bswap_64 OSSwapInt64 + ''; + destination = "/include/byteswap.h"; + }; + makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation { inherit src; @@ -25,6 +51,10 @@ let perl elf-header ] ++ lib.optionals stdenvNoCC.hostPlatform.isAndroid [ flex bison python rsync + ] ++ lib.optionals (stdenvNoCC.buildPlatform.isDarwin && + stdenvNoCC.hostPlatform.isMips) [ + darwin-endian-h + darwin-byteswap-h ]; extraIncludeDirs = lib.optional (with stdenvNoCC.hostPlatform; isPower && is32bit && isBigEndian) ["ppc"]; -- cgit 1.4.1