[libasansi] Add asansi-runtime-env package. 76/212876/8 accepted/tizen_5.5_base accepted/tizen_5.5_base_mobile_hotfix accepted/tizen_5.5_base_wearable_hotfix tizen_5.5_base tizen_5.5_base_mobile_hotfix tizen_5.5_base_wearable_hotfix tizen_5.5_tv accepted/tizen/5.5/base/20191030.082416 accepted/tizen/5.5/base/mobile/hotfix/20201023.084608 accepted/tizen/5.5/base/wearable/hotfix/20201023.080949 accepted/tizen/base/20190901.121333 submit/tizen_5.5_base/20191030.000001 submit/tizen_5.5_base_mobile_hotfix/20201023.171501 submit/tizen_5.5_base_wearable_hotfix/20201023.155601 submit/tizen_base/20190829.163531 tizen_5.5.m2_release
authorAndrey Drobyshev <a.drobyshev@samsung.com>
Tue, 27 Aug 2019 16:38:36 +0000 (19:38 +0300)
committerAndrey Drobyshev <a.drobyshev@samsung.com>
Thu, 29 Aug 2019 11:07:46 +0000 (14:07 +0300)
Change-Id: I1795b258492f7fa583c8c7a9901b0abdaf28d03c
Signed-off-by: Andrey Drobyshev <a.drobyshev@samsung.com>
packaging/asansictl [new file with mode: 0755]
packaging/gcc-contrib.spec

diff --git a/packaging/asansictl b/packaging/asansictl
new file mode 100755 (executable)
index 0000000..0086198
--- /dev/null
@@ -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
index e425802..06631a0 100644 (file)
@@ -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,-)