Commit cde2f0ea by Abseil Team Committed by Copybara-Service

Workaround MSan false positive.

On Linux Kernels >= 5.4 MSan reports a false positive when accessing thread local storage data from loaded libraries.

This was reported on Chromium (which on some build configurations uses absl as a dynamic library). More info here: crbug.com/1414573.

PiperOrigin-RevId: 508645053
Change-Id: I5d5a97e1ee7230cc23f3934a4ec5594b883918b4
parent fa485540
...@@ -622,6 +622,7 @@ cc_library( ...@@ -622,6 +622,7 @@ cc_library(
":hashtablez_sampler", ":hashtablez_sampler",
"//absl/base:config", "//absl/base:config",
"//absl/base:core_headers", "//absl/base:core_headers",
"//absl/base:dynamic_annotations",
"//absl/base:endian", "//absl/base:endian",
"//absl/base:prefetch", "//absl/base:prefetch",
"//absl/base:raw_logging_internal", "//absl/base:raw_logging_internal",
......
...@@ -706,6 +706,7 @@ absl_cc_library( ...@@ -706,6 +706,7 @@ absl_cc_library(
absl::container_common absl::container_common
absl::container_memory absl::container_memory
absl::core_headers absl::core_headers
absl::dynamic_annotations
absl::endian absl::endian
absl::hash absl::hash
absl::hash_policy_traits absl::hash_policy_traits
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <cstring> #include <cstring>
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/base/dynamic_annotations.h"
#include "absl/hash/hash.h" #include "absl/hash/hash.h"
namespace absl { namespace absl {
...@@ -44,6 +45,11 @@ constexpr size_t Group::kWidth; ...@@ -44,6 +45,11 @@ constexpr size_t Group::kWidth;
inline size_t RandomSeed() { inline size_t RandomSeed() {
#ifdef ABSL_HAVE_THREAD_LOCAL #ifdef ABSL_HAVE_THREAD_LOCAL
static thread_local size_t counter = 0; static thread_local size_t counter = 0;
// On Linux kernels >= 5.4 the MSAN runtime has a false-positive when
// accessing thread local storage data from loaded libraries
// (https://github.com/google/sanitizers/issues/1265), for this reason counter
// needs to be annotated as initialized.
ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(&counter, sizeof(size_t));
size_t value = ++counter; size_t value = ++counter;
#else // ABSL_HAVE_THREAD_LOCAL #else // ABSL_HAVE_THREAD_LOCAL
static std::atomic<size_t> counter(0); static std::atomic<size_t> counter(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment