Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2020697rdh; Tue, 26 Sep 2023 09:55:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoOsK5BU1o7rN0HhljnhkR6uiEOJ/FV3j/KL7yNd5z4cwbCTykOip4fqNH1KWVvnfmDYll X-Received: by 2002:a05:6a00:10c3:b0:690:41a1:9b6c with SMTP id d3-20020a056a0010c300b0069041a19b6cmr8981149pfu.10.1695747307649; Tue, 26 Sep 2023 09:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695747307; cv=none; d=google.com; s=arc-20160816; b=MjjcYDDbt5noWg6eQa1Qqz+BUYvmlGfZN5CK5FMuO1qfmS2+axu3FiHMJDjzWW/kbd bxXuJp7CMJ2+n5HyhmEFQPKDNBu8+Lo4/nTTYdxzaC7js4Vz2LFGyI5oo5xrzsgIgWn9 ditp7JOF+AYGURG3XSlqgcUmH1J6ZDmopMpS/lY7rEmr6Xr227/fnCaNOdYWZwG9Vsx1 70yivRe69dX+mk79RGv6nCAB72ru9eDIr+p8X9pKqc2G34wIPs7WNggVvBXjJiU0yxDP ixu5QvMjxmTnmnAV3RyGlMTaojhJOXbfMYqaJUAoLDb8vOF+b2kpV+ML5qXli/ae9BOh Wlhw== 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=ZuVUef5qU5iXA/d6rCQ0/myo2UpLCxW6JT/QDYQksNM=; fh=KM66WQVMbKeqNUX2E1EHtNAeiuZOH1qctZveFjRiKYM=; b=Y3NS1lADdZL1O7MKzsaAh7LwPGcAmTjM9Ee/+VPPg+8H9EUjWw/fu7A4XVfnU2lpg0 EiD/Kca4EdjCZ9yKAMZN7remHzWCA2LvVX5OLFvDineZSUSPElAprVMEeKTdhSnlLthh R1PcRjORjd/fNONPoDXqKkSKcOhOdyFiSMB1+k6T9SiSwbv/O6iXibrnWcEiVh4cAMDl /Rnh38BzxdfqyK00ePg03iMXTdOL5AhwbO6v4w89OidoA/pZNsGEnzD7YU0itXYpi0lZ gaAuT8XxrhNoMry/Doy7gYS0ktm54wmX+8runji6A/GGlljxIT0a6u1EhSGd7cjraEm4 /f0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oYeTi4U8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id o19-20020a056a0015d300b0068fdb060072si13970764pfu.341.2023.09.26.09.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 09:55:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oYeTi4U8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D2BCA801B494; Tue, 26 Sep 2023 09:53:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235498AbjIZQwq (ORCPT + 99 others); Tue, 26 Sep 2023 12:52:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235477AbjIZQwl (ORCPT ); Tue, 26 Sep 2023 12:52:41 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA07DCC8; Tue, 26 Sep 2023 09:52:29 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5237EC433CC; Tue, 26 Sep 2023 16:52:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695747149; bh=jZbXXpwO2YkG3T9wZrnoHzJGOBu0lJuRvun8uFcnm80=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oYeTi4U8bH1QgNPCJZfgga1Ep2Fw8dnKEc4zzysoAF/WId14gbXUq04eYGPcRBO7S FlQcf8Nf+p2nibebaTC8w/6Ed/QArZ/uzFAOrTxEjrRz/gHfCl+e9ojgGlP1d2Sdbr vVxN/bGTx3OQMuSrPbHgoeYC1Y+xyqt+AuiBbJSeJ4baDWlq7Ot29AeVSNds+guWkk l4+0XuqmFSlbmwCZeGBodUp4jF+ER0UjTkIKBElMi7zjjQ7AoBLJTZoZIoZAGB216J h/dA0bM8QDfTV2CGJIPt7hQusZhS7opBogPLS8fOvfum5eoCddyy00890+uYuCUi0L 1vO3vWgNjJ4jg== Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-1dd54aca17cso1754644fac.3; Tue, 26 Sep 2023 09:52:29 -0700 (PDT) X-Gm-Message-State: AOJu0YxGXmLAX8ESTdru+aGegIHe3BBLBAzwuoLnYDot0CVEk/+Omptg TB88zmJhTByumHCnOsLesnKmiefAcGUSEfWXXm8= X-Received: by 2002:a05:6870:2d5:b0:1d5:b0b9:f6f1 with SMTP id r21-20020a05687002d500b001d5b0b9f6f1mr12460899oaf.8.1695747148628; Tue, 26 Sep 2023 09:52:28 -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: Masahiro Yamada Date: Wed, 27 Sep 2023 01:51:51 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] rust: Respect HOSTCC when linking for host To: Matthew Maurer Cc: Nick Desaulniers , Finn Behrens , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , 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=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 26 Sep 2023 09:53:02 -0700 (PDT) On Tue, Sep 19, 2023 at 3:55=E2=80=AFAM Matthew Maurer = wrote: > > 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 link= er > > > > 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-fla= vor > > > 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=3D= lld` > > > > for $KBUILD_HOSTCFLAGS, because its build environment doesn't conta= in > > > > GNU binutils ("guilty, officer"). > > > Oddly, the Android kernel environment (Kleaf) is the one that I neede= d > > > 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= cream? > > Oh, right looking at your link: > > https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavo= r > > Seems like if `LLVM=3D1` is set, or `LD=3Dld.lld`, or CONFIG_LD_IS_LLD,= then > > 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. CONFIG_LD_IS_LLD=3Dy states that the linker for the kernel space is LLD. Host programs should not be affected. --=20 Best Regards Masahiro Yamada