Blame SOURCES/0003-PATCH-compiler-rt-Prevent-introduction-of-a-dependen.patch

c047fc
From 96339090681ae1dd9afe186ea14a460b61794707 Mon Sep 17 00:00:00 2001
c047fc
From: serge-sans-paille <sguelton@redhat.com>
c047fc
Date: Tue, 11 May 2021 14:38:21 +0200
c047fc
Subject: [PATCH][compiler-rt] Prevent introduction of a dependency of
c047fc
 libasan.a on libstdc++
c047fc
c047fc
This an attempt to fix an issue introduced by https://reviews.llvm.org/D70662
c047fc
c047fc
Function-scope static initialization are guarded in C++, so we should probably
c047fc
not use it because it introduces a dependency on __cxa_guard* symbols.
c047fc
In the context of clang, libasan is linked statically, and it currently needs to
c047fc
the odd situation where compiling C code with clang and asan requires -lstdc++.
c047fc
c047fc
I'm unsure of the portability requirements, providing a potential solution in
c047fc
this review.
c047fc
c047fc
Differential Revision: https://reviews.llvm.org/D102475
c047fc
---
c047fc
 compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp | 12 +++++++++---
c047fc
 1 file changed, 9 insertions(+), 3 deletions(-)
c047fc
c047fc
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
c047fc
index 2b10bdd..818f1af 100644
c047fc
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
c047fc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
c047fc
@@ -15,6 +15,7 @@
c047fc
 
c047fc
 #if SANITIZER_POSIX
c047fc
 
c047fc
+#include "sanitizer_atomic.h"
c047fc
 #include "sanitizer_common.h"
c047fc
 #include "sanitizer_flags.h"
c047fc
 #include "sanitizer_platform_limits_netbsd.h"
c047fc
@@ -166,9 +167,14 @@ bool SupportsColoredOutput(fd_t fd) {
c047fc
 #if !SANITIZER_GO
c047fc
 // TODO(glider): different tools may require different altstack size.
c047fc
 static uptr GetAltStackSize() {
c047fc
-  // SIGSTKSZ is not enough.
c047fc
-  static const uptr kAltStackSize = SIGSTKSZ * 4;
c047fc
-  return kAltStackSize;
c047fc
+  static atomic_uintptr_t kAltStackSize{0};
c047fc
+  uptr ret = atomic_load(&kAltStackSize, memory_order_relaxed);
c047fc
+  if (ret == 0) {
c047fc
+    // SIGSTKSZ is not enough.
c047fc
+    ret = SIGSTKSZ * 4;
c047fc
+    atomic_store(&kAltStackSize, ret, memory_order_relaxed);
c047fc
+  }
c047fc
+  return ret;
c047fc
 }
c047fc
 
c047fc
 void SetAlternateSignalStack() {
c047fc
-- 
c047fc
1.8.3.1
c047fc