[Android Software/Hacking General [Developers Only]] Besix2:
Hello,

Im currently trying to compile the stock Kernel from my device and add changes to so I can use it with nethunter. But I cant figure out how to compile it succesfully. So far I tried the guide on their website, tried my own things and these suggested by someone on their github and also tried it with clang.

Method 1:

Getting toolchain

Using command

export ARCH=arm64,export SUBARCH=arm64,export ANDROID_MAJOR_VERSION=10,export CROSS_COMPILE='pwd'/toolchain64/bin/aarch64-linux-android-,make "my_defconfig",make -j$(nproc)

After

Code:

make "my_defconfig"

it returned this:

make exynos 7885-a7y18lte_
Makefile:727: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: --stack-protector-strong not supported by compiler
Android GCC has been deprecated in favor of Clang, and will be removed from
Android in 2020-01 as per the deprecation plan in:
https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/master/GCC_4_9_DEPRECATION.md
Traceback (most recent call last):
File "/home/kali/kernelbuild/kernel/toolchain64/bin/aarch64-linux-android-gcc", line 75, in <module>
main(sys.argv)
File "/home/kali/kernelbuild/kernel/toolchain64/bin/aarch64-linux-android-gcc", line 72, in main
cw.invoke_compiler()
File "/home/kali/kernelbuild/kernel/toolchain64/bin/aarch64-linux-android-gcc", line 67, in invoke_compiler
os.execv(self.argvo, self.execargs)
OSError: [Errno 8] Exec format error
scripts/kconfig/conf --silentoldconfig Kconfig
Kconfig:15:warning: environment variable ANDROID_MAJOR_VERSION undefined
fs/sdcardfs//Kconfig:5: recursive inclusion detected. Inclusion path:
current file : 'fs/sdcardfs//kconfig'
included from: 'fs/sdcardfs//Kconfig:7'
make[2]: *** (scripts/kconfig/Makefile:38: silentoldconfig] Error 1
make[1]: *** [Makefile:562: silentoldconfig] Error 2
make: *** No rule to make target 'exynos 7885-a7y18lte_'. Stop.

Method 2:

I've used the build script that was already in my kernel folder. It looked like this:

#!/bin/bash

export ARCH=arm64
export CROSS_COMPILE=../PLATFORM/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
export ANDROID_MAJOR_VERSION=q

make exynos7885-a7y18lte_defconfig
make -j64

After noting that the path was empty I changed it to my other toolchain. The error message looked like this:

Makefile:727: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler

make: ../PLATFORM/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc: No such file or directory

scripts/kconfig/conf --silentoldconfig Kconfig

arch/Kconfig:404:warning: choice value must have a prompt

arch/Kconfig:406:warning: defaults for choice values not supported

.config:235:warning: override: CC_STACKPROTECTOR_STRONG changes choice state

configuration written to .config

include/config/auto.conf:622:warning: override: CC_STACKPROTECTOR_NONE changes choice state

Makefile:727: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler

make: ../PLATFORM/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc: No such file or directory

CHK include/config/kernel.release

CHK include/generated/uapi/linux/version.h

security/samsung/defex_lsm/Makefile:13: [DEFEX] INTEGRITY_ENABLE

security/samsung/defex_lsm/Makefile:118: [DEFEX] VTS false

CHK include/generated/utsrelease.h

HOSTLD scripts/dtc/dtc

CC scripts/mod/empty.o

/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x8): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x38): first defined here

CC scripts/mod/devicetable-offsets.s

/bin/sh: 1: ../PLATFORM/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc: not found

/bin/sh: 1: ../PLATFORM/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc: not found

make[2]: *** [scripts/Makefile.build:278: scripts/mod/empty.o] Error 127

make[2]: *** Waiting for unfinished jobs....

make[2]: *** [scripts/Makefile.build:153: scripts/mod/devicetable-offsets.s] Error 127

make[1]: *** [scripts/Makefile.build:484: scripts/mod] Error 2

make[1]: *** Waiting for unfinished jobs....

CHK include/generated/timeconst.h

CC kernel/bounds.s

/bin/sh: 1: ../PLATFORM/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc: not found

