Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp309609rdb; Mon, 18 Sep 2023 16:19:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCa4pQBHcK+x+N6zClVn+M+2Cn1dBOFk4GpFhvSLuU4wuP9MXeyIAtAg3m+4WOejMZulBZ X-Received: by 2002:a05:6808:21aa:b0:3a3:ed69:331 with SMTP id be42-20020a05680821aa00b003a3ed690331mr14971623oib.6.1695079189226; Mon, 18 Sep 2023 16:19:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695079189; cv=none; d=google.com; s=arc-20160816; b=gchu/ZxqydAh7Ll7bSa5zwFYj4nbONGSHlSK7TxQ3PIFz5bLCe19EMuacCONcL9uUm eS578I0jf6lP/4HlZ7Th7TQ31a2/43fIuLzLd/5+oCYauMQRuy/CuZ3StLjAaaMd/QCD 9+TQmP5cbKWjuz6a+LyC/963TqeuO5V79QrTTgFwTS+CRzJ+dHRVDYcQRQNMPzznwbF7 TrehtmcL+tNuufGARAO4hGcNk/Way+aN7Wd3wBagQiJRPfbm9293XFmw7lAh5JsmTfgM KcocAL6Y0J85sPW5cEAX7O1nf51ZiyReYudKUqv5BdGu9P4h3fBaS2EIIrxcfiWh3esM Uncw== 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=/mr4adhPkgNVKHO3js/mkzV6WskANfNP7vwkNde/9Lk=; fh=No99tuOUFLqEm3wC/MwzJDucZuOwlrYQJcmShlOaYP0=; b=F1Itawlcgejx6a8iX6+0novqys5LZZnJwjd0W0F6srUOi/aq2uH9SZ0MBLksJF0rhG R/jFKAuNvwkKCMfZTLUSKc4idhfhZ5tj92i2sQzN6qpPnDflx3grhAMYP5Le+xwXT2eF yx0BUOnm5Fj+7IGhLLDyBg7D5QLT0uhfTHVGaNsLkjg2iLkC2gorCxGWCaKrFNf2/jvc fxgatb2qdatdhBDBIiYbum6F2MfN4gNGFXCuCAK2oOvb6KVd6RZHUfsDY0r9d7OXh0X1 imXcAZFUmoiJ67cLq/tU5F3YezyjKR3epQdKahJTiXY39Pf2qnJYCZvMqrKomaq582+Y lVcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="B4EleTC/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s11-20020a65584b000000b005649f560ebesi200943pgr.525.2023.09.18.16.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 16:19:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="B4EleTC/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id AD9248070654; Mon, 18 Sep 2023 11:56:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229477AbjIRS4C (ORCPT + 99 others); Mon, 18 Sep 2023 14:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbjIRS4B (ORCPT ); Mon, 18 Sep 2023 14:56:01 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8DDDFC for ; Mon, 18 Sep 2023 11:55:55 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-52fa364f276so2376a12.1 for ; Mon, 18 Sep 2023 11:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695063354; x=1695668154; 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=/mr4adhPkgNVKHO3js/mkzV6WskANfNP7vwkNde/9Lk=; b=B4EleTC/c223+P6KkvjNjxmKQAU/NHhi+pjy6hDyLnXhO6Pag6UF7t4HOG+PWQWapS M8v5wD9Ag6iFA9WQPy0La7hqvsHsocTN2YgCWCWEvJi0gEXTIiBtvHWL79AQiVks/UxF ivWrRs8iwTcd8HWsobZsRhYH6tDPeVhq7sCE1ZbunC/RthPNatffNZB0+tYQ1PGiwEI2 ONwd35XtJpR/k4QLUjXeShAlprJRJe+R44lLHhYRZFKXB3CCs9GIrWEzHGlSpp3ZXuOx l9nIh/yMnFd1ihrhOo5+HaryJTIuc1pZtfj8eAQh4peBx5q1kAQT7roXS0JDRyv+lKLW qh+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695063354; x=1695668154; 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=/mr4adhPkgNVKHO3js/mkzV6WskANfNP7vwkNde/9Lk=; b=DZ3qzA8CltZuHpLxPnDnrJePBtp9Q0SIkAeURDnkYebkCwh4lR5QBWbZQBrEnQxNiw Cu9G3P+sF9aYg8tY+FDcDeBCsxzGlCDPY7UonOB4Qojwsc6Z2jy63vW2aDqw+3JNaMWx pQDsWojZULz91TqYNjSr39Jn3hnilg3xPInuiMc9+TE4tG6efr8Jh6QMrxRgU2uyefCQ Eek8wOFpAqLwdYCZVnGNOXbNdB/pDB2MfRLwTjM2fmWHH6rMzS03CEUQc5zc7FYKwCP7 dVvEQJtDHAu9dy1g39F9ID99mnznLnWG2nMq9hsNH+3OQtss99ih4avJX2oQzkY/yvC0 2nZA== X-Gm-Message-State: AOJu0YyavdXGO0yfg6kp5MaiFiz4gPbx3I7NkF335RvLA4RyguK3e7XM mR+Yz0S/XOdnAkl620uVCIiuSNFE7l6AqNyDRbA1vg== X-Received: by 2002:a50:8e4f:0:b0:523:bdc9:48a9 with SMTP id 15-20020a508e4f000000b00523bdc948a9mr21829edx.0.1695063353972; Mon, 18 Sep 2023 11:55:53 -0700 (PDT) MIME-Version: 1.0 References: <20230915172900.3784163-1-mmaurer@google.com> <9966E047-44E7-4665-9628-169F3EBE2F06@kloenk.dev> <0561303E-2089-43FC-AA31-836C7BB844B7@kloenk.dev> In-Reply-To: From: Matthew Maurer Date: Mon, 18 Sep 2023 11:55:41 -0700 Message-ID: Subject: Re: [PATCH] rust: Respect HOSTCC when linking for host To: Nick Desaulniers Cc: Finn Behrens , =?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 , 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_NONE,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 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 11:56:07 -0700 (PDT) On Mon, Sep 18, 2023 at 11:43=E2=80=AFAM Nick Desaulniers wrote: > > On Mon, Sep 18, 2023 at 9:38=E2=80=AFAM Matthew Maurer wrote: > > > > On Mon, Sep 18, 2023 at 8:25=E2=80=AFAM Nick Desaulniers > > wrote: > > > > > > What happens if you invoke the linker directly? > > Rust unfortunately currently doesn't support invoking the linker > > directly: https://github.com/rust-lang/rust/issues/73632 > > Wait; does Rust have its own linker? It doesn't use the system linker? > Perhaps that's necessary for the rust module format? If so, TIL. It does use the system linker (this is what -C linker is controlling), but the command line passed to the linker may change, extra object files may be added to the command line, etc. > > > > Generally, the kernel either invokes the compiler or the linker > > > directly. (For assembler, it is typically preprocessed, as are linker > > > scripts!) So invoking the linker directly is a common pattern in > > > kbuild. It also makes me slightly sad if the rust compiler ends up > > > invoking a c compiler, even if it's simply to drive the linker. > > As mentioned earlier, we could pass $HOSTLD, but if the linker isn't > > named something accurate (e.g. if the linker is not named lld, but is > > lld), we need to know how to pass a flavor: > > https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavo= r > > Would it be appropriate to just assume the linker is named correctly? > > If it were not, what does failure look like? That depends. I think it will usually look like "unrecognized flag: blah blah", but that's not guaranteed. > > command not found: asdfadfasdf This isn't about command-not-found, it's about "I set HOSTLD=3Dfoo/bar/weirdname, and it is an lld-like linker. rustc invoked it assuming it is an ld-like linker." > > Seems fine to me. If the user mis-specifies HOSTLD=3D, then they will > get a similar error, which should be prescriptive enough for them to > figure out how exactly they're "holding it wrong." > > > > For example, Android carries a downstream patch to set `-fuse-ld=3Dll= d` > > > for $KBUILD_HOSTCFLAGS, because its build environment doesn't contain > > > GNU binutils ("guilty, officer"). > > Oddly, the Android kernel environment (Kleaf) is the one that I needed > > this patch to build in, but it seemed to be working without a manual > > KBUILD_HOSTCFLAGS forwarding. > > Surprising that worked. > > > Overall, it sounds like you'd prefer if I set this to use > > `KBUILD_HOSTLD` and `KBUILD_HOSTLDFLAGS`, and leave the linker flavor > > to autodetect? > > Yes for the first two. > > Dunno, what precisely is a linker flavor? Is that like a flavor of ice c= ream? > Oh, right looking at your link: > https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavor > Seems like if `LLVM=3D1` is set, or `LD=3Dld.lld`, or CONFIG_LD_IS_LLD, t= hen > the flavor should be set to ld.lld, else ld. Then the > KBUILD_HOSTLDFLAGS need to be passed, probably. > > But how are there "linker flavors" like ld or ld.lld if you just said > "Rust unfortunately currently doesn't support invoking the linker > directly: https://github.com/rust-lang/rust/issues/73632". I'm having > trouble reconciling the two. Yes, what I meant by that is that *rustc* wants to invoke the linker, rather than having the surrounding build system invoke the linker. The exact command line passed to the linker in the final link, including potential synthetic objects, is considered an internal detail. > > Can we do something more like the below? > > ifdef CONFIG_LD_IS_LLD > hostrust_flags +=3D -C linker-flavor=3Dld.lld > else > hostrust_flags +=3D -C linker-flavor=3Dld > endif > hostrust_flags +=3D -C linker=3D$(HOSTLD) KBUILD_HOSTLDFLAGS> Yes, I can make host linking use `$(HOSTLD)` and pass the flavor based on CONFIG_LD_IS_LLD. I'll send a variant that does that this afternoon. > -- > Thanks, > ~Nick Desaulniers