Error while compiling android 3.10 kernel source - android

Recently I tryed to crosscompile android kernel for my xiaomi mi4c.
To do this I have downloaded and configured toolchain like this:
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b marshmallow-release toolchain64
export ARCH=arm64
export SUBARCH=arm64
export CROSS_COMPILE=`pwd`/toolchain64/bin/aarch64-linux-android-
then I cloned kernel source from here: https://github.com/AndropaX/android_kernel_xiaomi_msm8992
and do this:
make clean && make mrproper
make ARCH=arm64 resurrection_libra_defconfig
make ARCH=arm64 CROSS_COMPILE=$CROSS_COMPILE -j3
Then I have an error:
In file included from include/linux/kernel.h:14:0,
from include/linux/sched.h:15,
from /home/owner/android_kernel_xiaomi_msm8992/arch/arm64/include/asm/compat.h:25,
from /home/owner/android_kernel_xiaomi_msm8992/arch/arm64/include/asm/stat.h:23,
from include/linux/stat.h:5,
from include/linux/module.h:10,
from drivers/tspdrv/tspdrv.c:26:
drivers/tspdrv/ImmVibeSPI_ISA1000.c: In function 'ImmVibeSPI_ForceOut_SetSamples':
include/linux/dynamic_debug.h:64:16: error: implicit declaration of function 'KBUILD_STR' [-Werror=implicit-function-declaration]
static struct _ddebug __aligned(8) \
^
include/linux/dynamic_debug.h:76:2: note: in expansion of macro 'DEFINE_DYNAMIC_DEBUG_METADATA'
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
^
include/linux/printk.h:240:2: note: in expansion of macro 'dynamic_pr_debug'
dynamic_pr_debug(fmt, ##__VA_ARGS__)
^
drivers/tspdrv/ImmVibeSPI_ISA1000.c:573:2: note: in expansion of macro 'pr_debug'
pr_debug("%s: level = %d\n", __func__, level);
^
<command-line>:0:27: error: 'tspdrv' undeclared (first use in this function)
include/linux/dynamic_debug.h:66:14: note: in expansion of macro 'KBUILD_MODNAME'
.modname = KBUILD_MODNAME, \
^
include/linux/dynamic_debug.h:76:2: note: in expansion of macro 'DEFINE_DYNAMIC_DEBUG_METADATA'
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
^
include/linux/printk.h:240:2: note: in expansion of macro 'dynamic_pr_debug'
dynamic_pr_debug(fmt, ##__VA_ARGS__)
^
drivers/tspdrv/ImmVibeSPI_ISA1000.c:573:2: note: in expansion of macro 'pr_debug'
pr_debug("%s: level = %d\n", __func__, level);
^
<command-line>:0:27: note: each undeclared identifier is reported only once for each function it appears in
include/linux/dynamic_debug.h:66:14: note: in expansion of macro 'KBUILD_MODNAME'
.modname = KBUILD_MODNAME, \
^
include/linux/dynamic_debug.h:76:2: note: in expansion of macro 'DEFINE_DYNAMIC_DEBUG_METADATA'
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
^
include/linux/printk.h:240:2: note: in expansion of macro 'dynamic_pr_debug'
dynamic_pr_debug(fmt, ##__VA_ARGS__)
^
drivers/tspdrv/ImmVibeSPI_ISA1000.c:573:2: note: in expansion of macro 'pr_debug'
pr_debug("%s: level = %d\n", __func__, level);
^
drivers/tspdrv/tspdrv.c: At top level:
drivers/tspdrv/tspdrv.c:94:37: fatal error: tspdrvOutputDataHandler.c: No such file or directory
#include <tspdrvOutputDataHandler.c>
^
cc1: some warnings being treated as errors
compilation terminated.
So, the question is, what am I doing wrong? Maybe I need another toolchain for crosscompilation? Can sombody suggest one? I dont think there is an error in the kernel code. So what can go wrong?

So, after a few days I found the answer. Thanks to kay2777 from 4pda.
Look for KBUILD_CFLAGS in the main Makefile, and add the following to suppress warnings as errors:
KBUILD_CFLAGS += -w
// if all errors are to be suppressed
KBUILD_CFLAGS += -Wno-error=unused-but-set-variable
// if that specific error is to be suppressed.

Related

Building android kernel

since two weeks I try to build the kernel for my htc device. Getting the right sources is not the problem, but since gcc has been removed from toolchains it's a real nightmare. Following the proposals to use clang instead always ends in lot of error messages.
What I've done up to now?
Proper installation of latest android-ndk (21.3.6528147)
Successfully test cross-compiling (just a simple program) over commandline
setup ENV variables for kernel build: (export commands only if not set yet)
$ cd <kernel-source-root>
($ make mrproper) // just after failed attempt to build
$ export ARCH=arm64
$ export SUBARCH=arm64
$ export CROSS_COMPILE=<path-to-toolchain-llvm-bin-folder>
modify Makefile and AndroidKernel.mk
// replace all occurences of 'gcc' with 'clang'
-gcc
+clang
generate .config
$ make msm-perf_defconfig
perform build
$ make V=1
getting error messages:
// ...
../kernel/bounds.c:18:2: error: unexpected token at start of statement
DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);
^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
^
<inline asm>:2:1: note: instantiated into assembly here
->NR_PAGEFLAGS 21 __NR_PAGEFLAGS
^
../kernel/bounds.c:19:2: error: unexpected token at start of statement
DEFINE(MAX_NR_ZONES, __MAX_NR_ZONES);
^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
^
<inline asm>:2:1: note: instantiated into assembly here
->MAX_NR_ZONES 3 __MAX_NR_ZONES
^
../kernel/bounds.c:21:2: error: unexpected token at start of statement
DEFINE(NR_CPUS_BITS, ilog2(CONFIG_NR_CPUS));
^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
^
<inline asm>:2:1: note: instantiated into assembly here
->NR_CPUS_BITS 3 ilog2(CONFIG_NR_CPUS)
^
../kernel/bounds.c:23:2: error: unexpected token at start of statement
DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t));
^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
^
<inline asm>:2:1: note: instantiated into assembly here
->SPINLOCK_SIZE 4 sizeof(spinlock_t)
^
4 errors generated.
make[2]: *** [kernel/bounds.s] Error 1
make[1]: *** [prepare0] Error 2
make: *** [sub-make] Error 2
Does someone see what goes wrong?
Adding -no-integrated-as to the build command fixed it.
According to clang developers:
Add -no-integrated-as. This is a known abuse of the compiler to output something other than assembly.
reference
make ARCH=arm64 -j64 -no-integrated-as

