linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/6] perf: build: Fix cross compilation
@ 2024-07-17  8:22 Leo Yan
  2024-07-17  8:22 ` [PATCH v5 1/6] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Leo Yan @ 2024-07-17  8:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, Leo Yan, Thomas Richter, James Clark,
	amadio, linux-kernel, linux-perf-users

This patch series fixes cross compilation issues.

The first patch sets the package path if the package configuration path
is not specified. This helps the compiler to find the architecture's
package in a Multiarch system.

The patch 02 sets the Python configuration path and renames the .so to

The patches 03, 04 and 05 fix the static build failures.

The patch 06 adds document for how to cross compile.

Changes from v4:
- Polished patch 06 for removing redundant sentences.

Changes from v3:
- Added more completed comments and logs for PKG_CONFIG_SYSROOT_DIR.
  (Namhyung)
- Didn't include the patch 07 for "perf docs: Remove the Android cross
  building document" in this version, which will be sent out separately.
  (Namhyung/James)

Changes from v2:
- Reordered lib paths for PKG_CONFIG_LIBDIR. (Namhyung)
- Verified the Android NDK and based on the testing result to remove the
  file android.txt. (Ian)

Changes from v1:
- Kept the cross-compile-pkg-config if it is available. (Namhyung)
- Removed the patch 02 for fixing pkg-config path for libtraceevent, as
  this will be resolved in Guilherme Amadio's patch "perf build: Use
  pkg-config for feature check for libtrace{event,fs}".
- Added patch 06 for document.


Leo Yan (6):
  perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
  perf: build: Set Python configuration for cross compilation
  perf: build: Only link libebl.a for old libdw
  perf: build: Link lib 'lzma' for static build
  perf: build: Link lib 'zstd' for static build
  perf docs: Document cross compilation

 tools/build/feature/Makefile       | 53 ++++++++++++++++++++++++------
 tools/perf/Documentation/Build.txt | 28 ++++++++++++++++
 tools/perf/Makefile.config         | 20 ++++++++++-
 tools/perf/Makefile.perf           | 27 ++++++++++++++-
 4 files changed, 116 insertions(+), 12 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v5 1/6] perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
  2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
@ 2024-07-17  8:22 ` Leo Yan
  2024-07-17  8:22 ` [PATCH v5 2/6] perf: build: Set Python configuration " Leo Yan
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Leo Yan @ 2024-07-17  8:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, Leo Yan, Thomas Richter, James Clark,
	amadio, linux-kernel, linux-perf-users

On recent Linux distros like Ubuntu Noble and Debian Bookworm, the
'pkg-config-aarch64-linux-gnu' package is missing. As a result, the
aarch64-linux-gnu-pkg-config command is not available, which causes
build failures.

When a build passes the environment variables PKG_CONFIG_LIBDIR or
PKG_CONFIG_PATH, like a user uses make command or a build system
(like Yocto, Buildroot, etc) prepares the variables and passes to the
Perf's Makefile, the commit keeps these variables for package
configuration. Otherwise, this commit sets the PKG_CONFIG_LIBDIR
variable to use the Multiarch libs for the cross compilation.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/build/feature/Makefile | 25 ++++++++++++++++++++++++-
 tools/perf/Makefile.perf     | 27 ++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index ed54cef450f5..dff65d03d30d 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -82,7 +82,30 @@ FILES=                                          \
 
 FILES := $(addprefix $(OUTPUT),$(FILES))
 
-PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+# Some distros provide the command $(CROSS_COMPILE)pkg-config for
+# searching packges installed with Multiarch. Use it for cross
+# compilation if it is existed.
+ifneq (, $(shell which $(CROSS_COMPILE)pkg-config))
+  PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+else
+  PKG_CONFIG ?= pkg-config
+
+  # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR
+  # for modified system root, are required for the cross compilation.
+  # If these PKG_CONFIG environment variables are not set, Multiarch library
+  # paths are used instead.
+  ifdef CROSS_COMPILE
+    ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),)
+      CROSS_ARCH = $(shell $(CC) -dumpmachine)
+      PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
+      PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
+      PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
+      PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
+      PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
+      export PKG_CONFIG_LIBDIR
+    endif
+  endif
+endif
 
 all: $(FILES)
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 5c35c0d89306..a4a3dca2033a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -193,7 +193,32 @@ HOSTLD  ?= ld
 HOSTAR  ?= ar
 CLANG   ?= clang
 
-PKG_CONFIG = $(CROSS_COMPILE)pkg-config
+# Some distros provide the command $(CROSS_COMPILE)pkg-config for
+# searching packges installed with Multiarch. Use it for cross
+# compilation if it is existed.
+ifneq (, $(shell which $(CROSS_COMPILE)pkg-config))
+  PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+else
+  PKG_CONFIG ?= pkg-config
+
+  # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR
+  # for modified system root, is required for the cross compilation.
+  # If these PKG_CONFIG environment variables are not set, Multiarch library
+  # paths are used instead.
+  ifdef CROSS_COMPILE
+    ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),)
+      CROSS_ARCH = $(shell $(CC) -dumpmachine)
+      PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
+      PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
+      PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
+      PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
+      PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
+      export PKG_CONFIG_LIBDIR
+      $(warning Missing PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH and PKG_CONFIG_SYSROOT_DIR for cross compilation,)
+      $(warning set PKG_CONFIG_LIBDIR for using Multiarch libs.)
+    endif
+  endif
+endif
 
 RM      = rm -f
 LN      = ln -f
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v5 2/6] perf: build: Set Python configuration for cross compilation
  2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
  2024-07-17  8:22 ` [PATCH v5 1/6] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
