Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp961354rdb; Tue, 19 Sep 2023 16:07:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF83T6P+7nkMawCr7257qZFqohRL28eqNPwm4J+14j1so+4O82XcBP3W35RIjEvSN279PRz X-Received: by 2002:a17:902:ce88:b0:1c1:d730:f0c2 with SMTP id f8-20020a170902ce8800b001c1d730f0c2mr837858plg.61.1695164850720; Tue, 19 Sep 2023 16:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695164850; cv=none; d=google.com; s=arc-20160816; b=EswUKjvlbODw9WYLZKvOdGgRR89B6IVjHu86EShKuih9oXkx1r2NKKpLPGIEZftqGi Zhd5EbGhjR1t4iF6FquhBVXKwP32W64kBoelYG6sT4SAkDl8/jNIHLUdD2tLcsisZ4sF RDiHqKALT+YuxgT0vh96+CQ9uThdDKYz6qSnmQP31LyoL2XZ5oahubK2wK3OQwtZ6xct 57/oJm4n9r/VvSzQ3zqSQelIO7GzSl9cqLEMLiamybn1thjz7VaV0eU3avHzXd3gB9jm xI78NMLq8zrIHz8CHF/BIbhlefzQVqoc1egNjkRzF80hf2vFCYVABwV21oodJGLNMP/j hUUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+l4uEd0cg+MK1zLuMTcTMLF2fu+76E8W8FTaKs4YQfM=; fh=LTgB4UUZOaMn+Ucc0I1O5ymEoSBFzf/51+XtJNl4QhU=; b=lIcHyO5ukzuA2TZTAoAPRbDgbpId6Le4ghlsmul3N4WUTzNNJeCEEDgPaIZuIPztBN dfwtJ98QILh0ZEOIZtD32d84vAf/sXB+5wNaiGfPwLQSWkZ/cclCwl5T6Qpnrbjuxks2 yy678hrefwUtYUxjhumLCjEes+mq65gp/x/MkcKqxgt9wycofSiB3luRzp5dY+cNInHM QQ0HVyrPkMgQghGQL+qAuUP0ue/IuPYsaokDTsfXSFOV5NTedd49YP58ulXs1VB8D3bR UubBj5aow1aCbOc/hwSB+m3Yy74o+poNMU6OWkzrJP7WoehWZteiXaUPof7IoWv2Y4cv RZgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pEM5lbOD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ay6-20020a1709028b8600b001b8a4519706si10134825plb.19.2023.09.19.16.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 16:07:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pEM5lbOD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4E34582A8570; Tue, 19 Sep 2023 13:03:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232960AbjISUDI (ORCPT + 99 others); Tue, 19 Sep 2023 16:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232088AbjISUDH (ORCPT ); Tue, 19 Sep 2023 16:03:07 -0400 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33B278F for ; Tue, 19 Sep 2023 13:03:01 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-773a5bb6fb6so331107885a.3 for ; Tue, 19 Sep 2023 13:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695153780; x=1695758580; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+l4uEd0cg+MK1zLuMTcTMLF2fu+76E8W8FTaKs4YQfM=; b=pEM5lbOD0gL3PxI5i7i3zQpeJMr8WxD9QgkyW8ay96xWhiiAdDj7Pw7UcHAbvrzg1w uS1HJLCpvkCYT7uiC4kMFKNG0ZmXjCbRgHKvGmFb1J+zkYmeQlavPJr5CvCuEF3AJt6g SMYQQGV+e4YMOhjAqAANbKp9b5p8uhVwaBcrJpq+OPMrOHlh0JvbG25vKOCmxEb22IQ+ u3Sy8zD6jDfFDijAYjutAZ+kTqs1fQj1wPllcoOhkLoZumwLSdpLgX/of5bA8zyHb+qX 87CZeLbmdSyVii/0gmi2zj6XQ/GHWfM7L1TbDOdEYPHK2d61YJDqrjsvfOChwg4vBelH MGmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695153780; x=1695758580; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+l4uEd0cg+MK1zLuMTcTMLF2fu+76E8W8FTaKs4YQfM=; b=CXeneOlZETjuvI8fgYSqlTIJO6Gksv0xI2kARA1+qc4kgYRi34xmU+i+kwxWdj8gTM LWfnFJWKK/trbrMtI8BrGrX5zpT17FhHcyZNGphwjT8ExUAlhdYjsVcAa1WD95fcDSQ3 6gMbshwu7vccJg4hwNxwKiEJiOAxLZAy44JGGVZ3MOMuC2JOuU1EWD12Yt97XgLcR/yC kH795FxsRae2DWRcAv/a+59Sv50p73YvbMTuoo+FmBLCdXHgkcO1lGJaW+X85U4qDDra qHOdBqdwK02oQ0ra9jeUCmR4Gr9ckt8XsPSR0Nf1jeswpZwRPePnXk/2mRI7CK69W7n2 utig== X-Gm-Message-State: AOJu0Ywsr89IKCfD2jse1gYNw/w1jyViEPQcmHuPivn7OMbWVuea8ndW 3U410lioQ8WlqR96ZnEZoxvYJC8CbYwsA7EleWeZqQ== X-Received: by 2002:a0c:e448:0:b0:64f:69a3:af3f with SMTP id d8-20020a0ce448000000b0064f69a3af3fmr358512qvm.39.1695153780151; Tue, 19 Sep 2023 13:03:00 -0700 (PDT) MIME-Version: 1.0 References: <20230918234412.363087-2-mmaurer@google.com> In-Reply-To: From: Nick Desaulniers Date: Tue, 19 Sep 2023 13:02:45 -0700 Message-ID: Subject: Re: [PATCH v2] rust: Respect HOSTCC when linking for host To: Matthew Maurer Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Nathan Chancellor , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Tue, 19 Sep 2023 13:03:13 -0700 (PDT) On Tue, Sep 19, 2023 at 12:44=E2=80=AFPM Nick Desaulniers wrote: > > On Mon, Sep 18, 2023 at 4:44=E2=80=AFPM Matthew Maurer wrote: > > > > Currently, rustc defaults to invoking `cc`, even if `HOSTCC` is defined= , > > resulting in build failures in hermetic environments where `cc` does no= t > > exist. This includes both hostprogs and proc-macros. > > > > Since we are setting the linker to `HOSTCC`, we set the linker flavor t= o > > `gcc` explicitly. > > > > Signed-off-by: Matthew Maurer > > --- > > > > Updated the patch to reflect Nick's comment that KBUILD_HOSTLDFLAGS > > should be respected as well. > > > > I did not switch it to use HOSTLD for two reasons: > > * That variable is not globally defined - it is only available in two > > subdirectories of tools/ > > * C host scripts are linked by HOSTCC as well, even when linking a > > collection of object files. It *prints* HOSTLD, but invokes HOSTCC. > > See scripts/Makefile.host cmd_host-cmulti for an example. > > Sure, that makes sense to me, thanks for pointing that out. > > > > > rust/Makefile | 4 ++++ > > scripts/Makefile.host | 4 ++++ > > 2 files changed, 8 insertions(+) > > > > diff --git a/rust/Makefile b/rust/Makefile > > index 87958e864be0..b60b7eb8c5a0 100644 > > --- a/rust/Makefile > > +++ b/rust/Makefile > > @@ -380,9 +380,13 @@ $(obj)/exports_bindings_generated.h: $(obj)/bindin= gs.o FORCE > > $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE > > $(call if_changed,exports) > > > > +KBUILD_HOSTLDFLAGS_SQ =3D '$(subst ','\'',$(KBUILD_HOSTLDFLAGS))' > > I don't think we need to do this kind of escaping. If a linker flag is > passed to the linker directly as the driver has spaces such as `-z > relro`, if it is instead passed to the compiler as the driver will not > contain spaces (`-Wl,-z,relro`). As such, I don't think we need this > escaping (famous last words). Mind submitting a v3 without it? Thanks for clarifying off list that: ``` It's not escaping the spaces, it's escaping any quotes example: -Clink-args=3D'-Wl,-z,relro -Wl,-linker-plugin-lto' Without the quote, the second one would go to rustc rather than the linker ``` Sorry for misunderstanding what exactly we were escaping here and why; thanks for implementing my suggestion of passing along KBUILD_HOSTLDFLAGS though. That will avoid issues for Android downstream. Reviewed-by: Nick Desaulniers > > > + > > quiet_cmd_rustc_procmacro =3D $(RUSTC_OR_CLIPPY_QUIET) P $@ > > cmd_rustc_procmacro =3D \ > > $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ > > + -Clinker-flavor=3Dgcc -Clinker=3D$(HOSTCC) \ > > + -Clink-args=3D$(KBUILD_HOSTLDFLAGS_SQ) \ > > --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..dc0410cae5ca 100644 > > --- a/scripts/Makefile.host > > +++ b/scripts/Makefile.host > > @@ -87,10 +87,14 @@ hostcxx_flags =3D -Wp,-MMD,$(depfile) \ > > $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ > > $(HOSTCXXFLAGS_$(target-stem).o) > > > > +KBUILD_HOSTLDFLAGS_SQ =3D '$(subst ','\'',$(KBUILD_HOSTLDFLAGS))' > > + > > # `--out-dir` is required to avoid temporaries being created by `rustc= ` in the > > # current working directory, which may be not accessible in the out-of= -tree > > # modules case. > > hostrust_flags =3D --out-dir $(dir $@) --emit=3Ddep-info=3D$(depfile) = \ > > + -Clinker-flavor=3Dgcc -Clinker=3D$(HOSTCC) \ > > + -Clink-args=3D$(KBUILD_HOSTLDFLAGS_SQ) \ > > $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ > > $(HOSTRUSTFLAGS_$(target-stem)) > > > > -- > > 2.42.0.459.ge4e396fd5e-goog > > > > > -- > Thanks, > ~Nick Desaulniers --=20 Thanks, ~Nick Desaulniers