Skip to content

Commit 30f998c

Browse files
erthalionacmel
authored andcommitted
tools build: Fix rust cross compilation
Currently no target is specified to compile rust code when needed, which breaks cross compilation. E.g. for arm64: LD /tmp/build/tests/workloads/perf-test-in.o aarch64-linux-gnu-ld: /tmp/build/tests/workloads/code_with_type.a(code_with_type.code_with_type.d12f4324cb53c560-cgu.0.rcgu.o): Relocations in generic ELF (EM: 62) aarch64-linux-gnu-ld: /tmp/build/tests/workloads/code_with_type.a(code_with_type.code_with_type.d12f4324cb53c560-cgu.0.rcgu.o): Relocations in generic ELF (EM: 62) [...repeated...] aarch64-linux-gnu-ld: /tmp/build/tests/workloads/code_with_type.a(code_with_type.code_with_type.d12f4324cb53c560-cgu.0.rcgu.o): Relocations in generic ELF (EM: 62) aarch64-linux-gnu-ld: /tmp/build/tests/workloads/code_with_type.a(code_with_type.code_with_type.d12f4324cb53c560-cgu.0.rcgu.o): Relocations in generic ELF (EM: 62) aarch64-linux-gnu-ld: /tmp/build/tests/workloads/code_with_type.a: error adding symbols: file in wrong format make[5]: *** [/perf/tools/build/Makefile.build:162: /tmp/build/tests/workloads/perf-test-in.o] Error 1 make[4]: *** [/perf/tools/build/Makefile.build:156: workloads] Error 2 make[3]: *** [/perf/tools/build/Makefile.build:156: tests] Error 2 make[2]: *** [Makefile.perf:785: /tmp/build/perf-test-in.o] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [Makefile.perf:289: sub-make] Error 2 make: *** [Makefile:76: all] Error 2 Detect required target and pass it via rust_flags to the compiler. Note that CROSS_COMPILE might be different from what rust compiler expects, since it may omit the target vendor value, e.g. "aarch64-linux-gnu" instead of "aarch64-unknown-linux-gnu". Thus explicitly map supported CROSS_COMPILE values to corresponding Rust versions, as suggested by Miguel Ojeda. Tested using arm64 cross-compilation example from [1]. Fixes: 2e05bb5 ("perf test workload: Add code_with_type test workload") Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com> Cc: Levi Zim <i@kxxt.dev> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nicolas Schier <nsc@kernel.org> Link: https://perfwiki.github.io/main/arm64-cross-compilation-dockerfile/ [1] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent b6712d9 commit 30f998c

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

tools/build/Build.include

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ c_flags_2 = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(c_flags_1))
9898
c_flags = $(filter-out $(CFLAGS_REMOVE_$(obj)), $(c_flags_2))
9999
cxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(obj))
100100

101+
###
102+
# Rust flags to be used on rule definition, includes:
103+
# - global $(RUST_FLAGS)
104+
# - per target Rust flags
105+
# - per object Rust flags
106+
rust_flags_1 = $(RUST_FLAGS) $(RUST_FLAGS_$(basetarget).o) $(RUST_FLAGS_$(obj))
107+
rust_flags_2 = $(filter-out $(RUST_FLAGS_REMOVE_$(basetarget).o), $(rust_flags_1))
108+
rust_flags = $(filter-out $(RUST_FLAGS_REMOVE_$(obj)), $(rust_flags_2))
109+
101110
###
102111
## HOSTCC C flags
103112

tools/perf/Makefile.config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,24 @@ ifndef NO_RUST
11631163
CFLAGS += -DHAVE_RUST_SUPPORT
11641164
$(call detected,CONFIG_RUST_SUPPORT)
11651165
endif
1166+
1167+
ifneq ($(CROSS_COMPILE),)
1168+
RUST_TARGET_FLAGS_arm := arm-unknown-linux-gnueabi
1169+
RUST_TARGET_FLAGS_arm64 := aarch64-unknown-linux-gnu
1170+
RUST_TARGET_FLAGS_m68k := m68k-unknown-linux-gnu
1171+
RUST_TARGET_FLAGS_mips := mipsel-unknown-linux-gnu
1172+
RUST_TARGET_FLAGS_powerpc := powerpc64le-unknown-linux-gnu
1173+
RUST_TARGET_FLAGS_riscv := riscv64gc-unknown-linux-gnu
1174+
RUST_TARGET_FLAGS_s390 := s390x-unknown-linux-gnu
1175+
RUST_TARGET_FLAGS_x86 := x86_64-unknown-linux-gnu
1176+
RUST_TARGET_FLAGS_x86_64 := x86_64-unknown-linux-gnu
1177+
1178+
ifeq ($(RUST_TARGET_FLAGS_$(ARCH)),)
1179+
$(error Unknown rust cross compilation architecture $(ARCH))
1180+
endif
1181+
1182+
RUST_FLAGS += --target=$(RUST_TARGET_FLAGS_$(ARCH))
1183+
endif
11661184
endif
11671185

11681186
# Among the variables below, these:

tools/perf/Makefile.perf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ ifeq ($(PYLINT),1)
274274
PYLINT := $(shell which pylint 2> /dev/null)
275275
endif
276276

277-
export srctree OUTPUT RM CC CXX RUSTC LD AR CFLAGS CXXFLAGS V BISON FLEX AWK
277+
export srctree OUTPUT RM CC CXX RUSTC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK
278278
export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT
279279

280280
include $(srctree)/tools/build/Makefile.include

0 commit comments

Comments
 (0)