[PATCH] [lld] [ELF/x86_64] Fix initial-exec TLS access

Adhemerval Zanella adhemerval.zanella at linaro.org
Tue Jun 16 10:42:05 PDT 2015


Hi ruiu, shankar.easwaran,

Current approach for initial-exec in ELF/x86_64 is to create a GOT entry
and change the relocation to R_X86_64_PC32 to be handled as a GOT offfset.
However there are two issues with this approach: 1. the R_X86_64_PC32 is
not really required since the GOT relocation will be handle dynamically and
2. the TLS symbols are not being exported externally and then correct
realocation are not being applied.

This patch fixes the R_X86_64_GOTTPOFF handling by just emitting a
R_X86_64_TPOFF64 dynamically one; it also sets R_X86_64_TPOFF64 to be
handled by runtime one.  For second part, the patches uses a similar
strategy used for aarch64, by reimplementing buildDynamicSymbolTable
from X86_64ExecutableWriter and adding the TLS symbols in the dynamic
symbol table.

Some tests had to be adjusted due the now missing R_X86_64_PC32 relocation.
With this test the simple testcase:

t1.c:
__thread int t0;
__thread int t1;
__thread int t2;
__thread int t3;

t0:

extern __thread int t0;
extern __thread int t1;
extern __thread int t2;
extern __thread int t3;

__thread int t4;
__thread int t5;
__thread int t6;
__thread int t7;

int main ()
{
  t0 = 1;
  t1 = 2;
  t2 = 3;
  t3 = 4;

  t4 = 5;
  t5 = 6;
  t6 = 7;
  t7 = 8;

  printf ("%i %i %i %i\n", t0, t1, t2, t3);
  printf ("%i %i %i %i\n", t4, t5, t6, t7);

  return 0;
}

Shows correct output for x86_64.

http://reviews.llvm.org/D10479

Files:
  lib/ReaderWriter/ELF/X86_64/CMakeLists.txt
  lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h
  lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
  lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp
  lib/ReaderWriter/ELF/X86_64/X86_64SectionChunks.cpp
  lib/ReaderWriter/ELF/X86_64/X86_64SectionChunks.h
  lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
  test/elf/X86_64/extern-tls.test
  test/elf/gottpoff.test
  test/elf/tls.test

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10479.27772.patch
Type: text/x-patch
Size: 9922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150616/ac216591/attachment.bin>


More information about the llvm-commits mailing list