linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/7] perf: build: Fix cross compilation
@ 2024-07-06 18:29 Leo Yan
  2024-07-06 18:29 ` [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Leo Yan @ 2024-07-06 18:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Jiri Olsa,
	Mark Rutland, Adrian Hunter, Liang, Kan, Nick Terrell,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Richter, Changbin Du, James Clark, amadio, linux-kernel,
	linux-perf-users
  Cc: Leo Yan

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. The patch 07 is to
remove obsolete info for building perf with Android NDK.

This patch series is tested for building perf on x86_64 host for Arm64
target, with verified on Debian two distros (buster and bookworm).

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 (7):
  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
  perf docs: Remove the Android cross building document

 tools/build/feature/Makefile         | 54 +++++++++++++++----
 tools/perf/Documentation/Build.txt   | 37 +++++++++++++
 tools/perf/Documentation/android.txt | 78 ----------------------------
 tools/perf/Makefile.config           | 20 ++++++-
 tools/perf/Makefile.perf             | 26 +++++++++-
 5 files changed, 125 insertions(+), 90 deletions(-)
 delete mode 100644 tools/perf/Documentation/android.txt

-- 
2.34.1


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

* [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
  2024-07-06 18:29 [PATCH v3 0/7] perf: build: Fix cross compilation Leo Yan
@ 2024-07-06 18:29 ` Leo Yan
  2024-07-12  4:52   ` Namhyung Kim
  2024-07-06 18:29 ` [PATCH v3 2/7] perf: build: Set Python configuration " Leo Yan
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Leo Yan @ 2024-07-06 18:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Jiri Olsa,
	Mark Rutland, Adrian Hunter, Liang, Kan, Nick Terrell,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Richter, Changbin Du, James Clark, amadio, linux-kernel,
	linux-perf-users
  Cc: Leo Yan

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 | 26 +++++++++++++++++++++++++-
 tools/perf/Makefile.perf     | 26 +++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index ed54cef450f5..65fd2b2cfacb 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -82,7 +82,31 @@ 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 is required for the cross
+  # compilation. If both is not set, try to set the lib paths installed
+  # by multiarch.
+  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 and PKG_CONFIG_PATH for cross compilation,)
+      $(warning set PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR) for building with Multiarch libs.)
+    endif
+  endif
+endif
 
 all: $(FILES)
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 5c35c0d89306..270490be0a1a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -193,7 +193,31 @@ 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 is required for the cross
+  # compilation. If both is not set, try to set the lib paths installed
+  # by multiarch.
+  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 and PKG_CONFIG_PATH for cross compilation,)
+      $(warning set PKG_CONFIG_LIBDIR to $(PKG_CONFIG_LIBDIR) for using libs with Multiarch.)
+    endif
+  endif
+endif
 
 RM      = rm -f
 LN      = ln -f
-- 
2.34.1


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

* [PATCH v3 2/7] perf: build: Set Python configuration for cross compilation
  2024-07-06 18:29 [PATCH v3 0/7] perf: build: Fix cross compilation Leo Yan
  2024-07-06 18:29 ` [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
@ 2024-07-06 18:29 ` Leo Yan
  2024-07-06 18:29 ` [PATCH v3 3/7] perf: build: Only link libebl.a for old libdw Leo Yan
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Leo Yan @ 2024-07-06 18:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Jiri Olsa,
	Mark Rutland, Adrian Hunter, Liang, Kan, Nick Terrell,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Richter, Changbin Du, James Clark, amadio, linux-kernel,
	linux-perf-users
  Cc: Leo Yan

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] 15+ messages in thread

* [PATCH v3 3/7] perf: build: Only link libebl.a for old libdw
  2024-07-06 18:29 [PATCH v3 0/7] perf: build: Fix cross compilation Leo Yan
  2024-07-06 18:29 ` [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
  2024-07-06 18:29 ` [PATCH v3 2/7] perf: build: Set Python configuration " Leo Yan
@ 2024-07-06 18:29 ` Leo Yan
  2024-07-06 18:29 ` [PATCH v3 4/7] perf: build: Link lib 'lzma' for static build Leo Yan
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Leo Yan @ 2024-07-06 18:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Jiri Olsa,
	Mark Rutland, Adrian Hunter, Liang, Kan, Nick Terrell,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Richter, Changbin Du, James Clark, amadio, linux-kernel,
	linux-perf-users
  Cc: Leo Yan

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 65fd2b2cfacb..8107e530e433 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -171,7 +171,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] 15+ messages in thread

* [PATCH v3 4/7] perf: build: Link lib 'lzma' for static build
  2024-07-06 18:29 [PATCH v3 0/7] perf: build: Fix cross compilation Leo Yan
                   ` (2 preceding siblings ...)
  2024-07-06 18:29 ` [PATCH v3 3/7] perf: build: Only link libebl.a for old libdw Leo Yan
@ 2024-07-06 18:29 ` Leo Yan
  2024-07-06 18:29 ` [PATCH v3 5/7] perf: build: Link lib 'zstd' " Leo Yan
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Leo Yan @ 2024-07-06 18:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Jiri Olsa,
	Mark Rutland, Adrian Hunter, Liang, Kan, Nick Terrell,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Richter, Changbin Du, James Clark, amadio, linux-kernel,
	linux-perf-users
  Cc: Leo Yan

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 8107e530e433..abfd82595d81 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -212,27 +212,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] 15+ messages in thread

* [PATCH v3 5/7] perf: build: Link lib 'zstd' for static build
  2024-07-06 18:29 [PATCH v3 0/7] perf: build: Fix cross compilation Leo Yan
                   ` (3 preceding siblings ...)
  2024-07-06 18:29 ` [PATCH v3 4/7] perf: build: Link lib 'lzma' for static build Leo Yan
@ 2024-07-06 18:29 ` Leo Yan
  2024-07-06 18:29 ` [PATCH v3 6/7] perf docs: Document cross compilation Leo Yan
  2024-07-06 18:29 ` [PATCH v3 7/7] perf docs: Remove the Android cross building document Leo Yan
  6 siblings, 0 replies; 15+ messages in thread
From: Leo Yan @ 2024-07-06 18:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Jiri Olsa,
	Mark Rutland, Adrian Hunter, Liang, Kan, Nick Terrell,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Richter, Changbin Du, James Clark, amadio, linux-kernel,
	linux-perf-users
  Cc: Leo Yan

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 abfd82595d81..f871a1109df5 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -171,7 +171,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] 15+ messages in thread

* [PATCH v3 6/7] perf docs: Document cross compilation
  2024-07-06 18:29 [PATCH v3 0/7] perf: build: Fix cross compilation Leo Yan
                   ` (4 preceding siblings ...)
  2024-07-06 18:29 ` [PATCH v3 5/7] perf: build: Link lib 'zstd' " Leo Yan
@ 2024-07-06 18:29 ` Leo Yan
  2024-07-06 18:29 ` [PATCH v3 7/7] perf docs: Remove the Android cross building document Leo Yan
  6 siblings, 0 replies; 15+ messages in thread
From: Leo Yan @ 2024-07-06 18:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Jiri Olsa,
	Mark Rutland, Adrian Hunter, Liang, Kan, Nick Terrell,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Richter, Changbin Du, James Clark, amadio, linux-kernel,
	linux-perf-users
  Cc: Leo Yan, 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 | 37 ++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/tools/perf/Documentation/Build.txt b/tools/perf/Documentation/Build.txt
index 3766886c4bca..2237ceee74ba 100644
--- a/tools/perf/Documentation/Build.txt
+++ b/tools/perf/Documentation/Build.txt
@@ -71,3 +71,40 @@ 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
+====================
+The perf tool can be cross compiled in below methods.
+
+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 perf with dynamic linking:
+As Multiarch is commonly supported in Linux distros, therefore, we can
+install multiple architectures libs in the same system and then cross compile
+the Linux perf. For example, the Aarch64 libraries and toolchain can be
+installed on the x86_64 machine, based on it we can compile the perf for
+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] 15+ messages in thread

* [PATCH v3 7/7] perf docs: Remove the Android cross building document
  2024-07-06 18:29 [PATCH v3 0/7] perf: build: Fix cross compilation Leo Yan
                   ` (5 preceding siblings ...)
  2024-07-06 18:29 ` [PATCH v3 6/7] perf docs: Document cross compilation Leo Yan
@ 2024-07-06 18:29 ` Leo Yan
  2024-07-12  4:58   ` Namhyung Kim
  6 siblings, 1 reply; 15+ messages in thread
From: Leo Yan @ 2024-07-06 18:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Jiri Olsa,
	Mark Rutland, Adrian Hunter, Liang, Kan, Nick Terrell,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Richter, Changbin Du, James Clark, amadio, linux-kernel,
	linux-perf-users
  Cc: Leo Yan

