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
- 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.
You can remove this continue.