Build-wrapper dump empty under Alpine Linux

The Problem

I’m trying to scan the build artifact inside my Alpine-based Docker container without success.

My Dockerfile consists of the following:

FROM alpine:3.10 AS builder

RUN apk update && apk upgrade && apk --no-cache add  bash etc...

# Install glibc (needed for sonar build wrapper)
# https://github.com/sgerrand/alpine-pkg-glibc
RUN apk --no-cache add ca-certificates wget
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk
RUN apk add glibc-2.30-r0.apk

# Install Sonar-build-wrapper
RUN curl -s -L https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip -o sonarwrapper.zip \
  && unzip -qq sonarwrapper.zip \
  && rm -rf sonarwrapper.zip \
  && mv build-wrapper-linux-x86 build-wrapper

ENV PATH $PATH:/build-wrapper/

# Install Sonar-scanner-CLI
RUN curl -s -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492.zip -o sonarscanner.zip \
  && unzip -qq sonarscanner.zip \
  && rm -rf sonarscanner.zip \
  && mv sonar-scanner-3.3.0.1492 sonar-scanner

ENV SONAR_RUNNER_HOME=sonar-scanner
ENV PATH $PATH:/sonar-scanner/bin

WORKDIR /usr/src/app

# Copy project sources from host
COPY . ./src

# Build sources
RUN cd src/ && mkdir build && cd build && \
    cmake -DCMAKE_BUILD_TYPE=Debug \
      -D DOCKER_BUILD=ON \
      -D BUILD_SHARED_LIBS=ON \
      -D BUILD_TESTING=ON \
      -D BUILD_COVERAGE=ON \
      -D CONSOLE_LOG=ON \
      .. \
    && build-wrapper-linux-x86-64 --out-dir bw-output make -j$(nproc)

But I alway get an empty build-wrapper-dump and the logfile doesn’t help.

# (C) SonarSource SA, 2014-2019, info@sonarsource.com
# All SONARSOURCE programs and content are copyright protected.
# SONARSOURCE and SONARQUBE are trademarks of SonarSource SA. All rights are expressly reserved.
#
# This file is designed exclusively for use with the SONARSOURCE C / C++ / Objective-C Plugin.
# It may not be used in connection with any other software.
# Any other use is prohibited by law and may be grounds for immediate termination of your License.
{
"version":0,
"captures":[
]}

Fri Feb 07 14:11:54 2020: build-wrapper, version 6.6 (linux-x86)
Fri Feb 07 14:11:54 2020: System name: Linux Nodename: d6f67ad83b27 Release: 4.15.0-76-generic Version: #86~16.04.1-Ubuntu SMP Mon Jan 20 11:02:50 UTC 2020 Machine: x86_64
Fri Feb 07 14:11:54 2020: socket path: /tmp/build-wrapper-socket.CrkGtg
Fri Feb 07 14:11:54 2020: dynamic library found: /build-wrapper/libinterceptor-i686.so
Fri Feb 07 14:11:54 2020: dynamic library found: /build-wrapper/libinterceptor-x86_64.so
Fri Feb 07 14:11:54 2020: command executed as: <build-wrapper-linux-x86-64>
Fri Feb 07 14:11:54 2020: command line received: <make -j8>
Fri Feb 07 14:11:54 2020: env 0: <HOSTNAME=d6f67ad83b27>
Fri Feb 07 14:11:54 2020: env 1: <SHLVL=1>
Fri Feb 07 14:11:54 2020: env 2: <HOME=/root>
Fri Feb 07 14:11:54 2020: env 3: <OLDPWD=/usr/src/app/src>
Fri Feb 07 14:11:54 2020: env 4: <PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/build-wrapper/:/sonar-scanner/bin>
Fri Feb 07 14:11:54 2020: env 5: <SONAR_RUNNER_HOME=sonar-scanner>
Fri Feb 07 14:11:54 2020: env 6: <PWD=/usr/src/app/src/build>
Fri Feb 07 14:11:54 2020: executing: <make -j8>
Fri Feb 07 14:11:54 2020: initializing json file
Fri Feb 07 14:11:54 2020: process created with pid: 182
Fri Feb 07 14:11:54 2020: parent pid: 1
Fri Feb 07 14:11:54 2020: working directory: </usr/src/app/src/build>
Fri Feb 07 14:11:54 2020: executable: </build-wrapper/build-wrapper-linux-x86-64>
Fri Feb 07 14:11:54 2020: argv[0]: <build-wrapper-linux-x86-64>
Fri Feb 07 14:11:54 2020: argv[1]: <-c>
Fri Feb 07 14:11:54 2020: argv[2]: <>
Fri Feb 07 14:11:54 2020: argv[3]: <make>
Fri Feb 07 14:11:54 2020: argv[4]: <-j8>
Fri Feb 07 14:11:54 2020: skipping process with pid: 182
Fri Feb 07 14:14:00 2020: finalizing json file
Fri Feb 07 14:14:00 2020: returned with code: 0

Possible issue

The main source of concern is the fact that Alpine is musl-based while the build-wrapper was compiled with glibc. To run the wrapper inside Alpine I installed glibc using this package but I still see some errors.

bash-5.0$ ldd build-wrapper-linux-x86-64 
	/lib64/ld-linux-x86-64.so.2 (0x7fc5ea1ac000)
	libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc5ea1ac000)
	ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 (0x7fc5ea181000)
Error relocating build-wrapper-linux-x86-64: __strftime_l: symbol not found
Error relocating build-wrapper-linux-x86-64: __sprintf_chk: symbol not found

Is there a way around this?

Extra

I’ve attached the output of:

strace -f -E LD_DEBUG=all build-wrapper-linux-x86-64 --out-dir bw-output /bin/echo test >stdout.txt 2>stderr.txt

stdout.txt (5 Bytes) stderr.txt (661.4 KB) build-wrapper-log.txt (1.9 KB) build-wrapper-dump.json.txt (502 Bytes)

Can anybody help me with this?

Hi @mattdibi,

Alpine Linux is not supported, would you be able to use another distribution to analyze your project?

Hi @mpaladin,

Thank you for your quick reply. For our application footprint is critical and thus we adopted Alpine.
We’ll search other minimal Linux Distribution alternative to Alpine. Should we narrow our search to glibc-based distribution to be compatible with the build-wrapper/sonar-scanner? Are there other criteria we should keep in mind?

Hi @mattdibi,

No, that should be it.

@mpaladin

Great, thank you.

1 Like