From 5ff498e7bc1e5f1427ee4e86c34d58f38baafa43 Mon Sep 17 00:00:00 2001 From: HONG Yifan Date: Thu, 17 Oct 2024 21:04:30 +0000 Subject: [PATCH] FROMLIST: rust: add PROCMACROLDFLAGS These are additional flags to be passed when linking proc macros for the Rust toolchain. If unset, it defaults to $(HOSTLDFLAGS). This is needed because the list of flags to link hostprogs is not necessarily the same as the list of flags used to link libmacros.so. When we build proc macros, we need the latter, not the former. To distinguish between the two, introduce this new variable to stand out from HOSTLDFLAGS used to link other host progs. Signed-off-by: HONG Yifan Bug: 373900675 Link: https://lore.kernel.org/r/20241017210430.2401398-2-elsk@google.com Change-Id: Ifc678501880633e1074fea24bf1c4ec563b07a7e Signed-off-by: Alice Ryhl --- Documentation/kbuild/kbuild.rst | 7 +++++++ Makefile | 1 + rust/Makefile | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst index 74f2c42da6d1..f7b30ae9cac2 100644 --- a/Documentation/kbuild/kbuild.rst +++ b/Documentation/kbuild/kbuild.rst @@ -96,6 +96,13 @@ HOSTRUSTFLAGS ------------- Additional flags to be passed to $(HOSTRUSTC) when building host programs. +PROCMACROLDFLAGS +------------- +Additional flags to be passed when linking Rust proc macros. Since proc macros +are loaded by rustc at build time, they must be linked in a way that is +compatible with the rustc toolchain being used. If unset, it defaults to +$(HOSTLDFLAGS). + HOSTLDFLAGS ----------- Additional flags to be passed when linking host programs. diff --git a/Makefile b/Makefile index 9534876fe6ea..dc0e1de3869f 100644 --- a/Makefile +++ b/Makefile @@ -483,6 +483,7 @@ KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \ -I $(srctree)/scripts/include KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \ -Zallow-features= $(HOSTRUSTFLAGS) +KBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(HOSTLDFLAGS)) KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) diff --git a/rust/Makefile b/rust/Makefile index b5e0a73b78f3..3cd4dba4e1b6 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -336,7 +336,7 @@ 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))' \ + -Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \ --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ --crate-type proc-macro \ --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<