Commit 447798a1 authored by Mirko Bonadei's avatar Mirko Bonadei Committed by Commit Bot

Removing NaCL support and renaming symbols from dynamic_annotations.

Chromium already has dynamic_annotations in //base/third_party and
the Abseil version causes ODR violations and macros conflicts.

On top of that, the Abseil version wants to include a NaCL header but
the build environment does not configure the correct include path.

Since NaCL doesn't need dynamic_annotations (see [1]) and they are also
deprecated from Chromium (see [2]), this CL renames all the functions
and the macros defined by the Abseil copy and confines the usage of
Abseil's dynamic_annotations to Abseil itself (using GN visibility).

When Abseil will be rolled into Chromium's third_party, a script will
take care of renaming everything.

[1] - https://cs.chromium.org/chromium/src/base/third_party/dynamic_annotations/BUILD.gn?l=6&rcl=b3c2f366fdcdbe3388b3fda45ae475d4e66dfa88
[2] - https://cs.chromium.org/chromium/src/base/third_party/dynamic_annotations/README.chromium?l=6&rcl=6ef06b461ccae125f8c8d6e33dde10c550ff3780

Bug: webrtc:8821
Change-Id: I83a4b6caafc30e457cf67fa21eaea9d071a9eecf
Reviewed-on: https://chromium-review.googlesource.com/1049628Reviewed-by: default avatarPatrik Höglund <phoglund@chromium.org>
Commit-Queue: Mirko Bonadei <mbonadei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558227}
parent 35f88f0c
......@@ -18,36 +18,17 @@ How to update Abseil:
2. Copy the content of the Abseil git repo to //third_party/abseil-cpp.
4. Generate BUILD.gn files launching bazel_to_gn.py from //third_party/abseil-cpp.
5. Rename functions in absl/base/dynamic_annotations.{h,cc}
find . -type f -exec sed -i "s/ValgrindSlowdown(/AbslValgrindSlowdown(/g" {} \;
find . -type f -exec sed -i "s/RunningOnValgrind(/AbslRunningOnValgrind(/g" {} \;
find . -type f -exec sed -i "s/AnnotateBenignRace(/AbslAnnotateBenignRace(/g" {} \;
find . -type f -exec sed -i "s/AnnotateBenignRaceSized(/AbslAnnotateBenignRaceSized(/g" {} \;
find . -type f -exec sed -i "s/AnnotateEnableRaceDetection(/AbslAnnotateEnableRaceDetection(/g" {} \;
find . -type f -exec sed -i "s/AnnotateIgnoreReadsBegin(/AbslAnnotateIgnoreReadsBegin(/g" {} \;
find . -type f -exec sed -i "s/AnnotateIgnoreReadsEnd(/AbslAnnotateIgnoreReadsEnd(/g" {} \;
find . -type f -exec sed -i "s/AnnotateIgnoreWritesBegin(/AbslAnnotateIgnoreWritesBegin(/g" {} \;
find . -type f -exec sed -i "s/AnnotateIgnoreWritesEnd(/AbslAnnotateIgnoreWritesEnd(/g" {} \;
find . -type f -exec sed -i "s/AnnotateRWLockAcquired(/AbslAnnotateRWLockAcquired(/g" {} \;
find . -type f -exec sed -i "s/AnnotateRWLockCreate(/AbslAnnotateRWLockCreate(/g" {} \;
find . -type f -exec sed -i "s/AnnotateRWLockDestroy(/AbslAnnotateRWLockDestroy(/g" {} \;
find . -type f -exec sed -i "s/AnnotateRWLockReleased(/AbslAnnotateRWLockReleased(/g" {} \;
find . -type f -exec sed -i "s/AnnotateThreadName(/AbslAnnotateThreadName(/g" {} \;
find . -type f -exec sed -i "s/AnnotateRWLockCreateStatic(/AbslAnnotateRWLockCreateStatic(/g" {} \;
find . -type f -exec sed -i "s/AnnotateMemoryIsInitialized(/AbslAnnotateMemoryIsInitialized(/g" {} \;
find . -type f -exec sed -i "s/AnnotateMemoryIsUninitialized(/AbslAnnotateMemoryIsUninitialized(/g" {} \;
3. From //third_party/abseil-cpp/ launch ./rename_dynamic_annotations.sh.
This script will rewrite dynamic_annotations macros and function inside
Abseil in order to avoid ODR violations and macro clashing with Chromium
(see: https://github.com/abseil/abseil-cpp/issues/122).
Local Modifications:
* absl/copts.bzl has been translated to //third_party/absl-cpp/BUILD.gn. Both files
contain lists of compiler flags in order to reduce duplication.
* absl/copts.bzl has been translated to //third_party/absl-cpp/BUILD.gn. Both
files contain lists of compiler flags in order to reduce duplication.
* All the BUILD.bazel files has been translated to BUILD.gn files.
* Functions in absl/base/dynamic_annotations.{h,cc} have been renamed to avoid
ODR violations.
* Functions and macros in absl/base/dynamic_annotations.{h,cc} have been renamed
to avoid ODR violations (see step 3).
......@@ -72,6 +72,10 @@ source_set("dynamic_annotations") {
public = [
"dynamic_annotations.h",
]
# Abseil's dynamic annotations are only visible inside Abseil because
# their usage is deprecated in Chromium (see README.chromium for more info).
visibility = []
visibility = [ "../*" ]
}
source_set("core_headers") {
......
......@@ -22,17 +22,17 @@
#endif
/* Compiler-based ThreadSanitizer defines
DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL = 1
ABSL_DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL = 1
and provides its own definitions of the functions. */
#ifndef DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL
# define DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL 0
#ifndef ABSL_DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL
# define ABSL_DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL 0
#endif
/* Each function is empty and called (via a macro) only in debug mode.
The arguments are captured by dynamic tools at runtime. */
#if DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 && !defined(__native_client__)
#if ABSL_DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0
#if __has_feature(memory_sanitizer)
#include <sanitizer/msan_interface.h>
......@@ -84,7 +84,7 @@ void AbslAnnotateMemoryIsUninitialized(const char *, int,
#endif
}
static int GetAbslRunningOnValgrind(void) {
static int AbslGetRunningOnValgrind(void) {
#ifdef RUNNING_ON_VALGRIND
if (RUNNING_ON_VALGRIND) return 1;
#endif
......@@ -101,9 +101,9 @@ int AbslRunningOnValgrind(void) {
int local_running_on_valgrind = running_on_valgrind;
/* C doesn't have thread-safe initialization of statics, and we
don't want to depend on pthread_once here, so hack it. */
ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack");
ABSL_ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack");
if (local_running_on_valgrind == -1)
running_on_valgrind = local_running_on_valgrind = GetAbslRunningOnValgrind();
running_on_valgrind = local_running_on_valgrind = AbslGetRunningOnValgrind();
return local_running_on_valgrind;
}
......@@ -112,7 +112,7 @@ double AbslValgrindSlowdown(void) {
/* Same initialization hack as in AbslRunningOnValgrind(). */
static volatile double slowdown = 0.0;
double local_slowdown = slowdown;
ANNOTATE_BENIGN_RACE(&slowdown, "safe hack");
ABSL_ANNOTATE_BENIGN_RACE(&slowdown, "safe hack");
if (AbslRunningOnValgrind() == 0) {
return 1.0;
}
......@@ -126,4 +126,4 @@ double AbslValgrindSlowdown(void) {
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */
#endif /* ABSL_DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */
......@@ -583,7 +583,7 @@ static void *DoAllocWithArena(size_t request, LowLevelAlloc::Arena *arena) {
section.Leave();
result = &s->levels;
}
ANNOTATE_MEMORY_IS_UNINITIALIZED(result, request);
ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(result, request);
return result;
}
......
......@@ -403,11 +403,11 @@ class FixedArray {
const void* top = &right_redzone_ + 1;
// args: (beg, end, old_mid, new_mid)
if (creating) {
ANNOTATE_CONTIGUOUS_CONTAINER(beg, top, top, end);
ANNOTATE_CONTIGUOUS_CONTAINER(bot, beg, beg, bot);
ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(beg, top, top, end);
ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(bot, beg, beg, bot);
} else {
ANNOTATE_CONTIGUOUS_CONTAINER(beg, top, end, top);
ANNOTATE_CONTIGUOUS_CONTAINER(bot, beg, bot, beg);
ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(beg, top, end, top);
ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(bot, beg, bot, beg);
}
}
#endif // ADDRESS_SANITIZER
......@@ -415,9 +415,9 @@ class FixedArray {
using Buffer =
typename std::aligned_storage<sizeof(Holder), alignof(Holder)>::type;
ADDRESS_SANITIZER_REDZONE(left_redzone_);
ABSL_ADDRESS_SANITIZER_REDZONE(left_redzone_);
std::array<Buffer, N> space_;
ADDRESS_SANITIZER_REDZONE(right_redzone_);
ABSL_ADDRESS_SANITIZER_REDZONE(right_redzone_);
};
// specialization when N = 0.
......
......@@ -1447,7 +1447,7 @@ bool GetFileMappingHint(const void **start, const void **end, uint64_t *offset,
bool Symbolize(const void *pc, char *out, int out_size) {
// Symbolization is very slow under tsan.
ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
SAFE_ASSERT(out_size >= 0);
debugging_internal::Symbolizer *s = debugging_internal::AllocateSymbolizer();
const char *name = s->GetSymbol(pc);
......@@ -1466,7 +1466,7 @@ bool Symbolize(const void *pc, char *out, int out_size) {
}
}
debugging_internal::FreeSymbolizer(s);
ANNOTATE_IGNORE_READS_AND_WRITES_END();
ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_END();
return ok;
}
......
......@@ -27,7 +27,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/base/dynamic_annotations.h" // for RunningOnValgrind
#include "absl/base/dynamic_annotations.h" // for AbslRunningOnValgrind
#include "absl/base/macros.h"
#include "absl/strings/numbers.h"
......
......@@ -1781,9 +1781,9 @@ static inline bool EvalConditionIgnored(Mutex *mu, const Condition *cond) {
// So we "divert" (which un-ignores both memory accesses and synchronization)
// and then separately turn on ignores of memory accesses.
ABSL_TSAN_MUTEX_PRE_DIVERT(mu, 0);
ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
bool res = cond->Eval();
ANNOTATE_IGNORE_READS_AND_WRITES_END();
ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_END();
ABSL_TSAN_MUTEX_POST_DIVERT(mu, 0);
static_cast<void>(mu); // Prevent unused param warning in non-TSAN builds.
return res;
......
#!/bin/bash
# This script renames all the functions and the macros defined in
# absl/base/dynamic_annotations.{h,cc}.
#
# Chromium's dynamic_annotations live in //base/third_party/dynamic_annotations
# and the are in conflict with Abseil's dynamic_annotations (ODR violations and
# macro clashing).
# In order to avoid problems in Chromium, this copy of Abseil has its own
# dynamic_annotations renamed.
for w in \
AnnotateBarrierDestroy \
AnnotateBarrierInit \
AnnotateBarrierWaitAfter \
AnnotateBarrierWaitBefore \
AnnotateBenignRace \
AnnotateBenignRaceSized \
AnnotateCondVarSignal \
AnnotateCondVarSignalAll \
AnnotateCondVarWait \
AnnotateEnableRaceDetection \
AnnotateExpectRace \
AnnotateFlushExpectedRaces \
AnnotateFlushState \
AnnotateHappensAfter \
AnnotateHappensBefore \
AnnotateIgnoreReadsBegin \
AnnotateIgnoreReadsEnd \
AnnotateIgnoreSyncBegin \
AnnotateIgnoreSyncEnd \
AnnotateIgnoreWritesBegin \
AnnotateIgnoreWritesEnd \
AnnotateMemoryIsInitialized \
AnnotateMemoryIsUninitialized \
AnnotateMutexIsNotPHB \
AnnotateMutexIsUsedAsCondVar \
AnnotateNewMemory \
AnnotateNoOp \
AnnotatePCQCreate \
AnnotatePCQDestroy \
AnnotatePCQGet \
AnnotatePCQPut \
AnnotatePublishMemoryRange \
AnnotateRWLockAcquired \
AnnotateRWLockCreate \
AnnotateRWLockCreateStatic \
AnnotateRWLockDestroy \
AnnotateRWLockReleased \
AnnotateThreadName \
AnnotateTraceMemory \
AnnotateUnpublishMemoryRange \
GetRunningOnValgrind \
RunningOnValgrind \
ValgrindSlowdown \
; do
find absl/ -type f -exec sed -i "s/\b$w\b/Absl$w/g" {} \;
done
for w in \
ADDRESS_SANITIZER_REDZONE \
ANNOTALYSIS_ENABLED \
ANNOTATE_BARRIER_DESTROY \
ANNOTATE_BARRIER_INIT \
ANNOTATE_BARRIER_WAIT_AFTER \
ANNOTATE_BARRIER_WAIT_BEFORE \
ANNOTATE_BENIGN_RACE \
ANNOTATE_BENIGN_RACE_SIZED \
ANNOTATE_BENIGN_RACE_STATIC \
ANNOTATE_CONDVAR_LOCK_WAIT \
ANNOTATE_CONDVAR_SIGNAL \
ANNOTATE_CONDVAR_SIGNAL_ALL \
ANNOTATE_CONDVAR_WAIT \
ANNOTATE_CONTIGUOUS_CONTAINER \
ANNOTATE_ENABLE_RACE_DETECTION \
ANNOTATE_EXPECT_RACE \
ANNOTATE_FLUSH_EXPECTED_RACES \
ANNOTATE_FLUSH_STATE \
ANNOTATE_HAPPENS_AFTER \
ANNOTATE_HAPPENS_BEFORE \
ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN ANNOTATE_IGNORE_READS_AND_WRITES_END \
ANNOTATE_IGNORE_READS_BEGIN \
ANNOTATE_IGNORE_READS_END \
ANNOTATE_IGNORE_SYNC_BEGIN \
ANNOTATE_IGNORE_SYNC_END \
ANNOTATE_IGNORE_WRITES_BEGIN \
ANNOTATE_IGNORE_WRITES_END \
ANNOTATE_MEMORY_IS_INITIALIZED \
ANNOTATE_MEMORY_IS_UNINITIALIZED \
ANNOTATE_MUTEX_IS_USED_AS_CONDVAR \
ANNOTATE_NEW_MEMORY \
ANNOTATE_NOT_HAPPENS_BEFORE_MUTEX \
ANNOTATE_NO_OP \
ANNOTATE_PCQ_CREATE ANNOTATE_PCQ_DESTROY \
ANNOTATE_PCQ_GET ANNOTATE_PCQ_PUT \
ANNOTATE_PUBLISH_MEMORY_RANGE \
ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX \
ANNOTATE_RWLOCK_ACQUIRED \
ANNOTATE_RWLOCK_CREATE \
ANNOTATE_RWLOCK_CREATE_STATIC \
ANNOTATE_RWLOCK_DESTROY \
ANNOTATE_RWLOCK_RELEASED \
ANNOTATE_SWAP_MEMORY_RANGE \
ANNOTATE_THREAD_NAME \
ANNOTATE_TRACE_MEMORY \
ANNOTATE_UNPROTECTED_READ \
ANNOTATE_UNPUBLISH_MEMORY_RANGE \
ANNOTATIONS_ENABLED \
ATTRIBUTE_IGNORE_READS_BEGIN \
ATTRIBUTE_IGNORE_READS_END \
DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK \
DYNAMIC_ANNOTATIONS_ENABLED \
DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL \
DYNAMIC_ANNOTATIONS_GLUE \
DYNAMIC_ANNOTATIONS_GLUE0 \
DYNAMIC_ANNOTATIONS_IMPL \
DYNAMIC_ANNOTATIONS_NAME \
DYNAMIC_ANNOTATIONS_PREFIX \
DYNAMIC_ANNOTATIONS_PROVIDE_RUNNING_ON_VALGRIND \
DYNAMIC_ANNOTATIONS_WANT_ATTRIBUTE_WEAK \
; do
find absl/ -type f -exec sed -i "s/\b$w\b/ABSL_$w/g" {} \;
done
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