Is it possible to execute the so file generated from Anroid JNI?

I got a .so file from Android aar package with x86 , x86_64, armv7 etc.
Would it be possible for me to call the function in the .so file?
What I have been tried
created a main.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
printf("%d", Java_com_scaf_android_client_CodecUtils_stringFromJNI());
return 0;
}
execute
$ gcc -o main -lLockCore main.c
and I faced this error
main.c:4:15: warning: implicit declaration of function ‘Java_com_scaf_android_client_CodecUtils_stringFromJNI’ [-Wimplicit-function-declaration]
printf("%d", Java_com_scaf_android_client_CodecUtils_stringFromJNI());
^
/tmp/cc9vP9rb.o: In function `main':
main.c:(.text+0x14): undefined reference to `Java_com_scaf_android_client_CodecUtils_stringFromJNI'
collect2: error: ld returned 1 exit status

Error: use of undeclared identifier 'PTHREAD_MUTEX_ROBUST' cargo build liblmdb-sys for aarch64-linux-android target

I am trying to compile a rust project into an Android target (aarch64-linux-android).
From the comments in the lmdb code, it seems to need to run the compilation
"aarch64-linux-android-gcc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-o" "/Users/username/grin-wallet/target/aarch64-linux-android/release/build/liblmdb-sys-7a2d430dc3c9f3e3/out/mdb/libraries/liblmdb/mdb.o" "-c" "mdb/libraries/liblmdb/mdb.c"
with an additional -DMDB_USE_ROBUST=0 flag. Is this configurable from either the cargo build command or adding something to Cargo.toml?
The error I am getting is:
error: failed to run custom build command for `liblmdb-sys v0.2.2`
Caused by:
process didn't exit successfully: `/Users/username/grin-wallet/target/release/build/liblmdb-sys-b6bfc7b665736f9b/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("aarch64-linux-android")
TARGET = Some("aarch64-linux-android")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("aarch64-linux-android")
TARGET = Some("aarch64-linux-android")
HOST = Some("x86_64-apple-darwin")
CC_aarch64-linux-android = None
CC_aarch64_linux_android = None
TARGET_CC = None
CC = None
TARGET = Some("aarch64-linux-android")
HOST = Some("x86_64-apple-darwin")
CFLAGS_aarch64-linux-android = None
CFLAGS_aarch64_linux_android = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("false")
running: "aarch64-linux-android-gcc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-o" "/Users/username/grin-wallet/target/aarch64-linux-android/release/build/liblmdb-sys-7a2d430dc3c9f3e3/out/mdb/libraries/liblmdb/mdb.o" "-c" "mdb/libraries/liblmdb/mdb.c"
cargo:warning=mdb/libraries/liblmdb/mdb.c:4625:13: warning: implicit declaration of function 'pthread_mutexattr_setrobust' is invalid in C99 [-Wimplicit-function-declaration]
cargo:warning= || (rc = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST))
cargo:warning= ^
cargo:warning=mdb/libraries/liblmdb/mdb.c:4625:49: error: use of undeclared identifier 'PTHREAD_MUTEX_ROBUST'
cargo:warning= || (rc = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST))
cargo:warning= ^
cargo:warning=mdb/libraries/liblmdb/mdb.c:9821:33: warning: unused parameter 'env' [-Wunused-parameter]
cargo:warning=mdb_env_get_maxkeysize(MDB_env *env)
cargo:warning= ^
cargo:warning=mdb/libraries/liblmdb/mdb.c:10002:10: warning: implicit declaration of function 'pthread_mutex_consistent' is invalid in C99 [-Wimplicit-function-declaration]
cargo:warning= rc2 = mdb_mutex_consistent(mutex);
cargo:warning= ^
cargo:warning=mdb/libraries/liblmdb/mdb.c:351:37: note: expanded from macro 'mdb_mutex_consistent'
cargo:warning=#define mdb_mutex_consistent(mutex) pthread_mutex_consistent(mutex)
cargo:warning= ^
cargo:warning=3 warnings and 1 error generated.
exit code: 1
First, make sure you have all the android build targets installed:
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android
Then install cargo-ndk
cargo install cargo-ndk
Now you need to export a number of variables in the terminal that will be used by the build.
If you are using pkg-config then
export PKG_CONFIG_ALLOW_CROSS=1
The root directory of the NDK
export NDK_HOME=the_path_to_the_ndk
The platform version
export NDK_API_LEVEL=the_api_level
Note that the compilers must be specified as clang for newer versions of the NDK since GCC was deprecated in the android toolchain and is no longer present (some projects try to reference GCC by default)
export CC=$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android$NDK_API_LEVEL-clang
export CXX=$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android$NDK_API_LEVEL-clang++
Then the rest of the variables
export AR=$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar
export AS=$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-as
export LD=$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ld
export RANLIB=$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ranlib
export STRIP=$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip
You were on the right track in thinking -DMDB_USE_ROBUST=0, it just needed to be passed to the compiler flags
export CFLAGS=-DMDB_USE_ROBUST=0
Then in your rust project, you will need to create a .config directory in the same directory as your .toml file. Within the .config directory, you will need to create a config file.
In the config file you will need to specify the relevant build targets for each target you need built (replace NDK_HOME and NDK_API_LEVEL with their respective values)
[target.aarch64-linux-android]
ar = "<NDK_HOME>/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar"
linker = "<NDK_HOME>/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android<NDK_API_LEVEL>-clang"
You should then be able to build successfully with
cargo ndk --target aarch64-linux-android --android-platform $NDK_API_LEVEL -- build --release
You can't just build and targeting to linex-android, another way to do this is develop your app via Android Studio or with Flutter

