From 0925000d4812ae5ccefaf7b42ebe73a2466c9240 Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Fri, 26 Jan 2018 13:43:17 +0300 Subject: [PATCH] [ESan] EfficiencySanitizer support packages. Add esan-runtime-env, esan-build-env and esan-force-options packages. Change-Id: Ibd4deaf217092e4c4067ec408d176e7227369680 --- packaging/ESAN_OPTIONS | 0 packaging/gcc-contrib.spec | 128 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 packaging/ESAN_OPTIONS diff --git a/packaging/ESAN_OPTIONS b/packaging/ESAN_OPTIONS new file mode 100644 index 0000000..e69de29 diff --git a/packaging/gcc-contrib.spec b/packaging/gcc-contrib.spec index fa930ce..42ea2c4 100644 --- a/packaging/gcc-contrib.spec +++ b/packaging/gcc-contrib.spec @@ -14,6 +14,7 @@ %define lsan_arch x86_64 %ix86 armv7l aarch64 %define ubsan_arch x86_64 %ix86 ppc ppc64 %arm aarch64 %define cilkrts_arch x86_64 %ix86 +%define esan_arch x86_64 armv7l %ifarch armv7l %define ARCH armv7l @@ -48,9 +49,12 @@ %define isan_force_options -fsanitize=unsigned-integer-overflow %define tsan_force_options -fsanitize=thread -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread %define asan_runtime_options halt_on_error=false:start_deactivated=true:print_cmdline=true:quarantine_size_mb=1:detect_leaks=0:handle_segv=0:log_path=/tmp/asan.log:log_exe_name=1:fast_unwind_on_fatal=1 +%define esan_force_options -fsanitize=efficiency-working-set -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread +%define esan_cache_force_options -fsanitize=efficiency-cache-frag -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread %define ubsan_runtime_options print_cmdline=true:log_path=/tmp/ubsan.log %define lsan_runtime_options print_cmdline=true:detect_leaks=1:log_path=/tmp/lsan.log:log_exe_name=1:fast_unwind_on_malloc=false:malloc_context_size=5:suppressions=/lsan.supp:print_suppressions=false %define tsan_runtime_options print_cmdline=true:log_path=/tmp/tsan.log:detect_deadlocks=1:second_deadlock_stack=1 +%define esan_runtime_options print_cmdline=true:log_path=/tmp/esan.log Name: gcc-contrib%{?cross:-%{cross}} # With generated files in src we could drop the following @@ -72,6 +76,7 @@ Source23: extract-ubsan-logs Source24: lsan.supp Source25: TSAN_OPTIONS Source26: macros.asan +Source27: ESAN_OPTIONS Group: Development/Building Summary: GCC related scripts License: MIT @@ -270,6 +275,100 @@ chmod a-w %{libsubdir} /usr/bin/gcc-unforce-options [ -d /emul/ ] && chmod a-w /emul/usr/bin/ +%package -n esan-force-options +Summary: Scripts to enable automatic package sanitization +Group: System Environment +Requires: gcc +Requires: libesan + +%description -n esan-force-options +Scripts for ESan instrumentation + +%post -n esan-force-options +# Change mode to allow all users to run gcc-force/unforce-options +chmod a+w /usr/bin +chmod a+w %{libsubdir} +[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \ + && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w +/usr/bin/gcc-force-options %esan_force_options +# Add ESan-related macros +cat >> /usr/lib/rpm/tizen_macros << EOF + +%%esan_force_options %{esan_force_options} +%%gcc_unforce_options /usr/bin/gcc-unforce-options +%%gcc_force_options /usr/bin/gcc-force-options +%%gcc_force_default_options %%gcc_force_options %%esan_force_options +EOF + +%preun -n esan-force-options +# Restore read-only mode +chmod a-w /usr/bin +chmod a-w %{libsubdir} +[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \ + && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w +/usr/bin/gcc-unforce-options +[ -d /emul/ ] && chmod a-w /emul/usr/bin/ + +%package -n esan-cache-force-options +Summary: Scripts to enable automatic package sanitization +Group: System Environment +Requires: gcc +Requires: libesan + +%description -n esan-cache-force-options +Scripts for ESan instrumentation + +%post -n esan-cache-force-options +# Change mode to allow all users to run gcc-force/unforce-options +chmod a+w /usr/bin +chmod a+w %{libsubdir} +[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \ + && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w +/usr/bin/gcc-force-options %esan_cache_force_options +# Add ESan-related macros +cat >> /usr/lib/rpm/tizen_macros << EOF + +%%esan_cache_force_options %{esan_cache_force_options} +%%gcc_unforce_options /usr/bin/gcc-unforce-options +%%gcc_force_options /usr/bin/gcc-force-options +%%gcc_force_default_options %%gcc_force_options %%esan_cache_force_options +EOF + +%preun -n esan-cache-force-options +# Restore read-only mode +chmod a-w /usr/bin +chmod a-w %{libsubdir} +[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \ + && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w +/usr/bin/gcc-unforce-options +[ -d /emul/ ] && chmod a-w /emul/usr/bin/ + +%package -n esan-runtime-env +Summary: ESan runtime environment +Group: Development/Libraries +Requires: libesan +Requires(post): smack + +%description -n esan-runtime-env +ESan runtime environment + +%post -n esan-runtime-env +echo "%{esan_runtime_options}" > /ESAN_OPTIONS +chsmack -a "_" /ESAN_OPTIONS + +%package -n esan-build-env +Summary: ESan build environment +Group: Development/Libraries +Requires: libesan + +%description -n esan-build-env +ESan build environment + +%post -n esan-build-env +echo "%{esan_runtime_options}" > /ESAN_OPTIONS +echo ":process_range_access=0" >> /ESAN_OPTIONS +chsmack -a "_" /ESAN_OPTIONS + %package -n tsan-runtime-env Summary: TSan runtime environment Group: Development/Libraries @@ -417,6 +516,11 @@ cp %{SOURCE25} %{buildroot} chmod 644 %{buildroot}/TSAN_OPTIONS %endif +%ifarch %esan_arch +cp %{SOURCE27} %{buildroot} +chmod 644 %{buildroot}/ESAN_OPTIONS +%endif + mkdir -p %{buildroot}/%{_rpmconfigdir}/tizen/ install -m 0644 %{SOURCE21} %{buildroot}/ install -m 0644 %{SOURCE22} %{buildroot}/%{_rpmconfigdir}/ @@ -457,6 +561,20 @@ install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/ %{_prefix}/bin/gcc-unforce-options %endif +%ifarch %esan_arch +%files -n esan-force-options +%defattr(-,root,root,-) +%{_prefix}/bin/gcc-force-options +%{_prefix}/bin/gcc-unforce-options +%endif + +%ifarch %esan_arch +%files -n esan-cache-force-options +%defattr(-,root,root,-) +%{_prefix}/bin/gcc-force-options +%{_prefix}/bin/gcc-unforce-options +%endif + %files -n asan-build-env %defattr(-,root,root,-) /ASAN_OPTIONS @@ -488,6 +606,16 @@ install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/ %{_rpmconfigdir}/macros.ubsan %{_rpmconfigdir}/tizen/extract-ubsan-logs +%ifarch %esan_arch +%files -n esan-runtime-env +%defattr(-,root,root,-) +/ESAN_OPTIONS + +%files -n esan-build-env +%defattr(-,root,root,-) +/ESAN_OPTIONS +%endif + %files -n ubsan-runtime-env %defattr(-,root,root,-) %endif -- 2.7.4