mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Sanitizer: Support address sanitizer for x86_64 platform (#3212)
* Sanitizer: Support address sanitizer for x86_64 platform * Sanitizer: Not mac os need -static-libasan * Sanitizer: Add script for docker test. * Sanitizer: Refine build script. * Santizer: Fix ossrs/srs:dev-gcc7-cache cannot find libasan bug * Sanitizer: Support sanitizer when use ossrs/srs:dev-cache and ubuntuxx-cache * Sanitizer: Add sanitizer-static config Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
parent
e10fa6dc91
commit
961f701929
8 changed files with 76 additions and 9 deletions
|
@ -16,7 +16,7 @@ ENV DEBIAN_FRONTEND noninteractive
|
||||||
SHELL ["/bin/bash", "-c"]
|
SHELL ["/bin/bash", "-c"]
|
||||||
|
|
||||||
# Install depends tools.
|
# Install depends tools.
|
||||||
RUN apt-get update && apt-get install -y gcc make g++ patch unzip perl git
|
RUN apt-get update && apt-get install -y gcc make g++ patch unzip perl git libasan5
|
||||||
|
|
||||||
# Copy source code to docker.
|
# Copy source code to docker.
|
||||||
COPY . /srs
|
COPY . /srs
|
||||||
|
@ -24,7 +24,7 @@ WORKDIR /srs/trunk
|
||||||
|
|
||||||
# Build and install SRS.
|
# Build and install SRS.
|
||||||
# Note that SRT is enabled by default, so we configure without --srt=on.
|
# Note that SRT is enabled by default, so we configure without --srt=on.
|
||||||
RUN ./configure --jobs=${JOBS} --gb28181=on && make -j${JOBS} && make install
|
RUN ./configure --jobs=${JOBS} --gb28181=on --sanitizer-static=on && make -j${JOBS} && make install
|
||||||
|
|
||||||
# All config files for SRS.
|
# All config files for SRS.
|
||||||
RUN cp -R conf /usr/local/srs/conf && \
|
RUN cp -R conf /usr/local/srs/conf && \
|
||||||
|
|
|
@ -22,11 +22,11 @@ RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off --cxx11=off --
|
||||||
########################################################
|
########################################################
|
||||||
FROM ossrs/srs:dev6-cache AS centos6-baseline
|
FROM ossrs/srs:dev6-cache AS centos6-baseline
|
||||||
COPY . /srs
|
COPY . /srs
|
||||||
RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off --cxx11=off --cxx14=off && make -j2
|
RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off --cxx11=off --cxx14=off --sanitizer=off && make -j2
|
||||||
|
|
||||||
FROM ossrs/srs:dev6-cache AS centos6-all
|
FROM ossrs/srs:dev6-cache AS centos6-all
|
||||||
COPY . /srs
|
COPY . /srs
|
||||||
RUN cd /srs/trunk && ./configure --jobs=2 --srt=on --gb28181=on --cxx11=off --cxx14=off && make -j2
|
RUN cd /srs/trunk && ./configure --jobs=2 --srt=on --gb28181=on --cxx11=off --cxx14=off --sanitizer=off && make -j2
|
||||||
|
|
||||||
########################################################
|
########################################################
|
||||||
FROM ossrs/srs:ubuntu16-cache AS ubuntu16-baseline
|
FROM ossrs/srs:ubuntu16-cache AS ubuntu16-baseline
|
||||||
|
|
|
@ -8,5 +8,5 @@ COPY . /srs
|
||||||
WORKDIR /srs/trunk
|
WORKDIR /srs/trunk
|
||||||
|
|
||||||
# Note that we must enable the gcc7 or link failed.
|
# Note that we must enable the gcc7 or link failed.
|
||||||
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on --gcov=on --jobs=2
|
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on --gcov=on --sanitizer=off --jobs=2
|
||||||
RUN scl enable devtoolset-7 -- make -j2 utest
|
RUN scl enable devtoolset-7 -- make -j2 utest
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
FROM ossrs/srs:dev-gcc7-cache
|
FROM ossrs/srs:dev-gcc7-cache
|
||||||
|
|
||||||
# Install depends tools.
|
|
||||||
RUN yum install -y gcc make gcc-c++ patch unzip perl git
|
RUN yum install -y gcc make gcc-c++ patch unzip perl git
|
||||||
|
|
||||||
# Build and install SRS.
|
# Build and install SRS.
|
||||||
|
@ -8,7 +6,7 @@ COPY . /srs
|
||||||
WORKDIR /srs/trunk
|
WORKDIR /srs/trunk
|
||||||
|
|
||||||
# Note that we must enable the gcc7 or link failed.
|
# Note that we must enable the gcc7 or link failed.
|
||||||
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on --jobs=2
|
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on --sanitizer=off --jobs=2
|
||||||
RUN scl enable devtoolset-7 -- make -j2 utest
|
RUN scl enable devtoolset-7 -- make -j2 utest
|
||||||
|
|
||||||
# Build benchmark tool.
|
# Build benchmark tool.
|
||||||
|
|
|
@ -317,7 +317,8 @@ OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$re
|
||||||
OS_IS_LOONGARCH64=$(g++ -dM -E - </dev/null |grep '#define __loongarch64 1' -q && echo YES)
|
OS_IS_LOONGARCH64=$(g++ -dM -E - </dev/null |grep '#define __loongarch64 1' -q && echo YES)
|
||||||
OS_IS_MIPS64=$(g++ -dM -E - </dev/null |grep '#define __mips64 1' -q && echo YES)
|
OS_IS_MIPS64=$(g++ -dM -E - </dev/null |grep '#define __mips64 1' -q && echo YES)
|
||||||
OS_IS_LOONGSON=$(uname -r |grep -q loongson && echo YES)
|
OS_IS_LOONGSON=$(uname -r |grep -q loongson && echo YES)
|
||||||
echo "OS_IS_LOONGARCH64:$OS_IS_LOONGARCH64, OS_IS_MIPS64:$OS_IS_MIPS64, OS_IS_LOONGSON:$OS_IS_LOONGSON"
|
OS_IS_X86_64=$(g++ -dM -E - </dev/null |grep -q '#define __x86_64 1' && echo YES)
|
||||||
|
echo "OS_IS_LOONGARCH64:$OS_IS_LOONGARCH64, OS_IS_MIPS64:$OS_IS_MIPS64, OS_IS_LOONGSON:$OS_IS_LOONGSON, OS_IS_X86_64:$OS_IS_X86_64"
|
||||||
|
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
# for Centos, auto install tools by yum
|
# for Centos, auto install tools by yum
|
||||||
|
|
|
@ -62,6 +62,8 @@ SRS_LOG_TRACE=YES
|
||||||
# Experts options.
|
# Experts options.
|
||||||
SRS_USE_SYS_SSL=NO # Use system ssl(-lssl) if required.
|
SRS_USE_SYS_SSL=NO # Use system ssl(-lssl) if required.
|
||||||
SRS_VALGRIND=NO
|
SRS_VALGRIND=NO
|
||||||
|
SRS_SANITIZER=YES
|
||||||
|
SRS_SANITIZER_STATIC=NO
|
||||||
SRS_BUILD_TAG= # Set the object files tag name.
|
SRS_BUILD_TAG= # Set the object files tag name.
|
||||||
SRS_CLEAN=YES # Whether do "make clean" when configure.
|
SRS_CLEAN=YES # Whether do "make clean" when configure.
|
||||||
SRS_SIMULATOR=NO # Whether enable RTC simulate API.
|
SRS_SIMULATOR=NO # Whether enable RTC simulate API.
|
||||||
|
@ -150,6 +152,8 @@ Performance: @see https://blog.csdn.net/win_lin/article/details/5
|
||||||
--gmp=on|off Whether build memory profile with gperf tools. Default: $(value2switch $SRS_GPERF_MP)
|
--gmp=on|off Whether build memory profile with gperf tools. Default: $(value2switch $SRS_GPERF_MP)
|
||||||
--gcp=on|off Whether build cpu profile with gperf tools. Default: $(value2switch $SRS_GPERF_CP)
|
--gcp=on|off Whether build cpu profile with gperf tools. Default: $(value2switch $SRS_GPERF_CP)
|
||||||
--gprof=on|off Whether build SRS with gprof(GNU profile tool). Default: $(value2switch $SRS_GPROF)
|
--gprof=on|off Whether build SRS with gprof(GNU profile tool). Default: $(value2switch $SRS_GPROF)
|
||||||
|
--sanitizer=on|off Whether build SRS with address sanitizer. Default: $(value2switch $SRS_SANITIZER)
|
||||||
|
--sanitizer-static=on|off Whether build SRS with static libasan. Default: $(value2switch $SRS_SANITIZER_STATIC)
|
||||||
|
|
||||||
--nasm=on|off Whether build FFMPEG for RTC with nasm. Default: $(value2switch $SRS_NASM)
|
--nasm=on|off Whether build FFMPEG for RTC with nasm. Default: $(value2switch $SRS_NASM)
|
||||||
--srtp-nasm=on|off Whether build SRTP with ASM(openssl-asm), requires RTC and openssl-1.0.*. Default: $(value2switch $SRS_SRTP_ASM)
|
--srtp-nasm=on|off Whether build SRTP with ASM(openssl-asm), requires RTC and openssl-1.0.*. Default: $(value2switch $SRS_SRTP_ASM)
|
||||||
|
@ -330,6 +334,9 @@ function parse_user_option() {
|
||||||
--without-gprof) SRS_GPROF=NO ;;
|
--without-gprof) SRS_GPROF=NO ;;
|
||||||
--gprof) SRS_GPROF=$(switch2value $value) ;;
|
--gprof) SRS_GPROF=$(switch2value $value) ;;
|
||||||
|
|
||||||
|
--sanitizer) SRS_SANITIZER=$(switch2value $value) ;;
|
||||||
|
--sanitizer-static) SRS_SANITIZER_STATIC=$(switch2value $value) ;;
|
||||||
|
|
||||||
--use-sys-ssl) SRS_USE_SYS_SSL=YES ;;
|
--use-sys-ssl) SRS_USE_SYS_SSL=YES ;;
|
||||||
--sys-ssl) SRS_USE_SYS_SSL=$(switch2value $value) ;;
|
--sys-ssl) SRS_USE_SYS_SSL=$(switch2value $value) ;;
|
||||||
|
|
||||||
|
@ -550,6 +557,7 @@ function regenerate_options() {
|
||||||
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug=$(value2switch $SRS_DEBUG)"
|
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug=$(value2switch $SRS_DEBUG)"
|
||||||
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug-stats=$(value2switch $SRS_DEBUG_STATS)"
|
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug-stats=$(value2switch $SRS_DEBUG_STATS)"
|
||||||
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cross-build=$(value2switch $SRS_CROSS_BUILD)"
|
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cross-build=$(value2switch $SRS_CROSS_BUILD)"
|
||||||
|
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --sanitizer=$(value2switch $SRS_SANITIZER)"
|
||||||
if [[ $SRS_CROSS_BUILD_ARCH != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --arch=$SRS_CROSS_BUILD_ARCH"; fi
|
if [[ $SRS_CROSS_BUILD_ARCH != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --arch=$SRS_CROSS_BUILD_ARCH"; fi
|
||||||
if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --cpu=$SRS_CROSS_BUILD_CPU"; fi
|
if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --cpu=$SRS_CROSS_BUILD_CPU"; fi
|
||||||
if [[ $SRS_CROSS_BUILD_HOST != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --host=$SRS_CROSS_BUILD_HOST"; fi
|
if [[ $SRS_CROSS_BUILD_HOST != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --host=$SRS_CROSS_BUILD_HOST"; fi
|
||||||
|
|
19
trunk/configure
vendored
19
trunk/configure
vendored
|
@ -112,6 +112,16 @@ fi
|
||||||
if [[ $SRS_EXTRA_FLAGS != '' ]]; then
|
if [[ $SRS_EXTRA_FLAGS != '' ]]; then
|
||||||
CXXFLAGS="${CXXFLAGS} $SRS_EXTRA_FLAGS";
|
CXXFLAGS="${CXXFLAGS} $SRS_EXTRA_FLAGS";
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# For Sanitizer
|
||||||
|
# @doc: https://github.com/google/sanitizers/wiki/AddressSanitizer
|
||||||
|
if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES ]]; then
|
||||||
|
CXXFLAGS="${CXXFLAGS} -fsanitize=address -fno-omit-frame-pointer";
|
||||||
|
if [[ $SRS_SANITIZER_STATIC == YES ]]; then
|
||||||
|
CXXFLAGS="${CXXFLAGS} -static-libasan";
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Start to generate the Makefile.
|
# Start to generate the Makefile.
|
||||||
cat << END >> ${SRS_OBJS}/${SRS_MAKEFILE}
|
cat << END >> ${SRS_OBJS}/${SRS_MAKEFILE}
|
||||||
GCC = ${SRS_TOOL_CC}
|
GCC = ${SRS_TOOL_CC}
|
||||||
|
@ -198,6 +208,15 @@ if [[ $SRS_BACKTRACE == YES ]]; then
|
||||||
SrsLinkOptions="${SrsLinkOptions} -rdynamic";
|
SrsLinkOptions="${SrsLinkOptions} -rdynamic";
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# For address sanitizer
|
||||||
|
# @doc: https://github.com/google/sanitizers/wiki/AddressSanitizer
|
||||||
|
if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES ]]; then
|
||||||
|
SrsLinkOptions="${SrsLinkOptions} -fsanitize=address -fno-omit-frame-pointer";
|
||||||
|
if [[ $SRS_SANITIZER_STATIC == YES ]]; then
|
||||||
|
SrsLinkOptions="${SrsLinkOptions} -static-libasan";
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
# Modules, compile each module, then link to binary
|
# Modules, compile each module, then link to binary
|
||||||
#
|
#
|
||||||
|
|
41
trunk/scripts/docker_test.sh
Executable file
41
trunk/scripts/docker_test.sh
Executable file
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# cd ~/git/srs
|
||||||
|
work_dir=$(cd -P $(dirname $0) && cd ../.. && pwd) && cd $work_dir && echo "Run script in ${work_dir}"
|
||||||
|
if [[ ! -d trunk ]]; then echo "no ./trunk found"; exit 1; fi
|
||||||
|
|
||||||
|
echo "For trunk/Dockerfile.test"
|
||||||
|
docker build --tag srs:test -f trunk/Dockerfile.test . &&
|
||||||
|
docker build --tag srs:cov -f trunk/Dockerfile.cov .
|
||||||
|
if [[ $? -ne 0 ]]; then echo "Docker for test failed"; exit 1; fi
|
||||||
|
|
||||||
|
echo "For trunk/Dockerfile"
|
||||||
|
docker buildx build --platform linux/arm/v7 --output "type=image,push=false" --build-arg IMAGE=ossrs/srs:ubuntu20-cache -f trunk/Dockerfile . &&
|
||||||
|
docker buildx build --platform linux/arm64/v8 --output "type=image,push=false" --build-arg IMAGE=ossrs/srs:ubuntu20-cache -f trunk/Dockerfile . &&
|
||||||
|
docker buildx build --platform linux/amd64 --output "type=image,push=false" --build-arg IMAGE=ossrs/srs:ubuntu20-cache -f trunk/Dockerfile .
|
||||||
|
if [[ $? -ne 0 ]]; then echo "Docker for release failed"; exit 1; fi
|
||||||
|
|
||||||
|
echo "For trunk/Dockerfile.pkg"
|
||||||
|
docker build --tag srs:pkg --build-arg version=1.2.3 -f trunk/Dockerfile.pkg .
|
||||||
|
if [[ $? -ne 0 ]]; then echo "Docker for pkg failed"; exit 1; fi
|
||||||
|
|
||||||
|
echo "For trunk/Dockerfile.builds"
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-baseline . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-all . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-no-webrtc . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-no-asm . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-ansi-no-ffmpeg . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos6-baseline . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos6-all . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu16-baseline . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu16-all . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu18-baseline . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu18-all . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-baseline . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-all . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu16-cross-armv7 . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-cross-armv7 . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu16-cross-aarch64 . &&
|
||||||
|
DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-cross-aarch64 .
|
||||||
|
if [[ $? -ne 0 ]]; then echo "Docker for build failed"; exit 1; fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue