Ericsson / codechecker

CodeChecker is an analyzer tooling, defect database and viewer extension for static and dynamic analyzer tools.
https://codechecker.readthedocs.io
Apache License 2.0
2.28k stars 383 forks source link

There is something wrong with default clang autodetection #2429

Closed LebedevRI closed 5 years ago

LebedevRI commented 5 years ago

Describe the bug

$ clang --version
clang version 10.0.0-+20191116100608+584704c725a-1~exp1~20191116211218.2875 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
$ whereis clang
clang: /usr/lib/clang /usr/local/bin/clang /usr/include/clang /usr/share/clang
$ ls -lah /usr/local/bin/clang
lrwxrwxrwx 1 root root 17 Jul 26 15:29 /usr/local/bin/clang -> /usr/bin/clang-10

By default, CTU does not work:

$ CodeChecker analyze --ctu build-Clang-SANITIZE/compile_commands.json -o clang-sa-reports --verbose debug
usage: CodeChecker [-h] {analyze} ...
CodeChecker: error: unrecognized arguments: --ctu

But after following https://github.com/Ericsson/codechecker#configuring-clang-version and pointing those options at the /usr/bin/clang-10, it works. Since clang is in the $PATH, i.e. it can be executed without specifying the path said adjustment must not be necessary..

CodeChecker version

$ CodeChecker version
CodeChecker analyzer version:
---------------------------------------------------------------
Kind                 | Version                                 
---------------------------------------------------------------
Base package version | 6.11.0                                  
Package build date   | 2019-11-17T18:43                        
Git commit ID (hash) | 17d4645419142982d7789ecdc837eb3f1d0d9eaa
Git tag information  | 6.11                                    
---------------------------------------------------------------

CodeChecker web version:
------------------------------------------------------------------------
Kind                          | Version                                 
------------------------------------------------------------------------
Base package version          | 6.11.0                                  
Package build date            | 2019-11-17T18:43                        
Git commit ID (hash)          | 17d4645419142982d7789ecdc837eb3f1d0d9eaa
Git tag information           | 6.11                                    
Server supported API (Thrift) | 6.21                                    
Client API (Thrift)           | 6.21                                    
------------------------------------------------------------------------

Desktop (please complete the following information)

csordasmarton commented 5 years ago

@LebedevRI What is your output of the following command:

CodeChecker analyzers --details
csordasmarton commented 5 years ago

I think your problem will be the same as #2333. Is the clang-extdef-mapping binary available in your clang install directory?

https://github.com/Ericsson/codechecker/blob/17d4645419142982d7789ecdc837eb3f1d0d9eaa/analyzer/codechecker_analyzer/analyzers/clangsa/clang_options.py#L60-L77

LebedevRI commented 5 years ago

I think your problem will be the same as #2333. Is the clang-extdef-mapping binary available in your clang install directory?

Indeed that is the problem, as i wrote in the original comment:

But after following https://github.com/Ericsson/codechecker#configuring-clang-version and pointing those options at the /usr/bin/clang-10, it works. Since clang is in the $PATH, i.e. it can be executed without specifying the path said adjustment must not be necessary..

So the bug seems that if the clang is a symlink, it looks for clang-extdef-mapping only next to the symlink, but it does not try to dereference said symlink and look in that directory.

csordasmarton commented 5 years ago

It will get the installed directory by parsing the output of the clang --version command:

https://github.com/Ericsson/codechecker/blob/17d4645419142982d7789ecdc837eb3f1d0d9eaa/analyzer/codechecker_analyzer/analyzers/clangsa/ctu_autodetection.py#L66-L74

https://github.com/Ericsson/codechecker/blob/17d4645419142982d7789ecdc837eb3f1d0d9eaa/analyzer/codechecker_analyzer/analyzers/clangsa/version.py#L30-L57

And it will try to find the clang-extdef-mapping tool in this directory: https://github.com/Ericsson/codechecker/blob/17d4645419142982d7789ecdc837eb3f1d0d9eaa/analyzer/codechecker_analyzer/analyzers/clangsa/clang_options.py#L75-L77

LebedevRI commented 5 years ago

Interesting.

It will get the installed directory by parsing the output of the clang --version command:

Hm, it is weird that InstalledDir in clang --version isn't actually the install dir, but only the location of the clang that was originally executed:

$ /usr/local/bin/clang --version
clang version 10.0.0-+20191117100609+a516fbac520-1~exp1~20191117211154.2877 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
$ ls -lah /usr/local/bin/clang
lrwxrwxrwx 1 root root 17 Jul 26 15:29 /usr/local/bin/clang -> /usr/bin/clang-10
$ /usr/bin/clang-10 --version
clang version 10.0.0-+20191117100609+a516fbac520-1~exp1~20191117211154.2877 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
csordasmarton commented 5 years ago

@LebedevRI I created a pull request (#2430) that I think will solve your problem. Could you please check it and try it out?

The main idea that we will resolve symlinks of compiler binaries, so we will get --version option of the right clang binary, so the installed directory will be correct.