* [PATCH] kbuild: host: use single executable for rustc -C linker
@ 2026-02-25 10:28 Mohamad Alsadhan
2026-02-25 21:45 ` Nathan Chancellor
2026-02-26 10:12 ` Gary Guo
0 siblings, 2 replies; 3+ messages in thread
From: Mohamad Alsadhan @ 2026-02-25 10:28 UTC (permalink / raw)
To: nathan, nsc; +Cc: linux-kbuild, rust-for-linux, linux-kernel, Mohamad Alsadhan
rustc's -C linker= option expects a single executable path. When
HOSTCC contains a wrapper (e.g. "ccache gcc"), passing
-Clinker=$(HOSTCC) results in the shell splitting the value into
multiple words, and rustc interprets the additional word as an
input filename:
error: multiple input filenames provided ...
Use the last word of HOSTCC as the linker executable for host
Rust tools. This preserves wrapper usage for C host tools while
ensuring rustc receives a single executable path.
Closes: https://github.com/Rust-for-Linux/linux/issues/1224
Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
---
scripts/Makefile.host | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index c1dedf646..22eab2734 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -87,11 +87,18 @@ hostcxx_flags = -Wp,-MMD,$(depfile) \
$(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
$(HOSTCXXFLAGS_$(target-stem).o)
+# rustc's `-C linker=` expects a single executable path, not a command line.
+# HOSTCC may be a multi-word command when wrapped (e.g. "ccache gcc"),
+# which would otherwise be split by the shell and mis-parsed by rustc.
+#
+# Use a dedicated variable for the linker program used by host Rust tools.
+HOSTRUSTC_LINKER ?= $(lastword $(HOSTCC))
+
# `--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) \
+ -Clinker-flavor=gcc -Clinker=$(HOSTRUSTC_LINKER) \
-Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
$(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
$(HOSTRUSTFLAGS_$(target-stem))
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: host: use single executable for rustc -C linker
2026-02-25 10:28 [PATCH] kbuild: host: use single executable for rustc -C linker Mohamad Alsadhan
@ 2026-02-25 21:45 ` Nathan Chancellor
2026-02-26 10:12 ` Gary Guo
1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2026-02-25 21:45 UTC (permalink / raw)
To: Mohamad Alsadhan, Miguel Ojeda
Cc: nsc, linux-kbuild, rust-for-linux, linux-kernel
On Wed, Feb 25, 2026 at 01:28:19PM +0300, Mohamad Alsadhan wrote:
> rustc's -C linker= option expects a single executable path. When
> HOSTCC contains a wrapper (e.g. "ccache gcc"), passing
> -Clinker=$(HOSTCC) results in the shell splitting the value into
> multiple words, and rustc interprets the additional word as an
> input filename:
>
> error: multiple input filenames provided ...
>
> Use the last word of HOSTCC as the linker executable for host
> Rust tools. This preserves wrapper usage for C host tools while
> ensuring rustc receives a single executable path.
>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1224
>
> Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Miguel, as this is a Rust fix, do you want to take it? If so:
Acked-by: Nathan Chancellor <nathan@kernel.org>
Otherwise, I could take it via kbuild-fixes for 7.0.
> ---
> scripts/Makefile.host | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/Makefile.host b/scripts/Makefile.host
> index c1dedf646..22eab2734 100644
> --- a/scripts/Makefile.host
> +++ b/scripts/Makefile.host
> @@ -87,11 +87,18 @@ hostcxx_flags = -Wp,-MMD,$(depfile) \
> $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
> $(HOSTCXXFLAGS_$(target-stem).o)
>
> +# rustc's `-C linker=` expects a single executable path, not a command line.
> +# HOSTCC may be a multi-word command when wrapped (e.g. "ccache gcc"),
> +# which would otherwise be split by the shell and mis-parsed by rustc.
> +#
> +# Use a dedicated variable for the linker program used by host Rust tools.
> +HOSTRUSTC_LINKER ?= $(lastword $(HOSTCC))
I would probably use HOSTRUSTC_LD to mirror how the rest of Kbuild
refers to the linker.
> +
> # `--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) \
> + -Clinker-flavor=gcc -Clinker=$(HOSTRUSTC_LINKER) \
> -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
> $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
> $(HOSTRUSTFLAGS_$(target-stem))
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: host: use single executable for rustc -C linker
2026-02-25 10:28 [PATCH] kbuild: host: use single executable for rustc -C linker Mohamad Alsadhan
2026-02-25 21:45 ` Nathan Chancellor
@ 2026-02-26 10:12 ` Gary Guo
1 sibling, 0 replies; 3+ messages in thread
From: Gary Guo @ 2026-02-26 10:12 UTC (permalink / raw)
To: Mohamad Alsadhan, nathan, nsc; +Cc: linux-kbuild, rust-for-linux, linux-kernel
On Wed Feb 25, 2026 at 10:28 AM GMT, Mohamad Alsadhan wrote:
> rustc's -C linker= option expects a single executable path. When
> HOSTCC contains a wrapper (e.g. "ccache gcc"), passing
> -Clinker=$(HOSTCC) results in the shell splitting the value into
> multiple words, and rustc interprets the additional word as an
> input filename:
>
> error: multiple input filenames provided ...
>
> Use the last word of HOSTCC as the linker executable for host
> Rust tools. This preserves wrapper usage for C host tools while
> ensuring rustc receives a single executable path.
I don't think this is the right fix. Using only the last word is
(1) not what people asks for when they override HOSTCC. When a user ssays "call
ccache gcc", they don't want "gcc" to be invoked instead.
(2) not general enough. If instead of a wrapper, it's something with subcommand,
then this just breaks.
(3) going to cause surprises to people and be hard to troubleshoot when things
do not work.
I think the proper fix should be invoking a helper script with the multi-word
command be passed as environment variable which is then expanded by shell.
Best,
Gary
>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1224
>
> Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
> ---
> scripts/Makefile.host | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/Makefile.host b/scripts/Makefile.host
> index c1dedf646..22eab2734 100644
> --- a/scripts/Makefile.host
> +++ b/scripts/Makefile.host
> @@ -87,11 +87,18 @@ hostcxx_flags = -Wp,-MMD,$(depfile) \
> $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
> $(HOSTCXXFLAGS_$(target-stem).o)
>
> +# rustc's `-C linker=` expects a single executable path, not a command line.
> +# HOSTCC may be a multi-word command when wrapped (e.g. "ccache gcc"),
> +# which would otherwise be split by the shell and mis-parsed by rustc.
> +#
> +# Use a dedicated variable for the linker program used by host Rust tools.
> +HOSTRUSTC_LINKER ?= $(lastword $(HOSTCC))
> +
> # `--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) \
> + -Clinker-flavor=gcc -Clinker=$(HOSTRUSTC_LINKER) \
> -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
> $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
> $(HOSTRUSTFLAGS_$(target-stem))
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-26 10:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25 10:28 [PATCH] kbuild: host: use single executable for rustc -C linker Mohamad Alsadhan
2026-02-25 21:45 ` Nathan Chancellor
2026-02-26 10:12 ` Gary Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox