Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1049 from redstar/elf
Browse files Browse the repository at this point in the history
Consider TLS_DTV_OFFSET when calculating the TLS range.
  • Loading branch information
MartinNowak committed Nov 29, 2014
2 parents cc76a1a + 6b099ed commit 5c16984
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/rt/sections_linux.d
Expand Up @@ -820,12 +820,40 @@ struct tls_index

extern(C) void* __tls_get_addr(tls_index* ti);

/* The dynamic thread vector (DTV) pointers may point 0x8000 past the start of
* each TLS block. This is at least true for PowerPC and Mips platforms.
* See: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/powerpc/dl-tls.h;h=f7cf6f96ebfb505abfd2f02be0ad0e833107c0cd;hb=HEAD#l34
* https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/mips/dl-tls.h;h=93a6dc050cb144b9f68b96fb3199c60f5b1fcd18;hb=HEAD#l32
*/
version(X86)
enum TLS_DTV_OFFSET = 0x;
else version(X86_64)
enum TLS_DTV_OFFSET = 0x;
else version(ARM)
enum TLS_DTV_OFFSET = 0x;
else version(AArch64)
enum TLS_DTV_OFFSET = 0x;
else version(SPARC)
enum TLS_DTV_OFFSET = 0x;
else version(SPARC64)
enum TLS_DTV_OFFSET = 0x;
else version(PPC)
enum TLS_DTV_OFFSET = 0x8000;
else version(PPC64)
enum TLS_DTV_OFFSET = 0x8000;
else version(MIPS)
enum TLS_DTV_OFFSET = 0x8000;
else version(MIPS64)
enum TLS_DTV_OFFSET = 0x8000;
else
static assert( false, "Platform not supported." );

void[] getTLSRange(size_t mod, size_t sz)
{
if (mod == 0)
return null;

// base offset
auto ti = tls_index(mod, 0);
return __tls_get_addr(&ti)[0 .. sz];
return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. sz];
}

0 comments on commit 5c16984

Please sign in to comment.