2

I am attempting to build Perf for Android, cross-built for the ARM architecture from an x86_64 Ubuntu system (12.04). I am following the directions that come with the Linux kernel, at ./tools/perf/Documentation/android.txt. I have attempted both the NDK-based build, and the AOSP-derived-sysroot methods, documented in that same text file. However, I prefer the AOSP-derived-sysroot method.

This was sync of AOSP's 4.3_r3.1 tag, with kernel 3.10.17 added, and an appropriate .config file generated. (Cross-built kernel was built prior to cross-build Perf attempt below.)

Building Perf for the host platform works fine. But cross-building for ARM fails with the following error:

$ cd ~/work/aosp
$ source build/envsetup.sh
$ lunch
$ cd ${ANDROID_BUILD_TOP}/ndk
$ ./build/tools/build-ndk-sysroot.sh --abi=arm
$ export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm
$ export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi-
$ cd ${ANDROID_BUILD_TOP}/kernel/tools/perf
$ make ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} CFLAGS="--sysroot=${NDK_SYSROOT}"
...
    CC perf.o
In file included from /home/rbissell/work/aosp/kernel/arch/arm/include/uapi/asm/posix_types.h:35:0,
                 from /home/rbissell/work/aosp/kernel/include/uapi/linux/posix_types.h:35,
                 from /home/rbissell/work/aosp/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/../lib/gcc/arm-linux-androideabi/4.7/include-fixed/sys/types.h:46,
                 from /home/rbissell/work/aosp/ndk/build/platforms/android-3/arch-arm/usr/include/unistd.h:33,
                 from util/util.h:44,
                 from builtin.h:4,
                 from perf.c:9:
/home/rbissell/work/aosp/kernel/include/uapi/asm-generic/posix_types.h:4:29: fatal error: asm/bitsperlong.h: No such file or directory

There are numerous hits from Google on the topic of a missing 'bitsperlong.h' file, some of them even here on SO. For the most part, those questions & answers fall into one of the following categories:

  • Someone trying to build a kernel module (I am not)
  • Someone who isn't cross-building, and just needs to install host kernel headers (I do not)

The only solution offered at the SO link I provided above is to edit Perf's source file to include <asm-generic/bitsperlong.h> instead of <asm/bitsperlong.h>... another variant I've seen is to create a symbolic link in the latter directory to the former.

Neither of those solutions seem kosher to me, and in any case just lead to other compilation errors, such as:

$ ln -s /home/rbissell/work/aosp/kernel/include/asm-generic /home/rbissell/work/aosp/kernel/include/asm
$ make ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} CFLAGS="--sysroot=${NDK_SYSROOT}"
...
    CC perf.o
In file included from /home/rbissell/work/aosp/ndk/build/platforms/android-3/arch-arm/usr/include/unistd.h:33:0,
                 from util/util.h:44,
                 from builtin.h:4,
                 from perf.c:9:
/home/rbissell/work/aosp/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/../lib/gcc/arm-linux-androideabi/4.7/include-fixed
/sys/types.h:73:1: error: unknown type name '__kernel_nlink_t'

At first I thought this problem might have been caused by not cross-building the kernel itself within that same source tree prior to building Perf (as, perhaps the kernel build sets up some $ARCH-appropriate symlinks, or something,) but after doing so, I still had this same problem.

UPDATE: In case it helps, this was how I cross-built my kernel:

make ARCH=arm CROSS_COMPILE=/home/rbissell/work/aosp/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-
4

1 回答 1

0

Have you looked at external/linux-tools-perf/

于 2013-11-13T08:04:51.547 回答