How to find out gcc optimization level for ndk-build

I wrote native code on Android using NDK (jni). I want to disable gcc compiler optimization. At the moment I am adding LOCAL_CFLAGS += -O0 to Android.mk, I am not sure if it works.

I wrote code to check the loop overhead as follows:

 // gettime for(int i = 0 ; i<10000;i++) { } // gettime 

The temporary difference is too small, which I'm sure the loop has been removed by the compiler. I can change i to a mutable variable, but I want to check if I turned off compiler optimization correctly.

How do I know the level of optimization used by gcc (ndk-build), can I set make to verbose to receive all messages?

Thanks in advance.

+4
source share
2 answers

See how to turn off optimization: Problems with Android NDK assert.h

Mostly you need to add

 APP_OPTIM := debug 

to application.mk file

+8
source

The compiler defines a macro called __OPTIMIZE__ when optimization is enabled.

If you insert these lines in any C file, the compiler will fail if the make flags do not work for this file.

 #ifdef __OPTIMIZE__ #error Optimization enabled. That not right! #endif 

Another option is to check the arch-specific flags on the embedded binary (.o or executable).

 readelf -A myfile.o 

ARM has a flag indicating the level of optimization, but I think the Android toolchain might be a little old to use it correctly, so YMMV.

+6
source

Source: https://habr.com/ru/post/1395180/


All Articles