@ 2024-07-17  8:22 ` Leo Yan
  2024-07-17  8:22 ` [PATCH v5 3/6] perf: build: Only link libebl.a for old libdw Leo Yan
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Leo Yan @ 2024-07-17  8:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, Leo Yan, Thomas Richter, James Clark,
	amadio, linux-kernel, linux-perf-users

Python configuration has dedicated folders for different architectures.
For example, Python 3.11 has two folders as shown below, one for Arm64
and another for x86_64:

  /usr/lib/python3.11/config-3.11-aarch64-linux-gnu/
  /usr/lib/python3.11/config-3.11-x86_64-linux-gnu/

This commit updates the Python configuration path based on the
compiler's machine type, guiding the compiler to find the correct path
for Python libraries. It also renames the generated .so file name to
match the machine name.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/Makefile.config | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 7f1e016a9253..755fb78be76a 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -303,6 +303,11 @@ endif
 
 ifdef PYTHON_CONFIG
   PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
+  # Update the python flags for cross compilation
+  ifdef CROSS_COMPILE
+    PYTHON_NATIVE := $(shell echo $(PYTHON_EMBED_LDOPTS) | sed 's/\(-L.*\/\)\(.*-linux-gnu\).*/\2/')
+    PYTHON_EMBED_LDOPTS := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EMBED_LDOPTS))
+  endif
   PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
   PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
   PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
@@ -904,6 +909,9 @@ else
          PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no")
          ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes)
            PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])')
+           ifdef CROSS_COMPILE
+             PYTHON_EXTENSION_SUFFIX := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EXTENSION_SUFFIX))
+           endif
            LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX)
 	 else
            $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v5 3/6] perf: build: Only link libebl.a for old libdw
  2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
  2024-07-17  8:22 ` [PATCH v5 1/6] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
  2024-07-17  8:22 ` [PATCH v5 2/6] perf: build: Set Python configuration " Leo Yan
@ 2024-07-17  8:22 ` Leo Yan
  2024-07-17  8:22 ` [PATCH v5 4/6] perf: build: Link lib 'lzma' for static build Leo Yan
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Leo Yan @ 2024-07-17  8:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, Leo Yan, Thomas Richter, James Clark,
	amadio, linux-kernel, linux-perf-users

Since libdw version 0.177, elfutils has merged libebl.a into libdw (see
the commit "libebl: Don't install libebl.a, libebl.h and remove backends
from spec." in the elfutils repository).

As a result, libebl.a does not exist on Debian Bullseye and newer
releases, causing static perf builds to fail on these distributions.

This commit checks the libdw version and only links libebl.a if it
detects that the libdw version is older than 0.177.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/build/feature/Makefile | 12 +++++++++++-
 tools/perf/Makefile.config   | 12 +++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index dff65d03d30d..08b2be257639 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -170,7 +170,17 @@ $(OUTPUT)test-libopencsd.bin:
 
 DWARFLIBS := -ldw
 ifeq ($(findstring -static,${LDFLAGS}),-static)
-DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
+  DWARFLIBS += -lelf -lz -llzma -lbz2
+
+  LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
+  LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
+  LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
+
+  # Elfutils merged libebl.a into libdw.a starting from version 0.177,
+  # Link libebl.a only if libdw is older than this version.
+  ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
+    DWARFLIBS += -lebl
+  endif
 endif
 
 $(OUTPUT)test-dwarf.bin:
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 755fb78be76a..db3bc460d4c2 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -152,7 +152,17 @@ ifdef LIBDW_DIR
 endif
 DWARFLIBS := -ldw
 ifeq ($(findstring -static,${LDFLAGS}),-static)
-  DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
+  DWARFLIBS += -lelf -ldl -lz -llzma -lbz2
+
+  LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
+  LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
+  LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
+
+  # Elfutils merged libebl.a into libdw.a starting from version 0.177,
+  # Link libebl.a only if libdw is older than this version.
+  ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
+    DWARFLIBS += -lebl
+  endif
 endif
 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v5 4/6] perf: build: Link lib 'lzma' for static build
  2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
                   ` (2 preceding siblings ...)
  2024-07-17  8:22 ` [PATCH v5 3/6] perf: build: Only link libebl.a for old libdw Leo Yan
