summaryrefslogtreecommitdiff
path: root/rust/Makefile
diff options
context:
space:
mode:
authorMatthew Maurer <mmaurer@google.com>2023-10-06 00:39:58 +0300
committerMasahiro Yamada <masahiroy@kernel.org>2023-10-14 12:26:28 +0300
commit80bac83a739d36d227aa5c54f6ed417f13c086dd (patch)
treed7e473e4c988e02ccf6685e42207fb217c007f24 /rust/Makefile
parentffa46bbc5892ebba8a95c839dc302cad7f22c209 (diff)
downloadlinux-80bac83a739d36d227aa5c54f6ed417f13c086dd.tar.xz
rust: Respect HOSTCC when linking for host
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> Tested-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Acked-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Diffstat (limited to 'rust/Makefile')
-rw-r--r--rust/Makefile2
1 files changed, 2 insertions, 0 deletions
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 $@)) $<