Sonar-scanner fails to scan C code

Hi,

We are trying to use SonarCloud on a particular project which uses gcc-arm-none-eabi-5_4-2016q3 unlike all our other projects which use the 2019 version. This project also has the particuliarity that it uses precombiled object files but it builds correctly on our CI pipeline. SonarCloud however fails with the error message We have added the debug option, upgraded to the latest version of SonarScanner but still no luck. Please help.

Best regards,

Galaxy

Template for a good bug report, formatted with Markdown:

  • versions used: Scanner: sonar-scanner-4.6.0.2311-linux)
  • error observed (wrap logs/code around triple quote ``` for proper formatting)
14:16:57.082 DEBUG: Probing compiler: [/work/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc, -x, c, --std, gnu99, -mcpu=cortex-m4, --sysroot=/work/gcc-arm-none-eabi-5_4-2016q3/bin, -mthumb, -v, -dM, -E, -]
14:16:57.137 DEBUG: stdout:
14:16:57.138 DEBUG: stderr:
execv: No such file or directory
14:16:57.140 WARN: Invalid probe found, skip analysis of files: [/builds/terabee_embedded/positioning_system/drtls/application/[FILE_NAME].c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.143 WARN: Invalid probe found, skip analysis of files: [/builds/terabee_embedded/positioning_system/drtls/application/[FILE_NAME].c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.154 WARN: Invalid probe found, skip analysis of files: [/builds/application/[FILE_NAME].c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.161 WARN: Invalid probe found, skip analysis of files: [/builds/application/crc.c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.165 WARN: Invalid probe found, skip analysis of files: [/builds/application/device.c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.166 WARN: Invalid probe found, skip analysis of files: [/builds/error_check.c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.183 WARN: Invalid probe found, skip analysis of files: [/builds/application/leds.c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.183 WARN: Invalid probe found, skip analysis of files: [/builds/application/nvm.c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.184 WARN: Invalid probe found, skip analysis of files: [/builds/application/rtos_thread.c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.189 WARN: Invalid probe found, skip analysis of files: [/builds/application/[FILE_NAME].c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.197 WARN: Invalid probe found, skip analysis of files: [/builds/application/uart.c]
The compiler probe 'stdout' is expected to contain at least one '#define' directive:
14:16:57.199 INFO: PCH: unique=0 use=0 (forceInclude=0,throughHeader=0,firstInclude=0) out of 0 (forceInclude=0,throughHeader=0)
14:16:57.213 INFO: Subprocess(es) done in 213ms
14:16:57.214 INFO: 0 compilation units analyzed
14:16:57.285 INFO: ------------------------------------------------------------------------
14:16:57.286 INFO: EXECUTION FAILURE
14:16:57.287 INFO: ------------------------------------------------------------------------
14:16:57.289 INFO: Total time: 1:04.008s
14:16:57.425 INFO: Final Memory: 25M/77M
14:16:57.426 INFO: ------------------------------------------------------------------------
14:16:57.427 ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
  * you are using the latest version of the build-wrapper and the CFamily analyzer
  * you are correctly invoking the scanner with correct configuration
  * your compiler is supported
  * you are wrapping your build correctly
  * you are wrapping a full/clean build
  * you are providing the path to the correct build-wrapper output directory
  * you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:439)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:45)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:68)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:440)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:436)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:394)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
  • steps to reproduce
  • potential workaround

P.S.: use the #bug:fault sub-category if you’re hitting a specific crash/error , or the #bug:fp sub-category for rules-related behaviour

Hi @Galaxy,

could you try to run the following command by hand and share the output?

/work/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc -x c --std gnu99 -mcpu=cortex-
m4 --sysroot=/work/gcc-arm-none-eabi-5_4-2016q3/bin -mthumb -v -dM -E - < /dev/null

For some reason that command fails during analysis. Are you deleting the compiler after build and before the analysis? Are you running the analysis on the same environment of the build?

1 Like

Thanks @mpaladin, the problem was caused by us installing libc6-dev-i386 (so the 32 bit compiler can run on a 64 bit container) during the build stage. When we got to the sonarcloud-check stage, the lib was not installed (therefore a different environment as you pointed out) and therefore the compiler couldn’t execute.

Solved by adding libc6-dev-i386 to the dockerfile.

Hi @Galaxy ,

does it mean that you are using sonar-scanner docker?

To make sure you are getting a proper analysis, it is required to run the build and the analysis within the same container, one command after the other because the analyzer needs to access the files used during build (i.e. compiler and header files).

1 Like

Hi @mpaladin,

No we are using gitlab-runner executing on a docker image that gets called in multiple stages as in the example gitlab-ci.yml file generated by SonarCloud on project creation.

Hi @Galaxy ,

I believe you are referring to this generated file:

image: gcc

variables:
  SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
  GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task

get-sonar-binaries:
  stage: .pre
  cache:
    policy: push
    key: "${CI_COMMIT_SHORT_SHA}"
    paths:
      - build-wrapper/
      - sonar-scanner/
  script:
    # Download sonar-scanner
    - curl -sSLo ./sonar-scanner.zip 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip'
    - unzip -o sonar-scanner.zip
    - mv sonar-scanner-4.4.0.2170-linux sonar-scanner
    # Download build-wrapper
    - curl -sSLo ./build-wrapper-linux-x86.zip "${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip"
    - unzip -oj build-wrapper-linux-x86.zip -d ./build-wrapper
  only:
    - merge_requests
    - master
    - develop

build:
  stage: build
  cache:
    policy: pull-push
    key: "${CI_COMMIT_SHORT_SHA}"
    paths:
      - build-wrapper/
      - sonar-scanner/
      - bw-output/
  script:
    # Run the build inside the build wrapper
    - build-wrapper/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
  only:
    - merge_requests
    - master
    - develop

sonarcloud-check:
  stage: .post
  cache:
    policy: pull
    key: "${CI_COMMIT_SHORT_SHA}"
    paths:
      - build-wrapper/
      - sonar-scanner/
      - bw-output/
  script:
    - sonar-scanner/bin/sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}" -Dsonar.token="${SONAR_TOKEN}" -Dsonar.cfamily.build-wrapper-output=bw-output
  only:
    - merge_requests
    - master
    - develop

If the build part is running inside a container I would suggest you to squash the get-sonar-binaries and sonarcloud-check as part of the build step so that everything run within the same container.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.