joelagnel / adeb

A debian-based shell environment designed for Android and adb
Apache License 2.0
318 stars 98 forks source link

bcc compilation on target board failed #12

Closed rongqianfeng closed 5 years ago

rongqianfeng commented 6 years ago

Hi, I am trying to get adeb-BCC working on a Hikey970 android platform. By default, use the command “adeb prepare --build --bcc --kernelsrc usr/src/linux-4.9.119” to compile bcc is failed.

The error information are as follows: bash: cannot set terminal process group (16629): Inappropriate ioctl for device bash: no job control in this shell -- The C compiler identification is Clang 6.0.1 -- The CXX compiler identification is Clang 6.0.1 -- Check for working C compiler: /usr/bin/clang-6.0 -- Check for working C compiler: /usr/bin/clang-6.0 -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/clang++-6.0 -- Check for working CXX compiler: /usr/bin/clang++-6.0 -- broken CMake Error at /usr/share/cmake-3.11/Modules/CMakeTestCXXCompiler.cmake:45 (message): The C++ compiler

"/usr/bin/clang++-6.0"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /bcc-master/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_7686c/fast"
/usr/bin/make -f CMakeFiles/cmTC_7686c.dir/build.make CMakeFiles/cmTC_7686c.dir/build
make[1]: Entering directory '/bcc-master/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_7686c.dir/testCXXCompiler.cxx.o
/usr/bin/clang++-6.0     -o CMakeFiles/cmTC_7686c.dir/testCXXCompiler.cxx.o -c /bcc-master/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_7686c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7686c.dir/link.txt --verbose=1
/usr/bin/clang++-6.0       -rdynamic CMakeFiles/cmTC_7686c.dir/testCXXCompiler.cxx.o  -o cmTC_7686c 
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [CMakeFiles/cmTC_7686c.dir/build.make:87: cmTC_7686c] Error 1
make[1]: Leaving directory '/bcc-master/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:126: cmTC_7686c/fast] Error 2
rongqianfeng commented 6 years ago

Hi, I try the methods of @Linuxuser4 provide as follows,the bcc compilation on target board success.

  1. A softlink to stdc++ was required since compilation complained of missing stdc++ library. ln -s /usr/lib/gcc/aarch64-linux-gnu/7/libstdc++.so /usr/lib/libstdc++.so

  2. Two include paths needed to be provided to avoid missing header error. These were added in CMakeLists.txt in the base folder: include_directories(/usr/include/c++/7/) include_directories(/usr/include/aarch64-linux-gnu/c++/7/)

When run the command "funclatency do_sys_open" generate Issue 1: Headers are missing on the target device, but I don't know how to solve this problem. root@localhost:/# funclatency do_sys_open In file included from :2: In file included from /virtual/include/bcc/bpf.h:12: In file included from include/linux/types.h:5: include/uapi/linux/types.h:4:10: fatal error: 'asm/types.h' file not found

include <asm/types.h>

     ^~~~~~~~~~~~~

1 error generated. Traceback (most recent call last): File "/usr/share/bcc/tools/funclatency", line 206, in b = BPF(text=bpf_text) File "/usr/lib/python2.7/dist-packages/bcc/init.py", line 318, in init raise Exception("Failed to compile BPF text") Exception: Failed to compile BPF text

changchengx commented 6 years ago

I enabled adeb on x86 android platform. The issue is resolved in: https://github.com/iotcg/adeb/tree/develop. You can check the git log to find how to set the right environment variable to resolve these issues.

rongqianfeng commented 6 years ago

Yes, I have changed the source code in bashrc.common as follow:

WA for library link issue

LIBRARY_PATH=${LIBRARY_PATH}:/usr/lib/gcc/aarch64-linux-gnu/7/ export LIBRARY_PATH=${LIBRARY_PATH}:/usr/lib/aarch64-linux-gnu/

WA for include path issue

CPATH=${CPATH}:/usr/include/c++/7 export CPATH=${CPATH}:/usr/include/aarch64-linux-gnu/c++/7

WA for kernel include files on arm64 device

export CPATH=${CPATH}:/kernel-headers/include cat /proc/cpuinfo | grep -q aarch64 2>/dev/null rst=$? if [ $rst -eq 0 ] then CPATH=${CPATH}:/kernel-headers/arch/arm64/include/generated export CPATH=${CPATH}:/kernel-headers/arch/arm64/include/generated/uapi fi

The bcc compilation also failed, is my kernel config issue?

