Skip to content

Commit de04a79

Browse files
authored
[asan] Use standard POSIX code for AsanTSD (thread-specific data) handling (#15095)
As well use being less code to maintain and more shared code this also enables thread exit handling which means ASan now tracks thread exit where it didn't before. With the old/existing code noone was ever calling the ASan thread destructor (passed as arg0 to AsanTSDInit). I imagine this approach might not have been possible in the past since there were some issues with using pthread_keys with destructors (e.g. #15086). Testing by running entire `asan` test suite.
1 parent 944bf3c commit de04a79

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

system/lib/compiler-rt/lib/asan/asan_emscripten.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@ void InitializeAsanInterceptors() {}
3535

3636
void FlushUnneededASanShadowMemory(uptr p, uptr size) {}
3737

38-
// We can use a plain thread_local variable for TSD.
39-
static thread_local void *per_thread;
40-
41-
void *AsanTSDGet() { return per_thread; }
42-
43-
void AsanTSDSet(void *tsd) { per_thread = tsd; }
44-
45-
// There's no initialization needed, and the passed-in destructor
46-
// will never be called. Instead, our own thread destruction hook
47-
// (below) will call AsanThread::TSDDtor directly.
48-
void AsanTSDInit(void (*destructor)(void *tsd)) {
49-
DCHECK(destructor == &PlatformTSDDtor);
50-
}
51-
52-
void PlatformTSDDtor(void *tsd) { UNREACHABLE(__func__); }
53-
5438
extern "C" {
5539
void *emscripten_builtin_malloc(size_t size);
5640
void emscripten_builtin_free(void *memory);

system/lib/compiler-rt/lib/asan/asan_posix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void PlatformTSDDtor(void *tsd) {
115115
atomic_signal_fence(memory_order_seq_cst);
116116
AsanThread::TSDDtor(tsd);
117117
}
118-
#elif !SANITIZER_EMSCRIPTEN
118+
#else
119119
static pthread_key_t tsd_key;
120120
static bool tsd_key_inited = false;
121121
void AsanTSDInit(void (*destructor)(void *tsd)) {

0 commit comments

Comments
 (0)