From d112ab39c27b987120c42fc337782102f89bd97f Mon Sep 17 00:00:00 2001 From: Andrey Drobyshev Date: Tue, 27 Aug 2019 19:38:36 +0300 Subject: [PATCH] [libasansi] Add asansi-runtime-env package. Change-Id: I1795b258492f7fa583c8c7a9901b0abdaf28d03c Signed-off-by: Andrey Drobyshev --- packaging/asansictl | 147 +++++++++++++++++++++++++++++++++++++++++++++ packaging/gcc-contrib.spec | 16 +++++ 2 files changed, 163 insertions(+) create mode 100755 packaging/asansictl diff --git a/packaging/asansictl b/packaging/asansictl new file mode 100755 index 0000000..0086198 --- /dev/null +++ b/packaging/asansictl @@ -0,0 +1,147 @@ +#!/bin/sh + +set -eu + +SCRIPT_NAME=`basename "$0"` + +errecho() { + echo "$@" >&2 +} + +usage() { + echo "\ +Usage: $SCRIPT_NAME [options] + +Libasan interceptors switching tool. +When switching: + - changes library which libasan.so symlink points to + - modifies /ASAN_OPTIONS + - backups (or restores) original libasan + +Options: + -h, --help - display this help and exit + -c, --current - show currently set ASan library + -s, --set libasan|libasansi - set ASan library" +} + +errusage() { + usage >&2 +} + +check_file() { + if [ ! -f "$1" ]; then + errecho "$1: no such file" + exit 1 + fi +} + +init_libdir() { + if `rpm -q --quiet libasan`; then + LIBDIR=`rpm -ql libasan | grep '/libasan\.so$' | xargs dirname` + check_file "${LIBDIR}/libasan.so" + else + errecho "libasan package is not installed" + exit 1 + fi +} + +show_current_lib() { + basename `readlink -f "${LIBDIR}/libasan.so"` | cut -d. -f1 +} + +remount_rootfs() { + mount -o remount,rw / +} + +set_lib() { + local NEW_LIB="$1" + local OLD_LIB=`show_current_lib` + if [[ "$NEW_LIB" == "$OLD_LIB" ]]; then + echo "$NEW_LIB is already set" + exit 0 + fi + + case "$NEW_LIB" in + libasan) + echo 'Set libasan' + + # check presence of backups + check_file /ASAN_OPTIONS.BACKUP + check_file "${LIBDIR}/libasan.so.3.0.0.backup" + + remount_rootfs + + # restore ASan library + mv "${LIBDIR}/libasan.so.3.0.0.backup" "${LIBDIR}/libasan.so.3.0.0" + chsmack -a _ "${LIBDIR}/libasan.so.3.0.0" + + # restore ASan options + mv /ASAN_OPTIONS.BACKUP /ASAN_OPTIONS + chsmack -a _ /ASAN_OPTIONS + ;; + libasansi) + echo 'Set libasansi' + + # check presence of original files + check_file /ASAN_OPTIONS + check_file "${LIBDIR}/libasan.so.3.0.0" + + remount_rootfs + + # create backup + cp "${LIBDIR}/libasan.so.3.0.0" "${LIBDIR}/libasan.so.3.0.0.backup" + cp /ASAN_OPTIONS /ASAN_OPTIONS.BACKUP + + # change ASan options + echo "`cat /ASAN_OPTIONS`:enable_interceptors=0" > /ASAN_OPTIONS + chsmack -a _ /ASAN_OPTIONS + + # change ASan library + ln -sf "${LIBDIR}/libasansi.so" "${LIBDIR}/libasan.so.3.0.0" + chsmack -a _ "${LIBDIR}/libasan.so.3.0.0" + ;; + *) + errecho "Incorrect libname: $NEW_LIB" + errusage + exit 1 + ;; + esac +} + +if [ `id -u` -ne 0 ]; then + echo "This script must be run as root" + exit 1 +fi + +# parsing arguments +while [ "$#" -gt 0 ]; do + KEY="$1" + case "$KEY" in + -h|--help) + usage + exit 0 + ;; + -c|--current) + init_libdir + show_current_lib + exit 0 + ;; + -s|--set) + if [ "$#" -ne 2 ]; then + errusage + exit 1 + fi + NEW_LIB="$2" + init_libdir + set_lib "$NEW_LIB" + exit 0 + ;; + *) + errecho "Incorrect argument: $KEY" + errusage + exit 1 + esac +done + +errusage +exit 1 diff --git a/packaging/gcc-contrib.spec b/packaging/gcc-contrib.spec index e425802..06631a0 100644 --- a/packaging/gcc-contrib.spec +++ b/packaging/gcc-contrib.spec @@ -78,6 +78,7 @@ Source24: macros.gcc_warning Source25: extract-gcc-warning-logs Source26: macros.gcov Source27: extract-gcov-info +Source28: asansictl Group: Development/Building Summary: GCC related scripts License: MIT @@ -507,6 +508,14 @@ Requires: libasan %description -n asan-runtime-env Asan runtime environment +%package -n asansi-runtime-env +Summary: ASanSI runtime for target device +Group: Development/Libraries +Requires: asan-runtime-env + +%description -n asansi-runtime-env +Tool for switching interceptors state of libasan + %package -n ubsan-runtime-env Summary: UBSan runtime environment for target device Group: Development/Libraries @@ -629,6 +638,9 @@ install -m 0755 %{SOURCE25} %{buildroot}/%{_rpmconfigdir}/tizen/ install -m 0644 %{SOURCE26} %{buildroot}/%{_rpmconfigdir}/ install -m 0755 %{SOURCE27} %{buildroot}/%{_rpmconfigdir}/tizen/ +mkdir -p %{buildroot}%{_prefix}/sbin +install -m 0755 %{SOURCE28} %{buildroot}%{_prefix}/sbin/ + %files #%manifest gcc-contrib.manifest @@ -691,6 +703,10 @@ install -m 0755 %{SOURCE27} %{buildroot}/%{_rpmconfigdir}/tizen/ /ASAN_OPTIONS /etc/ld.so.preload +%files -n asansi-runtime-env +%defattr(-,root,root,-) +%{_prefix}/sbin/asansictl + %ifarch %lsan_arch %files -n lsan-runtime-env %defattr(-,root,root,-) -- 2.7.4