The Android NDK (as time being the latest LTS version is r26d) changes
toolchain to LLVM / Clang, so GCC compilers is not included in the NDK
anymore. Therefore, the Android document contains obsolete info for
building perf binary with NDK.

Furthermore, the Clang included in the Android NDK is problematic for
cross compilation Aarch64 target. The building reports multiple errors
with the compiler aarch64-linux-android34-clang.

Thus, delete Documentation/android.txt to avoid confusion.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/Documentation/android.txt | 78 ----------------------------
 1 file changed, 78 deletions(-)
 delete mode 100644 tools/perf/Documentation/android.txt

diff --git a/tools/perf/Documentation/android.txt b/tools/perf/Documentation/android.txt
deleted file mode 100644
index 24a59998fc91..000000000000
--- a/tools/perf/Documentation/android.txt
+++ /dev/null
@@ -1,78 +0,0 @@
-How to compile perf for Android
-=========================================
-
-I. Set the Android NDK environment
-------------------------------------------------
-
-(a). Use the Android NDK
-------------------------------------------------
-1. You need to download and install the Android Native Development Kit (NDK).
-Set the NDK variable to point to the path where you installed the NDK:
-  export NDK=/path/to/android-ndk
-
-2. Set cross-compiling environment variables for NDK toolchain and sysroot.
-For arm:
-  export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
-  export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
-For x86:
-  export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-
-  export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86
-
-This method is only tested for Android NDK versions Revision 11b and later.
-perf uses some bionic enhancements that are not included in prior NDK versions.
-You can use method (b) described below instead.
-
-(b). Use the Android source tree
------------------------------------------------
-1. Download the master branch of the Android source tree.
-Set the environment for the target you want using:
-  source build/envsetup.sh
-  lunch
-
-2. Build your own NDK sysroot to contain latest bionic changes and set the
-NDK sysroot environment variable.
-  cd ${ANDROID_BUILD_TOP}/ndk
-For arm:
-  ./build/tools/build-ndk-sysroot.sh --abi=arm
-  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm
-For x86:
-  ./build/tools/build-ndk-sysroot.sh --abi=x86
-  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86
-
-3. Set the NDK toolchain environment variable.
-For arm:
-  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi-
-For x86:
-  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android-
-
-II. Compile perf for Android
-------------------------------------------------
-You need to run make with the NDK toolchain and sysroot defined above:
-For arm:
-  make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
-For x86:
-  make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
-
-III. Install perf
------------------------------------------------
-You need to connect to your Android device/emulator using adb.
-Install perf using:
-  adb push perf /data/perf
-
-If you also want to use perf-archive you need busybox tools for Android.
-For installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh:
-  sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive
-  chmod +x /tmp/perf-archive
-  adb push /tmp/perf-archive /data/perf-archive
-
-IV. Environment settings for running perf
-------------------------------------------------
-Some perf features need environment variables to run properly.
-You need to set these before running perf on the target:
-  adb shell
-  # PERF_PAGER=cat
-
-IV. Run perf
-------------------------------------------------
-Run perf on your device/emulator to which you previously connected using adb:
-  # ./data/perf
-- 
2.34.1


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

