From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id QLY1LrK7cV9LWwAA0tVLHw (envelope-from ) for ; Mon, 28 Sep 2020 10:32:18 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id XEcPKrK7cV8ADgAAB5/wlQ (envelope-from ) for ; Mon, 28 Sep 2020 10:32:18 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2BADC9404D1 for ; Mon, 28 Sep 2020 10:32:18 +0000 (UTC) Received: from localhost ([::1]:55272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMqS8-0003ds-Rh for larch@yhetil.org; Mon, 28 Sep 2020 06:32:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMqRv-0003dh-5N for bug-guix@gnu.org; Mon, 28 Sep 2020 06:32:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40006) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kMqRt-0004yg-M2 for bug-guix@gnu.org; Mon, 28 Sep 2020 06:32:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kMqRt-0007TR-Jk for bug-guix@gnu.org; Mon, 28 Sep 2020 06:32:01 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#43668: Daemon tries to build GNU/Hurd derivations on GNU/Linux Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Mon, 28 Sep 2020 10:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43668 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 43668@debbugs.gnu.org Received: via spool by 43668-submit@debbugs.gnu.org id=B43668.160128909828687 (code B ref 43668); Mon, 28 Sep 2020 10:32:01 +0000 Received: (at 43668) by debbugs.gnu.org; 28 Sep 2020 10:31:38 +0000 Received: from localhost ([127.0.0.1]:51544 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kMqRV-0007SY-II for submit@debbugs.gnu.org; Mon, 28 Sep 2020 06:31:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34348) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kMqRS-0007SK-Gs for 43668@debbugs.gnu.org; Mon, 28 Sep 2020 06:31:35 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:40885) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMqRN-0004wy-7V for 43668@debbugs.gnu.org; Mon, 28 Sep 2020 06:31:29 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=37300 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kMqRJ-0000ip-QY for 43668@debbugs.gnu.org; Mon, 28 Sep 2020 06:31:27 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <87a6xacmw5.fsf@inria.fr> Date: Mon, 28 Sep 2020 12:31:22 +0200 In-Reply-To: <87a6xacmw5.fsf@inria.fr> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Mon, 28 Sep 2020 10:43:06 +0200") Message-ID: <875z7ychvp.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Spam-Score: -1.51 X-TUID: HSaSKDSNLRBi --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s skribis: > It=E2=80=99s no wonder that the GNU/Hurd executable fails to run on GNU/L= inux. > The reason the daemon tries to run it anyway is because of the hack > introduced in 7bf2a70a4ffd976d50638d3b9f2ec409763157df, in support of > transparent emulation via binfmt_misc. The thing is that x86 GNU/Hurd and GNU/Linux ELF binaries are indistinguishable AFAICS since they both use ELFOSABI_NONE: --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> ,use(guix elf) scheme@(guile-user)> ,use(rnrs io ports) scheme@(guile-user)> (define e (parse-elf (call-with-input-file "/gnu/store= /vq7zyb4hmlrafflmrcjbqccxp4dsx0s3-bash" get-bytevector-all))) scheme@(guile-user)> (elf-abi e) $6 =3D 0 scheme@(guile-user)> ELFOSABI_GNU $7 =3D 3 scheme@(guile-user)> (define e2 (parse-elf (call-with-input-file "/bin/sh" = get-bytevector-all))) scheme@(guile-user)> (elf-abi e2) $8 =3D 0 --8<---------------cut here---------------end--------------->8--- (The =E2=80=98file=E2=80=99 command does manage to recognize GNU/Hurd binar= ies, but I don=E2=80=99t know how it does it.) So I think we can=E2=80=99t count on an =E2=80=98execve=E2=80=99 error and = thus have to treat this case (same architecture but different OS kernel) specially, as shown below. Thoughts? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index 88f8d11103..ccec513d8d 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc @@ -1946,6 +1946,15 @@ void DerivationGoal::startBuilder() } +/* Return true if the operating system kernel part of SYSTEM1 and SYSTEM2 (the + bit that comes after the hyphen in system types such as "i686-linux") is + the same. */ +static bool sameOperatingSystemKernel(const std::string& system1, const std::string& system2) +{ + auto os1 = system1.substr(system1.find("-")); + auto os2 = system2.substr(system2.find("-")); + return os1 == os2; +} void DerivationGoal::runChild() { @@ -2208,9 +2217,20 @@ void DerivationGoal::runChild() foreach (Strings::iterator, i, drv.args) args.push_back(rewriteHashes(*i, rewritesToTmp)); - execve(drv.builder.c_str(), stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data()); - - int error = errno; + /* If DRV targets the same operating system kernel, try to execute it: + there might be binfmt_misc set up for user-land emulation of other + architectures. However, if it targets a different operating + system--e.g., "i586-gnu" vs. "x86_64-linux"--do not try executing + it: the ELF file for that OS is likely indistinguishable from a + native ELF binary and it would just crash at run time. */ + int error; + if (sameOperatingSystemKernel(drv.platform, settings.thisSystem)) { + execve(drv.builder.c_str(), stringsToCharPtrs(args).data(), + stringsToCharPtrs(envStrs).data()); + error = errno; + } else { + error = ENOEXEC; + } /* Right platform? Check this after we've tried 'execve' to allow for transparent emulation of different platforms with binfmt_misc --=-=-=--