Skip to content

Commit 801b76c

Browse files
committed
ASan conflicts with valgrind - cannot run both together.
1 parent 3a1d5b4 commit 801b76c

1 file changed

Lines changed: 15 additions & 35 deletions

File tree

Dockerfile.valgrind

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
# Dockerfile.valgrind - For memory error detection
2-
# Build with debug symbols and AddressSanitizer for catching memory bugs
1+
# Dockerfile.valgrind - For memory leak detection
2+
# Build with debug symbols and no optimization for meaningful Valgrind output
33
# Mirrors CI environment: Ubuntu 24.04 + PHP built from source
4-
#
5-
# Usage:
6-
# docker build -f Dockerfile.valgrind -t signalforge-asan .
7-
# docker run --rm -v $(pwd):/app -w /app signalforge-asan php test.php
8-
#
9-
# For valgrind (slower but different coverage):
10-
# docker run --rm -v $(pwd):/app -w /app signalforge-asan valgrind php test.php
114

125
ARG PHP_VERSION=8.5
136

@@ -17,10 +10,10 @@ ARG PHP_VERSION
1710
ENV DEBIAN_FRONTEND=noninteractive
1811

1912
LABEL maintainer="Signalforge Team"
20-
LABEL description="PHP ${PHP_VERSION} with signalforge_http extension (Debug + ASan + Valgrind)"
13+
LABEL description="PHP ${PHP_VERSION} with signalforge_http extension (Debug + Valgrind)"
2114
LABEL php.version="${PHP_VERSION}"
2215

23-
# Install build dependencies, valgrind, and ASan runtime
16+
# Install build dependencies AND valgrind
2417
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
2518
git \
2619
gcc \
@@ -34,8 +27,6 @@ RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
3427
bison \
3528
wget \
3629
valgrind \
37-
libasan8 \
38-
libubsan1 \
3930
libxml2-dev \
4031
libssl-dev \
4132
libcurl4-openssl-dev \
@@ -50,7 +41,7 @@ RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
5041
ca-certificates \
5142
&& rm -rf /var/lib/apt/lists/*
5243

53-
# Clone and build PHP from source with ASan
44+
# Clone and build PHP from source (with debug symbols)
5445
WORKDIR /tmp
5546
RUN MAJOR=$(echo ${PHP_VERSION} | cut -d. -f1); \
5647
MINOR=$(echo ${PHP_VERSION} | cut -d. -f2); \
@@ -60,13 +51,8 @@ RUN MAJOR=$(echo ${PHP_VERSION} | cut -d. -f1); \
6051
WORKDIR /tmp/php-src
6152
RUN ./buildconf --force > /dev/null
6253

63-
# Build PHP with AddressSanitizer and UndefinedBehaviorSanitizer
64-
# Using -O2 to match production GHCR build optimization level
65-
ENV CFLAGS="-g -O2 -fsanitize=address,undefined -fno-omit-frame-pointer"
66-
ENV CXXFLAGS="-g -O2 -fsanitize=address,undefined -fno-omit-frame-pointer"
67-
ENV LDFLAGS="-fsanitize=address,undefined"
68-
69-
RUN ./configure --quiet \
54+
# Configure PHP (same as Dockerfile, debug symbols will come from CFLAGS)
55+
RUN CFLAGS="-g" ./configure --quiet \
7056
--prefix=/usr/local \
7157
--with-config-file-path=/usr/local/etc/php \
7258
--with-config-file-scan-dir=/usr/local/etc/php/conf.d \
@@ -90,32 +76,26 @@ RUN make install
9076
# Create extension config directory
9177
RUN mkdir -p /usr/local/etc/php/conf.d
9278

93-
# Copy and build http extension with ASan
79+
# Copy and build http extension with debug symbols (no optimization for accurate valgrind)
9480
WORKDIR /build
9581
COPY . /build
9682

9783
RUN /usr/local/bin/phpize \
98-
&& CFLAGS="-g -O2 -fsanitize=address,undefined -fno-omit-frame-pointer" \
99-
LDFLAGS="-fsanitize=address,undefined" \
100-
./configure --enable-signalforge_http \
84+
&& CFLAGS="-g -O0" ./configure --enable-signalforge_http \
10185
&& make -j$(nproc) \
10286
&& make install
10387

10488
# Enable extension
10589
RUN echo "extension=signalforge_http.so" > /usr/local/etc/php/conf.d/signalforge_http.ini
10690

107-
# Configure PHP for debugging
108-
RUN echo "zend.assertions=1" >> /usr/local/etc/php/conf.d/debug.ini
109-
110-
# ASan environment variables for better error reporting
111-
ENV ASAN_OPTIONS="detect_leaks=1:abort_on_error=1:print_stats=1:check_initialization_order=1"
112-
ENV UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1"
91+
# Configure PHP for Valgrind
92+
RUN echo "zend.assertions=1" >> /usr/local/etc/php/conf.d/valgrind.ini
11393

114-
# Enable extension
115-
RUN echo "extension=signalforge_http.so" > /usr/local/etc/php/conf.d/signalforge_http.ini
94+
# Get run-tests.php from PHP source
95+
RUN wget -q -O /opt/run-tests.php https://raw.githubusercontent.com/php/php-src/master/run-tests.php
11696

117-
# Verify extension is loaded (may show ASan output, that's OK)
118-
RUN php -m | grep signalforge_http || echo "Extension check - ASan may report issues above"
97+
# Verify extension is loaded
98+
RUN php -m | grep signalforge_http
11999

120100
WORKDIR /ext
121101
CMD ["php", "-v"]

0 commit comments

Comments
 (0)