[PATCH v3 7/7] perf docs: Remove the Android cross building document

Leo Yan posted 7 patches 1 year, 5 months ago
There is a newer version of this series
[PATCH v3 7/7] perf docs: Remove the Android cross building document
Posted by Leo Yan 1 year, 5 months ago
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
Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
Posted by Namhyung Kim 1 year, 5 months ago
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
>
Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
Posted by Leo Yan 1 year, 5 months ago
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
Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
Posted by James Clark 1 year, 5 months ago

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
Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
Posted by Leo Yan 1 year, 5 months ago

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
Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
Posted by Ian Rogers 1 year, 5 months ago
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
> >