rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] rust: Respect HOSTCC when linking for host
@ 2023-10-05 21:39 Matthew Maurer
  2023-10-05 22:16 ` Martin Rodriguez Reboredo
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Matthew Maurer @ 2023-10-05 21:39 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada,
	Nathan Chancellor, Nick Desaulniers
  Cc: Matthew Maurer, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Nicolas Schier,
	Tom Rix, rust-for-linux, linux-kernel, linux-kbuild, llvm

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. The linker-flavor selects both which linker to search
for if the linker is unset, and which kind of linker flags to pass.
Without this flag, `rustc` would attempt to determine which flags to
pass based on the name of the binary passed as `HOSTCC`. `gcc` is the
name of the linker-flavor used by `rustc` for all C compilers, including
both `gcc` and `clang`.

Signed-off-by: Matthew Maurer <mmaurer@google.com>
---

Edited to use escsq in both Makefiles, as per Masahiro Yamada's
suggestion.

 rust/Makefile         | 2 ++
 scripts/Makefile.host | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/rust/Makefile b/rust/Makefile
index 87958e864be0..2ddd821d9435 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -383,6 +383,8 @@ $(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) \
+		-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
+		-Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
 		--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..08d83d9db31a 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -91,6 +91,8 @@ 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) \
+		 -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
+		 -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
                  $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
                  $(HOSTRUSTFLAGS_$(target-stem))
 
-- 
2.42.0.609.gbb76f46606-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] rust: Respect HOSTCC when linking for host
  2023-10-05 21:39 [PATCH v4] rust: Respect HOSTCC when linking for host Matthew Maurer
@ 2023-10-05 22:16 ` Martin Rodriguez Reboredo
  2023-10-06  9:39 ` Alice Ryhl
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-10-05 22:16 UTC (permalink / raw)
  To: Matthew Maurer, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Masahiro Yamada, Nathan Chancellor, Nick Desaulniers
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Nicolas Schier, Tom Rix,
	rust-for-linux, linux-kernel, linux-kbuild, llvm

On 10/5/23 18:39, 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. The linker-flavor selects both which linker to search
> for if the linker is unset, and which kind of linker flags to pass.
> Without this flag, `rustc` would attempt to determine which flags to
> pass based on the name of the binary passed as `HOSTCC`. `gcc` is the
> name of the linker-flavor used by `rustc` for all C compilers, including
> both `gcc` and `clang`.
> 
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> ---
> [...]
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v4] rust: Respect HOSTCC when linking for host
  2023-10-05 21:39 [PATCH v4] rust: Respect HOSTCC when linking for host Matthew Maurer
  2023-10-05 22:16 ` Martin Rodriguez Reboredo
