Skip to content

Commit 0b5af59

Browse files
Abseil Teamsuertreus
authored andcommitted
Export of internal Abseil changes
-- 1a5831c2b4b85e0151b7952e47f4b80827937620 by Laramie Leavitt <[email protected]>: Implement FuzzingBitGen, an adapter which allows existing randomized tests which use absl::BitGenRef to easily integrate with fuzz testing. I found myself implementing a similar option in our tensorstore project to fuzz test a storage layer and figured that it would be more useful as a common tool with defaults that take the non-random path. This is similar to the FuzzedDataProvider mechanism which generates random values from a fuzz string, and is used to generate fuzz test inputs, and internally it uses FuzzedDataProvider. The basic technique used here is to construct mocking lambdas for all of the absl mock distribution configurations, and forwarding the parameters to fuzzing-specific implementations that call into FuzzedDataProvider. The default paths for the distributions are either the bounds or a median value. PiperOrigin-RevId: 358432715 -- e7968538c5ef5cd0b9822dbeac0f659b5e7d49b3 by Derek Mauro <[email protected]>: Give extern C symbols a unique name when the inline namespace is given. This partially addresses #851 PiperOrigin-RevId: 358403842 GitOrigin-RevId: 1a5831c2b4b85e0151b7952e47f4b80827937620 Change-Id: Id5ca0251498e390a8efa7210a17cc2cabb2c7dd8
1 parent b5173c8 commit 0b5af59

19 files changed

+86
-49
lines changed

absl/base/config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,16 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
121121
#if ABSL_OPTION_USE_INLINE_NAMESPACE == 0
122122
#define ABSL_NAMESPACE_BEGIN
123123
#define ABSL_NAMESPACE_END
124+
#define ABSL_INTERNAL_C_SYMBOL(x) x
124125
#elif ABSL_OPTION_USE_INLINE_NAMESPACE == 1
125126
#define ABSL_NAMESPACE_BEGIN \
126127
inline namespace ABSL_OPTION_INLINE_NAMESPACE_NAME {
127128
#define ABSL_NAMESPACE_END }
129+
#define ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v) x##_##v
130+
#define ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, v) \
131+
ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v)
132+
#define ABSL_INTERNAL_C_SYMBOL(x) \
133+
ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, ABSL_OPTION_INLINE_NAMESPACE_NAME)
128134
#else
129135
#error options.h is misconfigured.
130136
#endif

absl/base/dynamic_annotations.h

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
// Define race annotations.
111111

112112
#if ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 1
113+
// Some of the symbols used in this section (e.g. AnnotateBenignRaceSized) are
114+
// defined by the compiler-based santizer implementation, not by the Abseil
115+
// library. Therefore they do not use ABSL_INTERNAL_C_SYMBOL.
113116

114117
// -------------------------------------------------------------
115118
// Annotations that suppress errors. It is usually better to express the
@@ -286,17 +289,22 @@ ABSL_INTERNAL_END_EXTERN_C
286289
// Define IGNORE_READS_BEGIN/_END annotations.
287290

288291
#if ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED == 1
292+
// Some of the symbols used in this section (e.g. AnnotateIgnoreReadsBegin) are
293+
// defined by the compiler-based implementation, not by the Abseil
294+
// library. Therefore they do not use ABSL_INTERNAL_C_SYMBOL.
289295

290296
// Request the analysis tool to ignore all reads in the current thread until
291297
// ABSL_ANNOTATE_IGNORE_READS_END is called. Useful to ignore intentional racey
292298
// reads, while still checking other reads and all writes.
293299
// See also ABSL_ANNOTATE_UNPROTECTED_READ.
294-
#define ABSL_ANNOTATE_IGNORE_READS_BEGIN() \
295-
ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsBegin)(__FILE__, __LINE__)
300+
#define ABSL_ANNOTATE_IGNORE_READS_BEGIN() \
301+
ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsBegin) \
302+
(__FILE__, __LINE__)
296303

