All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Matthew Maurer <mmaurer@google.com>
Cc: "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>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nicolas@fjasle.eu>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kbuild@vger.kernel.org
Subject: Re: [PATCH v2] rust: Respect HOSTCC when linking for host
Date: Tue, 19 Sep 2023 13:02:45 -0700	[thread overview]
Message-ID: <CAKwvOdmanTTOmmwSMn2rQa5Ri_TpTTp7XMXZQfVh_GA694VvAA@mail.gmail.com> (raw)
In-Reply-To: <CAKwvOdmsNwszu4Vk1K7e39hencNcjEmjr5q7EbTJCjdY5TDsFA@mail.gmail.com>

On Tue, Sep 19, 2023 at 12:44 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Mon, Sep 18, 2023 at 4:44 PM Matthew Maurer <mmaurer@google.com> 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.
> >
> > Signed-off-by: Matthew Maurer <mmaurer@google.com>
> > ---
> >
> > Updated the patch to reflect Nick's comment that KBUILD_HOSTLDFLAGS
> > should be respected as well.
> >
> > I did not switch it to use HOSTLD for two reasons:
> > * That variable is not globally defined - it is only available in two
> >   subdirectories of tools/
> > * C host scripts are linked by HOSTCC as well, even when linking a
> >   collection of object files. It *prints* HOSTLD, but invokes HOSTCC.
> >   See scripts/Makefile.host cmd_host-cmulti for an example.
>
> Sure, that makes sense to me, thanks for pointing that out.
>
> >
> >  rust/Makefile         | 4 ++++
> >  scripts/Makefile.host | 4 ++++
> >  2 files changed, 8 insertions(+)
> >
> > diff --git a/rust/Makefile b/rust/Makefile
> > index 87958e864be0..b60b7eb8c5a0 100644
> > --- a/rust/Makefile
> > +++ b/rust/Makefile
> > @@ -380,9 +380,13 @@ $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
> >  $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
> >         $(call if_changed,exports)
> >
> > +KBUILD_HOSTLDFLAGS_SQ = '$(subst ','\'',$(KBUILD_HOSTLDFLAGS))'
>
> I don't think we need to do this kind of escaping. If a linker flag is
> passed to the linker directly as the driver has spaces such as `-z
> relro`, if it is instead passed to the compiler as the driver will not
> contain spaces (`-Wl,-z,relro`). As such, I don't think we need this
> escaping (famous last words).  Mind submitting a v3 without it?

Thanks for clarifying off list that:
```
It's not escaping the spaces, it's escaping any quotes
example: -Clink-args='-Wl,-z,relro -Wl,-linker-plugin-lto'
Without the quote, the second one would go to rustc rather than the linker
```

Sorry for misunderstanding what exactly we were escaping here and why;
thanks for implementing my suggestion of passing along
KBUILD_HOSTLDFLAGS though.  That will avoid issues for Android
downstream.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> > +
> >  quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
> >        cmd_rustc_procmacro = \
> >         $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
> > +               -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
> > +               -Clink-args=$(KBUILD_HOSTLDFLAGS_SQ) \
> >                 --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..dc0410cae5ca 100644
> > --- a/scripts/Makefile.host
> > +++ b/scripts/Makefile.host
> > @@ -87,10 +87,14 @@ hostcxx_flags  = -Wp,-MMD,$(depfile) \
> >                   $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
> >                   $(HOSTCXXFLAGS_$(target-stem).o)
> >
> > +KBUILD_HOSTLDFLAGS_SQ = '$(subst ','\'',$(KBUILD_HOSTLDFLAGS))'
> > +
> >  # `--out-dir` is required to avoid temporaries being created by `rustc` in the
> >  # current working directory, which may be not accessible in the out-of-tree
> >  # modules case.
> >  hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
> > +                -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
> > +                -Clink-args=$(KBUILD_HOSTLDFLAGS_SQ) \
> >                   $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
> >                   $(HOSTRUSTFLAGS_$(target-stem))
> >
> > --
> > 2.42.0.459.ge4e396fd5e-goog
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers



-- 
Thanks,
~Nick Desaulniers

  reply	other threads:[~2023-09-19 20:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 23:43 [PATCH v2] rust: Respect HOSTCC when linking for host Matthew Maurer
2023-09-19 19:18 ` Martin Rodriguez Reboredo
2023-09-19 19:44 ` Nick Desaulniers
2023-09-19 20:02   ` Nick Desaulniers [this message]
2023-09-26 10:45 ` Alice Ryhl
2023-09-26 17:02 ` 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=CAKwvOdmanTTOmmwSMn2rQa5Ri_TpTTp7XMXZQfVh_GA694VvAA@mail.gmail.com \
    --to=ndesaulniers@google.com \
    --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=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.