From a5766d2fc2021a510f3f267ec385ee7803407d0d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 5 Nov 2016 13:36:50 +0000 Subject: [PATCH 1/9] fix package name --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 3babd56d..eac14a0d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,6 @@ llvm-toolchain-3.8 (1:3.8.1-14) unstable; urgency=medium - * libclang-common-3.9-dev: missing multilib binaries for the sanatizer + * libclang-common-3.8-dev: missing multilib binaries for the sanatizer libraries (Closes: #841923) Many thanks to Norbert Lange for the changes From d2b338b512db5dcc05a3755374794d4e81625b7d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 5 Nov 2016 13:38:47 +0000 Subject: [PATCH 2/9] fix typo --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index eac14a0d..bccd342e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,6 @@ llvm-toolchain-3.8 (1:3.8.1-14) unstable; urgency=medium - * libclang-common-3.8-dev: missing multilib binaries for the sanatizer + * libclang-common-3.8-dev: missing multilib binaries for the sanitizer libraries (Closes: #841923) Many thanks to Norbert Lange for the changes From 96c9df4917d8272c21e6a704bd03965281c94d08 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 6 Nov 2016 14:44:45 +0000 Subject: [PATCH 3/9] Limit build-deps on g++-multilib where it is available: amd64 i386 kfreebsd-amd64 mips mips64 mips64el mipsel powerpc ppc64 s390 s390x sparc sparc64 x32 --- debian/changelog | 8 ++++++++ debian/control | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index bccd342e..b68e5a88 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +llvm-toolchain-3.8 (1:3.8.1-15) unstable; urgency=medium + + * Limit build-deps on g++-multilib where it is available: + amd64 i386 kfreebsd-amd64 mips mips64 mips64el mipsel powerpc ppc64 s390 + s390x sparc sparc64 x32 + + -- Sylvestre Ledru Sun, 06 Nov 2016 15:44:34 +0100 + llvm-toolchain-3.8 (1:3.8.1-14) unstable; urgency=medium * libclang-common-3.8-dev: missing multilib binaries for the sanitizer diff --git a/debian/control b/debian/control index f9c5319c..66c2dd35 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 9.0), flex, bison, dejagnu, tcl, expect, libedit-dev, swig, python-six, python-sphinx, ocaml-nox, binutils-dev, libjsoncpp-dev, lcov, procps, help2man, dh-ocaml, zlib1g-dev, - g++-multilib + g++-multilib [amd64 i386 kfreebsd-amd64 mips mips64 mips64el mipsel powerpc ppc64 s390 s390x sparc sparc64 x32] Build-Conflicts: oprofile, ocaml, libllvm-3.4-ocaml-dev, libllvm-3.5-ocaml-dev, libllvm-3.8-ocaml-dev Standards-Version: 3.9.8 From b5789da75929b89b67044146d7bb08c1ed9e2c3e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 6 Nov 2016 19:52:51 +0000 Subject: [PATCH 4/9] add <\!cross> in the build dep options --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 66c2dd35..80c274d8 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 9.0), flex, bison, dejagnu, tcl, expect, libedit-dev, swig, python-six, python-sphinx, ocaml-nox, binutils-dev, libjsoncpp-dev, lcov, procps, help2man, dh-ocaml, zlib1g-dev, - g++-multilib [amd64 i386 kfreebsd-amd64 mips mips64 mips64el mipsel powerpc ppc64 s390 s390x sparc sparc64 x32] + g++-multilib [amd64 i386 kfreebsd-amd64 mips mips64 mips64el mipsel powerpc ppc64 s390 s390x sparc sparc64 x32] Build-Conflicts: oprofile, ocaml, libllvm-3.4-ocaml-dev, libllvm-3.5-ocaml-dev, libllvm-3.8-ocaml-dev Standards-Version: 3.9.8 From ce0db5670a07b6facfb25fdd57f722bf1f039c40 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 11 Nov 2016 15:14:50 +0000 Subject: [PATCH 5/9] Fix segfaults in the memory sanitizers (Closes: #842642) Caused by the newer glibc. Many thanks for Nobert Lange for everything --- debian/changelog | 7 + debian/patches/series | 3 + ...ream-asan-msan-fix-reallocation-logic.diff | 54 ++++++++ .../upstream-fix-asan-initialization.diff | 102 ++++++++++++++ ...m-msan-prevent-initialization-failure.diff | 124 ++++++++++++++++++ 5 files changed, 290 insertions(+) create mode 100644 debian/patches/upstream-asan-msan-fix-reallocation-logic.diff create mode 100644 debian/patches/upstream-fix-asan-initialization.diff create mode 100644 debian/patches/upstream-msan-prevent-initialization-failure.diff diff --git a/debian/changelog b/debian/changelog index b68e5a88..9718b17e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +llvm-toolchain-3.8 (1:3.8.1-16) unstable; urgency=medium + + * Fix segfaults in the memory sanitizers (Closes: #842642) + Caused by the newer glibc. Many thanks for Nobert Lange for everything + + -- Sylvestre Ledru Fri, 11 Nov 2016 16:14:31 +0100 + llvm-toolchain-3.8 (1:3.8.1-15) unstable; urgency=medium * Limit build-deps on g++-multilib where it is available: diff --git a/debian/patches/series b/debian/patches/series index b2ecdd27..54a1f0c3 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -51,3 +51,6 @@ lldb-arm64.diff clang-tidy-run-bin.diff silent-llvm-symbolizer.diff +upstream-asan-msan-fix-reallocation-logic.diff +upstream-fix-asan-initialization.diff +upstream-msan-prevent-initialization-failure.diff diff --git a/debian/patches/upstream-asan-msan-fix-reallocation-logic.diff b/debian/patches/upstream-asan-msan-fix-reallocation-logic.diff new file mode 100644 index 00000000..70c352d3 --- /dev/null +++ b/debian/patches/upstream-asan-msan-fix-reallocation-logic.diff @@ -0,0 +1,54 @@ +From c8a185bc3169b0a6d2cd8beedc77033461830037 Mon Sep 17 00:00:00 2001 +From: Maxim Ostapenko +Date: Mon, 26 Sep 2016 08:11:21 +0000 +Subject: [PATCH] [asan, msan] Fix reallocation logic when + IsInDlsymAllocPool(ptr) is true. + +git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282389 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + lib/asan/asan_malloc_linux.cc | 8 +++++--- + lib/msan/msan_interceptors.cc | 8 +++++++- + 2 files changed, 12 insertions(+), 4 deletions(-) + +diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cc b/compiler-rt/lib/asan/asan_malloc_linux.cc +index d7a22d6..a78767c 100644 +--- a/compiler-rt/lib/asan/asan_malloc_linux.cc ++++ b/compiler-rt/lib/asan/asan_malloc_linux.cc +@@ -79,10 +79,12 @@ INTERCEPTOR(void*, realloc, void *ptr, uptr size) { + uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym; + uptr copy_size = Min(size, kDlsymAllocPoolSize - offset); + void *new_ptr; +- if (UNLIKELY(!asan_inited)) ++ if (UNLIKELY(!asan_inited)) { + new_ptr = AllocateFromLocalPool(size); +- else +- new_ptr = asan_malloc(size, &stack); ++ } else { ++ copy_size = size; ++ new_ptr = asan_malloc(copy_size, &stack); ++ } + internal_memcpy(new_ptr, ptr, copy_size); + return new_ptr; + } +diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc +index 2aeaef4..93b93ae 100644 +--- a/compiler-rt/lib/msan/msan_interceptors.cc ++++ b/compiler-rt/lib/msan/msan_interceptors.cc +@@ -935,7 +935,13 @@ INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) { + if (UNLIKELY(IsInDlsymAllocPool(ptr))) { + uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym; + uptr copy_size = Min(size, kDlsymAllocPoolSize - offset); +- void *new_ptr = AllocateFromLocalPool(size); ++ void *new_ptr; ++ if (UNLIKELY(!msan_inited)) { ++ new_ptr = AllocateFromLocalPool(copy_size); ++ } else { ++ copy_size = size; ++ new_ptr = MsanReallocate(&stack, ptr, copy_size, sizeof(u64), false); ++ } + internal_memcpy(new_ptr, ptr, copy_size); + return new_ptr; + } +-- +2.10.2 + diff --git a/debian/patches/upstream-fix-asan-initialization.diff b/debian/patches/upstream-fix-asan-initialization.diff new file mode 100644 index 00000000..d9e71178 --- /dev/null +++ b/debian/patches/upstream-fix-asan-initialization.diff @@ -0,0 +1,102 @@ +From 570ee9dd7a6f90b0370a86535cbde6738d0ccf67 Mon Sep 17 00:00:00 2001 +From: Maxim Ostapenko +Date: Mon, 16 May 2016 07:20:53 +0000 +Subject: [PATCH] [asan] Fix asan initialization failure with newer (2.23+) + glibc in use. + +This patch tries to fix https://llvm.org/bugs/show_bug.cgi?id=27310 by using the same hack for malloc as we use for calloc: allocate corresponding memory from internal buffer when ASan is not initialized. +This way we could avoid nasty '==6987==AddressSanitizer CHECK failed: ../../../../libsanitizer/asan/asan_rtl.cc:556 "((!asan_init_is_running && "ASan init calls itself!")) != (0)" (0x0, 0x0)' errors in +environments with glibc 2.23+ in use, where _dl_signal_error, called from dlsym for undefined symbols calls malloc in order to get a buffer for error message. + +Differential Revision: http://reviews.llvm.org/D20235 + + +git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269633 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + lib/asan/asan_malloc_linux.cc | 42 ++++++++++++++++++++++++------------------ + 1 file changed, 24 insertions(+), 18 deletions(-) + +diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cc b/compiler-rt/lib/asan/asan_malloc_linux.cc +index a81f19f..162abd2 100644 +--- a/compiler-rt/lib/asan/asan_malloc_linux.cc ++++ b/compiler-rt/lib/asan/asan_malloc_linux.cc +@@ -26,52 +26,58 @@ + // ---------------------- Replacement functions ---------------- {{{1 + using namespace __asan; // NOLINT + +-static const uptr kCallocPoolSize = 1024; +-static uptr calloc_memory_for_dlsym[kCallocPoolSize]; ++static uptr allocated_for_dlsym; ++static const uptr kDlsymAllocPoolSize = 1024; ++static uptr alloc_memory_for_dlsym[kDlsymAllocPoolSize]; + +-static bool IsInCallocPool(const void *ptr) { +- sptr off = (sptr)ptr - (sptr)calloc_memory_for_dlsym; +- return 0 <= off && off < (sptr)kCallocPoolSize; ++static bool IsInDlsymAllocPool(const void *ptr) { ++ uptr off = (uptr)ptr - (uptr)alloc_memory_for_dlsym; ++ return off < sizeof(alloc_memory_for_dlsym); ++} ++ ++static void *AllocateFromLocalPool(uptr size_in_bytes) { ++ uptr size_in_words = RoundUpTo(size_in_bytes, kWordSize) / kWordSize; ++ void *mem = (void*)&alloc_memory_for_dlsym[allocated_for_dlsym]; ++ allocated_for_dlsym += size_in_words; ++ CHECK_LT(allocated_for_dlsym, kDlsymAllocPoolSize); ++ return mem; + } + + INTERCEPTOR(void, free, void *ptr) { + GET_STACK_TRACE_FREE; +- if (UNLIKELY(IsInCallocPool(ptr))) ++ if (UNLIKELY(IsInDlsymAllocPool(ptr))) + return; + asan_free(ptr, &stack, FROM_MALLOC); + } + + INTERCEPTOR(void, cfree, void *ptr) { + GET_STACK_TRACE_FREE; +- if (UNLIKELY(IsInCallocPool(ptr))) ++ if (UNLIKELY(IsInDlsymAllocPool(ptr))) + return; + asan_free(ptr, &stack, FROM_MALLOC); + } + + INTERCEPTOR(void*, malloc, uptr size) { ++ if (UNLIKELY(!asan_inited)) ++ // Hack: dlsym calls malloc before REAL(malloc) is retrieved from dlsym. ++ return AllocateFromLocalPool(size); + GET_STACK_TRACE_MALLOC; + return asan_malloc(size, &stack); + } + + INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) { +- if (UNLIKELY(!asan_inited)) { ++ if (UNLIKELY(!asan_inited)) + // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym. +- static uptr allocated; +- uptr size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize; +- void *mem = (void*)&calloc_memory_for_dlsym[allocated]; +- allocated += size_in_words; +- CHECK(allocated < kCallocPoolSize); +- return mem; +- } ++ return AllocateFromLocalPool(nmemb * size); + GET_STACK_TRACE_MALLOC; + return asan_calloc(nmemb, size, &stack); + } + + INTERCEPTOR(void*, realloc, void *ptr, uptr size) { + GET_STACK_TRACE_MALLOC; +- if (UNLIKELY(IsInCallocPool(ptr))) { +- uptr offset = (uptr)ptr - (uptr)calloc_memory_for_dlsym; +- uptr copy_size = Min(size, kCallocPoolSize - offset); ++ if (UNLIKELY(IsInDlsymAllocPool(ptr))) { ++ uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym; ++ uptr copy_size = Min(size, kDlsymAllocPoolSize - offset); + void *new_ptr = asan_malloc(size, &stack); + internal_memcpy(new_ptr, ptr, copy_size); + return new_ptr; +-- +2.10.2 + diff --git a/debian/patches/upstream-msan-prevent-initialization-failure.diff b/debian/patches/upstream-msan-prevent-initialization-failure.diff new file mode 100644 index 00000000..ba52b590 --- /dev/null +++ b/debian/patches/upstream-msan-prevent-initialization-failure.diff @@ -0,0 +1,124 @@ +From 827ea206c1078fc7c7da287984a7ba4563390589 Mon Sep 17 00:00:00 2001 +From: Maxim Ostapenko +Date: Fri, 23 Sep 2016 07:40:55 +0000 +Subject: [PATCH] [msan] Prevent initialization failure with newer (2.23+) + glibc in use. + +This patch is pretty the same as http://reviews.llvm.org/D20235 that we used +for ASan. Using the same hack for MSan fixes its initialization with newer +Glibc in use. + +Differential Revision: https://reviews.llvm.org/D24736 + + +git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282232 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + lib/asan/asan_malloc_linux.cc | 6 +++++- + lib/msan/msan_interceptors.cc | 43 +++++++++++++++++++++++++++++++------------ + 2 files changed, 36 insertions(+), 13 deletions(-) + +diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cc b/compiler-rt/lib/asan/asan_malloc_linux.cc +index 162abd2..d7a22d6 100644 +--- a/compiler-rt/lib/asan/asan_malloc_linux.cc ++++ b/compiler-rt/lib/asan/asan_malloc_linux.cc +@@ -78,7 +78,11 @@ INTERCEPTOR(void*, realloc, void *ptr, uptr size) { + if (UNLIKELY(IsInDlsymAllocPool(ptr))) { + uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym; + uptr copy_size = Min(size, kDlsymAllocPoolSize - offset); +- void *new_ptr = asan_malloc(size, &stack); ++ void *new_ptr; ++ if (UNLIKELY(!asan_inited)) ++ new_ptr = AllocateFromLocalPool(size); ++ else ++ new_ptr = asan_malloc(size, &stack); + internal_memcpy(new_ptr, ptr, copy_size); + return new_ptr; + } +diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc +index f23d3ee..2aeaef4 100644 +--- a/compiler-rt/lib/msan/msan_interceptors.cc ++++ b/compiler-rt/lib/msan/msan_interceptors.cc +@@ -64,6 +64,23 @@ bool IsInInterceptorScope() { + return in_interceptor_scope; + } + ++static uptr allocated_for_dlsym; ++static const uptr kDlsymAllocPoolSize = 1024; ++static uptr alloc_memory_for_dlsym[kDlsymAllocPoolSize]; ++ ++static bool IsInDlsymAllocPool(const void *ptr) { ++ uptr off = (uptr)ptr - (uptr)alloc_memory_for_dlsym; ++ return off < sizeof(alloc_memory_for_dlsym); ++} ++ ++static void *AllocateFromLocalPool(uptr size_in_bytes) { ++ uptr size_in_words = RoundUpTo(size_in_bytes, kWordSize) / kWordSize; ++ void *mem = (void *)&alloc_memory_for_dlsym[allocated_for_dlsym]; ++ allocated_for_dlsym += size_in_words; ++ CHECK_LT(allocated_for_dlsym, kDlsymAllocPoolSize); ++ return mem; ++} ++ + #define ENSURE_MSAN_INITED() do { \ + CHECK(!msan_init_is_running); \ + if (!msan_inited) { \ +@@ -227,14 +244,14 @@ INTERCEPTOR(void *, pvalloc, SIZE_T size) { + + INTERCEPTOR(void, free, void *ptr) { + GET_MALLOC_STACK_TRACE; +- if (!ptr) return; ++ if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return; + MsanDeallocate(&stack, ptr); + } + + #if !SANITIZER_FREEBSD + INTERCEPTOR(void, cfree, void *ptr) { + GET_MALLOC_STACK_TRACE; +- if (!ptr) return; ++ if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return; + MsanDeallocate(&stack, ptr); + } + #define MSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree) +@@ -907,27 +924,29 @@ INTERCEPTOR(int, epoll_pwait, int epfd, void *events, int maxevents, + + INTERCEPTOR(void *, calloc, SIZE_T nmemb, SIZE_T size) { + GET_MALLOC_STACK_TRACE; +- if (UNLIKELY(!msan_inited)) { ++ if (UNLIKELY(!msan_inited)) + // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym. +- const SIZE_T kCallocPoolSize = 1024; +- static uptr calloc_memory_for_dlsym[kCallocPoolSize]; +- static SIZE_T allocated; +- SIZE_T size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize; +- void *mem = (void*)&calloc_memory_for_dlsym[allocated]; +- allocated += size_in_words; +- CHECK(allocated < kCallocPoolSize); +- return mem; +- } ++ return AllocateFromLocalPool(nmemb * size); + return MsanCalloc(&stack, nmemb, size); + } + + INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) { + GET_MALLOC_STACK_TRACE; ++ if (UNLIKELY(IsInDlsymAllocPool(ptr))) { ++ uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym; ++ uptr copy_size = Min(size, kDlsymAllocPoolSize - offset); ++ void *new_ptr = AllocateFromLocalPool(size); ++ internal_memcpy(new_ptr, ptr, copy_size); ++ return new_ptr; ++ } + return MsanReallocate(&stack, ptr, size, sizeof(u64), false); + } + + INTERCEPTOR(void *, malloc, SIZE_T size) { + GET_MALLOC_STACK_TRACE; ++ if (UNLIKELY(!msan_inited)) ++ // Hack: dlsym calls malloc before REAL(malloc) is retrieved from dlsym. ++ return AllocateFromLocalPool(size); + return MsanReallocate(&stack, nullptr, size, sizeof(u64), false); + } + +-- +2.10.2 + From 7edcbc81fc4ed3b071852acf8428e74415246a85 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 11 Nov 2016 15:17:02 +0000 Subject: [PATCH 6/9] Enable the sanitizers testsuite --- debian/changelog | 1 + debian/rules | 3 +++ 2 files changed, 4 insertions(+) diff --git a/debian/changelog b/debian/changelog index 9718b17e..8156d8a7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ llvm-toolchain-3.8 (1:3.8.1-16) unstable; urgency=medium * Fix segfaults in the memory sanitizers (Closes: #842642) Caused by the newer glibc. Many thanks for Nobert Lange for everything + * Enable the sanitizers testsuite -- Sylvestre Ledru Fri, 11 Nov 2016 16:14:31 +0100 diff --git a/debian/rules b/debian/rules index d553e734..2e77ffaa 100755 --- a/debian/rules +++ b/debian/rules @@ -498,6 +498,9 @@ endif # Clang tests (CMake) $(MAKE) $(NJOBS) -C $(TARGET_BUILD) check-clang || true +# Sanitizer + $(MAKE) $(NJOBS) -C $(TARGET_BUILD) check-sanitize || true + # LLDB tests (CMake) ifeq (,$(filter $(DEB_HOST_ARCH), $(LLDB_DISABLE_ARCHS) armhf armel)) ifneq (,$(filter codecoverage,$(DEB_BUILD_OPTIONS))) From 42d0ccfc407a5f5b6cce790e18fa96653e208a51 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 11 Nov 2016 15:59:13 +0000 Subject: [PATCH 7/9] fix the patches --- debian/patches/series | 5 +- .../upstream-fix-asan-initialization.diff | 102 ------------------ 2 files changed, 2 insertions(+), 105 deletions(-) delete mode 100644 debian/patches/upstream-fix-asan-initialization.diff diff --git a/debian/patches/series b/debian/patches/series index 54a1f0c3..7e03b3ac 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -49,8 +49,7 @@ asan-glibc-2.24.diff lldb-dont-assume-64bit-systems-are-all-x86-64.patch lldb-arm64.diff clang-tidy-run-bin.diff - silent-llvm-symbolizer.diff -upstream-asan-msan-fix-reallocation-logic.diff -upstream-fix-asan-initialization.diff upstream-msan-prevent-initialization-failure.diff +upstream-asan-msan-fix-reallocation-logic.diff + diff --git a/debian/patches/upstream-fix-asan-initialization.diff b/debian/patches/upstream-fix-asan-initialization.diff deleted file mode 100644 index d9e71178..00000000 --- a/debian/patches/upstream-fix-asan-initialization.diff +++ /dev/null @@ -1,102 +0,0 @@ -From 570ee9dd7a6f90b0370a86535cbde6738d0ccf67 Mon Sep 17 00:00:00 2001 -From: Maxim Ostapenko -Date: Mon, 16 May 2016 07:20:53 +0000 -Subject: [PATCH] [asan] Fix asan initialization failure with newer (2.23+) - glibc in use. - -This patch tries to fix https://llvm.org/bugs/show_bug.cgi?id=27310 by using the same hack for malloc as we use for calloc: allocate corresponding memory from internal buffer when ASan is not initialized. -This way we could avoid nasty '==6987==AddressSanitizer CHECK failed: ../../../../libsanitizer/asan/asan_rtl.cc:556 "((!asan_init_is_running && "ASan init calls itself!")) != (0)" (0x0, 0x0)' errors in -environments with glibc 2.23+ in use, where _dl_signal_error, called from dlsym for undefined symbols calls malloc in order to get a buffer for error message. - -Differential Revision: http://reviews.llvm.org/D20235 - - -git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269633 91177308-0d34-0410-b5e6-96231b3b80d8 ---- - lib/asan/asan_malloc_linux.cc | 42 ++++++++++++++++++++++++------------------ - 1 file changed, 24 insertions(+), 18 deletions(-) - -diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cc b/compiler-rt/lib/asan/asan_malloc_linux.cc -index a81f19f..162abd2 100644 ---- a/compiler-rt/lib/asan/asan_malloc_linux.cc -+++ b/compiler-rt/lib/asan/asan_malloc_linux.cc -@@ -26,52 +26,58 @@ - // ---------------------- Replacement functions ---------------- {{{1 - using namespace __asan; // NOLINT - --static const uptr kCallocPoolSize = 1024; --static uptr calloc_memory_for_dlsym[kCallocPoolSize]; -+static uptr allocated_for_dlsym; -+static const uptr kDlsymAllocPoolSize = 1024; -+static uptr alloc_memory_for_dlsym[kDlsymAllocPoolSize]; - --static bool IsInCallocPool(const void *ptr) { -- sptr off = (sptr)ptr - (sptr)calloc_memory_for_dlsym; -- return 0 <= off && off < (sptr)kCallocPoolSize; -+static bool IsInDlsymAllocPool(const void *ptr) { -+ uptr off = (uptr)ptr - (uptr)alloc_memory_for_dlsym; -+ return off < sizeof(alloc_memory_for_dlsym); -+} -+ -+static void *AllocateFromLocalPool(uptr size_in_bytes) { -+ uptr size_in_words = RoundUpTo(size_in_bytes, kWordSize) / kWordSize; -+ void *mem = (void*)&alloc_memory_for_dlsym[allocated_for_dlsym]; -+ allocated_for_dlsym += size_in_words; -+ CHECK_LT(allocated_for_dlsym, kDlsymAllocPoolSize); -+ return mem; - } - - INTERCEPTOR(void, free, void *ptr) { - GET_STACK_TRACE_FREE; -- if (UNLIKELY(IsInCallocPool(ptr))) -+ if (UNLIKELY(IsInDlsymAllocPool(ptr))) - return; - asan_free(ptr, &stack, FROM_MALLOC); - } - - INTERCEPTOR(void, cfree, void *ptr) { - GET_STACK_TRACE_FREE; -- if (UNLIKELY(IsInCallocPool(ptr))) -+ if (UNLIKELY(IsInDlsymAllocPool(ptr))) - return; - asan_free(ptr, &stack, FROM_MALLOC); - } - - INTERCEPTOR(void*, malloc, uptr size) { -+ if (UNLIKELY(!asan_inited)) -+ // Hack: dlsym calls malloc before REAL(malloc) is retrieved from dlsym. -+ return AllocateFromLocalPool(size); - GET_STACK_TRACE_MALLOC; - return asan_malloc(size, &stack); - } - - INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) { -- if (UNLIKELY(!asan_inited)) { -+ if (UNLIKELY(!asan_inited)) - // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym. -- static uptr allocated; -- uptr size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize; -- void *mem = (void*)&calloc_memory_for_dlsym[allocated]; -- allocated += size_in_words; -- CHECK(allocated < kCallocPoolSize); -- return mem; -- } -+ return AllocateFromLocalPool(nmemb * size); - GET_STACK_TRACE_MALLOC; - return asan_calloc(nmemb, size, &stack); - } - - INTERCEPTOR(void*, realloc, void *ptr, uptr size) { - GET_STACK_TRACE_MALLOC; -- if (UNLIKELY(IsInCallocPool(ptr))) { -- uptr offset = (uptr)ptr - (uptr)calloc_memory_for_dlsym; -- uptr copy_size = Min(size, kCallocPoolSize - offset); -+ if (UNLIKELY(IsInDlsymAllocPool(ptr))) { -+ uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym; -+ uptr copy_size = Min(size, kDlsymAllocPoolSize - offset); - void *new_ptr = asan_malloc(size, &stack); - internal_memcpy(new_ptr, ptr, copy_size); - return new_ptr; --- -2.10.2 - From 849a2e688f1950deae10c439d5867b128648baab Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 11 Nov 2016 17:45:54 +0000 Subject: [PATCH 8/9] fix a typo in the check sanitizer --- debian/rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/rules b/debian/rules index 2e77ffaa..e55634c5 100755 --- a/debian/rules +++ b/debian/rules @@ -499,7 +499,7 @@ endif $(MAKE) $(NJOBS) -C $(TARGET_BUILD) check-clang || true # Sanitizer - $(MAKE) $(NJOBS) -C $(TARGET_BUILD) check-sanitize || true + $(MAKE) $(NJOBS) -C $(TARGET_BUILD) check-sanitizer || true # LLDB tests (CMake) ifeq (,$(filter $(DEB_HOST_ARCH), $(LLDB_DISABLE_ARCHS) armhf armel)) From 7a170d08f2b6b52b0c4a3014aff739f04cc82e3d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 11 Nov 2016 17:52:51 +0000 Subject: [PATCH 9/9] force the lang to be english and the system. Can cause issue with parsing french for example --- debian/patches/lit-force-lang.diff | 13 +++++++++++++ debian/patches/series | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 debian/patches/lit-force-lang.diff diff --git a/debian/patches/lit-force-lang.diff b/debian/patches/lit-force-lang.diff new file mode 100644 index 00000000..37a5d2cd --- /dev/null +++ b/debian/patches/lit-force-lang.diff @@ -0,0 +1,13 @@ +Index: llvm-toolchain-3.8-3.8.1/projects/compiler-rt/test/lit.common.cfg +=================================================================== +--- llvm-toolchain-3.8-3.8.1.orig/projects/compiler-rt/test/lit.common.cfg ++++ llvm-toolchain-3.8-3.8.1/projects/compiler-rt/test/lit.common.cfg +@@ -120,7 +120,7 @@ def is_linux_lto_supported(): + if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')): + return False + +- ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE) ++ ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'}) + ld_out = ld_cmd.stdout.read().decode() + ld_cmd.wait() + diff --git a/debian/patches/series b/debian/patches/series index 7e03b3ac..c2845b92 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -52,4 +52,4 @@ clang-tidy-run-bin.diff silent-llvm-symbolizer.diff upstream-msan-prevent-initialization-failure.diff upstream-asan-msan-fix-reallocation-logic.diff - +lit-force-lang.diff