* Re: [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
  2024-07-06 18:29 ` [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
@ 2024-07-12  4:52   ` Namhyung Kim
  2024-07-12 10:13     ` Leo Yan
  0 siblings, 1 reply; 15+ messages in thread
From: Namhyung Kim @ 2024-07-12  4:52 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Jiri Olsa, Mark Rutland,
	Adrian Hunter, Liang, Kan, Nick Terrell, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Thomas Richter,
	Changbin Du, James Clark, amadio, linux-kernel, linux-perf-users

Hi Leo,

On Sat, Jul 06, 2024 at 07:29:06PM +0100, Leo Yan wrote:
> 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 | 26 +++++++++++++++++++++++++-
>  tools/perf/Makefile.perf     | 26 +++++++++++++++++++++++++-
>  2 files changed, 50 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index ed54cef450f5..65fd2b2cfacb 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -82,7 +82,31 @@ 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 is required for the cross

And PKG_CONFIG_SYSROOT_DIR too.


> +  # compilation. If both is not set, try to set the lib paths installed
> +  # by multiarch.
> +  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 and PKG_CONFIG_PATH for cross compilation,)

Probably you need to add it here too.

> +      $(warning set PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR) for building with Multiarch libs.)

I guess the message would get too long.  Maybe it's ok to hide the
actual value..

In addition, I think this message will be displayed multiple times -
once here and later in Makefile.perf.  Maybe we can show it once in
the latter only?

Thanks,
Namhyung


> +    endif
> +  endif
> +endif
>  
>  all: $(FILES)
>  
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 5c35c0d89306..270490be0a1a 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -193,7 +193,31 @@ 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 is required for the cross
> +  # compilation. If both is not set, try to set the lib paths installed
> +  # by multiarch.
> +  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 and PKG_CONFIG_PATH for cross compilation,)
> +      $(warning set PKG_CONFIG_LIBDIR to $(PKG_CONFIG_LIBDIR) for using libs with Multiarch.)
> +    endif
> +  endif
> +endif
>  
>  RM      = rm -f
>  LN      = ln -f
> -- 
> 2.34.1
> 

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

* Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
  2024-07-06 18:29 ` [PATCH v3 7/7] perf docs: Remove the Android cross building document Leo Yan
@ 2024-07-12  4:58   ` Namhyung Kim
  2024-07-12  5:37     ` Ian Rogers
  2024-07-12 11:02     ` Leo Yan
  0 siblings, 2 replies; 15+ messages in thread
From: Namhyung Kim @ 2024-07-12  4:58 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Jiri Olsa, Mark Rutland,
	Adrian Hunter, Liang, Kan, Nick Terrell, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Thomas Richter,
	Changbin Du, James Clark, amadio, linux-kernel, linux-perf-users

On Sat, Jul 06, 2024 at 07:29:12PM +0100, Leo Yan wrote:
> The Android NDK (as time being the latest LTS version is r26d) changes
> toolchain to LLVM / Clang, so GCC compilers is not included in the NDK
> anymore. Therefore, the Android document contains obsolete info for
> building perf binary with NDK.

Do you know if the version prior to the change is still used?

> 
> Furthermore, the Clang included in the Android NDK is problematic for
> cross compilation Aarch64 target. The building reports multiple errors
> with the compiler aarch64-linux-android34-clang.
> 
> Thus, delete Documentation/android.txt to avoid confusion.

If so, maybe we can keep the document little more and add a note that
this works only for some old versions.

I'm also curious if it's still broken after your fixes.

Thanks,
Namhyung

> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
>  tools/perf/Documentation/android.txt | 78 ----------------------------
>  1 file changed, 78 deletions(-)
>  delete mode 100644 tools/perf/Documentation/android.txt
> 
> diff --git a/tools/perf/Documentation/android.txt b/tools/perf/Documentation/android.txt
> deleted file mode 100644
> index 24a59998fc91..000000000000
> --- a/tools/perf/Documentation/android.txt
> +++ /dev/null
> @@ -1,78 +0,0 @@
> -How to compile perf for Android
> -=========================================
> -
> -I. Set the Android NDK environment
> -------------------------------------------------
> -
> -(a). Use the Android NDK
> -------------------------------------------------
> -1. You need to download and install the Android Native Development Kit (NDK).
> -Set the NDK variable to point to the path where you installed the NDK:
> -  export NDK=/path/to/android-ndk
> -
> -2. Set cross-compiling environment variables for NDK toolchain and sysroot.
> -For arm:
> -  export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
> -  export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
> -For x86:
> -  export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-
> -  export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86
> -
> -This method is only tested for Android NDK versions Revision 11b and later.
> -perf uses some bionic enhancements that are not included in prior NDK versions.
> -You can use method (b) described below instead.
> -
> -(b). Use the Android source tree
> ------------------------------------------------
> -1. Download the master branch of the Android source tree.
> -Set the environment for the target you want using:
> -  source build/envsetup.sh
> -  lunch
> -
> -2. Build your own NDK sysroot to contain latest bionic changes and set the
> -NDK sysroot environment variable.
> -  cd ${ANDROID_BUILD_TOP}/ndk
> -For arm:
> -  ./build/tools/build-ndk-sysroot.sh --abi=arm
> -  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm
> -For x86:
> -  ./build/tools/build-ndk-sysroot.sh --abi=x86
> -  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86
> -
> -3. Set the NDK toolchain environment variable.
> -For arm:
> -  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi-
> -For x86:
> -  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android-
> -
> -II. Compile perf for Android
> -------------------------------------------------
> -You need to run make with the NDK toolchain and sysroot defined above:
> -For arm:
> -  make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
> -For x86:
> -  make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
> -
> -III. Install perf
> ------------------------------------------------
> -You need to connect to your Android device/emulator using adb.
> -Install perf using:
> -  adb push perf /data/perf
> -
> -If you also want to use perf-archive you need busybox tools for Android.
> -For installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh:
> -  sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive
> -  chmod +x /tmp/perf-archive
> -  adb push /tmp/perf-archive /data/perf-archive
> -
> -IV. Environment settings for running perf
> -------------------------------------------------
> -Some perf features need environment variables to run properly.
> -You need to set these before running perf on the target:
> -  adb shell
> -  # PERF_PAGER=cat
> -
> -IV. Run perf
> -------------------------------------------------
> -Run perf on your device/emulator to which you previously connected using adb:
> -  # ./data/perf
> -- 
> 2.34.1
> 

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

* Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
  2024-07-12  4:58   ` Namhyung Kim
@ 2024-07-12  5:37     ` Ian Rogers
  2024-07-12 11:02     ` Leo Yan
  1 sibling, 0 replies; 15+ messages in thread
From: Ian Rogers @ 2024-07-12  5:37 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Leo Yan, Arnaldo Carvalho de Melo, Jiri Olsa, Mark Rutland,
	Adrian Hunter, Liang, Kan, Nick Terrell, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Thomas Richter,
	Changbin Du, James Clark, amadio, linux-kernel, linux-perf-users

On Thu, Jul 11, 2024 at 9:58 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Sat, Jul 06, 2024 at 07:29:12PM +0100, Leo Yan wrote:
> > The Android NDK (as time being the latest LTS version is r26d) changes
> > toolchain to LLVM / Clang, so GCC compilers is not included in the NDK
> > anymore. Therefore, the Android document contains obsolete info for
> > building perf binary with NDK.
>
> Do you know if the version prior to the change is still used?

The git log last mentions NDK 12 from 2016 working. I suspect these
instructions haven't worked for a good long while.

Thanks,
Ian

> >
> > Furthermore, the Clang included in the Android NDK is problematic for
> > cross compilation Aarch64 target. The building reports multiple errors
> > with the compiler aarch64-linux-android34-clang.
> >
> > Thus, delete Documentation/android.txt to avoid confusion.
>
> If so, maybe we can keep the document little more and add a note that
> this works only for some old versions.
>
> I'm also curious if it's still broken after your fixes.
>
> Thanks,
> Namhyung
>
> >
> > Signed-off-by: Leo Yan <leo.yan@arm.com>
> > ---
> >  tools/perf/Documentation/android.txt | 78 ----------------------------
> >  1 file changed, 78 deletions(-)
> >  delete mode 100644 tools/perf/Documentation/android.txt
> >
> > diff --git a/tools/perf/Documentation/android.txt b/tools/perf/Documentation/android.txt
> > deleted file mode 100644
> > index 24a59998fc91..000000000000
> > --- a/tools/perf/Documentation/android.txt
> > +++ /dev/null
> > @@ -1,78 +0,0 @@
> > -How to compile perf for Android
> > -=========================================
> > -
> > -I. Set the Android NDK environment
> > -------------------------------------------------
> > -
> > -(a). Use the Android NDK
> > -------------------------------------------------
> > -1. You need to download and install the Android Native Development Kit (NDK).
> > -Set the NDK variable to point to the path where you installed the NDK:
> > -  export NDK=/path/to/android-ndk
> > -
> > -2. Set cross-compiling environment variables for NDK toolchain and sysroot.
> > -For arm:
> > -  export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
> > -  export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm
> > -For x86:
> > -  export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-
> > -  export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86
> > -
> > -This method is only tested for Android NDK versions Revision 11b and later.
> > -perf uses some bionic enhancements that are not included in prior NDK versions.
> > -You can use method (b) described below instead.
> > -
> > -(b). Use the Android source tree
> > ------------------------------------------------
> > -1. Download the master branch of the Android source tree.
> > -Set the environment for the target you want using:
> > -  source build/envsetup.sh
> > -  lunch
> > -
> > -2. Build your own NDK sysroot to contain latest bionic changes and set the
> > -NDK sysroot environment variable.
> > -  cd ${ANDROID_BUILD_TOP}/ndk
> > -For arm:
> > -  ./build/tools/build-ndk-sysroot.sh --abi=arm
> > -  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm
> > -For x86:
> > -  ./build/tools/build-ndk-sysroot.sh --abi=x86
> > -  export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86
> > -
> > -3. Set the NDK toolchain environment variable.
> > -For arm:
> > -  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi-
> > -For x86:
> > -  export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android-
> > -
> > -II. Compile perf for Android
> > -------------------------------------------------
> > -You need to run make with the NDK toolchain and sysroot defined above:
> > -For arm:
> > -  make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
> > -For x86:
> > -  make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}"
> > -
> > -III. Install perf
> > ------------------------------------------------
> > -You need to connect to your Android device/emulator using adb.
> > -Install perf using:
> > -  adb push perf /data/perf
> > -
> > -If you also want to use perf-archive you need busybox tools for Android.
> > -For installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh:
> > -  sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive
> > -  chmod +x /tmp/perf-archive
> > -  adb push /tmp/perf-archive /data/perf-archive
> > -
> > -IV. Environment settings for running perf
> > -------------------------------------------------
> > -Some perf features need environment variables to run properly.
> > -You need to set these before running perf on the target:
> > -  adb shell
> > -  # PERF_PAGER=cat
> > -
> > -IV. Run perf
> > -------------------------------------------------
> > -Run perf on your device/emulator to which you previously connected using adb:
> > -  # ./data/perf
> > --
> > 2.34.1
> >

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

