code from {A, UB}San to sanitizer_common code.
Add -fno-omit-frame-pointer -U_FORTIFY_SOURCE to lsan-force-options because
LSan heavily relies on frame pointers. Disable LSan in QEMU builds through
LSAN_OPTIONS file. Refactor Tizen specific patches in ASan and UBSan.
Change-Id: I95f59243352e75d6cd0eae22e7aaa02ab0e96cfc
Signed-off-by: Maxim Ostapenko <m.ostapenko@samsung.com>
ubsan_parser.ParseString(ubsan_default_options);
#endif
- // Read from command line.
- const char *options = GetEnv("ASAN_OPTIONS");
- // If environment variable ASAN_OPTIONS is not set use predefined file to
- // init options.
- bool getFlagsFromFile = options == 0;
- char *asanFlags = 0;
- uptr len = GetPageSizeCached();
- uptr read_len = 0;
- if (getFlagsFromFile) {
- ReadFileToBuffer("/ASAN_OPTIONS", &asanFlags, &len, &read_len,
- GetPageSizeCached());
- options = asanFlags;
- }
-
+ int mmaped = 0;
+ const char *options =
+ GetRuntimeOptions("ASAN_OPTIONS", "/ASAN_OPTIONS", &mmaped);
asan_parser.ParseString(options);
+
#if CAN_SANITIZE_LEAKS
lsan_parser.ParseString(GetEnv("LSAN_OPTIONS"));
#endif
f->quarantine_size_mb = kDefaultQuarantineSizeMb;
}
- if (getFlagsFromFile)
- UnmapOrDie(asanFlags, len);
-
+ if (mmaped)
+ UnmapOrDie((void *)options, GetPageSizeCached());
}
} // namespace __asan
kHighShadowBeg > kMidMemEnd);
}
-extern "C"
-int mount(const char *source, const char *target, const char *filesystemtype,
- unsigned long mountflags, const void *data);
-
static void MaybeDisableUlimit() {
if (!AddressSpaceIsUnlimited())
SetAddressSpaceUnlimited();
}
-bool MaybeMountProcFS() {
- if (FileExists("/proc/self/maps")) return true;
-
- if(0 != mount("proc", "/proc", "proc", 0, 0)) {
- Report("Failed to mount /proc, Asan is likely to fail\n");
- return false;
- }
- return true;
-}
-
static void AsanInitInternal() {
if (LIKELY(asan_inited)) return;
MaybeMountProcFS();
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_flag_parser.h"
#include "sanitizer_common/sanitizer_stacktrace.h"
+#include "sanitizer_common/sanitizer_libc.h"
#include "lsan_allocator.h"
#include "lsan_common.h"
#include "lsan_thread.h"
RegisterLsanFlags(&parser, f);
RegisterCommonFlags(&parser);
- parser.ParseString(GetEnv("LSAN_OPTIONS"));
+ int mmaped = 0;
+ const char *options =
+ GetRuntimeOptions("LSAN_OPTIONS", "/LSAN_OPTIONS", &mmaped);
+ parser.ParseString(options);
SetVerbosity(common_flags()->verbosity);
if (Verbosity()) ReportUnrecognizedFlags();
if (common_flags()->help) parser.PrintFlagDescriptions();
+ __sanitizer_set_report_path(common_flags()->log_path);
+
+ if (mmaped)
+ UnmapOrDie((void *)options, GetPageSizeCached());
}
extern "C" void __lsan_init() {
Printf("\n\n");
}
+const char *GetRuntimeOptions(const char *env_option, const char *filename,
+ int *mmaped) {
+ // Read from command line.
+ const char *options = GetEnv(env_option);
+ // If environment variable {A, L, UB}SAN_OPTIONS is not set use predefined
+ // file to init options.
+ bool getFlagsFromFile = options == 0;
+ char *flags = 0;
+ uptr len = GetPageSizeCached();
+ uptr read_len = 0;
+ if (getFlagsFromFile) {
+ ReadFileToBuffer(filename, &flags, &len, &read_len, GetPageSizeCached());
+ *mmaped = 1;
+ options = flags;
+ }
+ return options;
+}
+
} // namespace __sanitizer
using namespace __sanitizer; // NOLINT
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
+const char *GetRuntimeOptions(const char *env_option, const char *filename,
+ int *mmaped);
+
} // namespace __sanitizer
inline void *operator new(__sanitizer::operator_new_size_type size,
return all == 0;
}
+bool MaybeMountProcFS() {
+ if (FileExists("/proc/self/maps"))
+ return true;
+
+ if (0 != mount("proc", "/proc", "proc", 0, 0)) {
+ Report("Failed to mount /proc, %s is likely to fail\n", SanitizerToolName);
+ return false;
+ }
+ return true;
+}
+
} // namespace __sanitizer
// Error handling
bool internal_iserror(uptr retval, int *rverrno = nullptr);
+extern "C" int mount(const char *source, const char *target,
+ const char *filesystemtype, unsigned long mountflags,
+ const void *data);
+
+bool MaybeMountProcFS();
+
} // namespace __sanitizer
#endif // SANITIZER_LIBC_H
// Override from user-specified string.
parser.ParseString(MaybeCallUbsanDefaultOptions());
- // Read from command line.
- const char *options = GetEnv("UBSAN_OPTIONS");
- char *ubsanFlags = 0;
- uptr len = GetPageSizeCached();
- uptr read_len = 0;
- bool getFlagsFromFile = ubsanFlags == 0;
- // Override from predefined file if exists.
- if (getFlagsFromFile) {
- ReadFileToBuffer("/UBSAN_OPTIONS", &ubsanFlags, &len, &read_len,
- GetPageSizeCached());
- options = ubsanFlags;
- }
+ int mmaped = 0;
+ const char *options =
+ GetRuntimeOptions("UBSAN_OPTIONS", "/UBSAN_OPTIONS", &mmaped);
parser.ParseString(options);
- UnmapOrDie(ubsanFlags, len);
+
+ if (mmaped)
+ UnmapOrDie((void *)options, GetPageSizeCached());
SetVerbosity(common_flags()->verbosity);
if (Verbosity()) ReportUnrecognizedFlags();
--- /dev/null
+detect_leaks=0
Source16: gcc-unforce-options
Source17: ASAN_OPTIONS
Source18: asan_symbolize.py
-Source19: gcc.manifest
+Source19: LSAN_OPTIONS
+Source20: gcc.manifest
Group: Development/Building
Summary: The GNU C Compiler and Support Files
License: GPL-3.0+
# Change mode to allow all users to run gcc-force/unforce-options
chmod a+w /usr/bin
[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-4.9.2/obj/gcc/
-/usr/bin/gcc-force-options -fsanitize=leak
+/usr/bin/gcc-force-options -fsanitize=leak -fno-omit-frame-pointer -U_FORTIFY_SOURCE
%preun -n lsan-force-options
# Restore read-only mode
chmod a-w /usr/bin
[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-4.9.2/obj/gcc/
/usr/bin/gcc-unforce-options
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/
%package -n asan-build-env
Summary: Asan build environment
%post -n lsan-build-env
# Add /usr/lib64/liblsan.so to /etc/ld.so.preload
[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig
-echo "%{libdir}/liblsan.so" > /etc/ld.so.preload
+echo "liblsan.so" > /etc/ld.so.preload
[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload
[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig
%prep
%setup -q -n gcc-%{version}
-cp %{SOURCE19} .
+cp %{SOURCE20} .
tar xf %{SOURCE10}
ln -sf gmp-6.0.0 gmp
cp %{SOURCE17} %{buildroot}
chmod 644 %{buildroot}/ASAN_OPTIONS
+
+%ifarch %lsan_arch
+cp %{SOURCE19} %{buildroot}
+chmod 644 %{buildroot}/LSAN_OPTIONS
+%endif
}
%files
%ifarch %lsan_arch
%files -n lsan-build-env
%defattr(-,root,root,-)
+/LSAN_OPTIONS
%endif
%files -n sanitizer-devel
Source16: gcc-unforce-options
Source17: ASAN_OPTIONS
Source18: asan_symbolize.py
-Source19: gcc.manifest
+Source19: LSAN_OPTIONS
+Source20: gcc.manifest
Group: Development/Building
Summary: The GNU C Compiler and Support Files
License: GPL-3.0+
# Change mode to allow all users to run gcc-force/unforce-options
chmod a+w /usr/bin
[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-4.9.2/obj/gcc/
-/usr/bin/gcc-force-options -fsanitize=leak
+/usr/bin/gcc-force-options -fsanitize=leak -fno-omit-frame-pointer -U_FORTIFY_SOURCE
%preun -n lsan-force-options
# Restore read-only mode
chmod a-w /usr/bin
[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-4.9.2/obj/gcc/
/usr/bin/gcc-unforce-options
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/
%package -n asan-build-env
Summary: Asan build environment
%post -n lsan-build-env
# Add /usr/lib64/liblsan.so to /etc/ld.so.preload
[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig
-echo "%{libdir}/liblsan.so" > /etc/ld.so.preload
+echo "liblsan.so" > /etc/ld.so.preload
[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload
[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig
%prep
%setup -q -n gcc-%{version}
-cp %{SOURCE19} .
+cp %{SOURCE20} .
tar xf %{SOURCE10}
ln -sf gmp-6.0.0 gmp
cp %{SOURCE17} %{buildroot}
chmod 644 %{buildroot}/ASAN_OPTIONS
+
+%ifarch %lsan_arch
+cp %{SOURCE19} %{buildroot}
+chmod 644 %{buildroot}/LSAN_OPTIONS
+%endif
}
%files
%ifarch %lsan_arch
%files -n lsan-build-env
%defattr(-,root,root,-)
+/LSAN_OPTIONS
%endif
%files -n sanitizer-devel
Source16: gcc-unforce-options
Source17: ASAN_OPTIONS
Source18: asan_symbolize.py
-Source19: gcc.manifest
+Source19: LSAN_OPTIONS
+Source20: gcc.manifest
Group: Development/Building
Summary: The GNU C Compiler and Support Files
License: GPL-3.0+
# Change mode to allow all users to run gcc-force/unforce-options
chmod a+w /usr/bin
[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-4.9.2/obj/gcc/
-/usr/bin/gcc-force-options -fsanitize=leak
+/usr/bin/gcc-force-options -fsanitize=leak -fno-omit-frame-pointer -U_FORTIFY_SOURCE
%preun -n lsan-force-options
# Restore read-only mode
chmod a-w /usr/bin
[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-4.9.2/obj/gcc/
/usr/bin/gcc-unforce-options
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/
%package -n asan-build-env
Summary: Asan build environment
%post -n lsan-build-env
# Add /usr/lib64/liblsan.so to /etc/ld.so.preload
[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig
-echo "%{libdir}/liblsan.so" > /etc/ld.so.preload
+echo "liblsan.so" > /etc/ld.so.preload
[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload
[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig
%prep
%setup -q -n gcc-%{version}
-cp %{SOURCE19} .
+cp %{SOURCE20} .
tar xf %{SOURCE10}
ln -sf gmp-6.0.0 gmp
cp %{SOURCE17} %{buildroot}
chmod 644 %{buildroot}/ASAN_OPTIONS
+
+%ifarch %lsan_arch
+cp %{SOURCE19} %{buildroot}
+chmod 644 %{buildroot}/LSAN_OPTIONS
+%endif
}
%files
%ifarch %lsan_arch
%files -n lsan-build-env
%defattr(-,root,root,-)
+/LSAN_OPTIONS
%endif
%files -n sanitizer-devel