linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: hupu <hupu.gm@gmail.com>
To: namhyung@kernel.org, irogers@google.com, peterz@infradead.org,
	 mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com,
	 alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	adrian.hunter@intel.com,  nathan@kernel.org,
	nick.desaulniers+lkml@gmail.com, morbo@google.com,
	 justinstitt@google.com, linux-kernel@vger.kernel.org,
	 linux-perf-users@vger.kernel.org
Subject: Re: [RFC] perf build: Allow passing extra Clang flags via EXTRA_CLANG_FLAGS
Date: Mon, 13 Oct 2025 16:07:58 +0800	[thread overview]
Message-ID: <CADHxFxRMUhn=VdG5uzrosTUpwAMHi+zO7NTYVikWzFdnKrUJ4w@mail.gmail.com> (raw)
In-Reply-To: <20251013080609.2070555-1-hupu.gm@gmail.com>

Hi Maintainer,

I encountered some issues while cross-compiling perf (ARCH=arm64),
particularly when enabling the BPF option. During the build, Clang
fails to compile BPF programs due to missing header files. The
relevant error messages are as follows:


---------------------------------------
/usr/bin/ld: skipping incompatible
/home/hupu/work/tools/crosstool-ng/output/aarch64-dumpstack-linux-gnu/bin/../aarch64-dumpstack-linux-gnu/sysroot/usr/lib/aarch64-linux-gnu/libzstd.a
when searching for -lzstd
/usr/bin/ld: skipping incompatible
/home/hupu/work/tools/crosstool-ng/output/aarch64-dumpstack-linux-gnu/bin/../aarch64-dumpstack-linux-gnu/sysroot/usr/lib/libc.a
when searching for -lc
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libcrypto.a(libcrypto-lib-dso_dlfcn.o):
in function `dlfcn_globallookup':
(.text+0x1f): warning: Using 'dlopen' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libcrypto.a(libcrypto-lib-bio_addr.o):
in function `BIO_lookup_ex':
(.text+0xdbc): warning: Using 'getaddrinfo' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libcrypto.a(libcrypto-lib-bio_sock.o):
in function `BIO_gethostbyname':
(.text+0x85): warning: Using 'gethostbyname' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
  CLANG   /home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/bpf_prog_profiler.bpf.o
  CLANG   /home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/bperf_leader.bpf.o
  CLANG   /home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/bperf_follower.bpf.o
  CLANG   /home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/bperf_cgroup.bpf.o
In file included from <built-in>:2:
In file included from ./util/bpf_skel/perf_version.h:6:
In file included from <built-in>:2:
In file included from ./util/bpf_skel/perf_version.h:6:
In file included from
/home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/../vmlinux.h:7:
In file included from
/home/hupu/work/code/explore/linux-mainline/tools/include/uapi/linux/perf_event.h:19:
/usr/include/linux/ioctl.h:5:10: fatal error: 'asm/ioctl.h' file not found
    In file included from
/home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/../vmlinux.h:5
| #include <asm/ioctl.h>
      |          ^~~~~~~~~~~~~
7:
In file included from
/home/hupu/work/code/explore/linux-mainline/tools/include/uapi/linux/perf_event.h:19:
In file included from <built-in>:2:
In file included from ./util/bpf_skel/perf_version.h:6:
In file included from
/home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/../vmlinux.h:7:
In file included from
/home/hupu/work/code/explore/linux-mainline/tools/include/uapi/linux/perf_event.h:19:
/usr/include/linux/ioctl.h:5:10: fatal error: 'asm/ioctl.h' file not found
    5 | #include <asm/ioctl.h>
      |          ^~~~~~~~~~~~~
/usr/include/linux/ioctl.h:5:10: fatal error: 'asm/ioctl.h' file not found
    5 | #include <asm/ioctl.h>
      |          ^~~~~~~~~~~~~
1 error generated.
make[3]: *** [Makefile.perf:1259:
/home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/bperf_leader.bpf.o]
Error 1
make[3]: *** Waiting for unfinished jobs....
In file included from <built-in>:2:
In file included from ./util/bpf_skel/perf_version.h:6:
In file included from
/home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/../vmlinux.h:7:
In file included from
/home/hupu/work/code/explore/linux-mainline/tools/include/uapi/linux/perf_event.h:19:
/usr/include/linux/ioctl.h:5:10: fatal error: 'asm/ioctl.h' file not found
    5 | #include <asm/ioctl.h>
      |          ^~~~~~~~~~~~~
1 error generated.
make[3]: *** [Makefile.perf:1259:
/home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/bperf_cgroup.bpf.o]
Error 1
1 error generated.
1 error generated.
make[3]: *** [Makefile.perf:1259:
/home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/bpf_prog_profiler.bpf.o]
Error 1
make[3]: *** [Makefile.perf:1259:
/home/hupu/work/code/explore/output/build-mainline/tools/perf/util/bpf_skel/.tmp/bperf_follower.bpf.o]
Error 1
make[2]: *** [Makefile.perf:289: sub-make] Error 2
make[1]: *** [Makefile:76: all] Error 2
make: *** [Makefile:93: perf] Error 2
---------------------------------------


This happens because the eBPF part of perf is compiled with Clang,
which by default searches only the host /usr/include/ paths for
headers, not the cross-compilation sysroot. As a result, it cannot
find the ARM64-specific asm/ioctl.h.

To address this issue, I wrote a patch that introduces a new make
variable, EXTRA_CLANG_FLAGS. This allows passing custom Clang options
via the command line during the BPF skeleton build, for example
--sysroot or custom include paths, without modifying Makefile.perf
itself.

Example usage:
  EXTRA_CLANG_FLAGS="--sysroot=$SYSROOT"
  make perf ARCH=arm64 EXTRA_CLANG_FLAGS="$EXTRA_CLANG_FLAGS"

I have tested this approach and it works. However, I am not sure if
this is the optimal solution, so I would like to discuss this further
with you and get your feedback.

Thanks,
hupu

  reply	other threads:[~2025-10-13  8:08 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-13  8:06 [RFC] perf build: Allow passing extra Clang flags via EXTRA_CLANG_FLAGS hupu
2025-10-13  8:07 ` hupu [this message]
2025-10-13 15:46   ` Ian Rogers
2025-10-13 16:14     ` Leo Yan
2025-10-14  2:31       ` hupu
2025-10-15  9:30         ` Leo Yan
2025-10-15 11:47           ` hupu
2025-10-15 12:55             ` Leo Yan
2025-10-18 10:05             ` hupu
2025-10-19  2:30               ` Namhyung Kim
2025-10-19  7:57                 ` hupu
2025-10-20  1:16                   ` Namhyung Kim
2025-10-20  2:38                     ` hupu
2025-10-20  2:40                       ` [PATCH] perf build: Support passing extra Clang options via EXTRA_BPF_FLAGS hupu
2025-10-20  4:16                         ` Namhyung Kim
2025-10-20  8:00                           ` hupu
2025-10-20  8:02                             ` hupu
2025-10-20 10:15                           ` Leo Yan
2025-10-20 12:51                             ` hupu
2025-10-20 13:02                               ` hupu
2025-10-21  3:11                                 ` hupu
2025-11-18  7:18                                   ` hupu
2025-11-18  7:28                                     ` hupu
2025-11-19  9:43                                       ` hupu
2025-11-20 19:22                                         ` Namhyung Kim
2025-11-21 10:17                                           ` hupu
2025-11-24  7:26                                             ` hupu
2025-11-24  7:34                                               ` hupu
2025-11-25  8:13                                                 ` Namhyung Kim
2025-11-25 12:52                                                   ` hupu
2025-11-25 13:07                                                     ` hupu
2025-11-25 16:10                                                       ` Leo Yan
2025-11-26 13:44                                                         ` hupu
2025-12-05  6:33                                                           ` hupu
2025-12-08  9:05                                                             ` hupu
2025-12-10 10:24                                                               ` hupu
2025-12-11 10:39                                                           ` Leo Yan
2025-12-12  6:12                                                             ` hupu
2025-10-20 13:50                               ` Leo Yan
2025-10-20  2:45                       ` hupu
2025-10-14  1:57     ` [RFC] perf build: Allow passing extra Clang flags via EXTRA_CLANG_FLAGS hupu

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='CADHxFxRMUhn=VdG5uzrosTUpwAMHi+zO7NTYVikWzFdnKrUJ4w@mail.gmail.com' \
    --to=hupu.gm@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).