297304
// Stop ignoring reads.
298-
#define ABSL_ANNOTATE_IGNORE_READS_END() \
299-
ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsEnd)(__FILE__, __LINE__)
305+
#define ABSL_ANNOTATE_IGNORE_READS_END() \
306+
ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsEnd) \
307+
(__FILE__, __LINE__)
300308

301309
// Function prototypes of annotations provided by the compiler-based sanitizer
302310
// implementation.
@@ -316,16 +324,22 @@ ABSL_INTERNAL_END_EXTERN_C
316324
// TODO(delesley) -- The exclusive lock here ignores writes as well, but
317325
// allows IGNORE_READS_AND_WRITES to work properly.
318326

319-
#define ABSL_ANNOTATE_IGNORE_READS_BEGIN() \
320-
ABSL_INTERNAL_GLOBAL_SCOPED(AbslInternalAnnotateIgnoreReadsBegin)()
327+
#define ABSL_ANNOTATE_IGNORE_READS_BEGIN() \
328+
ABSL_INTERNAL_GLOBAL_SCOPED( \
329+
ABSL_INTERNAL_C_SYMBOL(AbslInternalAnnotateIgnoreReadsBegin)) \
330+
()
321331

322-
#define ABSL_ANNOTATE_IGNORE_READS_END() \
323-
ABSL_INTERNAL_GLOBAL_SCOPED(AbslInternalAnnotateIgnoreReadsEnd)()
332+
#define ABSL_ANNOTATE_IGNORE_READS_END() \
333+
ABSL_INTERNAL_GLOBAL_SCOPED( \
334+
ABSL_INTERNAL_C_SYMBOL(AbslInternalAnnotateIgnoreReadsEnd)) \
335+
()
324336

325-
ABSL_INTERNAL_STATIC_INLINE void AbslInternalAnnotateIgnoreReadsBegin()
337+
ABSL_INTERNAL_STATIC_INLINE void ABSL_INTERNAL_C_SYMBOL(
338+
AbslInternalAnnotateIgnoreReadsBegin)()
326339
ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE {}
327340

328-
ABSL_INTERNAL_STATIC_INLINE void AbslInternalAnnotateIgnoreReadsEnd()
341+
ABSL_INTERNAL_STATIC_INLINE void ABSL_INTERNAL_C_SYMBOL(
342+
AbslInternalAnnotateIgnoreReadsEnd)()
329343
ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE {}
330344

331345
#else

absl/base/internal/spinlock_akaros.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
extern "C" {
2222

23-
ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
23+
ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)(
2424
std::atomic<uint32_t>* /* lock_word */, uint32_t /* value */,
2525
int /* loop */, absl::base_internal::SchedulingMode /* mode */) {
2626
// In Akaros, one must take care not to call anything that could cause a
@@ -29,7 +29,7 @@ ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
2929
// arbitrary code.
3030
}
3131

32-
ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockWake(
32+
ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)(
3333
std::atomic<uint32_t>* /* lock_word */, bool /* all */) {}
3434

3535
} // extern "C"

absl/base/internal/spinlock_linux.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static_assert(sizeof(std::atomic<uint32_t>) == sizeof(int),
5656

5757
extern "C" {
5858

59-
ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
59+
ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)(
6060
std::atomic<uint32_t> *w, uint32_t value, int loop,
6161
absl::base_internal::SchedulingMode) {
6262
absl::base_internal::ErrnoSaver errno_saver;
@@ -66,8 +66,8 @@ ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
6666
syscall(SYS_futex, w, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, value, &tm);
6767
}
6868

69-
ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockWake(std::atomic<uint32_t> *w,
70-
bool all) {
69+
ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)(
70+
std::atomic<uint32_t> *w, bool all) {
7171
syscall(SYS_futex, w, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, all ? INT_MAX : 1, 0);
7272
}
7373

absl/base/internal/spinlock_posix.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
extern "C" {
2727

28-
ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
28+
ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)(
2929
std::atomic<uint32_t>* /* lock_word */, uint32_t /* value */, int loop,
3030
absl::base_internal::SchedulingMode /* mode */) {
3131
absl::base_internal::ErrnoSaver errno_saver;
@@ -40,7 +40,7 @@ ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
4040
}
4141
}
4242

43-
ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockWake(
43+
ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)(
4444
std::atomic<uint32_t>* /* lock_word */, bool /* all */) {}
4545

4646
} // extern "C"

absl/base/internal/spinlock_wait.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,23 @@ ABSL_NAMESPACE_END
7171
// By changing our extension points to be extern "C", we dodge this
7272
// check.
7373
extern "C" {
74-
void AbslInternalSpinLockWake(std::atomic<uint32_t> *w, bool all);
75-
void AbslInternalSpinLockDelay(
74+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)(std::atomic<uint32_t> *w,
75+
bool all);
76+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)(
7677
std::atomic<uint32_t> *w, uint32_t value, int loop,
7778
absl::base_internal::SchedulingMode scheduling_mode);
7879
}
7980

8081
inline void absl::base_internal::SpinLockWake(std::atomic<uint32_t> *w,
8182
bool all) {
82-
AbslInternalSpinLockWake(w, all);
83+
ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)(w, all);
8384
}
8485

8586
inline void absl::base_internal::SpinLockDelay(
8687
std::atomic<uint32_t> *w, uint32_t value, int loop,
8788
absl::base_internal::SchedulingMode scheduling_mode) {
88-
AbslInternalSpinLockDelay(w, value, loop, scheduling_mode);
89+
ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)
90+
(w, value, loop, scheduling_mode);
8991
}
9092

9193
#endif // ABSL_BASE_INTERNAL_SPINLOCK_WAIT_H_

absl/base/internal/spinlock_win32.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
extern "C" {
2222

23-
void AbslInternalSpinLockDelay(std::atomic<uint32_t>* /* lock_word */,
24-
uint32_t /* value */, int loop,
25-
absl::base_internal::SchedulingMode /* mode */) {
23+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)(
24+
std::atomic<uint32_t>* /* lock_word */, uint32_t /* value */, int loop,
25+
absl::base_internal::SchedulingMode /* mode */) {
2626
if (loop == 0) {
2727
} else if (loop == 1) {
2828
Sleep(0);
@@ -31,7 +31,7 @@ void AbslInternalSpinLockDelay(std::atomic<uint32_t>* /* lock_word */,
3131
}
3232
}
3333

34-
void AbslInternalSpinLockWake(std::atomic<uint32_t>* /* lock_word */,
35-
bool /* all */) {}
34+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)(
35+
std::atomic<uint32_t>* /* lock_word */, bool /* all */) {}
3636

3737
} // extern "C"

absl/container/internal/hashtablez_sampler.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ static bool ShouldForceSampling() {
181181
if (ABSL_PREDICT_TRUE(state == kDontForce)) return false;
182182

183183
if (state == kUninitialized) {
184-
state = AbslContainerInternalSampleEverything() ? kForce : kDontForce;
184+
state = ABSL_INTERNAL_C_SYMBOL(AbslContainerInternalSampleEverything)()
185+
? kForce
186+
: kDontForce;
185187
global_state.store(state, std::memory_order_relaxed);
186188
}
187189
return state == kForce;

absl/container/internal/hashtablez_sampler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void SetHashtablezMaxSamples(int32_t max);
313313
// initialization of static storage duration objects.
314314
// The definition of this constant is weak, which allows us to inject a
315315
// different value for it at link time.
316-
extern "C" bool AbslContainerInternalSampleEverything();
316+
extern "C" bool ABSL_INTERNAL_C_SYMBOL(AbslContainerInternalSampleEverything)();
317317

318318
} // namespace container_internal
319319
ABSL_NAMESPACE_END

absl/container/internal/hashtablez_sampler_force_weak_definition.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ ABSL_NAMESPACE_BEGIN
2121
namespace container_internal {
2222

2323
// See hashtablez_sampler.h for details.
24-
extern "C" ABSL_ATTRIBUTE_WEAK bool AbslContainerInternalSampleEverything() {
24+
extern "C" ABSL_ATTRIBUTE_WEAK bool ABSL_INTERNAL_C_SYMBOL(
25+
AbslContainerInternalSampleEverything)() {
2526
return false;
2627
}
2728

0 commit comments

Comments
 (0)