diff options
author | Rich Felker <dalias@aerifal.cx> | 2015-06-25 22:22:00 +0000 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-06-25 22:22:00 +0000 |
commit | 6ba5517a460c6c438f64d69464fdfc3269a4c91a (patch) | |
tree | 87dda4a304c22209e3e7eca908592e9ec1816ff8 /arch | |
parent | ce337daa00e42d4f2d9a4d9ae0ed51b20249d924 (diff) | |
download | musl-6ba5517a460c6c438f64d69464fdfc3269a4c91a.tar.gz musl-6ba5517a460c6c438f64d69464fdfc3269a4c91a.tar.xz musl-6ba5517a460c6c438f64d69464fdfc3269a4c91a.zip |
fix local-dynamic model TLS on mips and powerpc
the TLS ABI spec for mips, powerpc, and some other (presently unsupported) RISC archs has the return value of __tls_get_addr offset by +0x8000 and the result of DTPOFF relocations offset by -0x8000. I had previously assumed this part of the ABI was actually just an implementation detail, since the adjustments cancel out. however, when the local dynamic model is used for accessing TLS that's known to be in the same DSO, either of the following may happen: 1. the -0x8000 offset may already be applied to the argument structure passed to __tls_get_addr at ld time, without any opportunity for runtime relocations. 2. __tls_get_addr may be used with a zero offset argument to obtain a base address for the module's TLS, to which the caller then applies immediate offsets for individual objects accessed using the local dynamic model. since the immediate offsets have the -0x8000 adjustment applied to them, the base address they use needs to include the +0x8000 offset. it would be possible, but more complex, to store the pointers in the dtv[] array with the +0x8000 offset pre-applied, to avoid the runtime cost of adding 0x8000 on each call to __tls_get_addr. this change could be made later if measurements show that it would help.
Diffstat (limited to 'arch')
-rw-r--r-- | arch/mips/pthread_arch.h | 2 | ||||
-rw-r--r-- | arch/powerpc/pthread_arch.h | 2 |
2 files changed, 4 insertions, 0 deletions
diff --git a/arch/mips/pthread_arch.h b/arch/mips/pthread_arch.h index f8e35ae4..904a2489 100644 --- a/arch/mips/pthread_arch.h +++ b/arch/mips/pthread_arch.h @@ -13,4 +13,6 @@ static inline struct pthread *__pthread_self() #define TLS_ABOVE_TP #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) +#define DTP_OFFSET 0x8000 + #define CANCEL_REG_IP (3-(union {int __i; char __b;}){1}.__b) diff --git a/arch/powerpc/pthread_arch.h b/arch/powerpc/pthread_arch.h index 4115ec8c..1cbfc223 100644 --- a/arch/powerpc/pthread_arch.h +++ b/arch/powerpc/pthread_arch.h @@ -12,6 +12,8 @@ static inline struct pthread *__pthread_self() #define TLS_ABOVE_TP #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) +#define DTP_OFFSET 0x8000 + // offset of the PC register in mcontext_t, divided by the system wordsize // the kernel calls the ip "nip", it's the first saved value after the 32 // GPRs. |