%define quadmath_arch %ix86 x86_64 ia64
%define tsan_arch x86_64 aarch64
%define asan_arch x86_64 %ix86 ppc ppc64 %sparc %arm aarch64
+%define hwasan_arch aarch64
%define itm_arch x86_64 %ix86 %arm ppc ppc64 ppc64le s390 s390x %sparc aarch64
%define atomic_arch x86_64 %ix86 %arm aarch64 ppc ppc64 ppc64le s390 s390x %sparc m68k
%define lsan_arch x86_64 %ix86 armv7l aarch64
%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 hwasan_force_options -fsanitize=hwaddress -fsanitize-recover=hwaddress -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread
+%define hwasan_runtime_options halt_on_error=false:print_cmdline=true:handle_segv=0:log_path=/tmp/hwasan.log:log_exe_name=1
+
Name: gcc-contrib%{?cross:-%{cross}}
# With generated files in src we could drop the following
## until here, but at least renaming and patching info files breaks this
Source26: macros.gcov
Source27: extract-gcov-info
Source28: asansictl
+Source29: hwasan_stub.c
Group: Development/Building
Summary: GCC related scripts
License: MIT
# Remove additional macros from config
sed -e '\|^\# /etc/rpm/macros.asan$|,\|^\# /etc/rpm/macros.asan ends here|d' -i /usr/lib/rpm/tizen_macros
+%package -n libhwasan-stub
+Summary: HWASan stub library to enable cross build
+Group: System Environment
+Requires: rpm
+
+%description -n libhwasan-stub
+HWASan stub library for cross build
+
+%package -n hwasan-force-options
+Summary: Scripts to enable automatic package sanitization
+Group: System Environment
+Requires: gcc rpm
+Requires: libhwasan
+
+%description -n hwasan-force-options
+Scripts for HWASan instrumentation
+
+%post -n hwasan-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 %hwasan_force_options -fno-common
+# Add ASan-related macros
+cat >> /usr/lib/rpm/tizen_macros << EOF
+
+%%hwasan_force_options %{hwasan_force_options}
+%%gcc_unforce_options %%{lua: rpm.define("hwasan_unforced 1"); print("/usr/bin/gcc-unforce-options")}
+%%gcc_force_options /usr/bin/gcc-force-options
+%%gcc_force_default_options %%gcc_force_options %%hwasan_force_options -fno-common
+%%restore_fcommon \\
+ %%gcc_unforce_options \\
+ %%gcc_force_options %%hwasan_force_options -fcommon
+EOF
+
+# HWASan needs a whole shadow address space
+# Using ulimit can only set the value for current user so we need to set /etc/security/limits.conf directly.
+sed '/End of file/i\abuild\tsoft\tas\t-1\nabuild\thard\tas\t-1' -i /etc/security/limits.conf
+
+%preun -n hwasan-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
+# Restore limit configurations set for HWASan
+sed '/abuild/d' -i /etc/security/limits.conf
+
%package -n ubsan-force-options
Summary: Scripts to enable automatic package sanitization
Group: System Environment
# Restore /etc/ld.so.preload
[ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload
+%package -n hwasan-build-env
+Summary: HWAsan build environment
+Group: Development/Libraries
+Requires: libhwasan
+
+%description -n hwasan-build-env
+HWAsan build environment
+
%package -n lsan-runtime-env
Summary: LSan runtime environment
Group: Development/Libraries
%description -n asansi-runtime-env
Tool for switching interceptors state of libasan
+%package -n hwasan-runtime-env
+Summary: HWAsan runtime environment for target device
+Group: Development/Libraries
+Requires: libhwasan
+
+%description -n hwasan-runtime-env
+HWAsan runtime environment
+
%package -n ubsan-runtime-env
Summary: UBSan runtime environment for target device
Group: Development/Libraries
%prep
+%ifarch x86_64
+cp %{SOURCE29} .
+%endif
+
%build
# Generate runtime options for sanitizers
-echo "%{asan_runtime_options}" | tee ASAN_OPTIONS
+echo "%{asan_runtime_options}" | tee ASAN_OPTIONS
+echo "%{hwasan_runtime_options}" | tee HWASAN_OPTIONS
echo "%{lsan_runtime_options}" | tee LSAN_OPTIONS
echo "%{tsan_runtime_options}" | tee TSAN_OPTIONS
echo "%{ubsan_runtime_options}" | tee UBSAN_OPTIONS
echo "%{libdir}/libasan.so" | tee asan-runtime-ld.so.preload
+%ifarch x86_64
+gcc -shared -o libhwasan.so -fPIC hwasan_stub.c
+%endif
+
%install
mkdir -p %buildroot%_prefix
mkdir -p %buildroot%_prefix/bin
install -m 0644 ASAN_OPTIONS %{buildroot}
install -m 0644 asan-runtime-ld.so.preload %{buildroot}/etc/ld.so.preload
+%ifarch x86_64
+mkdir -p %{buildroot}/%{_libdir}
+install -m 755 libhwasan.so %{buildroot}/%{_libdir}
+%endif
+
+%ifarch %hwasan_arch
+install -m 0644 HWASAN_OPTIONS %{buildroot}
+%endif
+
%ifarch %lsan_arch
install -m 0644 LSAN_OPTIONS %{buildroot}
install -m 0644 %{SOURCE21} %{buildroot}
%{_prefix}/bin/gcc-unforce-options
%{_rpmconfigdir}/macros.asan
+%ifarch %hwasan_arch
+%files -n hwasan-force-options
+%defattr(-,root,root,-)
+%{_prefix}/bin/gcc-force-options
+%{_prefix}/bin/gcc-unforce-options
+%endif
+
%files -n ubsan-force-options
%defattr(-,root,root,-)
%{_prefix}/bin/gcc-force-options
%defattr(-,root,root,-)
%{_prefix}/sbin/asansictl
+%ifarch %hwasan_arch
+%files -n hwasan-build-env
+%defattr(-,root,root,-)
+/HWASAN_OPTIONS
+
+%files -n hwasan-runtime-env
+%defattr(-,root,root,-)
+/HWASAN_OPTIONS
+%endif
+
+%ifarch x86_64
+%files -n libhwasan-stub
+%defattr(-,root,root,-)
+%{libdir}/libhwasan.so
+%endif
+
%ifarch %lsan_arch
%files -n lsan-runtime-env
%defattr(-,root,root,-)