Skip to content

Commit 0f3bb46

Browse files
authored
Cherry-picks for LTS 2020_09_23 Patch Release 2
* Fixes preprocessor condition for symbols __tsan_mutex_read_lock and __tsan_mutex_try_lock * Fixes race in AddressIsReadable file descriptors using stronger memory ordering * Fixes CMake dependency issues and adds `-Wl,--no-undefined` to avoid these issues in the future.
1 parent bd0de71 commit 0f3bb46

File tree

7 files changed

+80
-59
lines changed

7 files changed

+80
-59
lines changed

absl/debugging/internal/address_is_readable.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static void Unpack(uint64_t x, int *pid, int *read_fd, int *write_fd) {
6868
// unimplemented.
6969
// This is a namespace-scoped variable for correct zero-initialization.
7070
static std::atomic<uint64_t> pid_and_fds; // initially 0, an invalid pid.
71+
7172
bool AddressIsReadable(const void *addr) {
7273
absl::base_internal::ErrnoSaver errno_saver;
7374
// We test whether a byte is readable by using write(). Normally, this would
@@ -86,7 +87,7 @@ bool AddressIsReadable(const void *addr) {
8687
int pid;
8788
int read_fd;
8889
int write_fd;
89-
uint64_t local_pid_and_fds = pid_and_fds.load(std::memory_order_relaxed);
90+
uint64_t local_pid_and_fds = pid_and_fds.load(std::memory_order_acquire);
9091
Unpack(local_pid_and_fds, &pid, &read_fd, &write_fd);
9192
while (current_pid != pid) {
9293
int p[2];
@@ -98,13 +99,13 @@ bool AddressIsReadable(const void *addr) {
9899
fcntl(p[1], F_SETFD, FD_CLOEXEC);
99100
uint64_t new_pid_and_fds = Pack(current_pid, p[0], p[1]);
100101
if (pid_and_fds.compare_exchange_strong(
101-
local_pid_and_fds, new_pid_and_fds, std::memory_order_relaxed,
102+
local_pid_and_fds, new_pid_and_fds, std::memory_order_release,
102103
std::memory_order_relaxed)) {
103104
local_pid_and_fds = new_pid_and_fds; // fds exposed to other threads
104105
} else { // fds not exposed to other threads; we can close them.
105106
close(p[0]);
106107
close(p[1]);
107-
local_pid_and_fds = pid_and_fds.load(std::memory_order_relaxed);
108+
local_pid_and_fds = pid_and_fds.load(std::memory_order_acquire);
108109
}
109110
Unpack(local_pid_and_fds, &pid, &read_fd, &write_fd);
110111
}
@@ -124,7 +125,7 @@ bool AddressIsReadable(const void *addr) {
124125
// If pid_and_fds contains the problematic file descriptors we just used,
125126
// this call will forget them, and the loop will try again.
126127
pid_and_fds.compare_exchange_strong(local_pid_and_fds, 0,
127-
std::memory_order_relaxed,
128+
std::memory_order_release,
128129
std::memory_order_relaxed);
129130
}
130131
} while (errno == EBADF);

absl/flags/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ absl_cc_library(
183183
DEPS
184184
absl::base
185185
absl::config
186+
absl::flags_commandlineflag
186187
absl::flags_commandlineflag_internal
187188
absl::flags_config
188189
absl::flags_marshalling

absl/status/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ absl_cc_library(
6464
COPTS
6565
${ABSL_DEFAULT_COPTS}
6666
DEPS
67+
absl::status
6768
absl::core_headers
6869
absl::raw_logging_internal
6970
absl::type_traits

absl/synchronization/mutex.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "absl/base/internal/spinlock.h"
5151
#include "absl/base/internal/sysinfo.h"
5252
#include "absl/base/internal/thread_identity.h"
53+
#include "absl/base/internal/tsan_mutex_interface.h"
5354
#include "absl/base/port.h"
5455
#include "absl/debugging/stacktrace.h"
5556
#include "absl/debugging/symbolize.h"
@@ -705,7 +706,7 @@ static constexpr bool kDebugMode = false;
705706
static constexpr bool kDebugMode = true;
706707
#endif
707708

708-
#ifdef ABSL_HAVE_THREAD_SANITIZER
709+
#ifdef ABSL_INTERNAL_HAVE_TSAN_INTERFACE
709710
static unsigned TsanFlags(Mutex::MuHow how) {
710711
return how == kShared ? __tsan_mutex_read_lock : 0;
711712
}
@@ -1767,7 +1768,7 @@ static inline bool EvalConditionAnnotated(const Condition *cond, Mutex *mu,
17671768
// All memory accesses are ignored inside of mutex operations + for unlock
17681769
// operation tsan considers that we've already released the mutex.
17691770
bool res = false;
1770-
#ifdef ABSL_HAVE_THREAD_SANITIZER
1771+
#ifdef ABSL_INTERNAL_HAVE_TSAN_INTERFACE
17711772
const int flags = read_lock ? __tsan_mutex_read_lock : 0;
17721773
const int tryflags = flags | (trylock ? __tsan_mutex_try_lock : 0);
17731774
#endif

ci/linux_gcc-latest_libstdcxx_cmake.sh

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,36 @@ if [[ -z ${ABSL_CMAKE_BUILD_TYPES:-} ]]; then
3434
ABSL_CMAKE_BUILD_TYPES="Debug Release"
3535
fi
3636

37+
if [[ -z ${ABSL_CMAKE_BUILD_SHARED:-} ]]; then
38+
ABSL_CMAKE_BUILD_SHARED="OFF ON"
39+
fi
40+
3741
source "${ABSEIL_ROOT}/ci/linux_docker_containers.sh"
3842
readonly DOCKER_CONTAINER=${LINUX_GCC_LATEST_CONTAINER}
3943

4044
for std in ${ABSL_CMAKE_CXX_STANDARDS}; do
4145
for compilation_mode in ${ABSL_CMAKE_BUILD_TYPES}; do
42-
echo "--------------------------------------------------------------------"
43-
echo "Testing with CMAKE_BUILD_TYPE=${compilation_mode} and -std=c++${std}"
44-
45-
time docker run \
46-
--volume="${ABSEIL_ROOT}:/abseil-cpp:ro" \
47-
--workdir=/abseil-cpp \
48-
--tmpfs=/buildfs:exec \
49-
--cap-add=SYS_PTRACE \
50-
--rm \
51-
-e CFLAGS="-Werror" \
52-
-e CXXFLAGS="-Werror" \
53-
${DOCKER_CONTAINER} \
54-
/bin/bash -c "
55-
cd /buildfs && \
56-
cmake /abseil-cpp \
57-
-DABSL_USE_GOOGLETEST_HEAD=ON \
58-
-DABSL_RUN_TESTS=ON \
59-
-DCMAKE_BUILD_TYPE=${compilation_mode} \
60-
-DCMAKE_CXX_STANDARD=${std} && \
61-
make -j$(nproc) && \
62-
ctest -j$(nproc) --output-on-failure"
46+
for build_shared in ${ABSL_CMAKE_BUILD_SHARED}; do
47+
time docker run \
48+
--volume="${ABSEIL_ROOT}:/abseil-cpp:ro" \
49+
--workdir=/abseil-cpp \
50+
--tmpfs=/buildfs:exec \
51+
--cap-add=SYS_PTRACE \
52+
--rm \
53+
-e CFLAGS="-Werror" \
54+
-e CXXFLAGS="-Werror" \
55+
${DOCKER_CONTAINER} \
56+
/bin/bash -c "
57+
cd /buildfs && \
58+
cmake /abseil-cpp \
59+
-DABSL_USE_GOOGLETEST_HEAD=ON \
60+
-DABSL_RUN_TESTS=ON \
61+
-DBUILD_SHARED_LIBS=${build_shared} \
62+
-DCMAKE_BUILD_TYPE=${compilation_mode} \
63+
-DCMAKE_CXX_STANDARD=${std} \
64+
-DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined\" && \
65+
make -j$(nproc) && \
66+
ctest -j$(nproc) --output-on-failure"
67+
done
6368
done
6469
done

ci/linux_gcc_alpine_cmake.sh

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,35 @@ if [[ -z ${ABSL_CMAKE_BUILD_TYPES:-} ]]; then
3434
ABSL_CMAKE_BUILD_TYPES="Debug Release"
3535
fi
3636

37+
if [[ -z ${ABSL_CMAKE_BUILD_SHARED:-} ]]; then
38+
ABSL_CMAKE_BUILD_SHARED="OFF ON"
39+
fi
40+
3741
source "${ABSEIL_ROOT}/ci/linux_docker_containers.sh"
3842
readonly DOCKER_CONTAINER=${LINUX_ALPINE_CONTAINER}
3943

4044
for std in ${ABSL_CMAKE_CXX_STANDARDS}; do
4145
for compilation_mode in ${ABSL_CMAKE_BUILD_TYPES}; do
42-
echo "--------------------------------------------------------------------"
43-
echo "Testing with CMAKE_BUILD_TYPE=${compilation_mode} and -std=c++${std}"
44-
45-
time docker run \
46-
--volume="${ABSEIL_ROOT}:/abseil-cpp:ro" \
47-
--workdir=/abseil-cpp \
48-
--tmpfs=/buildfs:exec \
49-
--cap-add=SYS_PTRACE \
50-
--rm \
51-
-e CFLAGS="-Werror" \
52-
-e CXXFLAGS="-Werror" \
53-
"${DOCKER_CONTAINER}" \
54-
/bin/sh -c "
55-
cd /buildfs && \
56-
cmake /abseil-cpp \
57-
-DABSL_USE_GOOGLETEST_HEAD=ON \
58-
-DABSL_RUN_TESTS=ON \
59-
-DCMAKE_BUILD_TYPE=${compilation_mode} \
60-
-DCMAKE_CXX_STANDARD=${std} && \
61-
make -j$(nproc) && \
62-
ctest -j$(nproc) --output-on-failure"
46+
for build_shared in ${ABSL_CMAKE_BUILD_SHARED}; do
47+
time docker run \
48+
--volume="${ABSEIL_ROOT}:/abseil-cpp:ro" \
49+
--workdir=/abseil-cpp \
50+
--tmpfs=/buildfs:exec \
51+
--cap-add=SYS_PTRACE \
52+
--rm \
53+
-e CFLAGS="-Werror" \
54+
-e CXXFLAGS="-Werror" \
55+
"${DOCKER_CONTAINER}" \
56+
/bin/sh -c "
57+
cd /buildfs && \
58+
cmake /abseil-cpp \
59+
-DABSL_USE_GOOGLETEST_HEAD=ON \
60+
-DABSL_RUN_TESTS=ON \
61+
-DCMAKE_BUILD_TYPE=${compilation_mode} \
62+
-DCMAKE_CXX_STANDARD=${std} \
63+
-DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined\" && \
64+
make -j$(nproc) && \
65+
ctest -j$(nproc) --output-on-failure"
66+
done
6367
done
6468
done

ci/macos_xcode_cmake.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ if [[ -z ${ABSL_CMAKE_BUILD_TYPES:-} ]]; then
2828
ABSL_CMAKE_BUILD_TYPES="Debug"
2929
fi
3030

31+
if [[ -z ${ABSL_CMAKE_BUILD_SHARED:-} ]]; then
32+
ABSL_CMAKE_BUILD_SHARED="OFF ON"
33+
fi
34+
3135
for compilation_mode in ${ABSL_CMAKE_BUILD_TYPES}; do
32-
BUILD_DIR=$(mktemp -d ${compilation_mode}.XXXXXXXX)
33-
cd ${BUILD_DIR}
36+
for build_shared in ${ABSL_CMAKE_BUILD_SHARED}; do
37+
BUILD_DIR=$(mktemp -d ${compilation_mode}.XXXXXXXX)
38+
cd ${BUILD_DIR}
3439

35-
# TODO(absl-team): Enable -Werror once all warnings are fixed.
36-
time cmake ${ABSEIL_ROOT} \
37-
-GXcode \
38-
-DCMAKE_BUILD_TYPE=${compilation_mode} \
39-
-DCMAKE_CXX_STANDARD=11 \
40-
-DABSL_USE_GOOGLETEST_HEAD=ON \
41-
-DABSL_RUN_TESTS=ON
42-
time cmake --build .
43-
time ctest -C ${compilation_mode} --output-on-failure
40+
# TODO(absl-team): Enable -Werror once all warnings are fixed.
41+
time cmake ${ABSEIL_ROOT} \
42+
-GXcode \
43+
-DBUILD_SHARED_LIBS=${build_shared} \
44+
-DCMAKE_BUILD_TYPE=${compilation_mode} \
45+
-DCMAKE_CXX_STANDARD=11 \
46+
-DCMAKE_MODULE_LINKER_FLAGS="-Wl,--no-undefined" \
47+
-DABSL_USE_GOOGLETEST_HEAD=ON \
48+
-DABSL_RUN_TESTS=ON
49+
time cmake --build .
50+
time ctest -C ${compilation_mode} --output-on-failure
51+
done
4452
done

0 commit comments

Comments
 (0)