pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

compiler-rt-netbsd: Revamp local patches for atexit(3)



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Mon Nov 6 19:33:11 2017 +0100
Changeset:	08193d130d4ef4dbddf0f8347a9ab187c0e75e8e

Modified Files:
	compiler-rt-netbsd/distinfo
	compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
Added Files:
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__allocator.cc
	compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__allocator__internal.h
	compiler-rt-netbsd/patches/patch-test_tsan_atexit3.cc

Log Message:
compiler-rt-netbsd: Revamp local patches for atexit(3)

"Correct atexit(3) support in TSan/NetBSD"
https://reviews.llvm.org/D39619

Sponsored by <The NetBSD Foundation>

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=08193d130d4ef4dbddf0f8347a9ab187c0e75e8e

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 compiler-rt-netbsd/distinfo                        |  5 ++-
 ...h-lib_sanitizer__common_sanitizer__allocator.cc | 30 ++++++++++++++
 ...itizer__common_sanitizer__allocator__internal.h | 13 ++++++
 .../patch-lib_tsan_rtl_tsan__interceptors.cc       | 25 ++++++------
 .../patches/patch-test_tsan_atexit3.cc             | 46 ++++++++++++++++++++++
 5 files changed, 106 insertions(+), 13 deletions(-)

diffs:
diff --git a/compiler-rt-netbsd/distinfo b/compiler-rt-netbsd/distinfo
index cc46cf3ef8..038b1b52be 100644
--- a/compiler-rt-netbsd/distinfo
+++ b/compiler-rt-netbsd/distinfo
@@ -3,6 +3,9 @@ $NetBSD: distinfo,v 1.35 2015/09/11 01:21:57 tnn Exp $
 SHA1 (patch-cmake_config-ix.cmake) = a1814db3e044ce3954655fea1e157a96bfa8df2f
 SHA1 (patch-lib_fuzzer_tests_CMakeLists.txt) = 38ca750154dfc9843a56748078235824b772a147
 SHA1 (patch-lib_msan_msan.h) = ce3f544490aebc1db73be9e3388f0a9d31d5b369
-SHA1 (patch-lib_tsan_rtl_tsan__interceptors.cc) = 9ad8e5545c28ac0a284e557934712a8a7c949539
+SHA1 (patch-lib_sanitizer__common_sanitizer__allocator.cc) = 464615041890651425a1e298e4321683dde3b750
+SHA1 (patch-lib_sanitizer__common_sanitizer__allocator__internal.h) = 7f77138aa4249dcc9578a556bec0ba2af7a51133
+SHA1 (patch-lib_tsan_rtl_tsan__interceptors.cc) = 243e026dd9b159468911141013833e61eb8e42d1
 SHA1 (patch-lib_tsan_rtl_tsan__rtl.cc) = bc3d6aa81515ac4a4fc5b504e93b3ac8de355371
 SHA1 (patch-lib_tsan_rtl_tsan__rtl__amd64.S) = 6df0f2af44ebfec76d3b237c984eff63ee93b30f
