Get the latest tech news

A deep dive into implicit thread-local storage (2018)


forth TLS) is pretty cool, it may appear to be simple at first glance but a good and efficient TLS implementation requires concerted effort from compiler, linker, dynamic linker, kernel, and language runtime. On Linux, an excellent treatment to this topic is Ulrich Drepper’s ELF Handling For Thread-Local Storage, this blog post is my take on the same topic but with a different emphasis on how the details are presented.

After wading through several false positive hits, we arrive at a macro definition TLS_INIT_TP, which uses inline assembly to trigger arch_prctl syscall directly and is responsible for updating the FS register to point to TCB. This finding confirms our previous hypothesis that the dynamic linker runtime allocates and sets up the TCB or struct pthread and then uses arch_prctl to bind the TLS to at least the main thread. DTV has a deceptively simple data structure, but it’s an unfortunate victim of many C trickeries (e.g. negative pointer arithmetics, type aliasing, badly named member variables, etc…).

Get the Android app

Or read this on Hacker News

Read more on:

Photo of deep dive

deep dive

Photo of local storage

local storage

Related news:

News photo

Alan Wake 2: a deep dive into Remedy's high-end ray tracing

News photo

Activision shows deep dive on Call of Duty: Modern Warfare III multiplayer as beta revs up

News photo

The Initial Access Broker Economy: A Deep Dive into Dark Web Hacking Forums