#endif
const char *GCC = "/usr/bin/gcc";
-static const int ASAN_OPTIONS_MAX = 7;
static const int ASAN_OPTIONS_MIN = 3;
+#ifndef HWASAN_BUILD
+static const int ASAN_OPTIONS_MAX = 7;
+#else
+static const int ASAN_OPTIONS_MAX = 5;
+#endif
static std::string blacklist[] = {
"rtld", "/dl-", "elf", "string/mem", "time/time", "time/gettimeofday",
"time/timegm", "time/timespec_get", "nptl/libc_pthread_init",
"nptl/register-atfork",
+#ifndef HWASAN_BUILD
// In Tizen, ASan tries to write error log to procfs, in case procfs is not
// mounted, this action will generate a kernel panic. So, just disable
// errors which happens because of dword-aligned reading by glibc.
- "string"};
+ "string",
+#else
+ "/init-", "ctype-info", "setjmp/",
+#endif
+};
+#ifndef HWASAN_BUILD
static const char *asan_options[ASAN_OPTIONS_MAX] = {
"-fno-omit-frame-pointer", "-Wno-error", "-DSKIP_IFUNC",
"-fsanitize-recover=address", "-fsanitize=address", "--param",
"asan-use-after-return=0",
};
+#else
+static const char *asan_options[ASAN_OPTIONS_MAX] = {
+ "-fno-omit-frame-pointer", "-Wno-error", "-DSKIP_IFUNC",
+ "-fsanitize=hwaddress", "-fsanitize-recover=hwaddress",
+};
+#endif
static const char *defs_option = "-Wl,-z,defs";
static const size_t defs_option_length = 11;
std::cerr << "Errno: " << errno;
#endif
}
-
Summary: glibc with ASan instrumentation
License: LGPL-2.1+ and LGPL-2.1+-with-GCC-exception and GPL-2.0+
Requires: glibc = %{version}
+Requires: rpm
%description asan
This package provides glibc with ASan instrumentation
%post asan
-ln -s --force /%{_lib}/libc-2.24-asan.so /%{_lib}/libc.so.6
+ln -s --force /%{_lib}/libc-%{version}-asan.so /%{_lib}/libc.so.6
%preun asan
-ln -s --force /%{_lib}/libc-2.24.so /%{_lib}/libc.so.6
+ln -s --force /%{_lib}/libc-%{version}.so /%{_lib}/libc.so.6
%endif
}
+%{?hwasan:
+%ifarch %hwasan_arch
+%package hwasan
+Summary: glibc with Hwasan instrumentation
+License: LGPL-2.1+ and LGPL-2.1+-with-GCC-exception and GPL-2.0+
+Requires: glibc = %{version}
+Requires: rpm
+
+%description hwasan
+This package provides glibc with Hwasan instrumentation
+
+%post hwasan
+ln -s --force /%{_lib}/libc-%{version}-hwasan.so /%{_lib}/libc.so.6
+
+%preun hwasan
+ln -s --force /%{_lib}/libc-%{version}.so /%{_lib}/libc.so.6
+
+%endif
+}
+
+
%{?glibc_dump_configure:
%package configure-dump
Summary: GNU Glibc configure dump
conf_cflags="$BuildFlags -funwind-tables -fPIC"
%{?asan: conf_cflags="$conf_cflags -DASAN_INIT_FIRST"}
+%{?hwasan: conf_cflags="$conf_cflags -DASAN_INIT_FIRST -Wno-error=pragmas"}
profile="--disable-profile"
%{?build_profile:profile="--enable-profile"}
%{?glibc_dump_configure:patch_configure.pl ..}
# Glibc must have both functions' implementations
CPPFLAGS="-U_LARGEFILE_SOURCE -U_LARGEFILE64_SOURCE -U_FILE_OFFSET_BITS"
%endif
+CPPFLAGS+=" -DASAN_INIT_FIRST"
# chmod +x $HERE/asan-glibc-gcc-wrapper.py
# build static wrapper, because we don't want asan to intercept allocators
# make -r -j $J -C $GLIBC objdir=`pwd` install_root=$ASAN_INST install-lib
popd
%endif
- }
+}
+
+%{?hwasan:
+%ifarch %{hwasan_arch}
+configure_flags="--prefix=/usr --without-cvs --without-selinux --enable-stackguard-randomization --enable-obsolete-rpc --disable-mathvec"
+configure_flags="$configure_flags --disable-sanity-checks"
+
+HERE=%{_builddir}/%{name}-%{version}
+J=${J:-32}
+GLIBC=$HERE
+ASAN_BUILD=$HERE/hwasan-build
+unset CXXFLAGS
+unset CFLAGS
+unset LDFLAGS
+%ifarch %arm aarch64
+# Glibc must have both functions' implementations
+CPPFLAGS="-U_LARGEFILE_SOURCE -U_LARGEFILE64_SOURCE -U_FILE_OFFSET_BITS"
+%endif
+CPPFLAGS+=" -DASAN_INIT_FIRST"
+
+# chmod +x $HERE/asan-glibc-gcc-wrapper.py
+# build static wrapper, because we don't want asan to intercept allocators
+g++ -o gcc-wrapper gcc-wrapper.cc -O3 -funroll-loops -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-exceptions -static -DHWASAN_BUILD
+
+rm -rf $ASAN_BUILD
+mkdir -p $ASAN_BUILD
+pushd $ASAN_BUILD
+# Legacy python wrapper call was:
+# CC=$HERE/asan-glibc-gcc-wrapper.py $GLIBC/configure $configure_flags
+CPPFLAGS=$CPPFLAGS \
+ CC=$HERE/gcc-wrapper $GLIBC/configure $configure_flags
+
+# Quick build - builds only libraries, but does not create symlinks.
+make -r -j $J -C $GLIBC objdir=`pwd` subdir_lib
+# make -r -j $J -C $GLIBC objdir=`pwd` install_root=$ASAN_INST install-lib
+popd
+%endif
+}
+
%{?glibc_exit_on_make_finish:
echo "Glibc build is complete and environment is ready, exiting"
HERE=%{_builddir}/%{name}-%{version}
GLIBC=$HERE
ASAN_BUILD=$HERE/asan-build
-cp $ASAN_BUILD/libc.so %{buildroot}/%{_lib}/libc-2.24-asan.so
+cp $ASAN_BUILD/libc.so %{buildroot}/%{_lib}/libc-%{version}-asan.so
+%endif
+}
+
+%{?hwasan:
+%ifarch %{hwasan_arch}
+HERE=%{_builddir}/%{name}-%{version}
+GLIBC=$HERE
+ASAN_BUILD=$HERE/hwasan-build
+cp $ASAN_BUILD/libc.so %{buildroot}/%{_lib}/libc-%{version}-hwasan.so
%endif
}
%ifarch %{asan_arch}
%files asan
%manifest %{name}.manifest
-/%{_lib}/libc-2.24-asan.so
+/%{_lib}/libc-%{version}-asan.so
+%endif
+}
+
+%{?hwasan:
+%ifarch %{hwasan_arch}
+%files hwasan
+%manifest %{name}.manifest
+/%{_lib}/libc-%{version}-hwasan.so
%endif
}