@ 2024-07-17  8:22 ` Leo Yan
  2024-07-17  8:22 ` [PATCH v5 5/6] perf: build: Link lib 'zstd' " Leo Yan
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Leo Yan @ 2024-07-17  8:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, Leo Yan, Thomas Richter, James Clark,
	amadio, linux-kernel, linux-perf-users

The libunwind feature test failed with the static linkage. This is due
to the 'lzma' lib is missed, so link it to dismiss building failure.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/build/feature/Makefile | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 08b2be257639..2d5be5c17d65 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -211,27 +211,27 @@ $(OUTPUT)test-numa_num_possible_cpus.bin:
 	$(BUILD) -lnuma
 
 $(OUTPUT)test-libunwind.bin:
-	$(BUILD) -lelf
+	$(BUILD) -lelf -llzma
 
 $(OUTPUT)test-libunwind-debug-frame.bin:
-	$(BUILD) -lelf
+	$(BUILD) -lelf -llzma
 $(OUTPUT)test-libunwind-x86.bin:
-	$(BUILD) -lelf -lunwind-x86
+	$(BUILD) -lelf -llzma -lunwind-x86
 
 $(OUTPUT)test-libunwind-x86_64.bin:
-	$(BUILD) -lelf -lunwind-x86_64
+	$(BUILD) -lelf -llzma -lunwind-x86_64
 
 $(OUTPUT)test-libunwind-arm.bin:
-	$(BUILD) -lelf -lunwind-arm
+	$(BUILD) -lelf -llzma -lunwind-arm
 
 $(OUTPUT)test-libunwind-aarch64.bin:
-	$(BUILD) -lelf -lunwind-aarch64
+	$(BUILD) -lelf -llzma -lunwind-aarch64
 
 $(OUTPUT)test-libunwind-debug-frame-arm.bin:
-	$(BUILD) -lelf -lunwind-arm
+	$(BUILD) -lelf -llzma -lunwind-arm
 
 $(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
-	$(BUILD) -lelf -lunwind-aarch64
+	$(BUILD) -lelf -llzma -lunwind-aarch64
 
 $(OUTPUT)test-libaudit.bin:
 	$(BUILD) -laudit
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v5 5/6] perf: build: Link lib 'zstd' for static build
  2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
                   ` (3 preceding siblings ...)
  2024-07-17  8:22 ` [PATCH v5 4/6] perf: build: Link lib 'lzma' for static build Leo Yan
@ 2024-07-17  8:22 ` Leo Yan
  2024-07-17  8:22 ` [PATCH v5 6/6] perf docs: Document cross compilation Leo Yan
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Leo Yan @ 2024-07-17  8:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, Leo Yan, Thomas Richter, James Clark,
	amadio, linux-kernel, linux-perf-users

When build static perf, Makefile reports the error:

  Makefile.config:480: No libdw DWARF unwind found, Please install
  elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR

The libdw has been installed on the system, but the build system fails
to build the feature detecting binary 'test-libdw-dwarf-unwind'. The
failure is caused by missing to link the lib 'zstd'.

Link lib 'zstd' for the static build, in the end, the dwarf feature can
be enabled in the static perf.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/build/feature/Makefile | 2 +-
 tools/perf/Makefile.config   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 2d5be5c17d65..4af6a9582f15 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -170,7 +170,7 @@ $(OUTPUT)test-libopencsd.bin:
 
 DWARFLIBS := -ldw
 ifeq ($(findstring -static,${LDFLAGS}),-static)
-  DWARFLIBS += -lelf -lz -llzma -lbz2
+  DWARFLIBS += -lelf -lz -llzma -lbz2 -lzstd
 
   LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
   LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index db3bc460d4c2..0f918475d7b6 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -152,7 +152,7 @@ ifdef LIBDW_DIR
 endif
 DWARFLIBS := -ldw
 ifeq ($(findstring -static,${LDFLAGS}),-static)
