]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
rust: Respect HOSTCC when linking for host
authorMatthew Maurer <mmaurer@google.com>
Thu, 5 Oct 2023 21:39:58 +0000 (21:39 +0000)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 14 Oct 2023 09:26:28 +0000 (18:26 +0900)
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>
rust/Makefile
scripts/Makefile.host

index 87958e864be02508a01085a3929901eb49b1c565..2ddd821d943590d53c71809a03d091dda8430c64 100644 (file)
@@ -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 $@)) $<
index 8f7f842b54f9ee2fc2c30c6b0c037fc3cb70ad99..08d83d9db31a138420f075dd45630046a76d1180 100644 (file)
@@ -91,6 +91,8 @@ hostcxx_flags  = -Wp,-MMD,$(depfile) \
 # 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) \
+                -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
                  $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
                  $(HOSTRUSTFLAGS_$(target-stem))