public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>,
	linux-perf-users@vger.kernel.org, Miguel Ojeda <ojeda@kernel.org>,
	Levi Zim <i@kxxt.dev>, Namhyung Kim <namhyung@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	rust-for-linux <rust-for-linux@vger.kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nicolas Schier <nsc@kernel.org>
Subject: Re: [PATCH v4] tools build: Fix rust cross compilation
Date: Wed, 4 Mar 2026 11:39:14 -0300	[thread overview]
Message-ID: <aahEEkHP5g-T_tFg@x1> (raw)
In-Reply-To: <CAP-5=fXLNybYv08dDfAqAsDBzbOPzQY4EZQvdY0WZsfrMu9Yyg@mail.gmail.com>

On Tue, Feb 24, 2026 at 08:41:57AM -0800, Ian Rogers wrote:
> On Wed, Feb 18, 2026 at 7:48 AM Dmitrii Dolgov <9erthalion6@gmail.com> wrote:
> >
> > 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: 2e05bb52a12 ("perf test workload: Add code_with_type test workload")
> > Link: https://perfwiki.github.io/main/arm64-cross-compilation-dockerfile/ [1]
> > Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
> > ---
> > Changes in v4
> > - Fixed incorrect target name for riscv
> >
> > Changes in v3
> > - Improved commit message, add an example of the compilation failure
> >
> > Changes in v2:
> > - Map supported CROSS_COMPILE values to corresponding Rust targets
> >
> >
> >  tools/build/Build.include  |  9 +++++++++
> >  tools/perf/Makefile.config | 14 ++++++++++++++
> >  tools/perf/Makefile.perf   |  2 +-
> >  3 files changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/build/Build.include b/tools/build/Build.include
> > index e45b2eb0d24..cd0baa7a168 100644
> > --- a/tools/build/Build.include
> > +++ b/tools/build/Build.include
> > @@ -98,6 +98,15 @@ c_flags_2 = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(c_flags_1))
> >  c_flags   = $(filter-out $(CFLAGS_REMOVE_$(obj)), $(c_flags_2))
> >  cxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(obj))
> >
> > +###
> > +# Rust flags to be used on rule definition, includes:
> > +# - global $(RUST_FLAGS)
> > +# - per target Rust flags
> > +# - per object Rust flags
> > +rust_flags_1 = $(RUST_FLAGS) $(RUST_FLAGS_$(basetarget).o) $(RUST_FLAGS_$(obj))
> > +rust_flags_2 = $(filter-out $(RUST_FLAGS_REMOVE_$(basetarget).o), $(rust_flags_1))
> > +rust_flags   = $(filter-out $(RUST_FLAGS_REMOVE_$(obj)), $(rust_flags_2))
> > +
> >  ###
> >  ## HOSTCC C flags
> >
> > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> > index a8dc72cfe48..214d8f6d9b8 100644
> > --- a/tools/perf/Makefile.config
> > +++ b/tools/perf/Makefile.config
> > @@ -1163,6 +1163,20 @@ ifndef NO_RUST
> >      CFLAGS += -DHAVE_RUST_SUPPORT
> >      $(call detected,CONFIG_RUST_SUPPORT)
> >    endif
> > +
> > +  ifneq ($(CROSS_COMPILE),)
> > +    RUST_TARGET_FLAGS_arm      := arm-unknown-linux-gnueabi
> > +    RUST_TARGET_FLAGS_arm64    := aarch64-unknown-linux-gnu
> > +    RUST_TARGET_FLAGS_m68k     := m68k-unknown-linux-gnu
> > +    RUST_TARGET_FLAGS_mips     := mipsel-unknown-linux-gnu
> > +    RUST_TARGET_FLAGS_powerpc  := powerpc64le-unknown-linux-gnu
> > +    RUST_TARGET_FLAGS_riscv    := riscv64gc-unknown-linux-gnu
> > +    RUST_TARGET_FLAGS_s390     := s390x-unknown-linux-gnu
> > +    RUST_TARGET_FLAGS_x86      := x86_64-unknown-linux-gnu
> > +    RUST_TARGET_FLAGS_x86_64   := x86_64-unknown-linux-gnu
> > +
> > +    RUST_FLAGS += --target=$(RUST_TARGET_FLAGS_$(ARCH))
> 
> I'm wondering about lesser tested platforms like loongarch, csky,
> xtensa but I don't know how to concoct a triple for these. I wonder if
> there should be a test for a missing string like:
> 
>   ifeq($(RUST_TARGET_FLAGS_$(ARCH)),)
>     $(error Unknown rust cross compilation architecture $(ARCH))
>   endif
> 
> other than this:
> 
> Reviewed-by: Ian Rogers <irogers@google.com>

Thanks, applied to perf-tools, for v7.0.

- Arnaldo

  reply	other threads:[~2026-03-04 14:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-18 15:47 [PATCH v4] tools build: Fix rust cross compilation Dmitrii Dolgov
2026-02-24 16:41 ` Ian Rogers
2026-03-04 14:39   ` Arnaldo Carvalho de Melo [this message]
2026-03-06  0:01     ` Miguel Ojeda
2026-03-06 12:14       ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aahEEkHP5g-T_tFg@x1 \
    --to=acme@kernel.org \
    --cc=9erthalion6@gmail.com \
    --cc=i@kxxt.dev \
    --cc=irogers@google.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox