Skip to content

Commit cf6ab6b

Browse files
Abseil Teamderekmauro
authored andcommitted
Changes imported from Abseil "staging" branch:
- b527a3e4b36b644ac424e3c525b1cd393f6f6c40 Fix some typos in the usage examples by Jorg Brown <[email protected]> - 82be4a9adf3bb0ddafc0d46274969c99afffe870 Fix typo in optional.h comment. by Abseil Team <[email protected]> - d6ee63bf8fc51fba074c23b33cebc28c808d7f07 Remove internal-only identifiers from code. by Daniel Katz <[email protected]> - f9c3ad2f0d73f53b21603638af8b4bed636e79f4 Use easier understandable names for absl::StartsWith and ... by Abseil Team <[email protected]> - 7c16c14fefee89c927b8789d6043c4691bcffc9b Add -Wno-missing-prototypes back to the LLVM copts. by Derek Mauro <[email protected]> - 2f4b7d2e50c7023240242f1e15db60ccd7e8768d IWYU | absl/strings by Juemin Yang <[email protected]> - a99cbcc1daa34a2d6a2bb26de275e05173cc77e9 IWYU | absl/type by Juemin Yang <[email protected]> - 12e1146d0fc76c071d7e0ebaabb62f0a984fae66 Use LLVM_FLAGS and LLVM_TEST_FLAGS when --compiler=llvm. by Derek Mauro <[email protected]> - cd6bea616abda558d0bace5bd77455662a233688 IWYU | absl/debugging by Juemin Yang <[email protected]> - d9a7382e59d46a8581b6b7a31cd5a48bb89326e9 IWYU | absl/synchronization by Juemin Yang <[email protected]> - 07ec7d6d5a4a666f4183c5d0ed9c342baa7b24bc IWYU | absl/numeric by Juemin Yang <[email protected]> - 12bfe40051f4270f8707e191af5652f83f2f750c Remove the RoundTrip{Float,Double}ToBuffer routines from ... by Jorg Brown <[email protected]> - eeb4fd67c9d97f66cb9475c3c5e51ab132f1c810 Adds conversion functions for converting between absl/tim... by Greg Miller <[email protected]> - 59a2108d05d4ea85dc5cc11e49b2cd2335d4295a Change Substitute to use %.6g formatting rather than 15/1... by Jorg Brown <[email protected]> - 394becb48e0fcd161642cdaac5120d32567e0ef8 IWYU | absl/meta by Juemin Yang <[email protected]> - 1e5da6e8da336699b2469dcf6dda025b9b0ec4c9 Rewrite atomic_hook.h to not use std::atomic<T*> under Wi... by Greg Falcon <[email protected]> GitOrigin-RevId: b527a3e4b36b644ac424e3c525b1cd393f6f6c40 Change-Id: I14e331d91c956ef045ac7927091a9f179716de0c
1 parent 53c239d commit cf6ab6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+629
-831
lines changed

absl/BUILD.bazel

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ config_setting(
2525
},
2626
)
2727

