title: What are the real ELF TLS ABI requirements for each cpu arch?
body: <p><a href="http://www.akkadia.org/drepper/tls.pdf" rel="noreferrer">Ulrich Drepper's paper</a> on thread-local storage outlines the TLS ABI for several different cpu architectures, but I'm finding it insufficient as a basis for implementing TLS for two reasons:</p>
  
  <ol>
  <li>It omits a number of important archs like ARM, MIPS, etc. (while including a bunch of completely-irrelevant ones like Itanium)</li>
  <li>More importantly, it mixes a lot of implementation details with ABI, so that it's hard to tell which properties are required for interoperability, and which are just aspects of his implementation.</li>
  </ol>
  
  <p>As an example, the only actual ABI requirements for i386 are:</p>
  
  <ul>
  <li><code>%gs:0</code> points to a pointer to itself.</li>
  <li>The main executable's TLS segment, if any, must be located at a fixed (by the linker, negative) offset from this address.</li>
  <li>All other TLS segments for initially-loaded libraries must have a runtime-constant (i.e. same for each thread, but not necessarily the same across different program runs) offsets relative to this address (and the dynamic linker must be able to fill in relocations with these offsets).</li>
  <li><code>___tls_get_addr</code> and <code>__tls_get_addr</code> functions must exist with the correct semantics for looking up arbitrary TLS segments.</li>
  </ul>
  
  <p>In particular, the existence or layout of a DTV is <strong>not</strong> part of the ABI, nor is the ordering/layout of TLS segments other than the main program's.</p>
  
  <p>It seems that any arch using "TLS variant II" has roughly the above ABI requirements. But I don't understand the requirements of "TLS variant I" very well at all, and it seems from reading sources (in uClibc and glibc) that there may even be several variants of "variant I".</p>
  
  <p>Are there any better documents I should be looking at, or can somebody familiar with the workings of TLS explain the ABI requirements to me?</p>