From 89481bdfec835f7d84c5c236117e3a0da4cc6a9f Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Fri, 17 Nov 2017 15:37:07 +0300 Subject: [PATCH] [TSan] Support cross building. In case we want to build binary with TSan for aarch64 CPU under qemu-user on x86_64 CPU, we should make sure that we don't make any architecture dependent checks at the runtime. To support this, new flag "run_under_qemu" was added and now available under TSAN_OPTIONS. Change-Id: Ifad929d284d30b720afd60a60a88fa129f37d4a6 --- libsanitizer/tsan/tsan_flags.inc | 1 + libsanitizer/tsan/tsan_platform_linux.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/libsanitizer/tsan/tsan_flags.inc b/libsanitizer/tsan/tsan_flags.inc index 78f5e80..be03755 100644 --- a/libsanitizer/tsan/tsan_flags.inc +++ b/libsanitizer/tsan/tsan_flags.inc @@ -79,3 +79,4 @@ TSAN_FLAG(bool, ignore_interceptors_accesses, false, "Ignore reads and writes from all interceptors.") TSAN_FLAG(bool, shared_ptr_interceptor, true, "Track atomic reference counting in libc++ shared_ptr and weak_ptr.") +TSAN_FLAG(bool, run_under_qemu, false, "Support to run under qemu.") diff --git a/libsanitizer/tsan/tsan_platform_linux.cc b/libsanitizer/tsan/tsan_platform_linux.cc index 2ed5718..b47e01e 100644 --- a/libsanitizer/tsan/tsan_platform_linux.cc +++ b/libsanitizer/tsan/tsan_platform_linux.cc @@ -270,6 +270,12 @@ void InitializePlatform() { // Initialize the guard pointer used in {sig}{set,long}jump. InitializeGuardPtr(); #endif + // If we call execve for "/proc/self/exe" under qemu-user, + // we will get an error, because kernel will try to ReExec + // qemu instead of TSaned binary. + if (UNLIKELY(flags()->run_under_qemu)) + return; + if (reexec) ReExec(); } -- 2.7.4