Coverity Scan fails to build <stdlib.h> with _GNU_SOURCE defined

情到浓时终转凉″ 提交于 2019-12-07 11:41:47

问题


The Coverity Scan Build Tool fails to compile any C file that includes <stdlib.h> on Ubuntu 18.04 when _GNU_SOURCE is defined:

$ cat > main.c
#include <stdlib.h>
int main() {
}
$ 
$ gcc -D_GNU_SOURCE=1 -o main main.c 
$ 
$ /opt/cov-analysis/bin/cov-build --dir cov-int gcc -D_GNU_SOURCE=1 -o main main.c 
Coverity Build Capture (64-bit) version 2017.07 on Linux 4.15.0-20-generic x86_64
...
[WARNING] Emitted 0 C/C++ compilation units (0%) successfully
...
$ 

The same build works perfectly on Ubuntu 16.04 or without _GNU_SOURCE defined:

$ /volatile/local/cov-analysis/bin/cov-build --dir cov-int gcc -o main main.c 
Coverity Build Capture (64-bit) version 2017.07 on Linux 4.15.0-20-generic x86_64
...
Emitted 1 C/C++ compilation units (100%) successfully
...
$ 

How to get Coverity Scan to build C sources with _GNU_SOURCEdefined on Ubuntu 18.04?

For those interested file cov-int/build-log.txt can be found here:
https://gist.github.com/DimitriPapadopoulos/0dcd9018eed26401cc6095087d9cc1d5


回答1:


After contacting Coverity support, it appears this is known bug. They suggested I work around it by switching from the default Ubuntu 18.04 compiler (GCC 7) to the previous version (GCC 6):

sudo apt install gcc-6

Indeed _Float32, _Float32x, _Float64, _Float64x and _Float128 were introduced in GCC 7.




回答2:


Coverity is failing to define the types GCC would define, but then it's claiming to be GCC anyway. Here's a workaround: https://gist.github.com/vathpela/0cede6d6eb5b0ec0791c6afc4282c340#file-fix_coverity-h

Just be sure you do:

#include "fix_coverity.h"

before stdlib.h gets included, whether directly or indirectly.



来源:https://stackoverflow.com/questions/50434236/coverity-scan-fails-to-build-stdlib-h-with-gnu-source-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!