public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Which version fixed intersecting stack and static tls block?
@ 2021-01-05 22:09 Fangrui Song
  2021-01-06 11:56 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Fangrui Song @ 2021-01-05 22:09 UTC (permalink / raw)
  To: libc-alpha

I want to remove a piece of code in a compiler-rt (which includes
runtime for sanitizers) patch: https://reviews.llvm.org/D93866

   if (!main) {
     // If stack and tls intersect, make them non-intersecting.
     if (*tls_addr > *stk_addr && *tls_addr < *stk_addr + *stk_size) {
       CHECK_GT(*tls_addr + *tls_size, *stk_addr);
       CHECK_LE(*tls_addr + *tls_size, *stk_addr + *stk_size);
       *stk_size -= *tls_size;
       *tls_addr = *stk_addr + *stk_size;
     }
   }

(The "tls" refers to the static TLS block.
https://sourceware.org/bugzilla/show_bug.cgi?id=16291 is relevant.)
For cross references: https://code.woboq.org/llvm/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp.html#515

The code was committed in the 2012 commit "[tsan] First commit of
ThreadSanitizer (TSan) run-time library." so I suspect the mentioned
glibc issue has long been fixed.  If someone knows when this started to
work, it would be of great help: if the fix is new then compiler-rt
should keep the compatibility for a while.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Which version fixed intersecting stack and static tls block?
  2021-01-05 22:09 Which version fixed intersecting stack and static tls block? Fangrui Song
@ 2021-01-06 11:56 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2021-01-06 11:56 UTC (permalink / raw)
  To: Fangrui Song via Libc-alpha; +Cc: Fangrui Song

* Fangrui Song via Libc-alpha:

> I want to remove a piece of code in a compiler-rt (which includes
> runtime for sanitizers) patch: https://reviews.llvm.org/D93866
>
>    if (!main) {
>      // If stack and tls intersect, make them non-intersecting.
>      if (*tls_addr > *stk_addr && *tls_addr < *stk_addr + *stk_size) {
>        CHECK_GT(*tls_addr + *tls_size, *stk_addr);
>        CHECK_LE(*tls_addr + *tls_size, *stk_addr + *stk_size);
>        *stk_size -= *tls_size;
>        *tls_addr = *stk_addr + *stk_size;
>      }
>    }
>
> (The "tls" refers to the static TLS block.
> https://sourceware.org/bugzilla/show_bug.cgi?id=16291 is relevant.)
> For cross references: https://code.woboq.org/llvm/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp.html#515
>
> The code was committed in the 2012 commit "[tsan] First commit of
> ThreadSanitizer (TSan) run-time library." so I suspect the mentioned
> glibc issue has long been fixed.  If someone knows when this started to
> work, it would be of great help: if the fix is new then compiler-rt
> should keep the compatibility for a while.

I think the quoted code is basically an artifact of the sanitizers'
attempt to divine glibc internal state from externally accessible (but
yet still implementation-internal) interfaces.  So you will have to
figure out what the sanitizers actually need, and see if there is a
more direct way to compute it today.

The TCB/thread descriptor allocation has not changed in a material way
since 2012, only the size computation was tweaked, to deal with guard
region requirements (stack clash protection) and increased userspace
stack usage for signal handlers (mainly on aarch64 and x86-64).

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-06 11:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 22:09 Which version fixed intersecting stack and static tls block? Fangrui Song
2021-01-06 11:56 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).