Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp295704rdb; Mon, 18 Sep 2023 15:47:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoHhTmDPs8IFLyeQjN6DvzwE8bOFfaNECN4PRbBSpRxYWAHED12R+E1Pz5f7hWTMTu9Ivx X-Received: by 2002:a17:902:c403:b0:1c3:f745:1cd5 with SMTP id k3-20020a170902c40300b001c3f7451cd5mr13910685plk.34.1695077236617; Mon, 18 Sep 2023 15:47:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695077236; cv=none; d=google.com; s=arc-20160816; b=KzZInrBwjWX2oBsatKh5iw6MFfCrpBRjMz2XLRq2SsbRPZZWb0aAm0NEgAzUfk2UxL 7z1h17dNodq12dvtBou42DPw225dlvH5PzMBeBr3NhjHch0p9HFzWaraPNoqI9QNu4r4 FnaBGm4u4eIEcgOzBIoxF183/ol8YR1fbLTtTeg2t+fm5j47fUPkj8k+1JyltXRmyYrp 7SuJx8u0yFfKaJk/VrA2aPv2GfEHdNZLbR3FV9Ifo/jRV6wvF0RkDhf0Y1JpC/P37Fn4 /Y5O3taoXfA+fdk3VjDr2vwWtHjpk4N7HiPjycInXSxzFQvPrOuo+0wrAgUFKEO6PF8U V8iQ== 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=kGggz20caFzafUF2A1Vven9jC5oystZUe3kde8zcZIk=; fh=gfE7L+XW2Z6y+c45SBULpR7z1KD6I+cAWmynmtRKiWw=; b=jsPTCbiw3LsG0w76W/NJZV2OHKek52szX0hRZxOYqLy8oOXUxUKbug4MbA8cpSU5xj yKcCFUSOSRjjxRTteYBjAzIbx68Vx48/PpZkY3bHElCFPxunZp6f/It+famtySxthFQx 4UkbMwoex5oTT4tJ95uL62dvsqcf13QCwPjhbDXIZN6f/gZb8bj9aIosv68wyY1CCbTL 64ZaFq8Qu3nAxDtxjxYAjWHqaUQFPfAvSXN2/U1dxwBGsdVINu2o9j5dbTH4hNHCfbw2 TX4XlJAA7zGM3JLTEsfHH3OMlt1gnfNE7/3fIZOSmMmirZgXTaEqMNe0y/5CiqPf6AFR rTmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="UJ/SEvC+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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. [23.128.96.34]) by mx.google.com with ESMTPS id o5-20020a17090323c500b001b025aba9f2si8708273plh.22.2023.09.18.15.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 15:47:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="UJ/SEvC+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 ABE7B840FE20; Mon, 18 Sep 2023 11:43:24 -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 S229561AbjIRSnZ (ORCPT + 99 others); Mon, 18 Sep 2023 14:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbjIRSnW (ORCPT ); Mon, 18 Sep 2023 14:43:22 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC29F10D for ; Mon, 18 Sep 2023 11:43:16 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-6563bca1b38so17273816d6.1 for ; Mon, 18 Sep 2023 11:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695062596; x=1695667396; 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=kGggz20caFzafUF2A1Vven9jC5oystZUe3kde8zcZIk=; b=UJ/SEvC+s0+IOOpfEqqte5BgzI0WhzEiFo0xQfPJmft7acj9spen6qLOjiN1RLfqP/ NbkifY6t6Kb79lJZSxqYLPb9s5W7/MHrdPm2ygkAB/IvHBe/JjTu/rJHAOAsfBqW4lD8 dA3xRq1oQP9zMoQXf7PrUj30V6pI6p+Xean6RiFt7gYsa3F0R+ZaBj1t5WwwwdJE20Z5 2wlhqwYSXQGne81UesPlktyMugoQwBpzwLXHGvIMyV3aEOQs/ZcDSqJViYtP+A5R63JP 0xVDxWx5KFWxNAp6sf+LYAdNfseFdOEcZrqfkMgMyd+d7q/jPncEpIdF0sQUGGCIScqn Ln4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695062596; x=1695667396; 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=kGggz20caFzafUF2A1Vven9jC5oystZUe3kde8zcZIk=; b=eh6gKzXkGMCb97K+hj3p4gAM9k9KoNSI/VSvJHENrwAhRU0J9KC2JilLu6mmPXgtxP 4i8ccrgokp576uaAUiz9WENU7KQBz0OqnzQAQLT7WQg80u8ZEX7RqR6Acw40SJ/LvoBS 306nR9yqXQwYZ4I++5agXu0/tdwSughyqGNmYrzpLb4/RHhf3rid7XoPtouiJWzt4ipu qX3BDjqv9ZM+AKp8GlYDRFTGVaxu8NREvkmEESRuLYLUxQY93gQw78SYT1nKNaKDtDmx wILNqZHyIDLVEaa2xTcs1Ihd5/7If9wajzNW6KOwZWlRDbIia/sScy9MvS6sKjDGo/h1 0rGQ== X-Gm-Message-State: AOJu0Yz1YaNKO00u/dKUW+/2dD59p5p/0lKL3RFs11wZ+Pz8Wu0swjjb 37V7NEx2OIP73/oM7PRVCmDjr87ZzEOWu82VGmngxQ== X-Received: by 2002:a0c:c985:0:b0:658:2f85:29ce with SMTP id b5-20020a0cc985000000b006582f8529cemr2054758qvk.58.1695062595805; Mon, 18 Sep 2023 11:43:15 -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: Nick Desaulniers Date: Mon, 18 Sep 2023 11:43:04 -0700 Message-ID: Subject: Re: [PATCH] rust: Respect HOSTCC when linking for host To: Matthew Maurer 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_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]); Mon, 18 Sep 2023 11:43:24 -0700 (PDT) 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. > > 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-flavor > Would it be appropriate to just assume the linker is named correctly? If it were not, what does failure look like? command not found: asdfadfasdf 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=3Dlld` > > 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 cre= am? 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, the= n 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. 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) --=20 Thanks, ~Nick Desaulniers