2021-01-25 09:51:51 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
PHASES=(${@:-CONFIGURE MAKE INSTALL CHECK DISTCHECK})
|
|
|
|
COMPILER="${COMPILER:?}"
|
2021-01-29 12:00:56 -06:00
|
|
|
COMPILER_VERSION="${COMPILER_VERSION}"
|
2021-01-30 11:43:33 -06:00
|
|
|
CFLAGS=(-O1 -g)
|
|
|
|
CXXFLAGS=(-O1 -g)
|
2021-01-26 05:39:22 -06:00
|
|
|
|
|
|
|
if [[ "$COMPILER" == clang ]]; then
|
2021-01-29 12:00:56 -06:00
|
|
|
CC="clang${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
|
|
|
CXX="clang++${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
2021-01-26 05:39:22 -06:00
|
|
|
elif [[ "$COMPILER" == gcc ]]; then
|
2021-01-29 12:00:56 -06:00
|
|
|
CC="gcc${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
|
|
|
CXX="g++${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
2021-01-26 05:39:22 -06:00
|
|
|
fi
|
2021-01-25 09:51:51 -06:00
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
for phase in "${PHASES[@]}"; do
|
|
|
|
case $phase in
|
2021-01-30 11:33:26 -06:00
|
|
|
CONFIGURE)
|
|
|
|
opts=(
|
|
|
|
--disable-use-tty-group
|
|
|
|
--disable-makeinstall-chown
|
|
|
|
--enable-all-programs
|
|
|
|
--without-python
|
|
|
|
--enable-werror
|
|
|
|
)
|
2021-01-25 09:51:51 -06:00
|
|
|
|
2021-01-30 11:43:33 -06:00
|
|
|
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
|
2021-01-30 11:33:26 -06:00
|
|
|
opts+=(--enable-fuzzing-engine)
|
2021-01-30 11:43:33 -06:00
|
|
|
CFLAGS+=(-shared-libasan)
|
|
|
|
CXXFLAGS+=(-shared-libasan)
|
2021-01-30 11:33:26 -06:00
|
|
|
fi
|
2021-01-25 09:51:51 -06:00
|
|
|
|
2021-01-30 11:33:26 -06:00
|
|
|
sudo -E git clean -xdf
|
2021-01-25 09:51:51 -06:00
|
|
|
|
2021-01-30 11:33:26 -06:00
|
|
|
./autogen.sh
|
2021-01-30 11:43:33 -06:00
|
|
|
CC="$CC" CXX="$CXX" CFLAGS="${CFLAGS[@]}" CXXFLAGS="${CXXFLAGS[@]}" ./configure "${opts[@]}"
|
2021-01-30 11:33:26 -06:00
|
|
|
;;
|
|
|
|
MAKE)
|
|
|
|
make -j
|
|
|
|
make -j check-programs
|
|
|
|
;;
|
|
|
|
INSTALL)
|
|
|
|
make install DESTDIR=/tmp/dest
|
|
|
|
;;
|
|
|
|
CHECK)
|
2021-01-30 11:43:33 -06:00
|
|
|
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
|
ci: deal with uninstrumented binaries using instrumented libs
All `eject` tests were failing under ASan, since they call /bin/mount,
which is uninstrumented, but it picks up the instrumented `libblkid`
library, causing ASan to complain:
gcc:
ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
eject: unmount of `/home/runner/work/util-linux/util-linux/tests/output/eject/umount-by-disk-mounted-mnt' failed
clang:
/bin/umount: symbol lookup error: /home/runner/work/util-linux/util-linux/.libs/libblkid.so.1: undefined symbol: __sancov_lowest_stack
eject: unmount of `/home/runner/work/util-linux/util-linux/tests/output/eject/umount-by-disk-mounted-mnt' failed
Subsequently, all tests which require the `scsi_debug` module get skipped,
since it's still in use due to the failed umount:
fdisk: align 512/4K ... SKIPPED (cannot remove scsi_debug module (rmmod))
fdisk: align 512/4K +alignment_offset ... SKIPPED (cannot remove scsi_debug module (rmmod))
fdisk: align 512/4K +MD ... SKIPPED (cannot remove scsi_debug module (rmmod))
In case of gcc this can be easily resolved by setting $LD_PRELOAD to the
respective ASan library. clang makes this a bit more difficult, since it
compiles the ASan library statically, so firstly we need to force dynamic
linking (via -shared-asan), and then add the runtime DSO path to the
linker cache, since it's in a non-standard path.
2021-01-29 15:01:02 -06:00
|
|
|
|
2021-01-30 11:43:33 -06:00
|
|
|
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
|
2021-01-30 11:33:26 -06:00
|
|
|
fi
|
ci: deal with uninstrumented binaries using instrumented libs
All `eject` tests were failing under ASan, since they call /bin/mount,
which is uninstrumented, but it picks up the instrumented `libblkid`
library, causing ASan to complain:
gcc:
ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
eject: unmount of `/home/runner/work/util-linux/util-linux/tests/output/eject/umount-by-disk-mounted-mnt' failed
clang:
/bin/umount: symbol lookup error: /home/runner/work/util-linux/util-linux/.libs/libblkid.so.1: undefined symbol: __sancov_lowest_stack
eject: unmount of `/home/runner/work/util-linux/util-linux/tests/output/eject/umount-by-disk-mounted-mnt' failed
Subsequently, all tests which require the `scsi_debug` module get skipped,
since it's still in use due to the failed umount:
fdisk: align 512/4K ... SKIPPED (cannot remove scsi_debug module (rmmod))
fdisk: align 512/4K +alignment_offset ... SKIPPED (cannot remove scsi_debug module (rmmod))
fdisk: align 512/4K +MD ... SKIPPED (cannot remove scsi_debug module (rmmod))
In case of gcc this can be easily resolved by setting $LD_PRELOAD to the
respective ASan library. clang makes this a bit more difficult, since it
compiles the ASan library statically, so firstly we need to force dynamic
linking (via -shared-asan), and then add the runtime DSO path to the
linker cache, since it's in a non-standard path.
2021-01-29 15:01:02 -06:00
|
|
|
|
2021-01-30 11:33:26 -06:00
|
|
|
./tests/run.sh --show-diff
|
|
|
|
;;
|
|
|
|
DISTCHECK)
|
|
|
|
make distcheck
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo >&2 "Unknown phase '$phase'"
|
|
|
|
exit 1
|
2021-01-25 09:51:51 -06:00
|
|
|
esac
|
|
|
|
done
|