This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by zatrazz on Jun 16 2015, 10:42 AM.

Details

Summary

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

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

Diff Detail

Event Timeline

zatrazz updated this revision to Diff 27772.Jun 16 2015, 10:42 AM
zatrazz retitled this revision from to [lld] [ELF/x86_64] Fix initial-exec TLS access.
zatrazz updated this object.
zatrazz edited the test plan for this revision. (Show Details)
zatrazz added reviewers: ruiu, shankar.easwaran.
zatrazz added a project: lld.
zatrazz added subscribers: Unknown Object (MLST), lld.
ruiu accepted this revision.Jun 16 2015, 3:08 PM
ruiu edited edge metadata.

LGTM with these minor fixes.

lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h
43

You can remove this continue.

lib/ReaderWriter/ELF/X86_64/X86_64SectionChunks.cpp
19

Move { to the end of the last line.

lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
33

Ditto

This revision is now accepted and ready to land.Jun 16 2015, 3:08 PM
zatrazz closed this revision.Jun 24 2015, 6:34 AM