make[1]: *** [Kbuild:20: kernel/bounds.s] Error 127

make[1]: *** Waiting for unfinished jobs....

make: *** [Makefile:1086: prepare0] Error 2

make: *** Waiting for unfinished jobs....

collect2: error: ld returned 1 exit status

make[2]: *** [scripts/Makefile.host:100: scripts/dtc/dtc] Error 1

make[1]: *** [scripts/Makefile.build:484: scripts/dtc] Error 2

make: *** [Makefile:576: scripts] Error 2

Method 3: Here I've used clang and followed this. I noticed that the binutils that he suggested where empty so I used the toolchain from the kali tutorial. My only problem was that I dont had any 32bit gcc folders so in the script i used the same toolchain for both.

Empty Script:

make O=out ARCH=arm64 <defconfig>

PATH="<path to clang folder>/bin:<path to 64-bit gcc folder>/bin:<path to 32-bit gcc folder>/bin:${PATH}" \
make -j$(nproc --all) O=out \
ARCH=arm64 \
CC=clang \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-android- \
CROSS_COMPILE_ARM32=arm-linux-androideabi-

My script:

make O=out ARCH=arm64 ANDROID_MAJOR_VERSION=q exynos7885-a7y18lte_defconfig

PATH="/home/kali/kernelbuild/kernel/linux-x86/clang-stable/bin:/home/kali/kernelbuild/kernel/toolchain64/bin:/home/kali/kernelbuild/kernel/toolchain64/bin:${PATH}" \
make -j$(nproc --all) O=out \
ARCH=arm64 \
CC=clang \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-android- \
CROSS_COMPILE_ARM32=arm-linux-androideabi-

Error message:

make[1]: Entering directory '/home/kali/kernelbuild/kernel/Kernel/out'
arch/Kconfig:404:warning: choice value must have a prompt
arch/Kconfig:406:warning: defaults for choice values not supported
arch/arm64/configs/exynos7885-a7y18lte_defconfig:235:warning: override: CC_STACKPROTECTOR_STRONG changes choice state
#
# configuration written to .config
#
make[1]: Leaving directory '/home/kali/kernelbuild/kernel/Kernel/out'
make[1]: Entering directory '/home/kali/kernelbuild/kernel/Kernel/out'
make[1]: ../scripts/clang-android.sh: Permission denied
CHK include/generated/uapi/linux/version.h
scripts/kconfig/conf --silentoldconfig Kconfig
Kconfig:15:warning: environment variable ANDROID_MAJOR_VERSION undefined
scripts/kconfig/conf --silentoldconfig Kconfig
Kconfig:15:warning: environment variable ANDROID_MAJOR_VERSION undefined
fs/sdcardfs//Kconfig:5: recursive inclusion detected. Inclusion path:
current file : 'fs/sdcardfs//Kconfig'
included from: 'fs/sdcardfs//Kconfig:7'
make[3]: *** [../scripts/kconfig/Makefile:38: silentoldconfig] Error 1
make[2]: *** [../Makefile:562: silentoldconfig] Error 2
make[1]: *** [/home/kali/kernelbuild/kernel/Kernel/Makefile:604: include/config/auto.conf] Error 2
make[1]: *** Waiting for unfinished jobs....
fs/sdcardfs//Kconfig:5: recursive inclusion detected. Inclusion path:
current file : 'fs/sdcardfs//Kconfig'
included from: 'fs/sdcardfs//Kconfig:7'
make[3]: *** [../scripts/kconfig/Makefile:38: silentoldconfig] Error 1
make[2]: *** [../Makefile:562: silentoldconfig] Error 2
make[1]: *** [/home/kali/kernelbuild/kernel/Kernel/Makefile:604: include/config/tristate.conf] Error 2
make[1]: Leaving directory '/home/kali/kernelbuild/kernel/Kernel/out'
make: *** [Makefile:152: sub-make] Error 2

My Device:

Samsung Galaxy A7 2018 (SM-A750FN)

Kernel Version: 4.4

Android version: 10

Im only trying to compile the kernel and before that enter

Code:

make menuconfig

so I can make the required changes. Thanks for any Help or Advice.