-  DWARFLIBS += -lelf -ldl -lz -llzma -lbz2
+  DWARFLIBS += -lelf -ldl -lz -llzma -lbz2 -lzstd
 
   LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
   LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v5 6/6] perf docs: Document cross compilation
  2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
                   ` (4 preceding siblings ...)
  2024-07-17  8:22 ` [PATCH v5 5/6] perf: build: Link lib 'zstd' " Leo Yan
@ 2024-07-17  8:22 ` Leo Yan
  2024-07-17 15:22 ` [PATCH v5 0/6] perf: build: Fix " Ian Rogers
  2024-07-25  6:53 ` Leo Yan
  7 siblings, 0 replies; 11+ messages in thread
From: Leo Yan @ 2024-07-17  8:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, Leo Yan, Thomas Richter, James Clark,
	amadio, linux-kernel, linux-perf-users
  Cc: James Clark

Records the commands for cross compilation with two methods.

The first method relies on Multiarch. The second approach is to explicitly
specify the PKG_CONFIG variables, which is widely used in build system
(like Buildroot, Yocto, etc).

Co-developed-by: James Clark <james.clark@arm.com>
Signed-off-by: James Clark <james.clark@arm.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/Documentation/Build.txt | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tools/perf/Documentation/Build.txt b/tools/perf/Documentation/Build.txt
index 3766886c4bca..83dc87c662b6 100644
--- a/tools/perf/Documentation/Build.txt
+++ b/tools/perf/Documentation/Build.txt
@@ -71,3 +71,31 @@ supported by GCC. UBSan detects undefined behaviors of programs at runtime.
   $ UBSAN_OPTIONS=print_stacktrace=1 ./perf record -a
 
 If UBSan detects any problem at runtime, it outputs a “runtime error:” message.
+
+4) Cross compilation
+====================
+As Multiarch is commonly supported in Linux distributions, we can install
+libraries for multiple architectures on the same system and then cross-compile
+Linux perf. For example, Aarch64 libraries and toolchains can be installed on
+an x86_64 machine, allowing us to compile perf for an Aarch64 target.
+
+Below is the command for building the perf with dynamic linking.
+
+  $ cd /path/to/Linux
+  $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf
+
+For static linking, the option `LDFLAGS="-static"` is required.
+
+  $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
+    LDFLAGS="-static" -C tools/perf
+
+In the embedded system world, a use case is to explicitly specify the package
+configuration paths for cross building:
+
+  $ PKG_CONFIG_SYSROOT_DIR="/path/to/cross/build/sysroot" \
+    PKG_CONFIG_LIBDIR="/usr/lib/:/usr/local/lib" \
+    make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf
+
+In this case, the variable PKG_CONFIG_SYSROOT_DIR can be used alongside the
+variable PKG_CONFIG_LIBDIR or PKG_CONFIG_PATH to prepend the sysroot path to
+the library paths for cross compilation.
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v5 0/6] perf: build: Fix cross compilation
  2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
                   ` (5 preceding siblings ...)
  2024-07-17  8:22 ` [PATCH v5 6/6] perf docs: Document cross compilation Leo Yan
@ 2024-07-17 15:22 ` Ian Rogers
  2024-07-25  6:53 ` Leo Yan
  7 siblings, 0 replies; 11+ messages in thread
From: Ian Rogers @ 2024-07-17 15:22 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Adrian Hunter,
	Liang, Kan, Thomas Richter, James Clark, amadio, linux-kernel,
	linux-perf-users

On Wed, Jul 17, 2024 at 1:22 AM Leo Yan <leo.yan@arm.com> wrote:
>
> This patch series fixes cross compilation issues.
>
> The first patch sets the package path if the package configuration path
> is not specified. This helps the compiler to find the architecture's
> package in a Multiarch system.
>
> The patch 02 sets the Python configuration path and renames the .so to
>
> The patches 03, 04 and 05 fix the static build failures.
>
> The patch 06 adds document for how to cross compile.
>
> Changes from v4:
> - Polished patch 06 for removing redundant sentences.
>
> Changes from v3:
> - Added more completed comments and logs for PKG_CONFIG_SYSROOT_DIR.
>   (Namhyung)
> - Didn't include the patch 07 for "perf docs: Remove the Android cross
>   building document" in this version, which will be sent out separately.
>   (Namhyung/James)
>
> Changes from v2:
> - Reordered lib paths for PKG_CONFIG_LIBDIR. (Namhyung)
> - Verified the Android NDK and based on the testing result to remove the
>   file android.txt. (Ian)
>
> Changes from v1:
> - Kept the cross-compile-pkg-config if it is available. (Namhyung)
> - Removed the patch 02 for fixing pkg-config path for libtraceevent, as
>   this will be resolved in Guilherme Amadio's patch "perf build: Use
>   pkg-config for feature check for libtrace{event,fs}".
> - Added patch 06 for document.
>
>
> Leo Yan (6):
>   perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
>   perf: build: Set Python configuration for cross compilation
>   perf: build: Only link libebl.a for old libdw
>   perf: build: Link lib 'lzma' for static build
>   perf: build: Link lib 'zstd' for static build
>   perf docs: Document cross compilation

Tested-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5 0/6] perf: build: Fix cross compilation
  2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
                   ` (6 preceding siblings ...)
  2024-07-17 15:22 ` [PATCH v5 0/6] perf: build: Fix " Ian Rogers
@ 2024-07-25  6:53 ` Leo Yan
  2024-07-26  1:27   ` Namhyung Kim
  7 siblings, 1 reply; 11+ messages in thread
From: Leo Yan @ 2024-07-25  6:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, Thomas Richter, James Clark, amadio,
	linux-kernel, linux-perf-users

Hi Arnaldo, Namhyung,

On 7/17/2024 9:22 AM, Leo Yan wrote:
> This patch series fixes cross compilation issues.

If this series is fine for you, would you mind to pick up this series?

Thanks!

Leo

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5 0/6] perf: build: Fix cross compilation
  2024-07-25  6:53 ` Leo Yan