* Re: [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
  2024-07-12  4:52   ` Namhyung Kim
@ 2024-07-12 10:13     ` Leo Yan
  0 siblings, 0 replies; 15+ messages in thread
From: Leo Yan @ 2024-07-12 10:13 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Jiri Olsa, Mark Rutland,
	Adrian Hunter, Liang, Kan, Nick Terrell, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Thomas Richter,
	Changbin Du, James Clark, amadio, linux-kernel, linux-perf-users

Hi Namhyung,

On 7/12/24 05:52, Namhyung Kim wrote:

[...]

>> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
>> index ed54cef450f5..65fd2b2cfacb 100644
>> --- a/tools/build/feature/Makefile
>> +++ b/tools/build/feature/Makefile
>> @@ -82,7 +82,31 @@ 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 is required for the cross
> 
> And PKG_CONFIG_SYSROOT_DIR too.

I will refine the comment as:

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

>> +  # compilation. If both is not set, try to set the lib paths installed
>> +  # by multiarch.
>> +  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 and PKG_CONFIG_PATH for cross compilation,)
> 
> Probably you need to add it here too.

Will do.

>> +      $(warning set PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR) for building with Multiarch libs.)
> 
> I guess the message would get too long.  Maybe it's ok to hide the
> actual value..

Will do.

