summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2018-09-28 02:05:52 +0000
committerFangrui Song <maskray@google.com>2018-09-28 02:05:52 +0000
commit58f209f5d772787539af158d7854c26e71cfb627 (patch)
treede74684c13f1b398f949d7dd9ac935dcf1a964fa /compiler-rt
parent4328ea3443fe79b72a5ca6ac17c2952b528a1433 (diff)
downloadbcm5719-llvm-58f209f5d772787539af158d7854c26e71cfb627.tar.gz
bcm5719-llvm-58f209f5d772787539af158d7854c26e71cfb627.zip
[XRay] Guard local variables with `static` and struct with unnamed namespaces
Summary: This is for coding standard conformance, and for fixing an ODR violation issue: __xray::ThreadLocalData is defined twice and differently in xray_fdr_logging.cc and xray_basic_logging.cc Reviewers: dberris, mboerger, eizan Reviewed By: dberris Subscribers: delcypher, jfb, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D52639 llvm-svn: 343289
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/xray/xray_basic_logging.cc12
-rw-r--r--compiler-rt/lib/xray/xray_fdr_logging.cc5
2 files changed, 11 insertions, 6 deletions
diff --git a/compiler-rt/lib/xray/xray_basic_logging.cc b/compiler-rt/lib/xray/xray_basic_logging.cc
index a46c151af5c..ee28d598f8b 100644
--- a/compiler-rt/lib/xray/xray_basic_logging.cc
+++ b/compiler-rt/lib/xray/xray_basic_logging.cc
@@ -38,8 +38,9 @@
namespace __xray {
-SpinMutex LogMutex;
+static SpinMutex LogMutex;
+namespace {
// We use elements of this type to record the entry TSC of every function ID we
// see as we're tracing a particular thread's execution.
struct alignas(16) StackEntry {
@@ -62,15 +63,16 @@ struct alignas(64) ThreadLocalData {
int Fd = -1;
};
-static pthread_key_t PThreadKey;
-
-static atomic_uint8_t BasicInitialized{0};
-
struct BasicLoggingOptions {
int DurationFilterMicros = 0;
size_t MaxStackDepth = 0;
size_t ThreadBufferSize = 0;
};
+} // namespace
+
+static pthread_key_t PThreadKey;
+
+static atomic_uint8_t BasicInitialized{0};
struct BasicLoggingOptions GlobalOptions;
diff --git a/compiler-rt/lib/xray/xray_fdr_logging.cc b/compiler-rt/lib/xray/xray_fdr_logging.cc
index 07292c65b70..2d6af443d90 100644
--- a/compiler-rt/lib/xray/xray_fdr_logging.cc
+++ b/compiler-rt/lib/xray/xray_fdr_logging.cc
@@ -42,8 +42,10 @@
namespace __xray {
-atomic_sint32_t LoggingStatus = {XRayLogInitStatus::XRAY_LOG_UNINITIALIZED};
+static atomic_sint32_t LoggingStatus = {
+ XRayLogInitStatus::XRAY_LOG_UNINITIALIZED};
+namespace {
// Group together thread-local-data in a struct, then hide it behind a function
// call so that it can be initialized on first use instead of as a global. We
// force the alignment to 64-bytes for x86 cache line alignment, as this
@@ -72,6 +74,7 @@ struct alignas(64) ThreadLocalData {
// FDRLogging, and that we're going to clean it up when the thread exits.
BufferQueue *BQ = nullptr;
};
+} // namespace
static_assert(std::is_trivially_destructible<ThreadLocalData>::value,
"ThreadLocalData must be trivially destructible");
OpenPOWER on IntegriCloud