Skip to content

Commit a72dc86

Browse files
committed
tsan: tsan_interface.h: make constants static
Note that in C++ the static keyword is implicit for const objects. In C however it is not, and we get clashes at link time after including the header from more than one C file: lib.a(bar.o):(.rodata+0x0): multiple definition of `__tsan_mutex_linker_init' lib.a(foo.o):(.rodata+0x0): first defined here lib.a(bar.o):(.rodata+0xc): multiple definition of `__tsan_mutex_not_static' lib.a(foo.o):(.rodata+0xc): first defined here <snip> Indeed both foo.o and bar.o define the clashing symbols: $ nm foo.o <snip> 0000000000000000 R __tsan_mutex_linker_init 000000000000000c R __tsan_mutex_not_static <snip> Fix it by explicitly making the constants static. Reviewed-in: https://reviews.llvm.org/D75820 Author: cota (Emilio G. Cota)
1 parent ef4f939 commit a72dc86

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

compiler-rt/include/sanitizer/tsan_interface.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,34 @@ void __tsan_release(void *addr);
3838

3939
// Mutex has static storage duration and no-op constructor and destructor.
4040
// This effectively makes tsan ignore destroy annotation.
41-
const unsigned __tsan_mutex_linker_init = 1 << 0;
41+
static const unsigned __tsan_mutex_linker_init = 1 << 0;
4242
// Mutex is write reentrant.
43-
const unsigned __tsan_mutex_write_reentrant = 1 << 1;
43+
static const unsigned __tsan_mutex_write_reentrant = 1 << 1;
4444
// Mutex is read reentrant.
45-
const unsigned __tsan_mutex_read_reentrant = 1 << 2;
45+
static const unsigned __tsan_mutex_read_reentrant = 1 << 2;
4646
// Mutex does not have static storage duration, and must not be used after
4747
// its destructor runs. The opposite of __tsan_mutex_linker_init.
4848
// If this flag is passed to __tsan_mutex_destroy, then the destruction
4949
// is ignored unless this flag was previously set on the mutex.
50-
const unsigned __tsan_mutex_not_static = 1 << 8;
50+
static const unsigned __tsan_mutex_not_static = 1 << 8;
5151

5252
// Mutex operation flags:
5353

5454
// Denotes read lock operation.
55-
const unsigned __tsan_mutex_read_lock = 1 << 3;
55+
static const unsigned __tsan_mutex_read_lock = 1 << 3;
5656
// Denotes try lock operation.
57-
const unsigned __tsan_mutex_try_lock = 1 << 4;
57+
static const unsigned __tsan_mutex_try_lock = 1 << 4;
5858
// Denotes that a try lock operation has failed to acquire the mutex.
59-
const unsigned __tsan_mutex_try_lock_failed = 1 << 5;
59+
static const unsigned __tsan_mutex_try_lock_failed = 1 << 5;
6060
// Denotes that the lock operation acquires multiple recursion levels.
6161
// Number of levels is passed in recursion parameter.
6262
// This is useful for annotation of e.g. Java builtin monitors,
6363
// for which wait operation releases all recursive acquisitions of the mutex.
64-
const unsigned __tsan_mutex_recursive_lock = 1 << 6;
64+
static const unsigned __tsan_mutex_recursive_lock = 1 << 6;
6565
// Denotes that the unlock operation releases all recursion levels.
6666
// Number of released levels is returned and later must be passed to
6767
// the corresponding __tsan_mutex_post_lock annotation.
68-
const unsigned __tsan_mutex_recursive_unlock = 1 << 7;
68+
static const unsigned __tsan_mutex_recursive_unlock = 1 << 7;
6969

7070
// Annotate creation of a mutex.
7171
// Supported flags: mutex creation flags.
@@ -152,7 +152,7 @@ void __tsan_set_fiber_name(void *fiber, const char *name);
152152

153153
// Flags for __tsan_switch_to_fiber:
154154
// Do not establish a happens-before relation between fibers
155-
const unsigned __tsan_switch_to_fiber_no_sync = 1 << 0;
155+
static const unsigned __tsan_switch_to_fiber_no_sync = 1 << 0;
156156

157157
#ifdef __cplusplus
158158
} // extern "C"

0 commit comments

Comments
 (0)