[compiler-rt] r315509 - [sanitizer] Move the errno/ENOMEM allocator checks logic to separate .cc

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 11 14:20:04 PDT 2017


Author: cryptoad
Date: Wed Oct 11 14:20:04 2017
New Revision: 315509

URL: http://llvm.org/viewvc/llvm-project?rev=315509&view=rev
Log:
[sanitizer] Move the errno/ENOMEM allocator checks logic to separate .cc

Summary:
This is a new attempt at D38706, which had 2 issues.

The first one was that it broke TSan, because `sanitizer_errno.h` was not
directly included in `tsan_mman.cc`. This fixes the include.

The second one was that it broke the nolibc build, because `__errno_location`
couldn't be found. This adds the new .cc to the libcdep list instead of the
base one.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: kubamracek, mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D38743

Added:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=315509&r1=315508&r2=315509&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Wed Oct 11 14:20:04 2017
@@ -58,6 +58,7 @@ set(SANITIZER_NOLIBC_SOURCES
 
 set(SANITIZER_LIBCDEP_SOURCES
   sanitizer_common_libcdep.cc
+  sanitizer_allocator_checks.cc
   sancov_flags.cc
   sanitizer_coverage_fuchsia.cc
   sanitizer_coverage_libcdep_new.cc

Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.cc?rev=315509&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.cc Wed Oct 11 14:20:04 2017
@@ -0,0 +1,23 @@
+//===-- sanitizer_allocator_checks.cc ---------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Various checks shared between ThreadSanitizer, MemorySanitizer, etc. memory
+// allocators.
+//
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_errno.h"
+
+namespace __sanitizer {
+
+void SetErrnoToENOMEM() {
+  errno = errno_ENOMEM;
+}
+
+} // namespace __sanitizer

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.h?rev=315509&r1=315508&r2=315509&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_checks.h Wed Oct 11 14:20:04 2017
@@ -15,17 +15,22 @@
 #ifndef SANITIZER_ALLOCATOR_CHECKS_H
 #define SANITIZER_ALLOCATOR_CHECKS_H
 
-#include "sanitizer_errno.h"
 #include "sanitizer_internal_defs.h"
 #include "sanitizer_common.h"
 #include "sanitizer_platform.h"
 
 namespace __sanitizer {
 
+// The following is defined in a separate compilation unit to avoid pulling in
+// sanitizer_errno.h in this header, which leads to conflicts when other system
+// headers include errno.h. This is usually the result of an unlikely event,
+// and as such we do not care as much about having it inlined.
+void SetErrnoToENOMEM();
+
 // A common errno setting logic shared by almost all sanitizer allocator APIs.
 INLINE void *SetErrnoOnNull(void *ptr) {
   if (UNLIKELY(!ptr))
-    errno = errno_ENOMEM;
+    SetErrnoToENOMEM();
   return ptr;
 }
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc?rev=315509&r1=315508&r2=315509&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc Wed Oct 11 14:20:04 2017
@@ -13,6 +13,7 @@
 #include "sanitizer_common/sanitizer_allocator_checks.h"
 #include "sanitizer_common/sanitizer_allocator_interface.h"
 #include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_errno.h"
 #include "sanitizer_common/sanitizer_placement_new.h"
 #include "tsan_mman.h"
 #include "tsan_rtl.h"




More information about the llvm-commits mailing list