Backport 82150606fb11d28813ae6

This commit is contained in:
sergesanspaille 2021-05-10 20:10:48 +02:00
parent 4c0e4f5490
commit fcb75a9399
2 changed files with 77 additions and 1 deletions

View File

@ -0,0 +1,72 @@
From c85d1e10cad1fea2c43f9ec5332761d2ca725721 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka@google.com>
Date: Fri, 16 Apr 2021 09:50:24 -0700
Subject: [PATCH 2/2] [PATCH][compiler-rt] Sanitizer built against glibc 2.34
doesn't work
As mentioned in https://gcc.gnu.org/PR100114 , glibc starting with the
https://sourceware.org/git/?p=glibc.git;a=commit;h=6c57d320484988e87e446e2e60ce42816bf51d53
change doesn't define SIGSTKSZ and MINSIGSTKSZ macros to constants, but to sysconf function call.
sanitizer_posix_libcdep.cpp has
static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
which is generally fine, just means that when SIGSTKSZ is not a compile time constant will be initialized later.
The problem is that kAltStackSize is used in SetAlternateSignalStack which is called very early, from .preinit_array
initialization, i.e. far before file scope variables are constructed, which means it is not initialized and
mmapping 0 will fail:
==145==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
Here is one possible fix, another one could be to make kAltStackSize a preprocessor macro if _SG_SIGSTKSZ is defined
(but perhaps with having an automatic const variable initialized to it so that sysconf isn't at least called twice
during SetAlternateSignalStack.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D100645
(cherry picked from commit 82150606fb11d28813ae6da1101f5bda638165fe)
---
compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
index d29438c..2b10bdd 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
@@ -165,7 +165,11 @@ bool SupportsColoredOutput(fd_t fd) {
#if !SANITIZER_GO
// TODO(glider): different tools may require different altstack size.
-static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
+static uptr GetAltStackSize() {
+ // SIGSTKSZ is not enough.
+ static const uptr kAltStackSize = SIGSTKSZ * 4;
+ return kAltStackSize;
+}
void SetAlternateSignalStack() {
stack_t altstack, oldstack;
@@ -176,10 +180,10 @@ void SetAlternateSignalStack() {
// TODO(glider): the mapped stack should have the MAP_STACK flag in the
// future. It is not required by man 2 sigaltstack now (they're using
// malloc()).
- void* base = MmapOrDie(kAltStackSize, __func__);
+ void *base = MmapOrDie(GetAltStackSize(), __func__);
altstack.ss_sp = (char*) base;
altstack.ss_flags = 0;
- altstack.ss_size = kAltStackSize;
+ altstack.ss_size = GetAltStackSize();
CHECK_EQ(0, sigaltstack(&altstack, nullptr));
}
@@ -187,7 +191,7 @@ void UnsetAlternateSignalStack() {
stack_t altstack, oldstack;
altstack.ss_sp = nullptr;
altstack.ss_flags = SS_DISABLE;
- altstack.ss_size = kAltStackSize; // Some sane value required on Darwin.
+ altstack.ss_size = GetAltStackSize(); // Some sane value required on Darwin.
CHECK_EQ(0, sigaltstack(&altstack, &oldstack));
UnmapOrDie(oldstack.ss_sp, oldstack.ss_size);
}
--
1.8.3.1

View File

@ -10,7 +10,7 @@
Name: compiler-rt
Version: 12.0.0%{?rc_ver:~rc%{rc_ver}}
Release: 1%{?dist}
Release: 2%{?dist}
Summary: LLVM "compiler-rt" runtime libraries
License: NCSA or MIT
@ -20,6 +20,7 @@ Source1: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{versio
Source2: tstellar-gpg-key.asc
Patch0: 0001-PATCH-compiler-rt-Workaround-libstdc-limitation-wrt..patch
Patch1: 0002-PATCH-compiler-rt-Sanitizer-built-against-glibc-2.34.patch
BuildRequires: gcc
BuildRequires: gcc-c++
@ -109,6 +110,9 @@ popd
%endif
%changelog
* Mon May 10 2021 sguelton@redhat.com - 12.0.0-2
- Backport 82150606fb11d28813ae6
* Fri Apr 16 2021 Tom Stellard <tstellar@redhat.com> - 12.0.0-1
- 12.0.0 Release