From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6F7C3191CE for ; Wed, 1 Apr 2026 05:53:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775022837; cv=none; b=Opltlt1+iERdDq74rLrXW/nSLn92MIVsaN1db48ocMT1BzRUDUKbndd54UGXl/qkykzQ4HGuSe34EQ6/c9RwFaljTTtwINxAC+sCZzLW9o/9YQ/UR51amTeAeXl3QDWwCbsXWNzEuydxdxhEY9b1o87aQQYatUwSQh9FqkKSizA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775022837; c=relaxed/simple; bh=g2FoQjD+ArNIPRI0HL34xQaUJLyLkCq+KRxmtHtpMeg=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:From:Cc:To: References:In-Reply-To; b=H/nx/gincQ763CiW46Qu6ONnsMFbY9zRakrat9PgELhDUuioqgQiUrQbq+wAU6CAY8qLqgujnf1CL0eB5yTTFuzkyC0JzHAAvtK5oaTe3uyqAwovhfduAdm1d7ruV9ZHUaAEIZYrwr9T2iWz0160lOpFbU/4tr8dtHNPu/f1EX0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=smile.fr; spf=pass smtp.mailfrom=smile.fr; dkim=pass (1024-bit key) header.d=smile.fr header.i=@smile.fr header.b=miOiiczj; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=smile.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=smile.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=smile.fr header.i=@smile.fr header.b="miOiiczj" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-43d02a71526so1480401f8f.3 for ; Tue, 31 Mar 2026 22:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smile.fr; s=google; t=1775022834; x=1775627634; darn=vger.kernel.org; h=in-reply-to:references:to:cc:from:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XB7/8kUkGjpEbBIqSBg4jtEPus045GV075WAdXE0OaU=; b=miOiiczjl+VIf5jZ1SvdCFwI9wqlPFLwyiQuvl1aznCpFaTCrj9zlMQW7b7byeIrR2 ezSXGp1bKSkGxm7b4btUCigPC4NrjxcxZX7YMbtervBsy2JIdiINEzLY9obrWMh+tHCI 6Shyofb6VIWb9sj5rgxnYtea8+tr80h2ZkoTY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775022834; x=1775627634; h=in-reply-to:references:to:cc:from:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XB7/8kUkGjpEbBIqSBg4jtEPus045GV075WAdXE0OaU=; b=ARsWPB79vLyUIAWBHvupzCC4FWsQxtFLNyplNJIdEhjik7pVRMovfOS7piNK9ZNT9p VOTwoRr954lHXFjckwGPU+TsMPVZlptgf3DoQ1XQ6Eugmus9SjoLW1vDI81Ep/fq/ZsR 9t7oHO+X6Y37NrWwRI669vJKLNirp4M2ybgotM/9JsngejWa3xn0cIbTLuGEuc0BG4+G RMyqhPB3Dkq2KS2E+1E48MJkSyWrOgh5vD2Hql9haZJr4IKD/w7cKVFeLMBLvDpk4sbS yfUEY7N4g67XVbBQ9cz0BjvvtBuAJ+Bblsp9mz4rlftTPf2R8qUkS025J20HhpOs7xjM W3Dg== X-Forwarded-Encrypted: i=1; AJvYcCX28ocqI/KPFj0wxGlp2zMnaivrhZS2Octc5AwoPBVRd4b7C8xLFeP8KgcRuB9t7k02f1xVmOPhQR2NOdw=@vger.kernel.org X-Gm-Message-State: AOJu0Yya4681d+yGFQutjjVDWUtrLHrykAMyH65vaBm+cPpIB392c35V N/2zLX89opGK4ZsZsns5/LR4vwb8UE++2wwZM7STf9kr49pKHLl+CeW2ZXzxU2Itqc0= X-Gm-Gg: ATEYQzyzDpqqJrxTdfvfKQEHnKuuiPxoFpLVTJTxBjBw2wxC8dWebU4hrCDg/0SfNu4 dvgEASjQHvj3psYaHtUUNIc9Yn17TXIBGzii2Twliw7uPtz7vPDciS9cXwajYc2Z20FZLHqGCwz AXd93vVXeoEkngR45h1JV3taSkr3Ph/GknCtpZVter0fRQn82RunYvwCXGJP3fSfzam5p/HwcOO azbgvzjiQ2HcL25D2PF6Y4wWBtqGYdTijflaAlXpj/RZABLa2I3Qa7LH3sFwGQMA6ZZ+890FydQ uRJS4r44sVoBlR1Y2+EyVLWqTZOVkYQu2gxyIwEPYOTC91faeVVKAzZtrm7Q9FEX3LP5bLfU/5q 2sAIli/rmqt8YQixgseFVjzUJjtDxPmoHkdFgQ/uh7xtz+zncztJoUEYFyE4WryZ/YCuo1q87ft A99jKpfae4nm890cBybj13fM+4b6n+SzjXNHigfsATNEcaFaUXWanEUR6jn8+wU6XM5UIz1MAww kDEEuPZ8Jn+ X-Received: by 2002:a05:6000:1789:b0:439:f605:afde with SMTP id ffacd0b85a97d-43d1511182dmr4123708f8f.51.1775022834019; Tue, 31 Mar 2026 22:53:54 -0700 (PDT) Received: from localhost (2a02-8440-250e-3787-955e-4c3b-8b0d-0555.rev.sfr.net. [2a02:8440:250e:3787:955e:4c3b:8b0d:555]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf21e2a7asm35560544f8f.7.2026.03.31.22.53.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Mar 2026 22:53:53 -0700 (PDT) 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 Content-Type: text/plain; charset=UTF-8 Date: Wed, 01 Apr 2026 07:53:52 +0200 Message-Id: Subject: Re: [PATCH v6] kbuild: host: use single executable for rustc -C linker From: "Yoann Congal" Cc: , , To: "Mohamad Alsadhan" , "Nathan Chancellor" , "Nicolas Schier" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" X-Mailer: aerc 0.20.0 References: <20260331000802.380-1-mo@sdhn.cc> In-Reply-To: <20260331000802.380-1-mo@sdhn.cc> On Tue Mar 31, 2026 at 2:08 AM CEST, Mohamad Alsadhan wrote: > 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 I tested this patch in the original environnement for the issue : a ccache-enabled Yocto build. It works. Thanks! Tested-by: Yoann Congal > Signed-off-by: Mohamad Alsadhan > --- > 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.symve= rs \ > 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= .rlib 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_QUI= ET) 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.rli= b \ > - $(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 $(pi= n_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 F= ORCE > + $(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 specificati= ons > 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 = 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. > +# To work around this, we generate a wrapper script that forwards argume= nts 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-t= ree > # 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 \ Does using "scripts/" without a $(obj)/$(srctree)/... prefix always works? I know I've suggested this as a quick fix. But I did not think about it a lot. > -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 Yoann Congal Smile ECS