From eed6393d14d7b5456e61937dcd449284e9d8916c Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sat, 30 Jan 2021 18:43:33 +0100 Subject: [PATCH] ci: build both w/ and w/o sanitizers on GH Actions --- .github/workflows/cibuild.sh | 72 +++++++++++++++++++---------------- .github/workflows/cibuild.yml | 6 ++- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/.github/workflows/cibuild.sh b/.github/workflows/cibuild.sh index 7fc30c344c..d5ad531464 100755 --- a/.github/workflows/cibuild.sh +++ b/.github/workflows/cibuild.sh @@ -3,17 +3,15 @@ PHASES=(${@:-CONFIGURE MAKE INSTALL CHECK DISTCHECK}) COMPILER="${COMPILER:?}" COMPILER_VERSION="${COMPILER_VERSION}" +CFLAGS=(-O1 -g) +CXXFLAGS=(-O1 -g) if [[ "$COMPILER" == clang ]]; then CC="clang${COMPILER_VERSION:+-$COMPILER_VERSION}" CXX="clang++${COMPILER_VERSION:+-$COMPILER_VERSION}" - CFLAGS="-shared-libasan -O1 -g -fno-omit-frame-pointer" - CXXFLAGS="-shared-libasan -O1 -g -fno-omit-frame-pointer" elif [[ "$COMPILER" == gcc ]]; then CC="gcc${COMPILER_VERSION:+-$COMPILER_VERSION}" CXX="g++${COMPILER_VERSION:+-$COMPILER_VERSION}" - CFLAGS="-O1 -g -fno-omit-frame-pointer" - CXXFLAGS="-O1 -g -fno-omit-frame-pointer" fi set -ex @@ -25,20 +23,26 @@ for phase in "${PHASES[@]}"; do --disable-use-tty-group --disable-makeinstall-chown --enable-all-programs - --enable-asan - --enable-ubsan --without-python --enable-werror ) - if [[ "$COMPILER" == clang* ]]; then + if [[ "$SANITIZE" == "yes" ]]; then + opts+=(--enable-asan --enable-ubsan) + CFLAGS+=(-fno-omit-frame-pointer) + CXXFLAGS+=(-fno-omit-frame-pointer) + fi + + if [[ "$COMPILER" == clang* && "$SANITIZE" == "yes" ]]; then opts+=(--enable-fuzzing-engine) + CFLAGS+=(-shared-libasan) + CXXFLAGS+=(-shared-libasan) fi sudo -E git clean -xdf ./autogen.sh - CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" ./configure "${opts[@]}" + CC="$CC" CXX="$CXX" CFLAGS="${CFLAGS[@]}" CXXFLAGS="${CXXFLAGS[@]}" ./configure "${opts[@]}" ;; MAKE) make -j @@ -48,32 +52,34 @@ for phase in "${PHASES[@]}"; do make install DESTDIR=/tmp/dest ;; CHECK) - # All the following black magic is to make test/eject/umount work, since - # eject execl()s the uninstrumented /bin/umount binary, which confuses - # ASan. The workaround for this is to set $LD_PRELOAD to the ASan's - # runtime DSO, which works well with gcc without any additional hassle. - # However, since clang, by default, links ASan statically, we need to - # explicitly state we want dynamic linking (see -shared-libasan above). - # That, however, introduces another issue - clang's ASan runtime is in - # a non-standard path, so all binaries compiled in such way refuse - # to start. That's what the following blob of code is for - it detects - # the ASan's runtime path and adds the respective directory to - # the dynamic linker cache. - # - # The actual $LD_PRELOAD sheanigans are done directly in - # tests/ts/eject/umount. - asan_rt_name="$(ldd ./kill | awk '/lib.+asan.*.so/ {print $1; exit}')" - asan_rt_path="$($CC --print-file-name "$asan_rt_name")" - echo "Detected ASan runtime: $asan_rt_name ($asan_rt_path)" - if [[ -z "$asan_rt_name" || -z "$asan_rt_path" ]]; then - echo >&2 "Couldn't detect ASan runtime, can't continue" - exit 1 - fi + if [[ "$SANITIZE" == "yes" ]]; then + # All the following black magic is to make test/eject/umount work, since + # eject execl()s the uninstrumented /bin/umount binary, which confuses + # ASan. The workaround for this is to set $LD_PRELOAD to the ASan's + # runtime DSO, which works well with gcc without any additional hassle. + # However, since clang, by default, links ASan statically, we need to + # explicitly state we want dynamic linking (see -shared-libasan above). + # That, however, introduces another issue - clang's ASan runtime is in + # a non-standard path, so all binaries compiled in such way refuse + # to start. That's what the following blob of code is for - it detects + # the ASan's runtime path and adds the respective directory to + # the dynamic linker cache. + # + # The actual $LD_PRELOAD sheanigans are done directly in + # tests/ts/eject/umount. + asan_rt_name="$(ldd ./kill | awk '/lib.+asan.*.so/ {print $1; exit}')" + asan_rt_path="$($CC --print-file-name "$asan_rt_name")" + echo "Detected ASan runtime: $asan_rt_name ($asan_rt_path)" + if [[ -z "$asan_rt_name" || -z "$asan_rt_path" ]]; then + echo >&2 "Couldn't detect ASan runtime, can't continue" + exit 1 + fi - if [[ "$COMPILER" == clang* ]]; then - mkdir -p /etc/ld.so.conf.d/ - echo "${asan_rt_path%/*}" > /etc/ld.so.conf.d/99-clang-libasan.conf - ldconfig + if [[ "$COMPILER" == clang* ]]; then + mkdir -p /etc/ld.so.conf.d/ + echo "${asan_rt_path%/*}" > /etc/ld.so.conf.d/99-clang-libasan.conf + ldconfig + fi fi ./tests/run.sh --show-diff diff --git a/.github/workflows/cibuild.yml b/.github/workflows/cibuild.yml index e8556eba85..633cc1a8ed 100644 --- a/.github/workflows/cibuild.yml +++ b/.github/workflows/cibuild.yml @@ -17,8 +17,10 @@ jobs: fail-fast: false matrix: env: - - { COMPILER: "gcc", COMPILER_VERSION: "10" } - - { COMPILER: "clang", COMPILER_VERSION: "10" } + - { COMPILER: "gcc", COMPILER_VERSION: "10", SANITIZE: "yes" } + - { COMPILER: "gcc", COMPILER_VERSION: "10", SANITIZE: "no" } + - { COMPILER: "clang", COMPILER_VERSION: "10", SANITIZE: "yes" } + - { COMPILER: "clang", COMPILER_VERSION: "10", SANITIZE: "no" } env: ${{ matrix.env }} steps: - name: Repository checkout -- 2.39.5