什么是每个CPU拱真正的ELF ABI TLS的要求? [英] What are the real ELF TLS ABI requirements for each cpu arch?

查看:131
本文介绍了什么是每个CPU拱真正的ELF ABI TLS的要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

乌尔里希Drepper的论文概述了TLS ABI为几个不同的CPU架构,但我中号发现它不足以作为实施TLS的原因有两个基础:

Ulrich Drepper's paper 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:


  1. 它省略了许多功能,如ARM,MIPS等重要archs(同时还包括像安腾一堆完全无关的那些的)

  2. 更重要的是,它混合了很多与ABI实施细则,使之很难说是必需的互操作性哪些属性,哪些只是他实现的各个方面。

作为一个例子,为i386的唯一实际ABI要求是:

As an example, the only actual ABI requirements for i386 are:


  • %GS:0 指向一个指针本身

  • 主可执行文件的TLS段,如果有的话,必须位于一个固定的(通过连接体,负)从这个地址偏移量。

  • 用于最初加载的库中的所有其他的TLS段必须具有一个运行时恒定(即同为每个线程,但并不一定在不同的程序运行是相同的)偏移相对于该地址(以及动态链接程序必须能够补在与这些偏移搬迁)。

  • ___ tls_get_addr __ tls_get_addr 功能必须与查找任意TLS段正确的语义存在。

  • %gs:0 points to a pointer to itself.
  • The main executable's TLS segment, if any, must be located at a fixed (by the linker, negative) offset from this address.
  • 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).
  • ___tls_get_addr and __tls_get_addr functions must exist with the correct semantics for looking up arbitrary TLS segments.

在特别是数字电视的存在或布局的不可以的ABI的一部分,也不是比主程序的其他订货/ TLS段的布局。

In particular, the existence or layout of a DTV is not part of the ABI, nor is the ordering/layout of TLS segments other than the main program's.

看来,使用TLS变种II的牌坊有大约以上ABI要求。但我不明白TLS变种I的要求,很好可言的,它从阅读源(在uClibc里和glibc)看来,甚至有可能出现几个变种变种I。

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".

有什么更好的文件我应该看,或可有人熟悉TLS的工作原理解释ABI要求我?

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?

推荐答案

我可以迄今收集的最好的是:

The best I can gather so far is:

对于任何一个TLS变量, __ tls_get_addr 或其他特定拱功能必须存在并有用于查找任何TLS对象正确的语义,并且任意两个TLS之间的相对偏移段必须是一个运行时间常数(对于每个线程相同的偏移)。

For either TLS variant, __tls_get_addr or other arch-specific functions must exist and have the correct semantics for looking up any TLS object, and the relative offset between any two TLS segments must be a runtime constant (same offset for each thread).

有关TLS变种II(I386,等),线程指针寄存器(这实际上可能没有一个寄存器,但也许有些类似机制%葡萄糖:0 甚至会陷入内核空间;为了简单起见,虽然我们只把它叫做寄存器)点的刚刚过去的结束的的TLS段为主要的可执行文件,其中刚刚过去的终结包括四舍五入至在TLS段的对齐的倍数。

For TLS variant II (i386, etc.), the "thread pointer register" (which may not actually be a register, but perhaps some mechanism like %gs:0 or even a trap into kernelspace; for simplicity though let's just call it a register) points just past the end of the TLS segment for the main executable, where "just past the end" includes rounding up to the next multiple of the TLS segment's alignment.

有关TLS变种我的线程指针寄存器指向一些固定的距离的开始的在TLS段偏移的主要可执行文件。这种失调变化由牌坊。 (已经选择了一些丑陋的RISC archs通过符号16位偏移量,最大限度获取TLS的量,因为编译器无法知道是否已重定位偏移都是16位的,因此必须的方式,也令我非常没用始终使用负载上限/加指令)产生速度较慢,较大的32位偏移code。

For TLS variant I, the "thread pointer register" points to some fixed offset from the beginning of the TLS segment for the main executable. This offset varies by arch. (It has been chosen on some ugly RISC archs to maximize the amount of TLS accessible via signed 16-bit offsets, which strikes me as extremely useless since the compiler has no way of knowing whether the relocated offset will fit in 16 bits and thus must always generate the slower, larger 32-bit-offset code using load-upper/add instructions).

ABI的一部分。在这两个变种I和II,它是有道理来存储线程​​从线程指针寄存器的固定偏移实现内部资料,无论怎样安全地避免重叠TLS段。

As far as I can tell, nothing about TCBs, DTVs, etc. is part of the ABI, in the sense that applications are not permitted to access these structures, nor is the location of any TLS segment other than the main executable's part of the ABI. In both variants I and II, it makes sense to store implementation-internal information for the thread at a fixed offset from the "thread pointer register", in whichever way safely avoids overlapping the TLS segment.

这篇关于什么是每个CPU拱真正的ELF ABI TLS的要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