Cross Compiling PALSIADE for android

we are trying to build PALISADE (https://git.njit.edu/palisade/PALISADE) for Android. We have made some Progress by building “gmp” and “ntl” successfully for Android.
GMP is able to cross compile out of the box. NTL was a bit more tricky. We used https://github.com/nemirst/ntl-android but changed the headers and src to the version provided within PALISADE (10.5.0)
We also did some changes to the PALISADE makefiles so they support cross compiling using the android standalone toolchains. The issue is now, when trying to compile PALISADE using the cross compiled NTL and GMP lib we get the following errors:
PALISADE/bin/build/toolchains/aarch64-linux-android/bin/aarch64-linux-android-gcc --sysroot=PALISADE/bin/build/toolchains/aarch64-linux-android/sysroot -g -Wall -Werror -O3 -fopenmp -pthread -I src -Isrc/core/lib -Isrc/pke/lib -Isrc/abe/lib -Isrc/signature/lib -I test -I /opt/local/include/libomp -fopenmp -I third-party/include -I third-party/include/rapidjson -c -o bin/build/core/lib/math/benative-math-impl.o src/core/lib/math/benative-math-impl.cpp
In file included from src/core/lib/math/benative-math-impl.cpp:28:
In file included from src/core/lib/utils/../math/backend.h:43:
src/core/lib/math/native_int/binint.h:956:79: error: no viable conversion from 'const unsigned long' to 'NTL::wide_double'
return (uint_type)NTL::MulModPrecon(this->m_value,b.m_value,modulus.m_value,bInv.m_value);
^~~~~~~~~~~~
src/core/lib/math/transfrm.cpp:192:33: note: in instantiation of member function 'native_int::NativeInteger<unsigned long>::ModMulPreconOptimized' requested here
InputToFFT[i]=element[i].ModMulPreconOptimized((*rootOfUnityTable)[i],modulus,preconTable[i]);
^
third-party/include/NTL/sp_arith.h:405:4: note: candidate constructor not viable: no known conversion from 'const unsigned long' to 'const NTL::wide_double &' for 1st argument
wide_double(const wide_double& x) : data(x.data) { }
^
third-party/include/NTL/sp_arith.h:812:62: note: passing argument to parameter 'bninv' here
inline long MulModPrecon(long a, long b, long n, wide_double bninv)
^
In file included from src/core/lib/math/benative-math-impl.cpp:36:
src/core/lib/math/transfrm.cpp:107:48: error: too many arguments to function call, expected 4, have 5
preconRootOfUnityInverseTable, cycloOrder, ans);
^~~
src/core/lib/math/transfrm.cpp:300:38: note: in instantiation of member function 'lbcrypto::NumberTheoreticTransform<native_int::NativeVector<native_int::NativeInteger<unsigned long> > >::InverseTransformIterative' requested here
NumberTheoreticTransform<VecType>::InverseTransformIterative(element, *rootOfUnityITable,
^
src/core/lib/math/transfrm.h:67:3: note: 'ForwardTransformIterative' declared here
static void ForwardTransformIterative(const VecType& element, const VecType &rootOfUnityTable, const usint cycloOrder, VecType* result) {
^
In file included from src/core/lib/math/benative-math-impl.cpp:28:
In file included from src/core/lib/utils/../math/backend.h:43:
src/core/lib/math/native_int/binint.h:975:88: error: no viable conversion from 'const unsigned long' to 'NTL::wide_double'
this->m_value = (uint_type)NTL::MulModPrecon(this->m_value,b.m_value,modulus.m_value,bInv.m_value);
^~~~~~~~~~~~
src/core/lib/math/transfrm.cpp:313:21: note: in instantiation of member function 'native_int::NativeInteger<unsigned long>::ModMulPreconOptimizedEq' requested here
(*OpIFFT)[i].ModMulPreconOptimizedEq((*rootOfUnityITable)[i],nativeModulus,preconTable[i]);
^
third-party/include/NTL/sp_arith.h:405:4: note: candidate constructor not viable: no known conversion from 'const unsigned long' to 'const NTL::wide_double &' for 1st argument
wide_double(const wide_double& x) : data(x.data) { }
^
third-party/include/NTL/sp_arith.h:812:62: note: passing argument to parameter 'bninv' here
inline long MulModPrecon(long a, long b, long n, wide_double bninv)
^
3 errors generated.
make[1]: *** [bin/build/core/lib/math/benative-math-impl.o] Error 1
make: *** [all] Error 2
We would greatly appreciate any help in getting this library to build for Android.
EDIT: Spelling
This is a little late in response, but if you are still interested, newer versions of Palisade do not require GMP or NTL (those are only enabled when the user explicitly enables them in the CMake build process), so it may be easier to build now. You should be using the newest stable version at https://gitlab.com/palisade/palisade-release or if you are willing to try it out, the development version at https://gitlab.com/palisade/palisade-development
Cross compiling is a bit tricky, but it can be done. We are working on some embedded targets but they are not yet in the release stream.
We are looking into supporting an Android port in a future release, so any progress you make that you can share with us is most appreciated.
Dave Cousins -- PALISADE Development team.

error: 'nanf' is not a member of 'std' when building tensorflow android with quantized graph

I'm trying to build google android example using my own graph.
I used the quantization method explained here.
I've added "//tensorflow/contrib/quantization:cc_ops" and "//tensorflow/contrib/quantization/kernels:quantized_ops" to the build file.
When I run bazel build //tensorflow/examples/android:tensorflow_demo
I get the following errorERROR: /home/dani/tensorflow/tensorflow/core/BUILD:1065:1: C++ compilation of rule '//tensorflow/core:gpu_runtime' failed: arm-linux-androideabi-gcc failed: error executing command external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -fstack-protector-strong -fpic -ffunction-sections -funwind-tables ... (remaining 95 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
tensorflow/core/common_runtime/gpu/gpu_debug_allocator.cc: In member function 'virtual void* tensorflow::GPUNanResetAllocator::AllocateRaw(std::size_t, std::size_t)':
tensorflow/core/common_runtime/gpu/gpu_debug_allocator.cc:169:53: error: 'nanf' is not a member of 'std'
std::vector<float> nans(req_size / sizeof(float), std::nanf(""));
^
tensorflow/core/common_runtime/gpu/gpu_debug_allocator.cc:169:53: note: suggested alternative:
In file included from external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/cmath:44:0,
from external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/complex:44,
from ./tensorflow/core/framework/numeric_types.h:19,
from ./tensorflow/core/framework/allocator.h:24,
from ./tensorflow/core/common_runtime/visitable_allocator.h:20,
from ./tensorflow/core/common_runtime/gpu/gpu_debug_allocator.h:23,
from tensorflow/core/common_runtime/gpu/gpu_debug_allocator.cc:16:
external/androidndk/ndk/platforms/android-21/arch-arm/usr/include/math.h:354:7: note: 'nanf'
float nanf(const char *) __NDK_FPABI_MATH__ __pure2;
^
tensorflow/core/common_runtime/gpu/gpu_debug_allocator.cc: In member function 'virtual void tensorflow::GPUNanResetAllocator::DeallocateRaw(void*)':
tensorflow/core/common_runtime/gpu/gpu_debug_allocator.cc:182:53: error: 'nanf' is not a member of 'std'
std::vector<float> nans(req_size / sizeof(float), std::nanf(""));
^
tensorflow/core/common_runtime/gpu/gpu_debug_allocator.cc:182:53: note: suggested alternative:
In file included from external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/cmath:44:0,
from external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/complex:44,
from ./tensorflow/core/framework/numeric_types.h:19,
from ./tensorflow/core/framework/allocator.h:24,
from ./tensorflow/core/common_runtime/visitable_allocator.h:20,
from ./tensorflow/core/common_runtime/gpu/gpu_debug_allocator.h:23,
from tensorflow/core/common_runtime/gpu/gpu_debug_allocator.cc:16:
external/androidndk/ndk/platforms/android-21/arch-arm/usr/include/math.h:354:7: note: 'nanf'
float nanf(const char *) __NDK_FPABI_MATH__ __pure2;
^
Target //tensorflow/examples/android:tensorflow_demo failed to build
I've tried using both android-ndk-r10e and android-ndk-r11.
Thanks, Dan

Categories

Resources