Hacking
This page contains a list of recipes or tips in how to have get more of the tools and configurations distributed in LLVMLinux's build system.
Linux Kernel Hacking
Generating assembly files
In this example it will be shown how to generate security/tf_driver/tf_comm.c file from Nexus 7 target.
Go to the Nexus 7's target directory.
cd targets/nexus7
Build it.
make
Now, let's get only the build command that was used to build the kernel.
make MAKE_KERNEL_STOP=1
It will display the current environment and display the kernel command. These are the most important line that you should look at:
... --------------------------------------------------------------------- /usr/bin/gcc /mnt/w1/tinti/work/llvmlinux/toolchain/clang/install/bin/clang export ARCH=arm export ARM_CROSS_GCC_TOOLCHAIN=/mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6 export CC=clang -gcc-toolchain /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6 export CFLAGS=-isystem /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/lib/gcc/arm-linux-androideabi/4.6.x-google/include export COMPILER_PATH=/mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6 export CROSS_COMPILE=arm-linux-androideabi- export HOST=arm-linux-androideabi export HOST_TRIPLE=arm-linux-androideabi export JOBS=9 export KBUILD_OUTPUT= export LD= export MARCH= export MFLOAT= export PATH=/mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/bin:/mnt/w1/tinti/work/llvmlinux/arch/arm/bin:/mnt/w1/tinti/work/llvmlinux/toolchain/clang/install/bin:/home/tinti/.rvm/gems/ruby-1.9.3-p194@tinti/bin:/home/tinti/.rvm/gems/ruby-1.9.3-p194@global/bin:/home/tinti/.rvm/rubies/ruby-1.9.3-p194/bin:/home/tinti/.rvm/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/tinti/Qt5.0.0/5.0.0/gcc_64/bin:/home/tinti/Qt5.0.0/Tools/QtCreator/bin:/home/tinti/Local/bin:/mnt/w1/tinti/work/llvmlinux/arch/all/bin:/mnt/w1/tinti/work/llvmlinux/tools export TMPDIR=/mnt/w1/tinti/work/llvmlinux/targets/nexus7/tmp export USE_CCACHE= export V= --------------------------------------------------------------------- clang -gcc-toolchain /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6 -print-file-name=include /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/include make CONFIG_DEBUG_SECTION_MISMATCH=y CONFIG_DEBUG_INFO=1 -j9 CONFIG_NO_ERROR_ON_MISMATCH=y ARCH=arm CROSS_COMPILE=arm-linux-androideabi- CC="clang -gcc-toolchain /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6" CFLAGS_KERNEL="-isystem /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/lib/gcc/arm-linux-androideabi/4.6.x-google/include" CFLAGS_MODULE="-isystem /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/lib/gcc/arm-linux-androideabi/4.6.x-google/include" Command exited with non-zero status 1 --------------------------------------------------------------------- ...
Let's now build a command line based on those ones. First check the make command (you are not supposed to run it now):
make CONFIG_DEBUG_SECTION_MISMATCH=y CONFIG_DEBUG_INFO=1 -j9 CONFIG_NO_ERROR_ON_MISMATCH=y ARCH=arm CROSS_COMPILE=arm-linux-androideabi- CC="clang -gcc-toolchain /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6" CFLAGS_KERNEL="-isystem /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/lib/gcc/arm-linux-androideabi/4.6.x-google/include" CFLAGS_MODULE="-isystem /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/lib/gcc/arm-linux-androideabi/4.6.x-google/include"
Note that it will try to use clang command from the path and not LLVMLinux's ones. Set your path to use it on higher priority rather than system's clang.
export PATH=/mnt/w1/tinti/work/llvmlinux/toolchain/clang/install/bin:$PATH
The same must be done with arm-linux-androideabi toolchain.
export PATH=/mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/bin:$PATH
Now make sure that you have the proper versions.
which clang # should return /mnt/w1/tinti/work/llvmlinux/toolchain/clang/install/bin/clang which arm-linux-androideabi-gcc # should return /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc
Now we can use the toolchain generated by the project in Nexus 7's kernel.
cd src/android_kernel_nexus7
The make command should now use the proper toolchains for building the kernel. Now you can get benefit of all KBuild commands. Try generating the assembly for security/tf_driver/tf_comm.c
make CONFIG_DEBUG_SECTION_MISMATCH=y CONFIG_DEBUG_INFO=1 -j9 CONFIG_NO_ERROR_ON_MISMATCH=y ARCH=arm CROSS_COMPILE=arm-linux-androideabi- CC="clang -gcc-toolchain /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6" CFLAGS_KERNEL="-isystem /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/lib/gcc/arm-linux-androideabi/4.6.x-google/include" CFLAGS_MODULE="-isystem /mnt/w1/tinti/work/llvmlinux/arch/arm/toolchain/android/arm-linux-androideabi-4.6/lib/gcc/arm-linux-androideabi/4.6.x-google/include" security/tf_driver/tf_comm.s
Done, have fun.
