Re: linux/tools/perf cannot be compiled for Android - linux-4.15

From: Hank Qiu
Date: Thu Jun 07 2018 - 06:29:05 EST


Thank you for your reply.
I follow your instructions and use android-ndk-r15c and it works now.

But it's weird that I find it cannot work with android-ndk-r1, and it still throw me error "No gnu/libc-version.h found, please install glibc-dev[el]".
I compare android-ndk-r17 and android-ndk-r15c and find android-ndk-r17 is much smaller than android-ndk-r15c, almost 250MB. Maybe some big changes have been made to NDK.

Thank you again for solve my problem.

> Em Wed, Jun 06, 2018 at 05:39:33AM +0000, Hank Qiu escreveu:
> > Hi
> > I am trying to use tools/perf to tuning my Android devices.
>
> > But I cannot build it for Android successfully following the
> > instructions in tools/perf/Documentation/android.txt.
>
> > I download the latest NDK, which is android-ndk-r17 and follow the
> > instructions in section a to export NDK_TOOLCHAIN and NDK_SYSROOT for
> > arm.
>
> r17, ok, I'll create a new container with that one to see if there is something
> new, but see below for how I test it with r15c.
>
> > Then I compile perf for Android using the exact same command in this
> > documentation, but it cannot work and throw me an error "No
> > gnu/libc-version.h found, please install glibc-dev[el]". This
> > confuses me a lot, since I am using CROSS_COMPILE toolchain for
> > Android, and I cannot just use apt install glibc-dev to solve this
> > problem, because it will install glibc to my host rather than the
> > toolchain. By the way, I already installed glibc in my host.
>
> > My code is linux-4.15 and here are the instructions I used:
> > export
> > NDK_TOOLCHAIN=~/android-ndk-r17/toolchains/arm-linux-androideabi-4.9/p
> > rebuilt/linux-x86_64/bin/arm-linux-androideabi-
> > export NDK_SYSROOT=~/android-ndk-r17/platforms/android-24/arch-arm
> > make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN}
> EXTRA_CFLAGS="-pie -sysroot=${NDK_SYSROOT}"
>
> > I am wondering why I cannot build it successfully for Android
> > following the documentation.
>
> > I have google it for a long time, but they all suggest me to use
> > linux-tools-perf, which don't answer why linux/tools/perf cannot be
> > used.
>
> > If anyone know how to solve this issue, please help me. Looking
> > forward to your reply.
>
> I regularly test build it using a docker container, the one below, check if there is
> something you're missing. To make it clear, the build process is all in the
> rx_and_build.sh script, the Dockerfile is just to setup the environment, which
> you already have done, so just check the env vars and how they get used up to
> the point where the build takes place in rx_and_build.sh, which is in this line:
>
> make $EXTRA_MAKE_ARGS ARCH=$ARCH
> CROSS_COMPILE=$CROSS_COMPILE EXTRA_CFLAGS="$EXTRA_CFLAGS" -C
> /git/linux/tools/perf O=/tmp/build/perf
>
> # cat ~/git/linux-perf-tools-build/android/r15c/arm/Dockerfile
> # docker.io/acmel/linux-perf-tools-build-android-ndk:r15c-arm
> FROM docker.io/fedora:26
> MAINTAINER Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> ENV
> VERSION=android-ndk-r15c ENV NDK=/opt/${VERSION} ENV
> SOURCEFILE=${VERSION}-linux-x86_64.zip
> RUN dnf -y install make bison flex gcc unzip findutils tar xz && \
> dnf -y clean all && \
> mkdir -m 777 -p /tmp/build/perf /tmp/build/objtool && \
> curl -OL https://dl.google.com/android/repository/${SOURCEFILE} && \
> unzip -d /opt ${SOURCEFILE} && \
> rm -f ${SOURCEFILE} && \
> rm -rf ${NDK}/sources \
> ${NDK}/platforms/android-[19]* \
> ${NDK}/platforms/android-2[0-5]* \
> ${NDK}/platforms/android-26/arch-mips* \
> ${NDK}/platforms/android-26/arch-x86* \
> ${NDK}/toolchains/x86* \
> ${NDK}/toolchains/mips* \
> ${NDK}/toolchains/llvm* \
> ${NDK}/prebuilt/ \
> ${NDK}/python* \
> ${NDK}/shader-tools/ &&\
> rm -rf /usr/share/doc /usr/share/gtk-doc /usr/share/locale
> /usr/share/man RUN mkdir -m 777 -p /git /tmp/build/perf /tmp/build/objtool
> /tmp/build/linux && \
> groupadd -r perfbuilder && \
> useradd -m -r -g perfbuilder perfbuilder && \
> chown -R perfbuilder.perfbuilder /tmp/build/ /git/ ENV ARCH=arm ENV
> ARM_NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt
> /linux-x86_64/bin/arm-linux-androideabi-
> ENV ARM_NDK_SYSROOT=${NDK}/platforms/android-26/arch-arm
> ENV EXTRA_CFLAGS="-Wno-attributes -Wno-unused-function -pie
> --sysroot=${ARM_NDK_SYSROOT}"
> ENV CROSS_COMPILE=${ARM_NDK_TOOLCHAIN}
> ENV EXTRA_MAKE_ARGS=WERROR=0
> USER perfbuilder
> COPY rx_and_build.sh /
> ENTRYPOINT ["/rx_and_build.sh"]
>
>
> And then the rx_and_build.sh is:
>
>
> #!/bin/sh
> # Copyright (c) Red Hat Inc. 2017-
> # Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> # cross build Dockerfiles
> must have ENV lines for ARCH and CROSS_COMPILE
>
> export PATH=$PATH:$EXTRA_PATH
>
> if [ -z "$1" ] ; then
> export PERF_TARBALL=http://localhost/perf/perf-latest.tar.xz
> else
> export PERF_TARBALL=$1
> fi
>
> cd /git
> echo "Downloading $PERF_TARBALL..."
> curl -OL $PERF_TARBALL || wget $PERF_TARBALL xzcat `basename
> $PERF_TARBALL` | tar xf - && \ mv perf-*/ linux && \
>
> cat /git/linux/HEAD
>
> # print the version for dm to harvest and put in the status line
> ${CROSS_COMPILE}gcc -v
>
> make $EXTRA_MAKE_ARGS ARCH=$ARCH
> CROSS_COMPILE=$CROSS_COMPILE EXTRA_CFLAGS="$EXTRA_CFLAGS" -C
> /git/linux/tools/perf O=/tmp/build/perf && \ rm -rf /tmp/build/perf/{.[^.]*,*}
> && \ make $EXTRA_MAKE_ARGS ARCH=$ARCH
> CROSS_COMPILE=$CROSS_COMPILE EXTRA_CFLAGS="$EXTRA_CFLAGS"
> NO_LIBELF=1 -C /git/linux/tools/perf O=/tmp/build/perf || exit 1
>
> # Bail ou if we don't have clang, print the version for dm to harvest and put in
> the status line ${CROSS_COMPILE}clang -v || exit 0
>
> rm -rf /tmp/build/perf/{.[^.]*,*} && \
> make $EXTRA_MAKE_ARGS ARCH=$ARCH
> CROSS_COMPILE=$CROSS_COMPILE EXTRA_CFLAGS="$EXTRA_CFLAGS" -C
> /git/linux/tools/perf O=/tmp/build/perf CC=clang && \ rm -rf
> /tmp/build/perf/{.[^.]*,*} && \ make $EXTRA_MAKE_ARGS ARCH=$ARCH
> CROSS_COMPILE=$CROSS_COMPILE EXTRA_CFLAGS="$EXTRA_CFLAGS"
> NO_LIBELF=1 -C /git/linux/tools/perf O=/tmp/build/perf CC=clang
>
> rm -rf /tmp/build/perf/{.[^.]*,*} && \
> make $EXTRA_MAKE_ARGS ARCH=$ARCH
> CROSS_COMPILE=$CROSS_COMPILE EXTRA_CFLAGS="$EXTRA_CFLAGS"
> LIBCLANGLLVM=1 -C /git/linux/tools/perf O=/tmp/build/perf CC=clang
>
> rm -rf /tmp/build/perf/{.[^.]*,*} && \
> make $EXTRA_MAKE_ARGS ARCH=$ARCH
> CROSS_COMPILE=$CROSS_COMPILE EXTRA_CFLAGS="$EXTRA_CFLAGS"
> LIBCLANGLLVM=1 -C /git/linux/tools/perf O=/tmp/build/perf
>
> # Need tp create a MANIFEST on tools/objtool and/or make sure it uses # only
> stuff in tools/include/, etc.
> #make -C /git/linux/tools/objtool O=/tmp/build/objtool && \ # # We now use
> just a detached tarball, not the whole kernel sources # accessed via NFS, so...
> #make -C /git/linux O=/tmp/build/linux defconfig && \ #make -C /git/linux
> O=/tmp/build/linux headers_install && \ #make -C /git/linux O=/tmp/build/linux
> samples/bpf/
This email and any attachments thereto may contain private, confidential, and privileged material for the sole use of the intended recipient. Any review, copying, or distribution of this email (or any attachments thereto) by others is strictly prohibited. If you are not the intended recipient, please contact the sender immediately and permanently delete the original and any copies of this email and any attachments thereto.

æçåéäåéäæåååååææåæïääéäææääçãæçåèïçæçääéèãååæäæèçåéääçäääæãåææäåäääçåéäççæææèïèæçåéçåéäååéåçåéäååçåçéäã