@ 2024-07-26  1:27   ` Namhyung Kim
  2024-07-26 12:37     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 11+ messages in thread
From: Namhyung Kim @ 2024-07-26  1:27 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ian Rogers, Adrian Hunter,
	Liang, Kan, Thomas Richter, James Clark, amadio, linux-kernel,
	linux-perf-users

Hi Leo,

On Thu, Jul 25, 2024 at 07:53:18AM +0100, Leo Yan wrote:
> Hi Arnaldo, Namhyung,
> 
> On 7/17/2024 9:22 AM, Leo Yan wrote:
> > This patch series fixes cross compilation issues.
> 
> If this series is fine for you, would you mind to pick up this series?

Sure, I think we can carry this through perf-tools if Arnaldo is ok.

Thanks,
Namhyung


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v5 0/6] perf: build: Fix cross compilation
  2024-07-26  1:27   ` Namhyung Kim
@ 2024-07-26 12:37     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 11+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-07-26 12:37 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Leo Yan, Jiri Olsa, Ian Rogers, Adrian Hunter, Liang, Kan,
	Thomas Richter, James Clark, amadio, linux-kernel,
	linux-perf-users

On Thu, Jul 25, 2024 at 06:27:30PM -0700, Namhyung Kim wrote:
> Hi Leo,
> 
> On Thu, Jul 25, 2024 at 07:53:18AM +0100, Leo Yan wrote:
> > Hi Arnaldo, Namhyung,
> > 
> > On 7/17/2024 9:22 AM, Leo Yan wrote:
> > > This patch series fixes cross compilation issues.
> > 
> > If this series is fine for you, would you mind to pick up this series?
> 
> Sure, I think we can carry this through perf-tools if Arnaldo is ok.

Well, rc1 isn't out, this has been out for a few weeks, so I think its
ok to have it for the current merge window.

- Arnaldo

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-07-26 12:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-17  8:22 [PATCH v5 0/6] perf: build: Fix cross compilation Leo Yan
2024-07-17  8:22 ` [PATCH v5 1/6] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
2024-07-17  8:22 ` [PATCH v5 2/6] perf: build: Set Python configuration " Leo Yan
2024-07-17  8:22 ` [PATCH v5 3/6] perf: build: Only link libebl.a for old libdw Leo Yan
2024-07-17  8:22 ` [PATCH v5 4/6] perf: build: Link lib 'lzma' for static build Leo Yan
2024-07-17  8:22 ` [PATCH v5 5/6] perf: build: Link lib 'zstd' " Leo Yan
2024-07-17  8:22 ` [PATCH v5 6/6] perf docs: Document cross compilation Leo Yan
2024-07-17 15:22 ` [PATCH v5 0/6] perf: build: Fix " Ian Rogers
2024-07-25  6:53 ` Leo Yan
2024-07-26  1:27   ` Namhyung Kim
2024-07-26 12:37     ` Arnaldo Carvalho de Melo

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).