llvm / llvm/llvm-project

sanitize/tsan_interface.h is NOT modules friendly

Open
#164,216 3 comments 0 reactions 0 assignees View on GitHub
code-quality compiler-rt:tsan
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

fowarded from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122344.

GCC's libstdc++'s memory includes sanitize/tsan_interface.h if thread sanitizer is turned on BUT if you use memory in a modules to export anything, GCC 15+ errors out due to `TU-local entities` being in use:
```
error: 'template std::_Sp_atomic< >::_Atomic_count::~_Atomic_count()' exposes TU-local entity '__tsan_mutex_not_static'
tsan_interface.h:50:23: note: '__tsan_mutex_not_static' declared with internal linkage
50 | static const unsigned __tsan_mutex_not_static = 1 << 8;
```

That is __tsan_mutex_not_static is not modules friendly.
None of the following are:
```
// Mutex has static storage duration and no-op constructor and destructor.
// This effectively makes tsan ignore destroy annotation.
static const unsigned __tsan_mutex_linker_init = 1 << 0;
// Mutex is write reentrant.
static const unsigned __tsan_mutex_write_reentrant = 1 << 1;
// Mutex is read reentrant.
static const unsigned __tsan_mutex_read_reentrant = 1 << 2;
// Mutex does not have static storage duration, and must not be used after
// its destructor runs. The opposite of __tsan_mutex_linker_init.
// If this flag is passed to __tsan_mutex_destroy, then the destruction
// is ignored unless this flag was previously set on the mutex.
static const unsigned __tsan_mutex_not_static = 1 << 8;
```

These constants still are an issue:
https://github.com/llvm/llvm-project/blob/086666de834a72eadc302a18e2bc51ba2bce1937/compiler-rt/include/sanitizer/tsan_interface.h#L50

Contributor guide

Open the contributing guide

Research direction

Start with compiler-rt/include/sanitizer/tsan_interface.h around line 50 and inspect the four internal-linkage constants named in the issue. Reproduce the GCC 15+ modules error described in the report, then verify that exporting code using the ThreadSanitizer interface no longer exposes TU-local entities.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.