-- Configuring done -- Generating done -- Build files have been written to: /bcc-master/build Scanning dependencies of target bpf-static Scanning dependencies of target bpf-shared Scanning dependencies of target bcc-loader-static [ 1%] Building C object src/cc/CMakeFiles/bpf-static.dir/libbpf.c.o [ 1%] Building C object src/cc/CMakeFiles/bpf-shared.dir/libbpf.c.o [ 2%] Building CXX object src/cc/CMakeFiles/bcc-loader-static.dir/bcc_syms.cc.o In file included from /bcc-master/src/cc/libbpf.c:22: In file included from /usr/include/fcntl.h:35: In file included from /usr/include/aarch64-linux-gnu/bits/fcntl.h:61: In file included from /usr/include/aarch64-linux-gnu/bits/fcntl-linux.h:346: /kernel-headers/include/linux/falloc.h:12:2: error: unknown type name 's16' s16 l_type; In file included from /bcc-master/src/cc/libbpf.c:22: In file included from /usr/include/fcntl.h:35: In file included from /usr/include/aarch64-linux-gnu/bits/fcntl.h:61: ^In file included from /usr/include/aarch64-linux-gnu/bits/fcntl-linux.h :346: /kernel-headers/include/linux/falloc.h:12:2: error: unknown type name 's16' s16 l_type; ^ /kernel-headers/include/linux/falloc.h/kernel-headers/include/linux/falloc.h:13:2: :error: unknown type name 's16' s16 l_whence;13:2: error: unknown type name 's16' s16 l_whence; ... fatal error: too many errors emitted, stopping now [-ferror-limit=] 13 warnings and 20 errors generated. make[2]: [src/cc/CMakeFiles/bpf-shared.dir/build.make:63: src/cc/CMakeFiles/bpf-shared.dir/libbpf.c.o] Error 1 make[1]: [CMakeFiles/Makefile2:158: src/cc/CMakeFiles/bpf-shared.dir/all] Error 2 make: *** [Makefile:141: all] Error 2

changchengx commented 6 years ago

It's kernel head file issues. Two suspect points:

  1. Some kernel head files are not copied into kernel-headers.
  2. Need more specific CPATH to include the directory to tell gcc/clang to find the header file.

BTW, you can refer to below file to generate kernel-headers: https://github.com/iotcg/adeb/blob/develop/kernel-headers.sh As you know, we often build kernel out of kernel source directory, e.g. build_kernel. You can put kernel-header.sh under build_kernel and run the script, it will generate kernel-headers directory which includes all the required kernel head files.

joelagnel commented 6 years ago

Give us a day. We fixed the compilation issue. Pushing it

On Wed, Aug 15, 2018, 3:53 AM Changcheng notifications@github.com wrote:

It's kernel head file issues. Two suspect points:

  1. Some kernel head files are not copied into kernel-headers.
  2. Need more specific CPATH to include the directory to tell gcc/clang to find the header file.

BTW, you can refer to below file to generate kernel-headers: https://github.com/iotcg/adeb/blob/develop/kernel-headers.sh As you know, we often build kernel out of kernel source directory, e.g. build_kernel. You can put kernel-header.sh under build_kernel and run the script, it will generate kernel-headers directory which includes all the required kernel head files.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/joelagnel/adeb/issues/12#issuecomment-413162958, or mute the thread https://github.com/notifications/unsubscribe-auth/AACSVJsvWzVkNzCC2VztV7axlH_sCtULks5uQ_2bgaJpZM4V53VO .

changchengx commented 6 years ago

@joelagnel Glad to see your fix, waiting for PR. I also want to know how to resolve "library link issue" & "include head file issue" besides my method.

joelagnel commented 6 years ago

Actually, the issue I was talking about is different. Your compilation could be failing because of incorrect 'kernel-headers' as you pointed:

/kernel-headers/include/linux/falloc.h:12:2: error: unknown type name '__s16'

Erick is working on removing dependency on kernel headers. His prototype is already working but it has to be merged. It will be merged either today or tomorrow. After that the following command should work: “adeb prepare --build --bcc`

We will update you today or tomorrow. Thanks for the patience and for your help in making Androdeb better.

joelagnel commented 6 years ago

CC @ErickReyesR

joelagnel commented 6 years ago

@iotcg thanks for sharing your header build script. Could you send me a pull-request to add out-of-tree kernel header build support to --kernelsrc option? I think we will also need additional options maybe: --kernelsrc and --kernelout ?

joelagnel commented 6 years ago

Also as I was saying, we will also provide "backup" kernel headers incase --kernelsrc option is skipped which @ErickReyesR is working on.

changchengx commented 6 years ago

@joelagnel Per your request, PR: https://github.com/joelagnel/adeb/pull/13 This PR has been verified on local host and target device. It supports extract kernel headers when building kernel out-of-tree.

joelagnel commented 5 years ago

At the moment, I feel out-of-tree header building will complicate the flow too much. Also we have eliminated the need for kernel version as long as you are running a recent LTS kernel (headers will be automatically downloaded). For that reason, I am closing this. Thanks