Skip to content

Commit

Permalink
[sanitizer] Change GetDTLSRange (llvm#108345)
Browse files Browse the repository at this point in the history
We only need to change size, tls_beg should be unchanged.
  • Loading branch information
vitalybuka authored Sep 12, 2024
1 parent 2d47a0b commit ee92645
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ SANITIZER_WEAK_ATTRIBUTE
const void *__sanitizer_get_allocated_begin(const void *p);
}

static bool GetDTLSRange(uptr &tls_beg, uptr &tls_size) {
static uptr GetDTLSRange(uptr tls_beg) {
const void *start = __sanitizer_get_allocated_begin((void *)tls_beg);
if (!start)
return false;
tls_beg = (uptr)start;
tls_size = __sanitizer_get_allocated_size(start);
return 0;
CHECK_EQ(start, (void *)tls_beg);
uptr tls_size = __sanitizer_get_allocated_size(start);
VReport(2, "__tls_get_addr: glibc DTLS suspected; tls={%p,0x%zx}\n",
(void *)tls_beg, tls_size);
return true;
return tls_size;
}

DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
Expand All @@ -142,10 +142,12 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
// creation.
VReport(2, "__tls_get_addr: static tls: %p\n", (void *)tls_beg);
tls_size = 0;
} else if (!GetDTLSRange(tls_beg, tls_size)) {
VReport(2, "__tls_get_addr: Can't guess glibc version\n");
// This may happen inside the DTOR of main thread, so just ignore it.
tls_size = 0;
} else {
tls_size = GetDTLSRange(tls_beg);
if (tls_size) {
VReport(2, "__tls_get_addr: Can't guess glibc version\n");
// This may happen inside the DTOR of main thread, so just ignore it.
}
}
dtv->beg = tls_beg;
dtv->size = tls_size;
Expand Down

0 comments on commit ee92645

Please sign in to comment.