All of lore.kernel.org
 help / color / mirror / Atom feed
From: Finn Behrens <me@kloenk.dev>
To: Matthew Maurer <mmaurer@google.com>
Cc: "Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Nicolas Schier" <nicolas@fjasle.eu>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kbuild@vger.kernel.org
Subject: Re: [PATCH] rust: Respect HOSTCC when linking for host
Date: Sun, 17 Sep 2023 00:39:46 +0200	[thread overview]
Message-ID: <446E67B5-0200-4982-994B-B30C2DEDF098@kloenk.dev> (raw)
In-Reply-To: <CAGSQo02p0LWZgV8oVidwvN6X__rv3-rj+ZVg9SaZ5Kx+zYahYQ@mail.gmail.com>



On 16 Sep 2023, at 21:54, Matthew Maurer wrote:

> On Sat, Sep 16, 2023 at 11:07 AM Finn Behrens <me@kloenk.dev> wrote:
>>
>>
>>
>> On 16 Sep 2023, at 19:53, Björn Roy Baron wrote:
>>
>>> On Saturday, September 16th, 2023 at 18:52, Finn Behrens <me@kloenk.dev> wrote:
>>>
>>>>
>>>> On 15 Sep 2023, at 19:28, Matthew Maurer wrote:
>>>>
>>>>> Currently, rustc defaults to invoking `cc`, even if `HOSTCC` is defined,
>>>>> resulting in build failures in hermetic environments where `cc` does not
>>>>> exist. This includes both hostprogs and proc-macros.
>>>>>
>>>>> Since we are setting the linker to `HOSTCC`, we set the linker flavor to
>>>>> `gcc` explicitly.
>>>> But as `HOSTCC` could also be clang, the linker flavor would then be wrong, would that create a problem?
>>>
>>> Rustc uses the gcc linker flavor for clang too. There has been a proposal to split it up, but I'm not sure of the status of that. In any case clang's cli is similar enough to gcc that it works fine to use the gcc linker flavor.
>>>
>> In that case this looks very reasonable.
>>
>> Second thing I noticed is that `HOSTCC` could be the wrong variable, and `HOSTLD` would make more sense as we look for the linker and not the general C compiler.
>>
> Yes, thanks Bjorn - "gcc" is the linker flavor used for "Use the C
> compiler as a linker".
>
> With regards to HOSTLD, I was trying to make the minimum possible
> change. Currently, it is using the command `cc` as a linker, so this
> would preserve existing behavior when HOSTCC is unset.
>
> If we would prefer `HOSTLD` instead we can do that, but we would need
> to additionally inspect `LLVM` to set the linker flavor accordingly
> (e.g. set ld vs ld.lld).
>
> Do folks have strong opinions between these? My primary concern is to
> avoid calling programs by foo when their HOSTFOO variable is set.
I don’t have an educated opinion at all, mainly nudged in the direction, so that the existence if `HOSTLD` does not get overlooked. If there is a valid reason to not use it, this patch looks good to me.
>
> See https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavor
> for details on linker flavor settings.
>>>>>
>>>>> Signed-off-by: Matthew Maurer <mmaurer@google.com>
>>>>> ---
>>>>>  rust/Makefile         | 1 +
>>>>>  scripts/Makefile.host | 1 +
>>>>>  2 files changed, 2 insertions(+)
>>>>>
>>>>> diff --git a/rust/Makefile b/rust/Makefile
>>>>> index 87958e864be0..2a2352638f11 100644
>>>>> --- a/rust/Makefile
>>>>> +++ b/rust/Makefile
>>>>> @@ -383,6 +383,7 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
>>>>>  quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
>>>>>        cmd_rustc_procmacro = \
>>>>>     $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
>>>>> +           -C linker-flavor=gcc -C linker=$(HOSTCC) \
>>>>>             --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
>>>>>             --crate-type proc-macro \
>>>>>             --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
>>>>> diff --git a/scripts/Makefile.host b/scripts/Makefile.host
>>>>> index 8f7f842b54f9..0aa95a3af1c4 100644
>>>>> --- a/scripts/Makefile.host
>>>>> +++ b/scripts/Makefile.host
>>>>> @@ -91,6 +91,7 @@ hostcxx_flags  = -Wp,-MMD,$(depfile) \
>>>>>  # current working directory, which may be not accessible in the out-of-tree
>>>>>  # modules case.
>>>>>  hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
>>>>> +            -C linker-flavor=gcc -C linker=$(HOSTCC) \
>>>>>                   $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
>>>>>                   $(HOSTRUSTFLAGS_$(target-stem))
>>>>>
>>>>> --
>>>>> 2.42.0.459.ge4e396fd5e-goog

  reply	other threads:[~2023-09-16 22:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15 17:28 [PATCH] rust: Respect HOSTCC when linking for host Matthew Maurer
2023-09-15 22:51 ` Martin Rodriguez Reboredo
2023-09-16 16:52 ` Finn Behrens
2023-09-16 17:53   ` Björn Roy Baron
2023-09-16 18:06     ` Finn Behrens
2023-09-16 19:54       ` Matthew Maurer
2023-09-16 22:39         ` Finn Behrens [this message]
2023-09-17 13:24         ` Martin Rodriguez Reboredo
2023-09-18 15:24         ` Nick Desaulniers
2023-09-18 16:38           ` Matthew Maurer
2023-09-18 18:43             ` Nick Desaulniers
2023-09-18 18:55               ` Matthew Maurer
2023-09-26 16:51                 ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=446E67B5-0200-4982-994B-B30C2DEDF098@kloenk.dev \
    --to=me@kloenk.dev \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mmaurer@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nicolas@fjasle.eu \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.