Skip to content

Commit b226894

Browse files
committed
[sanitizer] Correct GetTls for x32
Since x32 pointer size is 4 bytes, the self pointer offset in TCB: struct { void *tcb; dtv_t *dtv; void *self; ... should be 8, not 16. Fixes llvm/llvm-project#55288 Differential Revision: https://reviews.llvm.org/D125025
1 parent d455569 commit b226894

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,11 @@ static void GetTls(uptr *addr, uptr *size) {
462462
#elif SANITIZER_GLIBC && defined(__x86_64__)
463463
// For aarch64 and x86-64, use an O(1) approach which requires relatively
464464
// precise ThreadDescriptorSize. g_tls_size was initialized in InitTlsSize.
465+
# if SANITIZER_X32
466+
asm("mov %%fs:8,%0" : "=r"(*addr));
467+
# else
465468
asm("mov %%fs:16,%0" : "=r"(*addr));
469+
# endif
466470
*size = g_tls_size;
467471
*addr -= *size;
468472
*addr += ThreadDescriptorSize();

0 commit comments

Comments
 (0)