Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5415738rdb; Sat, 16 Sep 2023 16:46:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJ2Ves5OwV+taI3DHiPrAqb3xPGRcZkKgOqTUIyXMiRZfbRkxh7KJs6nkYuwhwMC72k8/M X-Received: by 2002:a05:6358:98a7:b0:134:de8b:17f0 with SMTP id q39-20020a05635898a700b00134de8b17f0mr7029799rwa.19.1694907959805; Sat, 16 Sep 2023 16:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694907959; cv=none; d=google.com; s=arc-20160816; b=L0YfRCaNauOqH03VrwrzHcxV0B+9bHFKRAAGPhiRTc/uWO15nicM7HB8tdmdzSXFBX khw26jwGCouaS7ncwvvOdW4HBVpch79AB3mFrP4E06wKqYAYvH2sKah9Mh99Z0WCLXGB ch1GP7HVoiKDi1BQLOkF7ugxBALJ77lCPpIo0TBXL5Xx/9mJcYrt6nGy2ldBQ4Gj6nPx Q0z33sZ+rdtXM6mBgHx1bSRoiEcdu1McJQhAS6iLp5LF0R2ZMlAeB0F1yIhkXa4HvTSo a7zfr2TYtIAnm0hEniOoyyP788ZBDC0hfRtVDWa7hXzttpB6SRctj66AETvlsVq4F2B1 W/vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :from; bh=JA5/hvn6Yw4Y7noeFUIFzJHIZ1aDogb0GEKwEfAyknQ=; fh=ugcJOmAwUoQm9FLzWWokkCsOZ9uOGntJ4B1lhLRjg3g=; b=YF+1HcahVc+r59ipOEYf0fDpDjD0mHapFnd15CQoHK4YuGXpyTHzhjIQk/O9FGkDka 6fSGA3gGC10cvMEr98X2xyZmZf1DeKRSoSR9eoQPWwV5i+U7N36IgV++uNN/LWc30GAI h4TMXcrWEPXEpGu5MFu32HJTwzTKwqEPQtazNRETe2WMeA5+azBc9k1CyWAkhVoN4KqC tDySJUQG7RJDdfix/larrJc2omQLRcQgTDngnL3ecccJAC7pOD3yYHHKuL6WMrrFtPg9 4YfLLmIXe3qby9pN6bA8gfsmebOCwoZDTwMQeRCTt8i4qKJCXlqKrAuILeOCPjIrK1WS EIwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kloenk.dev header.s=mail header.b=MxI3K5J8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=kloenk.dev Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id q21-20020a056a00085500b0068e2dadcfc3si4994924pfk.48.2023.09.16.16.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 16:45:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kloenk.dev header.s=mail header.b=MxI3K5J8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=kloenk.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 8CF1F8096FD6; Sat, 16 Sep 2023 15:41:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231673AbjIPWkg (ORCPT + 99 others); Sat, 16 Sep 2023 18:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232389AbjIPWkY (ORCPT ); Sat, 16 Sep 2023 18:40:24 -0400 Received: from gimli.kloenk.dev (gimli.kloenk.dev [IPv6:2a01:4f8:c012:b874::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83068CD1; Sat, 16 Sep 2023 15:40:18 -0700 (PDT) From: Finn Behrens DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kloenk.dev; s=mail; t=1694904015; bh=JA5/hvn6Yw4Y7noeFUIFzJHIZ1aDogb0GEKwEfAyknQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MxI3K5J8je9HXIUV++EcVqahwcGKNrqLBY4fIUBlupxPltMiPRt8PshLntJJlH4lR FLy2/bTvn9sN9p7sBurRXXLd8n9zinJ5uhYtSl5cpUDN4zg450yyr3YGQfbAPpww7U Dnz0bOvY5Hjr04MDB3iHX5V5pb7KUShkNcmCHmtU= To: Matthew Maurer Cc: =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada , Boqun Feng , Gary Guo , Benno Lossin , Andreas Hindborg , Alice Ryhl , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: Re: [PATCH] rust: Respect HOSTCC when linking for host Date: Sun, 17 Sep 2023 00:39:46 +0200 Message-ID: <446E67B5-0200-4982-994B-B30C2DEDF098@kloenk.dev> In-Reply-To: References: <20230915172900.3784163-1-mmaurer@google.com> <9966E047-44E7-4665-9628-169F3EBE2F06@kloenk.dev> <0561303E-2089-43FC-AA31-836C7BB844B7@kloenk.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 16 Sep 2023 15:41:07 -0700 (PDT) On 16 Sep 2023, at 21:54, Matthew Maurer wrote: > On Sat, Sep 16, 2023 at 11:07=E2=80=AFAM Finn Behrens w= rote: >> >> >> >> On 16 Sep 2023, at 19:53, Bj=C3=B6rn Roy Baron wrote: >> >>> On Saturday, September 16th, 2023 at 18:52, Finn Behrens wrote: >>> >>>> >>>> On 15 Sep 2023, at 19:28, Matthew Maurer wrote: >>>> >>>>> Currently, rustc defaults to invoking `cc`, even if `HOSTCC` is def= ined, >>>>> resulting in build failures in hermetic environments where `cc` doe= s not >>>>> exist. This includes both hostprogs and proc-macros. >>>>> >>>>> Since we are setting the linker to `HOSTCC`, we set the linker flav= or to >>>>> `gcc` explicitly. >>>> But as `HOSTCC` could also be clang, the linker flavor would then be= wrong, would that create a problem? >>> >>> Rustc uses the gcc linker flavor for clang too. There has been a prop= osal to split it up, but I'm not sure of the status of that. In any case = clang's cli is similar enough to gcc that it works fine to use the gcc li= nker flavor. >>> >> In that case this looks very reasonable. >> >> Second thing I noticed is that `HOSTCC` could be the wrong variable, a= nd `HOSTLD` would make more sense as we look for the linker and not the g= eneral C compiler. >> > Yes, thanks Bjorn - "gcc" is the linker flavor used for "Use the C > compiler as a linker". > > With regards to HOSTLD, I was trying to make the minimum possible > change. Currently, it is using the command `cc` as a linker, so this > would preserve existing behavior when HOSTCC is unset. > > If we would prefer `HOSTLD` instead we can do that, but we would need > to additionally inspect `LLVM` to set the linker flavor accordingly > (e.g. set ld vs ld.lld). > > Do folks have strong opinions between these? My primary concern is to > avoid calling programs by foo when their HOSTFOO variable is set. I don=E2=80=99t have an educated opinion at all, mainly nudged in the dir= ection, so that the existence if `HOSTLD` does not get overlooked. If the= re is a valid reason to not use it, this patch looks good to me. > > See https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-f= lavor > for details on linker flavor settings. >>>>> >>>>> Signed-off-by: Matthew Maurer >>>>> --- >>>>> rust/Makefile | 1 + >>>>> scripts/Makefile.host | 1 + >>>>> 2 files changed, 2 insertions(+) >>>>> >>>>> diff --git a/rust/Makefile b/rust/Makefile >>>>> index 87958e864be0..2a2352638f11 100644 >>>>> --- a/rust/Makefile >>>>> +++ b/rust/Makefile >>>>> @@ -383,6 +383,7 @@ $(obj)/exports_kernel_generated.h: $(obj)/kerne= l.o FORCE >>>>> quiet_cmd_rustc_procmacro =3D $(RUSTC_OR_CLIPPY_QUIET) P $@ >>>>> cmd_rustc_procmacro =3D \ >>>>> $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ >>>>> + -C linker-flavor=3Dgcc -C linker=3D$(HOSTCC) \ >>>>> --emit=3Ddep-info=3D$(depfile) --emit=3Dlink=3D$@ --ext= ern proc_macro \ >>>>> --crate-type proc-macro \ >>>>> --crate-name $(patsubst lib%.so,%,$(notdir $@)) $< >>>>> diff --git a/scripts/Makefile.host b/scripts/Makefile.host >>>>> index 8f7f842b54f9..0aa95a3af1c4 100644 >>>>> --- a/scripts/Makefile.host >>>>> +++ b/scripts/Makefile.host >>>>> @@ -91,6 +91,7 @@ hostcxx_flags =3D -Wp,-MMD,$(depfile) \ >>>>> # current working directory, which may be not accessible in the ou= t-of-tree >>>>> # modules case. >>>>> hostrust_flags =3D --out-dir $(dir $@) --emit=3Ddep-info=3D$(depfi= le) \ >>>>> + -C linker-flavor=3Dgcc -C linker=3D$(HOSTCC) \ >>>>> $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ >>>>> $(HOSTRUSTFLAGS_$(target-stem)) >>>>> >>>>> -- >>>>> 2.42.0.459.ge4e396fd5e-goog