Skip to content

Commit 29a1062

Browse files
Maqrkkyuri91
authored andcommitted
Asan: Remove initializer for tsd_key
This caused a crash in asan with the current state of constructors and destructors. Originally, it's meant to be a thread_local with a constructor that runs lazily on first use. Currently in cheerp, thread_local constructors are not supported. Removing the initializer is safe because the struct is only ever used as a global, and it's initialized to zero by default. This was not a problem before, because the constructor was never run. Since it initialized to zero it had no effect. With the work on global destructors however, there is now a reason to run this constructor.
1 parent 98d893a commit 29a1062

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

compiler-rt/lib/asan/asan_cheerpwasm.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ void FlushUnneededASanShadowMemory(uptr p, uptr size) {}
3939

4040
static void (*tsd_destructor)(void *tsd) = nullptr;
4141

42+
// Cheerp: for now we've removed the initializer for tsd_key's constructor.
43+
// It caused a crash in ASAN because the constructor for the global is run after the asan module constructor has already used and set it.
44+
// Originally the global is meant to be a thread_local, but thread_local constructors and destructors are not yet supported.
4245
struct tsd_key {
43-
tsd_key() : key(nullptr) {}
46+
tsd_key() {}
4447
~tsd_key() {
4548
CHECK(tsd_destructor);
4649
if (key)

0 commit comments

Comments
 (0)