28-
config_setting(
29-
name = "hybrid_compiler",
30-
values = {
31-
"compiler": "hybrid",
32-
},
33-
)
34-
35-
config_setting(
36-
name = "llvm_warnings",
37-
values = {
38-
"define": "ABSL_LLVM_WARNINGS=1",
39-
},
40-
)
41-
4228
# following configs are based on mapping defined in: https://git.io/v5Ijz
4329
config_setting(
4430
name = "ios",

absl/base/BUILD.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ package(default_visibility = ["//visibility:public"])
3030

3131
licenses(["notice"]) # Apache 2.0
3232

33-
# Some header files in //base are directly exported for unusual use cases,
34-
# and the ABSL versions must also be exported for those users.
35-
3633
exports_files(["thread_annotations.h"])
3734

3835
cc_library(
@@ -188,7 +185,7 @@ cc_library(
188185
hdrs = ["internal/throw_delegate.h"],
189186
copts = ABSL_DEFAULT_COPTS + ABSL_EXCEPTIONS_FLAG,
190187
features = [
191-
"-use_header_modules", # b/33207452
188+
"-use_header_modules",
192189
],
193190
deps = [
194191
":base",

absl/base/attributes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@
526526
//
527527
// Note that this attribute is redundant if the variable is declared constexpr.
528528
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization)
529-
// NOLINTNEXTLINE(whitespace/braces) (b/36288871)
529+
// NOLINTNEXTLINE(whitespace/braces)
530530
#define ABSL_CONST_INIT [[clang::require_constant_initialization]]
531531
#else
532532
#define ABSL_CONST_INIT

absl/base/internal/atomic_hook.h

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,12 @@
1818

1919
#include <atomic>
2020
#include <cassert>
21+
#include <cstdint>
2122
#include <utility>
2223

2324
namespace absl {
2425
namespace base_internal {
2526

26-
// In current versions of MSVC (as of July 2017), a std::atomic<T> where T is a
27-
// pointer to function cannot be constant-initialized with an address constant
28-
// expression. That is, the following code does not compile:
29-
// void NoOp() {}
30-
// constexpr std::atomic<void(*)()> ptr(NoOp);
31-
//
32-
// This is the only compiler we support that seems to have this issue. We
33-
// conditionalize on MSVC here to use a fallback implementation. But we
34-
// should revisit this occasionally. If MSVC fixes this compiler bug, we
35-
// can then change this to be conditionalized on the value on _MSC_FULL_VER
36-
// instead.
37-
#ifdef _MSC_FULL_VER
38-
#define ABSL_HAVE_FUNCTION_ADDRESS_CONSTANT_EXPRESSION 0
39-
#else
40-
#define ABSL_HAVE_FUNCTION_ADDRESS_CONSTANT_EXPRESSION 1
41-
#endif
42-
4327
template <typename T>
4428
class AtomicHook;
4529

@@ -55,7 +39,7 @@ class AtomicHook<ReturnType (*)(Args...)> {
5539
public:
5640
using FnPtr = ReturnType (*)(Args...);
5741

58-
constexpr AtomicHook() : hook_(DummyFunction) {}
42+
constexpr AtomicHook() : hook_(kInitialValue) {}
5943

6044
// Stores the provided function pointer as the value for this hook.
6145
//
@@ -64,28 +48,16 @@ class AtomicHook<ReturnType (*)(Args...)> {
6448
// as a memory_order_release operation, and read accesses are implemented as
6549
// memory_order_acquire.
6650
void Store(FnPtr fn) {
67-
assert(fn);
68-
FnPtr expected = DummyFunction;
69-
hook_.compare_exchange_strong(expected, fn, std::memory_order_acq_rel,
70-
std::memory_order_acquire);
71-
// If the compare and exchange failed, make sure that's because hook_ was
72-
// already set to `fn` by an earlier call. Any other state reflects an API
73-
// violation (calling Store() multiple times with different values).
74-
//
75-
// Avoid ABSL_RAW_CHECK, since raw logging depends on AtomicHook.
76-
assert(expected == DummyFunction || expected == fn);
51+
bool success = DoStore(fn);
52+
static_cast<void>(success);
53+
assert(success);
7754
}
7855

7956
// Invokes the registered callback. If no callback has yet been registered, a
8057
// default-constructed object of the appropriate type is returned instead.
8158
template <typename... CallArgs>
8259
ReturnType operator()(CallArgs&&... args) const {
83-
FnPtr hook = hook_.load(std::memory_order_acquire);
84-
if (ABSL_HAVE_FUNCTION_ADDRESS_CONSTANT_EXPRESSION || hook) {
85-
return hook(std::forward<CallArgs>(args)...);
86-
} else {
87-
return ReturnType();
88-
}
60+
return DoLoad()(std::forward<CallArgs>(args)...);
8961
}
9062

9163
// Returns the registered callback, or nullptr if none has been registered.
@@ -98,23 +70,79 @@ class AtomicHook<ReturnType (*)(Args...)> {
9870
// Load()() unless you must conditionalize behavior on whether a hook was
9971
// registered.
10072
FnPtr Load() const {
101-
FnPtr ptr = hook_.load(std::memory_order_acquire);
73+
FnPtr ptr = DoLoad();
10274
return (ptr == DummyFunction) ? nullptr : ptr;
10375
}
10476

10577
private:
106-
#if ABSL_HAVE_FUNCTION_ADDRESS_CONSTANT_EXPRESSION
10778
static ReturnType DummyFunction(Args...) {
10879
return ReturnType();
10980
}
81+
82+
// Current versions of MSVC (as of September 2017) have a broken
83+
// implementation of std::atomic<T*>: Its constructor attempts to do the
84+
// equivalent of a reinterpret_cast in a constexpr context, which is not
85+
// allowed.
86+
//
87+
// This causes an issue when building with LLVM under Windows. To avoid this,
88+
// we use a less-efficient, intptr_t-based implementation on Windows.
89+
90+
#ifdef _MSC_FULL_VER
91+
#define ABSL_HAVE_WORKING_ATOMIC_POINTER 0
11092
#else
111-
static constexpr FnPtr DummyFunction = nullptr;
93+
#define ABSL_HAVE_WORKING_ATOMIC_POINTER 1
11294
#endif
11395

96+
#if ABSL_HAVE_WORKING_ATOMIC_POINTER
97+
static constexpr FnPtr kInitialValue = &DummyFunction;
98+
99+
// Return the stored value, or DummyFunction if no value has been stored.
100+
FnPtr DoLoad() const { return hook_.load(std::memory_order_acquire); }
101+
102+
// Store the given value. Returns false if a different value was already
103+
// stored to this object.
104+
bool DoStore(FnPtr fn) {
105+
assert(fn);
106+
FnPtr expected = DummyFunction;
107+
hook_.compare_exchange_strong(expected, fn, std::memory_order_acq_rel,
108+
std::memory_order_acquire);
109+
const bool store_succeeded = (expected == DummyFunction);
110+
const bool same_value_already_stored = (expected == fn);
111+
return store_succeeded || same_value_already_stored;
112+
}
113+
114114
std::atomic<FnPtr> hook_;
115+
#else // !ABSL_HAVE_WORKING_ATOMIC_POINTER
116+
// Use a sentinel value unlikely to be the address of an actual function.
117+
static constexpr intptr_t kInitialValue = 0;
118+
119+
static_assert(sizeof(intptr_t) >= sizeof(FnPtr),
120+
"intptr_t can't contain a function pointer");
121+
122+
FnPtr DoLoad() const {
123+
const intptr_t value = hook_.load(std::memory_order_acquire);
124+
if (value == 0) {
125+
return DummyFunction;
126+
}
127+
return reinterpret_cast<FnPtr>(value);
128+
}
129+
130+
bool DoStore(FnPtr fn) {
131+
assert(fn);
132+
const auto value = reinterpret_cast<intptr_t>(fn);
133+
intptr_t expected = 0;
134+
hook_.compare_exchange_strong(expected, value, std::memory_order_acq_rel,
135+
std::memory_order_acquire);
136+
const bool store_succeeded = (expected == 0);
137+
const bool same_value_already_stored = (expected == value);
138+
return store_succeeded || same_value_already_stored;
139+
}
140+
141+
std::atomic<intptr_t> hook_;
142+
#endif
115143
};
116144

117-
#undef ABSL_HAVE_FUNCTION_ADDRESS_CONSTANT_EXPRESSION
145+
#undef ABSL_HAVE_WORKING_ATOMIC_POINTER
118146

119147
} // namespace base_internal
120148
} // namespace absl

absl/base/internal/low_level_scheduling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
//
15-
// Core interfaces and definitions used by by low-level //base interfaces such
16-
// as SpinLock.
15+
// Core interfaces and definitions used by by low-level interfaces such as
16+
// SpinLock.
1717

1818
#ifndef ABSL_BASE_INTERNAL_LOW_LEVEL_SCHEDULING_H_
1919
#define ABSL_BASE_INTERNAL_LOW_LEVEL_SCHEDULING_H_

absl/base/internal/malloc_hook.cc

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,13 @@ void MallocHook::InvokeSbrkHookSlow(const void* result, ptrdiff_t increment) {
453453
} // namespace base_internal
454454
} // namespace absl
455455

456-
ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(google_malloc);
457-
ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(google_malloc);
458-
// actual functions are in debugallocation.cc or tcmalloc.cc
459456
ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(malloc_hook);
460457
ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(malloc_hook);
461458
// actual functions are in this file, malloc_hook.cc, and low_level_alloc.cc
459+
ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(google_malloc);
460+
ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(google_malloc);
462461
ABSL_DEFINE_ATTRIBUTE_SECTION_VARS(blink_malloc);
463462
ABSL_DECLARE_ATTRIBUTE_SECTION_VARS(blink_malloc);
464-
// actual functions are in third_party/blink_headless/.../{PartitionAlloc,
465-
// FastMalloc}.cpp.
466463

467464
#define ADDR_IN_ATTRIBUTE_SECTION(addr, name) \
468465
(reinterpret_cast<uintptr_t>(ABSL_ATTRIBUTE_SECTION_START(name)) <= \
@@ -486,23 +483,21 @@ static inline bool InHookCaller(const void* caller) {
486483
static absl::once_flag in_hook_caller_once;
487484

488485
static void InitializeInHookCaller() {
489-
ABSL_INIT_ATTRIBUTE_SECTION_VARS(google_malloc);
490-
if (ABSL_ATTRIBUTE_SECTION_START(google_malloc) ==
491-
ABSL_ATTRIBUTE_SECTION_STOP(google_malloc)) {
492-
ABSL_RAW_LOG(ERROR,
493-
"google_malloc section is missing, "
494-
"thus InHookCaller is broken!");
495-
}
496486
ABSL_INIT_ATTRIBUTE_SECTION_VARS(malloc_hook);
497487
if (ABSL_ATTRIBUTE_SECTION_START(malloc_hook) ==
498488
ABSL_ATTRIBUTE_SECTION_STOP(malloc_hook)) {
499489
ABSL_RAW_LOG(ERROR,
500490
"malloc_hook section is missing, "
501491
"thus InHookCaller is broken!");
502492
}
493+
ABSL_INIT_ATTRIBUTE_SECTION_VARS(google_malloc);
494+
if (ABSL_ATTRIBUTE_SECTION_START(google_malloc) ==
495+
ABSL_ATTRIBUTE_SECTION_STOP(google_malloc)) {
496+
ABSL_RAW_LOG(ERROR,
497+
"google_malloc section is missing, "
498+
"thus InHookCaller is broken!");
499+
}
503500
ABSL_INIT_ATTRIBUTE_SECTION_VARS(blink_malloc);
504-
// The blink_malloc section is only expected to be present in binaries
505-
// linking against the blink rendering engine in third_party/blink_headless.
506501
}
507502

508503
// We can improve behavior/compactness of this function
@@ -574,7 +569,8 @@ extern "C" int MallocHook_GetCallerStackTrace(
574569
// still allow users to disable this in special cases that can't be easily
575570
// detected during compilation, via -DABSL_MALLOC_HOOK_MMAP_DISABLE or #define
576571
// ABSL_MALLOC_HOOK_MMAP_DISABLE.
577-
// TODO(b/62370839): Remove MALLOC_HOOK_MMAP_DISABLE in CROSSTOOL for tsan and
572+
//
573+
// TODO(absl-team): Remove MALLOC_HOOK_MMAP_DISABLE in CROSSTOOL for tsan and
578574
// msan config; Replace MALLOC_HOOK_MMAP_DISABLE with
579575
// ABSL_MALLOC_HOOK_MMAP_DISABLE for other special cases.
580576
#if !defined(THREAD_SANITIZER) && !defined(MEMORY_SANITIZER) && \

absl/base/internal/raw_logging.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
//
3535
// This preprocessor token is also defined in raw_io.cc. If you need to copy
3636
// this, consider moving both to config.h instead.
37-
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || \
38-
defined(__GENCLAVE__)
37+
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__)
3938
#include <unistd.h>
4039

40+
4141
#define ABSL_HAVE_POSIX_WRITE 1
4242
#define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1
4343
#else
@@ -110,10 +110,6 @@ namespace {
110110

111111
// CAVEAT: vsnprintf called from *DoRawLog below has some (exotic) code paths
112112
// that invoke malloc() and getenv() that might acquire some locks.
113-
// If this becomes a problem we should reimplement a subset of vsnprintf
114-
// that does not need locks and malloc.
115-
// E.g. google3/third_party/clearsilver/core/util/snprintf.c
116-
// looks like such a reimplementation.
117113

118114
// Helper for RawLog below.
119115
// *DoRawLog writes to *buf of *size and move them past the written portion.

absl/base/internal/scheduling_mode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
//
15-
// Core interfaces and definitions used by by low-level //base interfaces such
16-
// as SpinLock.
15+
// Core interfaces and definitions used by by low-level interfaces such as
16+
// SpinLock.
1717

1818
#ifndef ABSL_BASE_INTERNAL_SCHEDULING_MODE_H_
1919
#define ABSL_BASE_INTERNAL_SCHEDULING_MODE_H_

absl/base/internal/spinlock_wait.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
// Operations to make atomic transitions on a word, and to allow
1919
// waiting for those transitions to become possible.
2020

21-
// This file is used internally in spinlock.cc and once.cc, and a few other
22-
// places listing in //base:spinlock_wait_users. If you need to use it outside
23-
// of //base, please request permission to be added to that list.
24-
2521
#include <stdint.h>
2622
#include <atomic>
2723

absl/base/internal/sysinfo.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ static int num_cpus = 0;
5757
static double nominal_cpu_frequency = 1.0; // 0.0 might be dangerous.
5858

5959
static int GetNumCPUs() {
60-
#if defined(__myriad2__) || defined(__GENCLAVE__)
61-
// TODO(b/28296132): Calling std::thread::hardware_concurrency() induces a
62-
// link error on myriad2 builds.
63-
// TODO(b/62709537): Support std::thread::hardware_concurrency() in gEnclalve.
60+
#if defined(__myriad2__)
6461
return 1;
6562
#else
6663
// Other possibilities:

0 commit comments

Comments
 (0)