> In addition, I think this message will be displayed multiple times -
> once here and later in Makefile.perf.  Maybe we can show it once in
> the latter only?

Will polish for this.

Thanks,
Leo

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

* Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
  2024-07-12  4:58   ` Namhyung Kim
  2024-07-12  5:37     ` Ian Rogers
@ 2024-07-12 11:02     ` Leo Yan
  2024-07-12 13:38       ` James Clark
  1 sibling, 1 reply; 15+ messages in thread
From: Leo Yan @ 2024-07-12 11:02 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Jiri Olsa, Mark Rutland,
	Adrian Hunter, Liang, Kan, Nick Terrell, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Thomas Richter,
	Changbin Du, James Clark, amadio, linux-kernel, linux-perf-users

Hi Namhyung,

On 7/12/24 05:58, Namhyung Kim wrote:
> On Sat, Jul 06, 2024 at 07:29:12PM +0100, Leo Yan wrote:

[...]

>> The Android NDK (as time being the latest LTS version is r26d) changes
>> toolchain to LLVM / Clang, so GCC compilers is not included in the NDK
>> anymore. Therefore, the Android document contains obsolete info for
>> building perf binary with NDK.
> 
> Do you know if the version prior to the change is still used?

Based on the Android NDK wiki claims [1], since NDK r15 (backed to 26th
July, 2017) "GCC is no longer supported. It will not be removed from the NDK
just yet, but is no longer receiving backports".

