Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure coverity for ndk-build

I would like to use coverity for static analysis, and I needed it for c++. Since my project uses Android NDK, I configured the compiler as:

cov-configure –comptype gcc –compiler ~/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-4.6

Then I ran cov-build –dir coverity ndk-build –j8 NDK_DEBUG=1

Everything builds, but I have a warning

*[*WARNING] No files were emitted. This may be due to a problem with your configuration
or because no files were actually compiled by your build command.
Please make sure you have configured the compilers actually used in the compilation.**

So I ignored the warning and ran

cov-analyze –dir coverity –all
**Coverity Static Analysis for C/C++ version 6.6.1 on Linux 2.6.38-8-server x86_64
Internal version numbers: d614fc01a4 p-eureka-push-15003.308

Looking for translation units
Error: no matching translation units.**

So is my compiler configured properly? Has anyone configured a compiler for Android NDK before?

like image 595
largotiticaca Avatar asked Jan 27 '14 23:01

largotiticaca


3 Answers

You indicated to coverity that the compiler is ~/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-4.6

Make sure this is the correct full path in the command (maybe replace '~'?), and that arm-linux-androideabi-gcc-4.6 is exactly what is used for compilation.

I had the same issue because Coverity expected GCC to be used, but my build used cc!

Then I set:

~/coverity-current/bin/cov-configure --compiler /usr/bin/cc --comptype gcc

It displayed:

[WARNING] A template configuration is recommended for this compiler.
Add "--template" to your command line, or use one of the
template configuration shortcut command lines below:

  cov-configure --gcc      # GNU C/C++ compiler (gcc/g++)
  cov-configure --msvc     # Microsoft C/C++ compiler (cl)
  cov-configure --java     # Sun Java compiler (javac)

You must remove the specific configuration before re-running with "--template".
* Configuring /usr/bin/cc as a C compiler
[WARNING] Config gcc-config-2 already exists for cc gcc gcc-4.8 as gcc and will be reused. 
* Configuring /usr/bin/cc as a C++ compiler
[WARNING] Config g++-config-2 already exists for cc gcc gcc-4.8 as g++ and will be reused. 

Generated coverity_config.xml at location /home/default/cov-analysis-linux64-X.X.X/config/coverity_config.xml
Successfully generated configuration for the compilers: cc gcc gcc-4.8

The cov-build command is:

../../coverity-current/bin/cov-build --dir ~/build_cov/myapp/cov-log-all-output make -C ~/build_cov/myapp

The result:

../../coverity-current/bin/cov-build --dir ~/build_cov/myapp/cov-log-all-output make -C ~/build_cov/myapp

[...]

76 C/C++ compilation units (100%) are ready for analysis
The cov-build utility completed successfully.

You have a bigger emit-db file in cov-log-all-output/c/emit/pcname/

like image 130
OlPo Avatar answered Nov 11 '22 10:11

OlPo


You should configure the correct compiler for NDK:

cov-configure --comptype gcc -compiler arm-linux-androideabi-gcc --template
like image 30
thiagolr Avatar answered Nov 11 '22 11:11

thiagolr


In coverity/build-log.txt, you should see all of the commands executed during the build (look for "EXECUTING:"). Double-check that the compiler commands match the compiler that you specified to cov-configure. You can configure more than one compiler, and it might be useful to configure a generic gcc ("cov-configure --gcc").

Keep in mind that if your ndk-build doesn't actually build anything then cov-build will give a similar message. In other words, the message doesn't always indicate a problem--it's possible that the build completed and didn't actually compile any files.

like image 1
Jon Jarboe Avatar answered Nov 11 '22 09:11

Jon Jarboe