[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOdnbbStoEeykYnx0jbnR=TAmmcdnOXbbA4Fx0BneFW8Fsg@mail.gmail.com>
Date: Mon, 18 Sep 2023 11:43:04 -0700
From: Nick Desaulniers <ndesaulniers@...gle.com>
To: Matthew Maurer <mmaurer@...gle.com>
Cc: Finn Behrens <me@...enk.dev>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Masahiro Yamada <masahiroy@...nel.org>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...sung.com>,
Alice Ryhl <aliceryhl@...gle.com>,
Nathan Chancellor <nathan@...nel.org>,
Nicolas Schier <nicolas@...sle.eu>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kbuild@...r.kernel.org
Subject: Re: [PATCH] rust: Respect HOSTCC when linking for host
On Mon, Sep 18, 2023 at 9:38 AM Matthew Maurer <mmaurer@...gle.com> wrote:
>
> On Mon, Sep 18, 2023 at 8:25 AM Nick Desaulniers
> <ndesaulniers@...gle.com> 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=, 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=lld`
> > 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 cream?
Oh, right looking at your link:
https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavor
Seems like if `LLVM=1` is set, or `LD=ld.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.
Can we do something more like the below?
ifdef CONFIG_LD_IS_LLD
hostrust_flags += -C linker-flavor=ld.lld
else
hostrust_flags += -C linker-flavor=ld
endif
hostrust_flags += -C linker=$(HOSTLD) <todo: figure out how to pass
KBUILD_HOSTLDFLAGS>
--
Thanks,
~Nick Desaulniers
Powered by blists - more mailing lists