From nobody Thu Apr 2 01:08:43 2026 Received: from outbound.ms.icloud.com (p-west3-cluster3-host10-snip4-7.eps.apple.com [57.103.72.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 852F42F87B for ; Tue, 31 Mar 2026 00:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=57.103.72.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774915753; cv=none; b=eh+k3ofvleBcvBCT8VXTTDk5Qse+GOHK2Y50jxSabU3i+KxBh8wOu8NL95iJih9A+0gS53RkPCLMLC/z5hJZClk5h5aZxfSiGsTJMQCbRpvns6h7AcoqQmPkwEhvRJ4r2b9g5H7Fo4AT1wLqyzd0AI9NkBhPoRCcBn4KqLkhjAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774915753; c=relaxed/simple; bh=dnnbJV0sTXh2CPBUsaI+ZkS6JT3vt2EoY+zkLPsiGYI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bRr85j+f4WDx5Yk3P5zgH72jUuZ5agdezyRTG75xOZSjVBmkgyNQyx3Vwlc6VDs8U1fuRG8Yi60Je2QcocM+M6Bw1WA3EaAFJcJ5fEM3EckfjJym8DFPB0tNWbLKDapv9xUqJFTqDHkxN7dLg1I1ia9tRPSbgvT5ihifQc9KKCI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sdhn.cc; spf=pass smtp.mailfrom=sdhn.cc; dkim=pass (2048-bit key) header.d=sdhn.cc header.i=@sdhn.cc header.b=OfH9/Eml; arc=none smtp.client-ip=57.103.72.248 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sdhn.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sdhn.cc Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sdhn.cc header.i=@sdhn.cc header.b="OfH9/Eml" Received: from outbound.ms.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-3a-100-percent-9 (Postfix) with ESMTPS id 5487D18000AC; Tue, 31 Mar 2026 00:09:08 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sdhn.cc; s=sig1; t=1774915750; x=1777507750; bh=Smne3kvEeW3OhPwYneVv7rprnRqi1ClwLKoCrpKcW6E=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=OfH9/EmldTD+p2bHHOgkNDKHiczX3APswqEe6M6BK/D5TIqUF6ljT92NYDayWtwg8J0BuSOfziW2a6vjbPevUyGOSrYbN0t9/XhG26iKZ2y7lJsmwU+DAawBu+9DW5bAoL9HEg20kd7UwjJ9nVhncCeYkbHgCniL7imT0ZYv8akDVJ831Be4K7bxzmEpc9lz41XoCeHXFhhLzdiOlHvHfODBp6uC4brGmbyCTubeMHjO/3Ax5SEoBgBO4kb+Oi1l5oVJWJvBZRPCxSS1SLxPQRqSuGYXvzjeYD6Iz3QO4VW2ArHvCjoHoojf+9+mLEO8k9qGopNqKxClqwd30GKPDg== mail-alias-created-date: 1772007648188 Received: from localhost.localdomain (unknown [17.57.154.37]) by p00-icloudmta-asmtp-us-west-3a-100-percent-9 (Postfix) with ESMTPSA id B2224180013D; Tue, 31 Mar 2026 00:09:03 +0000 (UTC) From: Mohamad Alsadhan To: Nathan Chancellor , Nicolas Schier , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: Mohamad Alsadhan , Yoann Congal , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH v6] kbuild: host: use single executable for rustc -C linker Date: Tue, 31 Mar 2026 03:08:01 +0300 Message-ID: <20260331000802.380-1-mo@sdhn.cc> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: seOAf2rxlFGUM32eJhcnyXWZcOsUjtRx X-Authority-Info-Out: v=2.4 cv=W4E1lBWk c=1 sm=1 tr=0 ts=69cb10a5 cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=NEAV23lmAAAA:8 a=VwQbUJbxAAAA:8 a=1jKZnVWUeMPpqZDTVXkA:9 X-Proofpoint-GUID: seOAf2rxlFGUM32eJhcnyXWZcOsUjtRx X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzMxMDAwMCBTYWx0ZWRfXyS9yr4hSqkMV 8iLsV3EeAVX+6Gb/ySDchja6l+HFsQhmbwpEWuowA3peZWsoEu8zD4FUaes+R5vOqOqOZKMnFn5 dEM1BlEaIEatcC2wAwBTjJ22WiG4BnVezNP8/l+cKFZH4M2NUL2rsZoshi21Yd6i2dGhoueKdrl 0JRyQVhqQrnFjJuVYcmFyDmxozzx+bKuazMixLulLIfHigBJCgrBGi4eUUippQlOkudXU9Yi+EH eUGtb7Z5LDThniEuHngy2y+vpOUGAyTTz6CeQapLfvYtNsadXum5idV4i53A5TsZXm9vCeOXS28 pSOTZoo6bz67ou3AbV74nsSxtRdD7VMX/DxpfMy+GCGMbF+o4t/gAj8/I/BL9c= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-30_01,2026-03-28_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 clxscore=1030 suspectscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2603310000 Content-Type: text/plain; charset="utf-8" rustc's -C linker=3D option expects a single executable path. When HOSTCC contains a wrapper (e.g. "ccache gcc"), passing `-Clinker=3D$(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 ... Generate a small wrapper script and pass it to -Clinker e.g. ``` #!/bin/sh exec ccache gcc "$@" ``` This fix should be general enough to address most if not all cases (incl. wrappers or subcommands) and avoids surprises of simpler fixes like just defaulting to gcc. This avoids passing the user command as an environment variable as that would be more challenging to trace and debug shell expansions. Link: https://github.com/Rust-for-Linux/linux/issues/1224 Suggested-by: Yoann Congal Signed-off-by: Mohamad Alsadhan Tested-by: Yoann Congal --- v5 -> v6: - Add fix to `rust/Makefile` as well (Yoann) - Include script to `.gitignore` and make clean (Nicolas) - Add back the outer `exec` to the command v4 -> v5: - Fix word splitting issues - Remove unnecessary `exec sh -c` and simplify generated script v3 -> v4: - Use filechk instead of if_changed macro to regenerate script - Remove trailing space at EOL v2 -> v3: - Scrap previous hacky approaches (e.g. using lastword) and go with a proper fix (Gary) which turned out not that complex to implement. v1 -> v2: - Rename HOSTRUSTC_LINKER to HOSTRUSTC_LD for consistency - Introduce explicit HOSTRUSTC_LD override - Warn when falling back due to multi-argument HOSTCC - Error out if a user-specified HOSTRUSTC_LD is not an executable v1: https://lore.kernel.org/all/20260225102819.16553-1-mo@sdhn.cc/ v2: https://lore.kernel.org/all/20260227132713.23106-1-mo@sdhn.cc/ v3: https://lore.kernel.org/all/20260312002852.11292-1-mo@sdhn.cc/ v4: https://lore.kernel.org/all/20260317112021.14353-1-mo@sdhn.cc/ v5: https://lore.kernel.org/all/20260321150034.9915-1-mo@sdhn.cc/ --- Makefile | 3 ++- rust/Makefile | 8 +++++--- scripts/.gitignore | 1 + scripts/Makefile.host | 23 +++++++++++++++++++++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 1a219bf1c..5ebeef67f 100644 --- a/Makefile +++ b/Makefile @@ -1651,7 +1651,8 @@ CLEAN_FILES +=3D vmlinux.symvers modules-only.symvers= \ modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \ compile_commands.json rust/test \ rust-project.json .vmlinux.objs .vmlinux.export.c \ - .builtin-dtbs-list .builtin-dtb.S + .builtin-dtbs-list .builtin-dtb.S \ + scripts/rustc-wrapper =20 # Directories & files removed with 'make mrproper' MRPROPER_FILES +=3D include/config include/generated \ diff --git a/rust/Makefile b/rust/Makefile index 5eca6a817..6bc761a31 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -565,7 +565,7 @@ $(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.r= lib FORCE quiet_cmd_rustc_procmacro =3D $(RUSTC_OR_CLIPPY_QUIET) P $@ cmd_rustc_procmacro =3D \ $(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \ - -Clinker-flavor=3Dgcc -Clinker=3D$(HOSTCC) \ + -Clinker-flavor=3Dgcc -Clinker=3Dscripts/rustc-wrapper \ -Clink-args=3D'$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \ --emit=3Ddep-info=3D$(depfile) --emit=3Dlink=3D$@ --extern proc_macro \ --crate-type proc-macro -L$(objtree)/$(obj) \ @@ -576,12 +576,14 @@ quiet_cmd_rustc_procmacro =3D $(RUSTC_OR_CLIPPY_QUIET= ) P $@ $(obj)/$(libmacros_name): private rustc_target_flags =3D \ --extern proc_macro2 --extern quote --extern syn $(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \ - $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE + $(obj)/libquote.rlib $(obj)/libsyn.rlib \ + scripts/rustc-wrapper FORCE +$(call if_changed_dep,rustc_procmacro) =20 $(obj)/$(libpin_init_internal_name): private rustc_target_flags =3D $(pin_= init_internal-flags) $(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \ - $(obj)/libproc_macro2.rlib $(obj)/libquote.rlib $(obj)/libsyn.rlib FOR= CE + $(obj)/libproc_macro2.rlib $(obj)/libquote.rlib $(obj)/libsyn.rlib \ + scripts/rustc-wrapper FORCE +$(call if_changed_dep,rustc_procmacro) =20 # `rustc` requires `-Zunstable-options` to use custom target specifications diff --git a/scripts/.gitignore b/scripts/.gitignore index 4215c2208..b3948b148 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -6,6 +6,7 @@ /kallsyms /module.lds /recordmcount +/rustc-wrapper /rustdoc_test_builder /rustdoc_test_gen /sign-file diff --git a/scripts/Makefile.host b/scripts/Makefile.host index c1dedf646..77a76c1d1 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -87,11 +87,30 @@ hostcxx_flags =3D -Wp,-MMD,$(depfile) \ $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ $(HOSTCXXFLAGS_$(target-stem).o) =20 +# rustc's `-Clinker=3D` expects a single executable path, not a command li= ne. +# `HOSTCC` may be a multi-word command when wrapped (e.g. "ccache gcc"), w= hich +# would otherwise be split by the shell and mis-parsed by rustc. +# To work around this, we generate a wrapper script that forwards argument= s to +# `HOSTRUSTC_LD` so that such commands can be used safely. +# +# Set `HOSTRUSTC_LD` for a different rustc linker command than `HOSTCC` +HOSTRUSTC_LD ?=3D $(HOSTCC) + +define filechk_rustc-wrapper + printf "%s\n" \ + '#!/bin/sh' \ + 'exec $(call escsq,$(HOSTRUSTC_LD)) "$$@"' +endef + +$(obj)/rustc-wrapper: FORCE + $(call filechk,rustc-wrapper) + $(Q)chmod +x $@ + # `--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 =3D --out-dir $(dir $@) --emit=3Ddep-info=3D$(depfile) \ - -Clinker-flavor=3Dgcc -Clinker=3D$(HOSTCC) \ + -Clinker-flavor=3Dgcc -Clinker=3Dscripts/rustc-wrapper \ -Clink-args=3D'$(call escsq,$(KBUILD_HOSTLDFLAGS))' \ $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ $(HOSTRUSTFLAGS_$(target-stem)) @@ -153,7 +172,7 @@ $(host-cxxobjs): $(obj)/%.o: $(obj)/%.cc FORCE quiet_cmd_host-rust =3D HOSTRUSTC $@ cmd_host-rust =3D \ $(HOSTRUSTC) $(hostrust_flags) --emit=3Dlink=3D$@ $< -$(host-rust): $(obj)/%: $(src)/%.rs FORCE +$(host-rust): $(obj)/%: $(src)/%.rs $(obj)/rustc-wrapper FORCE +$(call if_changed_dep,host-rust) =20 targets +=3D $(host-csingle) $(host-cmulti) $(host-cobjs) \ --=20 2.52.0