diff --git a/debian/changelog b/debian/changelog index d9ac3833..ebc7281e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,8 +2,11 @@ llvm-toolchain-3.9 (1:3.9.1-4) unstable; urgency=medium * d/p/amdgpu-regression.diff Fix a regression impacting mesa (Closes: #852616) + * d/p/esan-Fix-ESan-test-failure-on-Debian-Sid-bot*.diff: + cherry-pick upsream patch to make esan work with the new glibc + Thanks to Nobert Lange for investigating (Closes: #844092) - -- + -- Sylvestre Ledru Fri, 27 Jan 2017 11:02:15 +0100 llvm-toolchain-3.9 (1:3.9.1-3) unstable; urgency=medium diff --git a/debian/patches/esan-Fix-ESan-test-failure-on-Debian-Sid-bot.diff b/debian/patches/esan-Fix-ESan-test-failure-on-Debian-Sid-bot.diff new file mode 100644 index 00000000..9e00be40 --- /dev/null +++ b/debian/patches/esan-Fix-ESan-test-failure-on-Debian-Sid-bot.diff @@ -0,0 +1,103 @@ +From 2dca6dc37a0c7a7f2232677f0d8bc175f7e0aa1d Mon Sep 17 00:00:00 2001 +From: Qin Zhao +Date: Mon, 3 Oct 2016 20:03:10 +0000 +Subject: [PATCH] [esan] Fix ESan test failure on Debian Sid bot + +Summary: +Handles early allocation from dlsym by allocating memory from a local +static buffer. + +Reviewers: bruening + +Subscribers: kubabrecka + +Differential Revision: https://reviews.llvm.org/D25193 + +git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@283139 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + lib/esan/esan_interceptors.cpp | 42 ++++++++++++++++++++++++++++-------------- + 1 file changed, 28 insertions(+), 14 deletions(-) + +Index: llvm-toolchain-3.9-3.9.1/compiler-rt/lib/esan/esan_interceptors.cpp +=================================================================== +--- llvm-toolchain-3.9-3.9.1.orig/compiler-rt/lib/esan/esan_interceptors.cpp ++++ llvm-toolchain-3.9-3.9.1/compiler-rt/lib/esan/esan_interceptors.cpp +@@ -461,28 +461,35 @@ INTERCEPTOR(int, pthread_sigmask, int ho + // Malloc interceptors + //===----------------------------------------------------------------------===// + +-static char early_alloc_buf[128]; +-static bool used_early_alloc_buf; ++static const uptr early_alloc_buf_size = 1024; ++static uptr allocated_bytes; ++static char early_alloc_buf[early_alloc_buf_size]; ++ ++static bool isInEarlyAllocBuf(const void *ptr) { ++ return ((uptr)ptr >= (uptr)early_alloc_buf && ++ ((uptr)ptr - (uptr)early_alloc_buf) < sizeof(early_alloc_buf)); ++} + + static void *handleEarlyAlloc(uptr size) { + // If esan is initialized during an interceptor (which happens with some + // tcmalloc implementations that call pthread_mutex_lock), the call from +- // dlsym to calloc will deadlock. There is only one such calloc (dlsym +- // allocates a single pthread key), so we work around it by using a +- // static buffer for the calloc request. The loader currently needs +- // 32 bytes but we size at 128 to allow for future changes. ++ // dlsym to calloc will deadlock. ++ // dlsym may also call malloc before REAL(malloc) is retrieved from dlsym. ++ // We work around it by using a static buffer for the early malloc/calloc ++ // requests. + // This solution will also allow us to deliberately intercept malloc & family + // in the future (to perform tool actions on each allocation, without + // replacing the allocator), as it also solves the problem of intercepting + // calloc when it will itself be called before its REAL pointer is + // initialized. +- CHECK(!used_early_alloc_buf && size < sizeof(early_alloc_buf)); + // We do not handle multiple threads here. This only happens at process init + // time, and while it's possible for a shared library to create early threads + // that race here, we consider that to be a corner case extreme enough that + // it's not worth the effort to handle. +- used_early_alloc_buf = true; +- return (void *)early_alloc_buf; ++ void *mem = (void *)&early_alloc_buf[allocated_bytes]; ++ allocated_bytes += size; ++ CHECK_LT(allocated_bytes, early_alloc_buf_size); ++ return mem; + } + + INTERCEPTOR(void*, calloc, uptr size, uptr n) { +@@ -496,14 +503,20 @@ INTERCEPTOR(void*, calloc, uptr size, up + return res; + } + ++INTERCEPTOR(void*, malloc, uptr size) { ++ if (EsanDuringInit && REAL(malloc) == nullptr) ++ return handleEarlyAlloc(size); ++ void *ctx; ++ COMMON_INTERCEPTOR_ENTER(ctx, malloc, size); ++ return REAL(malloc)(size); ++} ++ + INTERCEPTOR(void, free, void *p) { + void *ctx; +- COMMON_INTERCEPTOR_ENTER(ctx, free, p); +- if (p == (void *)early_alloc_buf) { +- // We expect just a singleton use but we clear this for cleanliness. +- used_early_alloc_buf = false; ++ // There are only a few early allocation requests, so we simply skip the free. ++ if (isInEarlyAllocBuf(p)) + return; +- } ++ COMMON_INTERCEPTOR_ENTER(ctx, free, p); + REAL(free)(p); + } + +@@ -534,6 +547,7 @@ void initializeInterceptors() { + ESAN_MAYBE_INTERCEPT_PTHREAD_SIGMASK; + + INTERCEPT_FUNCTION(calloc); ++ INTERCEPT_FUNCTION(malloc); + INTERCEPT_FUNCTION(free); + + // TODO(bruening): intercept routines that other sanitizers intercept that diff --git a/debian/patches/esan-Fix-ESan-test-failure-on-Debian-Sid-bot2.diff b/debian/patches/esan-Fix-ESan-test-failure-on-Debian-Sid-bot2.diff new file mode 100644 index 00000000..79b9d56d --- /dev/null +++ b/debian/patches/esan-Fix-ESan-test-failure-on-Debian-Sid-bot2.diff @@ -0,0 +1,31 @@ +From 9b149609c0dc08dc75537c44d43038c0e34b1321 Mon Sep 17 00:00:00 2001 +From: Qin Zhao +Date: Fri, 7 Oct 2016 20:53:35 +0000 +Subject: [PATCH] [esan] Fix ESan test failure on Debian Sid bot + +Summary: Increase early allocation buffer size. + +Reviewers: bruening + +Subscribers: kubabrecka + +Differential Revision: https://reviews.llvm.org/D25380 + +git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@283598 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + lib/esan/esan_interceptors.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +Index: llvm-toolchain-3.9-3.9.1/compiler-rt/lib/esan/esan_interceptors.cpp +=================================================================== +--- llvm-toolchain-3.9-3.9.1.orig/compiler-rt/lib/esan/esan_interceptors.cpp ++++ llvm-toolchain-3.9-3.9.1/compiler-rt/lib/esan/esan_interceptors.cpp +@@ -461,7 +461,7 @@ INTERCEPTOR(int, pthread_sigmask, int ho + // Malloc interceptors + //===----------------------------------------------------------------------===// + +-static const uptr early_alloc_buf_size = 1024; ++static const uptr early_alloc_buf_size = 4096; + static uptr allocated_bytes; + static char early_alloc_buf[early_alloc_buf_size]; + diff --git a/debian/patches/series b/debian/patches/series index 3845eea4..1e40a91d 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -45,3 +45,5 @@ clang-arm-default-vfp3-on-armv7a.patch lldb-addversion-suffix-to-llvm-server-exec.patch lldb-server-link.diff amdgpu-regression.diff +esan-Fix-ESan-test-failure-on-Debian-Sid-bot.diff +esan-Fix-ESan-test-failure-on-Debian-Sid-bot2.diff