+SHA1 (patch-test_tsan_atexit3.cc) = 5abc7ce8bfde2f6c41ad6dc70c6030a183b71f1b
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__allocator.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__allocator.cc
new file mode 100644
index 0000000000..0e58567535
--- /dev/null
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__allocator.cc
@@ -0,0 +1,30 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_allocator.cc.orig	2017-10-17 18:35:46.000000000 +0000
++++ lib/sanitizer_common/sanitizer_allocator.cc
+@@ -180,6 +180,25 @@ void InternalFree(void *addr, InternalAl
+ // LowLevelAllocator
+ static LowLevelAllocateCallback low_level_alloc_callback;
+ 
++int InternalReallocArr(void *addr, uptr count, uptr size,
++                       InternalAllocatorCache *cache) {
++  void *oaddr;
++  void *naddr = 0;
++
++  internal_memcpy(&oaddr, addr, sizeof(addr));
++  if (!count || !size) {
++    InternalFree(oaddr, cache);
++    internal_memcpy(addr, &naddr, sizeof(addr));
++    return 0;
++  }
++
++  naddr = InternalRealloc(oaddr, count * size, cache);
++  if (!naddr) return -1;
++
++  internal_memcpy(addr, &naddr, sizeof(addr));
++  return 0;
++}
++
+ void *LowLevelAllocator::Allocate(uptr size) {
+   // Align allocation size.
+   size = RoundUpTo(size, 8);
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__allocator__internal.h b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__allocator__internal.h
new file mode 100644
index 0000000000..184c13655c
--- /dev/null
+++ b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__allocator__internal.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_allocator_internal.h.orig	2017-10-17 18:35:46.000000000 +0000
++++ lib/sanitizer_common/sanitizer_allocator_internal.h
+@@ -57,6 +57,8 @@ void *InternalRealloc(void *p, uptr size
+ void *InternalCalloc(uptr countr, uptr size,
+                      InternalAllocatorCache *cache = nullptr);
+ void InternalFree(void *p, InternalAllocatorCache *cache = nullptr);
++int InternalReallocArr(void *p, uptr count, uptr size,
++                       InternalAllocatorCache *cache = nullptr);
+ InternalAllocator *internal_allocator();
+ 
+ enum InternalAllocEnum {
diff --git a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc b/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
index c33864f482..ba1d4f8481 100644
--- a/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
+++ b/compiler-rt-netbsd/patches/patch-lib_tsan_rtl_tsan__interceptors.cc
@@ -1,19 +1,19 @@
 $NetBSD$
 
---- lib/tsan/rtl/tsan_interceptors.cc.orig	2017-11-06 03:58:05.389006908 +0000
+--- lib/tsan/rtl/tsan_interceptors.cc.orig	2017-11-06 03:58:05.000000000 +0000
 +++ lib/tsan/rtl/tsan_interceptors.cc
-@@ -391,7 +391,28 @@ struct AtExitCtx {
+@@ -391,10 +391,26 @@ struct AtExitCtx {
    void *arg;
  };
  
 -static void at_exit_wrapper(void *arg) {
+-  ThreadState *thr = cur_thread();
+-  uptr pc = 0;
+-  Acquire(thr, pc, (uptr)arg);
 +static struct AtExitCtx **AtExitStack;
 +static int AtExitStackSize;
 +
 +static void at_exit_wrapper() {
-+  ThreadState *thr = cur_thread();
-+  uptr pc = 0;
-+
 +  // Pop AtExitCtx from the top of the stack of callback functions
 +  AtExitCtx *ctx = AtExitStack[AtExitStackSize - 1];
 +  --AtExitStackSize;
@@ -23,27 +23,28 @@ $NetBSD$
 +    Die();
 +  }
 +
-+  Acquire(thr, pc, (uptr)ctx);
++  Acquire(cur_thread(), (uptr)0, (uptr)ctx);
 +  ((void(*)())ctx->f)();
 +  InternalFree(ctx);
 +}
 +
 +static void cxa_at_exit_wrapper(void *arg) {
-   ThreadState *thr = cur_thread();
-   uptr pc = 0;
-   Acquire(thr, pc, (uptr)arg);
-@@ -430,7 +451,24 @@ static int setup_at_exit_wrapper(ThreadS
++  Acquire(cur_thread(), 0, (uptr)arg);
+   AtExitCtx *ctx = (AtExitCtx*)arg;
+   ((void(*)(void *arg))ctx->f)(ctx->arg);
+   InternalFree(ctx);
+@@ -430,7 +446,24 @@ static int setup_at_exit_wrapper(ThreadS
    // Memory allocation in __cxa_atexit will race with free during exit,
    // because we do not see synchronization around atexit callback list.
    ThreadIgnoreBegin(thr, pc);
 -  int res = REAL(__cxa_atexit)(at_exit_wrapper, ctx, dso);
 +  int res;
-+  if (dso == 0) {
++  if (!dso) {
 +    // NetBSD does not preserve the 2nd argument if dso is equal to 0
 +    // Store ctx in a local stack-like structure
 +    res = REAL(__cxa_atexit)((void (*)(void *a))at_exit_wrapper, 0, 0);
 +    // Push AtExitCtx on the top of the stack of callback functions
-+    if (res == 0) {
++    if (!res) {
 +      ++AtExitStackSize;
 +      if (InternalReallocArr(&AtExitStack, AtExitStackSize,
 +                             sizeof(struct AtExitCtx *))) {
diff --git a/compiler-rt-netbsd/patches/patch-test_tsan_atexit3.cc b/compiler-rt-netbsd/patches/patch-test_tsan_atexit3.cc
new file mode 100644
index 0000000000..e5b520a679
--- /dev/null
+++ b/compiler-rt-netbsd/patches/patch-test_tsan_atexit3.cc
@@ -0,0 +1,46 @@
+$NetBSD$
+
+--- test/tsan/atexit3.cc.orig	2017-11-06 18:32:33.221125749 +0000
++++ test/tsan/atexit3.cc
+@@ -0,0 +1,41 @@
++// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
++
++#include <stdio.h>
++#include <stdlib.h>
++
++static void atexit5() {
++  fprintf(stderr, "5");
++}
++
++static void atexit4() {
++  fprintf(stderr, "4");
++}
++
++static void atexit3() {
++  fprintf(stderr, "3");
++}
++
++static void atexit2() {
++  fprintf(stderr, "2");
++}
++
++static void atexit1() {
++  fprintf(stderr, "1");
++}
++
++static void atexit0() {
++  fprintf(stderr, "\n");
++}
++
++int main() {
++  atexit(atexit0);
++  atexit(atexit1);
++  atexit(atexit2);
++  atexit(atexit3);
++  atexit(atexit4);
++  atexit(atexit5);
++}
++
++// CHECK-NOT: FATAL: ThreadSanitizer
++// CHECK-NOT: WARNING: ThreadSanitizer
++// CHECK: 54321


Home | Main Index | Thread Index | Old Index