Skip to content

Commit 8a38f60

Browse files
maurerTreehugger Robot
authored andcommitted
UPSTREAM: 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 <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Tested-by: Alice Ryhl <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Acked-by: Miguel Ojeda <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> [ Upstream commit 80bac83 ] Change-Id: I4359da23ee569dc4e7ed1c8c213834ee2bbdccc3
1 parent 7f8f6cf commit 8a38f60

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

rust/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
383383
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
384384
cmd_rustc_procmacro = \
385385
$(RUSTC_OR_CLIPPY) $(rust_common_flags) \
386+
-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
387+
-Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
386388
--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
387389
--crate-type proc-macro \
388390
--crate-name $(patsubst lib%.so,%,$(notdir $@)) $<

scripts/Makefile.host

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ hostcxx_flags = -Wp,-MMD,$(depfile) \
9191
# current working directory, which may be not accessible in the out-of-tree
9292
# modules case.
9393
hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \
94+
-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
95+
-Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
9496
$(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
9597
$(HOSTRUSTFLAGS_$(target-stem))
9698

0 commit comments

Comments
 (0)