>> Furthermore, the Clang included in the Android NDK is problematic for
>> cross compilation Aarch64 target. The building reports multiple errors
>> with the compiler aarch64-linux-android34-clang.
>>
>> Thus, delete Documentation/android.txt to avoid confusion.
> 
> If so, maybe we can keep the document little more and add a note that
> this works only for some old versions.
> 
> I'm also curious if it's still broken after your fixes.

When I tried Android NDK for cross building perf, it is still broken after
applied this series.

 From my testing, now using LLVM for native building works well:

   make LLVM=-15 VF=1 DEBUG=1 -C tools/perf

But it failed for cross compilation. Since Android NDK system root does not
contain some dependency libs, we must use extra options to disable some
features (e.g. NO_LIBELF=1 NO_LIBTRACEEVENT=1). The commands I tried for
cross building but failed:

   make ARCH=arm64 CC=$NDK_TOOLCHAIN/aarch64-linux-android-clang \
     LD=$NDK_TOOLCHAIN/ld.lld AR=$NDK_TOOLCHAIN/llvm-ar \
     NM=$NDK_TOOLCHAIN/llvm-nm STRIP=$NDK_TOOLCHAIN/llvm-strip \
     OBJCOPY=$NDK_TOOLCHAIN/llvm-objcopy \
     OBJDUMP=$NDK_TOOLCHAIN/llvm-objdump \
     READELF=$NDK_TOOLCHAIN/llvm-readelf \
     HOSTCC=$NDK_TOOLCHAIN/clang \
     HOSTCXX=$NDK_TOOLCHAIN/clang++ HOSTAR=$NDK_TOOLCHAIN/llvm-ar \
     HOSTLD=$NDK_TOOLCHAIN/ld.lld VF=1 DEBUG=1 NO_LIBELF=1 \
     NO_LIBTRACEEVENT=1 EXTRA_CFLAGS=-fgnuc-version=0 \
     -C tools/perf

Given the test result, my conclusion is the doc for Android cross building
is not useful for a long while. If we really want to support it, I would
like to suggest to take a separate task for fixing LLVM / Clang cross
compilation.

Thanks,
Leo

[1] https://github.com/android/ndk/wiki/Changelog-r15

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

* Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
  2024-07-12 11:02     ` Leo Yan
@ 2024-07-12 13:38       ` James Clark
  2024-07-15 14:48         ` Leo Yan
  0 siblings, 1 reply; 15+ messages in thread
From: James Clark @ 2024-07-12 13:38 UTC (permalink / raw)
  To: Leo Yan, Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Jiri Olsa, Mark Rutland,
	Adrian Hunter, Liang, Kan, Nick Terrell, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Thomas Richter,
	Changbin Du, amadio, linux-kernel, linux-perf-users



On 12/07/2024 12:02 pm, Leo Yan wrote:
> Hi Namhyung,
> 
> On 7/12/24 05:58, Namhyung Kim wrote:
>> On Sat, Jul 06, 2024 at 07:29:12PM +0100, Leo Yan wrote:
> 
> [...]
> 
>>> The Android NDK (as time being the latest LTS version is r26d) changes
>>> toolchain to LLVM / Clang, so GCC compilers is not included in the NDK
>>> anymore. Therefore, the Android document contains obsolete info for
>>> building perf binary with NDK.
>>
>> Do you know if the version prior to the change is still used?
> 
> Based on the Android NDK wiki claims [1], since NDK r15 (backed to 26th
> July, 2017) "GCC is no longer supported. It will not be removed from the 
> NDK
> just yet, but is no longer receiving backports".
> 
>>> Furthermore, the Clang included in the Android NDK is problematic for
>>> cross compilation Aarch64 target. The building reports multiple errors
>>> with the compiler aarch64-linux-android34-clang.
>>>
>>> Thus, delete Documentation/android.txt to avoid confusion.
>>
>> If so, maybe we can keep the document little more and add a note that
>> this works only for some old versions.
>>
>> I'm also curious if it's still broken after your fixes.
> 
> When I tried Android NDK for cross building perf, it is still broken after
> applied this series.
> 
>  From my testing, now using LLVM for native building works well:
> 
>    make LLVM=-15 VF=1 DEBUG=1 -C tools/perf
> 
> But it failed for cross compilation. Since Android NDK system root does not
> contain some dependency libs, we must use extra options to disable some
> features (e.g. NO_LIBELF=1 NO_LIBTRACEEVENT=1). The commands I tried for
> cross building but failed:
> 
>    make ARCH=arm64 CC=$NDK_TOOLCHAIN/aarch64-linux-android-clang \
>      LD=$NDK_TOOLCHAIN/ld.lld AR=$NDK_TOOLCHAIN/llvm-ar \
>      NM=$NDK_TOOLCHAIN/llvm-nm STRIP=$NDK_TOOLCHAIN/llvm-strip \
>      OBJCOPY=$NDK_TOOLCHAIN/llvm-objcopy \
>      OBJDUMP=$NDK_TOOLCHAIN/llvm-objdump \
>      READELF=$NDK_TOOLCHAIN/llvm-readelf \
>      HOSTCC=$NDK_TOOLCHAIN/clang \
>      HOSTCXX=$NDK_TOOLCHAIN/clang++ HOSTAR=$NDK_TOOLCHAIN/llvm-ar \
>      HOSTLD=$NDK_TOOLCHAIN/ld.lld VF=1 DEBUG=1 NO_LIBELF=1 \
>      NO_LIBTRACEEVENT=1 EXTRA_CFLAGS=-fgnuc-version=0 \
>      -C tools/perf
> 
> Given the test result, my conclusion is the doc for Android cross building
> is not useful for a long while. If we really want to support it, I would
> like to suggest to take a separate task for fixing LLVM / Clang cross
> compilation.

We could replace the entire contents of the file with something like 
"Android NDK compilation deprecated -- no longer supported". It might 
help someone in being able to recover the history of the file by leaving 
in some keywords. If you delete it it becomes very unlikely that the 
history will be found by someone trying to get it working again.

> 
> Thanks,
> Leo
> 
> [1] https://github.com/android/ndk/wiki/Changelog-r15

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

* Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
  2024-07-12 13:38       ` James Clark
