From 447f72b8efa34b20e24d609d94ff2adc922a7ae9 Mon Sep 17 00:00:00 2001 From: Evgeniy Didin Date: Wed, 24 Oct 2018 17:10:10 +0300 Subject: ARC: Accommodate TLS fix in Binutils [1] fixes clash of TLS variables on ARC and since LD now calculates relocations a bit different now we need to update dynamic loader as well otherwise relocs will be calculated improperly. Note this is an ABI change and should go in-line with corresponding ARC tools. That said either arc-2018.09 (to be released in few weeks) or the next version of upstream Binutils (2.32) are required for normal TLS work on ARC. Testcase: ----------------------------------8<------------------------------- #include int foo3(void); int foo1(void); #ifdef _SHARED int foo1(){ static __thread int val3=1; val3 += 2; return val3; } #elif _SHARED2 int foo3(){ static __thread int val2=0; val2 += 2; return val2; } #else int main(){ printf("foo1 = %d \n", foo1()); printf("foo3 = %d \n", foo3()); return 0; } #endif --------------------------------->8--------------------------------------- The result shoud be: ----8<---- foo1 = 3 foo3 = 2 ---->8---- Commands to build artefacts: ----------------------------------------8<------------------------------- arc-linux-gcc -fPIE -ffunction-sections -fdata-sections -pthread -Os \ -fPIC -o testtls.o -D_SHARED -c tst.c arc-linux-gcc -fPIE -ffunction-sections -fdata-sections -pthread -Os \ -fPIC -o testtls2.o -D_SHARED2 -c tst.c arc-linux-gcc -shared -o libtesttls.so testtls.o testtls2.o -lm -Os arc-linux-gcc tst.c -o tst.out -L./ -ltesttls -Os -fPIE --------------------------------->8--------------------------------------- Add path to libtesttls.so file to LD_LIBRARY_PATH before runnig tst.out application. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=714e9a954a2e4123dcb26bb8da850e1344de4f5f Signed-off-by: Alexey Brodkin Signed-off-by: Evgeniy Didin CC: Cupertino Miranda CC: Vineet Gupta CC: Waldemar Brodkorb --- ldso/ldso/arc/elfinterp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ldso') diff --git a/ldso/ldso/arc/elfinterp.c b/ldso/ldso/arc/elfinterp.c index a30c19bcb..61029185f 100644 --- a/ldso/ldso/arc/elfinterp.c +++ b/ldso/ldso/arc/elfinterp.c @@ -165,7 +165,7 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct r_scope_elem *scope, *reloc_addr = tls_tpnt->l_tls_modid; break; case R_ARC_TLS_DTPOFF: - *reloc_addr = symbol_addr; + *reloc_addr += symbol_addr; break; case R_ARC_TLS_TPOFF: CHECK_STATIC_TLS ((struct link_map *) tls_tpnt); -- cgit v1.2.3