1From 4064f77d2f550762cbf220fec7c26a8ce4219ea4 Mon Sep 17 00:00:00 2001
2From: Alexander Egorenkov <egorenar@linux.ibm.com>
3Date: Sun, 8 Aug 2021 11:19:52 +0200
4Subject: [PATCH] src/rtld/dl-tls.c: Fix TLS offsets computation for s390 arch
5
6rtld_determine_tlsoffsets() didn't handle s390 arch properly by falling
7back to the default case. If TLS_TCB_AT_TP is 1, then set offset to -1.
8
9From glibc's sysdeps/s390/nptl/tls.h:
10-------------------------------------
11/* The TCB can have any size and the memory following the address the
12   thread pointer points to is unspecified.  Allocate the TCB there.  */
13define TLS_TCB_AT_TP	1
14define TLS_DTV_AT_TP	0
15
16This lead to the following error:
17---------------------------------
18prelink-rtld: error while loading shared libraries: /lib64/libc.so.6: cannot handle TLS data
19
20Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
21---
22 src/rtld/dl-tls.c | 5 +++++
23 1 file changed, 5 insertions(+)
24
25diff --git a/src/rtld/dl-tls.c b/src/rtld/dl-tls.c
26index 280cee45f950..29422dcfd25e 100644
27--- a/src/rtld/dl-tls.c
28+++ b/src/rtld/dl-tls.c
29@@ -143,6 +143,11 @@ rtld_determine_tlsoffsets (int e_machine, struct r_scope_elem *search_list)
30       tls_tcb_size = 0;
31       break;
32
33+    case EM_S390:
34+      tls_tcb_at_tp = 1;
35+      tls_tcb_size = -1;
36+      break;
37+
38     default:
39       /* Hope there's no TLS!  */
40       for (i = 0; i < search_list->r_nlist; i++)
41--
422.31.1
43
44