@ 2024-07-15 14:48         ` Leo Yan
  0 siblings, 0 replies; 15+ messages in thread
From: Leo Yan @ 2024-07-15 14:48 UTC (permalink / raw)
  To: James Clark, Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ian Rogers, Jiri Olsa, Mark Rutland,
	Adrian Hunter, Liang, Kan, Nick Terrell, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Thomas Richter,
	Changbin Du, amadio, linux-kernel, linux-perf-users



On 7/12/24 14:38, James Clark wrote:

[...]

>> Given the test result, my conclusion is the doc for Android cross building
>> is not useful for a long while. If we really want to support it, I would
>> like to suggest to take a separate task for fixing LLVM / Clang cross
>> compilation.
> 
> We could replace the entire contents of the file with something like
> "Android NDK compilation deprecated -- no longer supported". It might
> help someone in being able to recover the history of the file by leaving
> in some keywords. If you delete it it becomes very unlikely that the
> history will be found by someone trying to get it working again.

A specific Android version has corresponding Linux kernels. It is likely
developers can find what they want, as they should work on an relative
old kernel source tree.

Given Namhyung and you both are concerned for removing the doc, I have
followed the suggestion, respined this patch and sent sepearately [1],
as this patch is not really related to cross building fix.

Thanks,
Leo

[1] 
https://lore.kernel.org/linux-perf-users/20240715143342.52236-1-leo.yan@arm.com/T/#u

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

end of thread, other threads:[~2024-07-15 14:48 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-06 18:29 [PATCH v3 0/7] perf: build: Fix cross compilation Leo Yan
2024-07-06 18:29 ` [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for " Leo Yan
2024-07-12  4:52   ` Namhyung Kim
2024-07-12 10:13     ` Leo Yan
2024-07-06 18:29 ` [PATCH v3 2/7] perf: build: Set Python configuration " Leo Yan
2024-07-06 18:29 ` [PATCH v3 3/7] perf: build: Only link libebl.a for old libdw Leo Yan
2024-07-06 18:29 ` [PATCH v3 4/7] perf: build: Link lib 'lzma' for static build Leo Yan
2024-07-06 18:29 ` [PATCH v3 5/7] perf: build: Link lib 'zstd' " Leo Yan
2024-07-06 18:29 ` [PATCH v3 6/7] perf docs: Document cross compilation Leo Yan
2024-07-06 18:29 ` [PATCH v3 7/7] perf docs: Remove the Android cross building document Leo Yan
2024-07-12  4:58   ` Namhyung Kim
2024-07-12  5:37     ` Ian Rogers
2024-07-12 11:02     ` Leo Yan
2024-07-12 13:38       ` James Clark
2024-07-15 14:48         ` Leo Yan

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