codechecker icon indicating copy to clipboard operation
codechecker copied to clipboard

Failed to load customized clang static analyzer

Open jackyxqz opened this issue 3 years ago • 3 comments

Describe the bug Enable customized clang static analyzer as suggested by help page. And it report error like this

export CC_ANALYZERS_FROM_PATH=1
export CC_CLANGSA_PLUGIN_DIR=<PATH_TO_MY_OWN_PLUGIN>/
CodeChecker analyze --ctu-analyze --analyzers clangsa --enable sensitive compile_commands.json -o ./reports-ctu

error: unable to find plugin 'checkercfg'                                                                                                                                         
                                                                                                                                                                                  
[ERROR 2022-02-09 16:09] -                                                                                                                                                        

Looking at the code, it seems like clang has changed the way to load plugin.

https://github.com/Ericsson/codechecker/blob/90eafcd31a3e856e1306aeef1d3c143cb2e13cc8/analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py#L196-L200

My clang version

 λ clang --version                           
Ubuntu clang version 12.0.0-3ubuntu1~20.04.4
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Change to this code works

            for plugin in config.analyzer_plugins:
                analyzer_cmd.extend(["-fplugin" + plugin]),

CodeChecker version

 λ CodeChecker version                                                                                                    
CodeChecker analyzer version:
---------------------------------------------------------------
Kind                 | Version                                 
---------------------------------------------------------------
Base package version | 6.18.2                                  
Package build date   | 2022-02-09T15:52                        
Git commit ID (hash) | 992d274c78b9a0436328c30a40d3b1de899902e2
Git tag information  | 6.18.2                                  
---------------------------------------------------------------

CodeChecker web version:
------------------------------------------------------------------------
Kind                          | Version                                 
------------------------------------------------------------------------
Base package version          | 6.18.2                                  
Package build date            | 2022-02-09T15:52                        
Git commit ID (hash)          | 992d274c78b9a0436328c30a40d3b1de899902e2
Git tag information           | 6.18.2                                  
Server supported API (Thrift) | 6.47                                    
Client API (Thrift)           | 6.47 

To Reproduce

export CC_ANALYZERS_FROM_PATH=1
export CC_CLANGSA_PLUGIN_DIR=<PATH_TO_MY_OWN_PLUGIN>/
CodeChecker analyze --ctu-analyze --analyzers clangsa --enable sensitive compile_commands.json -o ./reports-ctu

Expected behaviour I expect it can load my customized plugin and run analysis

Desktop (please complete the following information)

  • OS: Linux
 λ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

Additional context None

jackyxqz avatar Feb 09 '22 08:02 jackyxqz

Confirmed. Thanks for reporting it. It seems like we shouldn't have hardcoded one of our internal plugin names. You probably won't have it available xD

Your proposed fix should work. However, I would rather use -plugin as we were using previously. Let me investigate which should we use.

steakhal avatar Feb 11 '22 08:02 steakhal

According to my experiments, it seems like we don't even need to pass the -plugin nor the -fplugin options. For me, the -load is enough to get the checkers working. Please note that I was using a really old clang for testing this. @jackyxqz Could you please check this?

steakhal avatar Feb 11 '22 09:02 steakhal

FWIW I encountered this error and this issue lead me to solving it with the below patch:

 analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py   | 4 +---
 analyzer/codechecker_analyzer/analyzers/clangsa/statistics.py | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py b/analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py
index a1df95b2..95bd2479 100644
--- a/analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py
+++ b/analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py
@@ -197,9 +197,7 @@ class ClangSA(analyzer_base.SourceAnalyzer):
                             '-Qunused-arguments']
 
             for plugin in config.analyzer_plugins:
-                analyzer_cmd.extend(["-Xclang", "-plugin",
-                                     "-Xclang", "checkercfg",
-                                     "-Xclang", "-load",
+                analyzer_cmd.extend(["-Xclang", "-load",
                                      "-Xclang", plugin])
 
             analyzer_mode = 'plist-multi-file'
diff --git a/analyzer/codechecker_analyzer/analyzers/clangsa/statistics.py b/analyzer/codechecker_analyzer/analyzers/clangsa/statistics.py
index 150d2bd1..d6a7d840 100644
--- a/analyzer/codechecker_analyzer/analyzers/clangsa/statistics.py
+++ b/analyzer/codechecker_analyzer/analyzers/clangsa/statistics.py
@@ -35,9 +35,7 @@ def build_stat_coll_cmd(action, config, source):
            '--analyzer-output', 'text']
 
     for plugin in config.analyzer_plugins:
-        cmd.extend(["-Xclang", "-plugin",
-                    "-Xclang", "checkercfg",
-                    "-Xclang", "-load",
+        cmd.extend(["-Xclang", "-load",
                     "-Xclang", plugin])
 
     cmd.extend(['-Xclang',
-- 

tomrittervg avatar Aug 22 '22 20:08 tomrittervg