@ 2023-10-06  9:39 ` Alice Ryhl
  2023-10-06 20:39 ` Nick Desaulniers
  2023-10-07 15:37 ` Masahiro Yamada
  3 siblings, 0 replies; 7+ messages in thread
From: Alice Ryhl @ 2023-10-06  9:39 UTC (permalink / raw)
  To: mmaurer
  Cc: a.hindborg, alex.gaynor, aliceryhl, benno.lossin, bjorn3_gh,
	boqun.feng, gary, linux-kbuild, linux-kernel, llvm, masahiroy,
	nathan, ndesaulniers, nicolas, ojeda, rust-for-linux, trix,
	wedsonaf

Matthew Maurer <mmaurer@google.com> writes:
> 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. The linker-flavor selects both which linker to search
> for if the linker is unset, and which kind of linker flags to pass.
> Without this flag, `rustc` would attempt to determine which flags to
> pass based on the name of the binary passed as `HOSTCC`. `gcc` is the
> name of the linker-flavor used by `rustc` for all C compilers, including
> both `gcc` and `clang`.
> 
> Signed-off-by: Matthew Maurer <mmaurer@google.com>

Tested-by: Alice Ryhl <aliceryhl@google.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] rust: Respect HOSTCC when linking for host
  2023-10-05 21:39 [PATCH v4] rust: Respect HOSTCC when linking for host Matthew Maurer
  2023-10-05 22:16 ` Martin Rodriguez Reboredo
  2023-10-06  9:39 ` Alice Ryhl
@ 2023-10-06 20:39 ` Nick Desaulniers
  2023-10-07 15:37 ` Masahiro Yamada
  3 siblings, 0 replies; 7+ messages in thread
From: Nick Desaulniers @ 2023-10-06 20:39 UTC (permalink / raw)
  To: Matthew Maurer
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Masahiro Yamada,
	Nathan Chancellor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Nicolas Schier,
	Tom Rix, rust-for-linux, linux-kernel, linux-kbuild, llvm

On Thu, Oct 5, 2023 at 2:41 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. The linker-flavor selects both which linker to search
> for if the linker is unset, and which kind of linker flags to pass.
> Without this flag, `rustc` would attempt to determine which flags to
> pass based on the name of the binary passed as `HOSTCC`. `gcc` is the
> name of the linker-flavor used by `rustc` for all C compilers, including
> both `gcc` and `clang`.
>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> ---
>
> Edited to use escsq in both Makefiles, as per Masahiro Yamada's
> suggestion.

That looks better; thanks Matthew!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
>  rust/Makefile         | 2 ++
>  scripts/Makefile.host | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/rust/Makefile b/rust/Makefile
> index 87958e864be0..2ddd821d9435 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -383,6 +383,8 @@ $(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) \
> +               -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
> +               -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
>                 --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..08d83d9db31a 100644
> --- a/scripts/Makefile.host
> +++ b/scripts/Makefile.host
> @@ -91,6 +91,8 @@ 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) \
> +                -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
> +                -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
>                   $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
>                   $(HOSTRUSTFLAGS_$(target-stem))
>
> --
> 2.42.0.609.gbb76f46606-goog
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] rust: Respect HOSTCC when linking for host
  2023-10-05 21:39 [PATCH v4] rust: Respect HOSTCC when linking for host Matthew Maurer
                   ` (2 preceding siblings ...)
  2023-10-06 20:39 ` Nick Desaulniers
@ 2023-10-07 15:37 ` Masahiro Yamada
  2023-10-09 22:00   ` Miguel Ojeda
  3 siblings, 1 reply; 7+ messages in thread
From: Masahiro Yamada @ 2023-10-07 15:37 UTC (permalink / raw)
  To: Matthew Maurer
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Nathan Chancellor, Nick Desaulniers, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Nicolas Schier, Tom Rix, rust-for-linux, linux-kernel,
	linux-kbuild, llvm

On Fri, Oct 6, 2023 at 6:41 AM 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. The linker-flavor selects both which linker to search
> for if the linker is unset, and which kind of linker flags to pass.
> Without this flag, `rustc` would attempt to determine which flags to
> pass based on the name of the binary passed as `HOSTCC`. `gcc` is the
> name of the linker-flavor used by `rustc` for all C compilers, including
> both `gcc` and `clang`.
>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> ---
>
> Edited to use escsq in both Makefiles, as per Masahiro Yamada's
> suggestion.



Acked-by: Masahiro Yamada <masahiroy@kernel.org>

if Miguel picked this up.


Please let me know if I should pick this up.





-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] rust: Respect HOSTCC when linking for host
  2023-10-07 15:37 ` Masahiro Yamada
@ 2023-10-09 22:00   ` Miguel Ojeda
  2023-10-14  9:26     ` Masahiro Yamada
  0 siblings, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2023-10-09 22:00 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Matthew Maurer, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Nathan Chancellor, Nick Desaulniers, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Nicolas Schier, Tom Rix, rust-for-linux, linux-kernel,
	linux-kbuild, llvm

On Sat, Oct 7, 2023 at 5:38 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Acked-by: Masahiro Yamada <masahiroy@kernel.org>
>
> if Miguel picked this up.
>
> Please let me know if I should pick this up.

Thanks a lot for taking a look Masahiro -- either way is fine for me.
If you want to take it, please feel free to add my `Acked-by`.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4] rust: Respect HOSTCC when linking for host
  2023-10-09 22:00   ` Miguel Ojeda
@ 2023-10-14  9:26     ` Masahiro Yamada
  0 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2023-10-14  9:26 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Matthew Maurer, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Nathan Chancellor, Nick Desaulniers, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Nicolas Schier, Tom Rix, rust-for-linux, linux-kernel,
	linux-kbuild, llvm

On Tue, Oct 10, 2023 at 7:00 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Sat, Oct 7, 2023 at 5:38 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > Acked-by: Masahiro Yamada <masahiroy@kernel.org>
> >
> > if Miguel picked this up.
> >
> > Please let me know if I should pick this up.
>
> Thanks a lot for taking a look Masahiro -- either way is fine for me.
> If you want to take it, please feel free to add my `Acked-by`.
>
> Cheers,
> Miguel

I do not see this yet in linux-next.

So, I applied to linux-kbuild with Miguel's Ack now.



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-10-14  9:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-05 21:39 [PATCH v4] rust: Respect HOSTCC when linking for host Matthew Maurer
2023-10-05 22:16 ` Martin Rodriguez Reboredo
2023-10-06  9:39 ` Alice Ryhl
2023-10-06 20:39 ` Nick Desaulniers
2023-10-07 15:37 ` Masahiro Yamada
2023-10-09 22:00   ` Miguel Ojeda
2023-10-14  9:26     ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).