+
+ /* Make an initial pass setting up TLS before performing relocs.
+ * This provides the TP-based offset of each DSO's TLS for
+ * use in TP-relative relocations. After relocations, we need
+ * to copy the TLS images again in case they had relocs. */
+ tls_size += sizeof(struct pthread) + 4*sizeof(size_t);
+ __libc.tls_size = tls_size;
+ __libc.tls_cnt = tls_cnt;
+ if (tls_cnt) {
+ struct dso *p;
+ void *mem = mmap(0, __libc.tls_size, PROT_READ|PROT_WRITE,
+ MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+ if (mem==MAP_FAILED ||
+ !__install_initial_tls(__copy_tls(mem, tls_cnt))) {
+ dprintf(2, "%s: Error getting %zu bytes thread-local storage: %m\n",
+ argv[0], tls_size);
+ _exit(127);
+ }
+ for (p=head; p; p=p->next) {
+ if (!p->tls_id) continue;
+ p->tls_offset = (char *)__pthread_self()
+ - (char *)__pthread_self()->dtv[p->tls_id];
+ }
+ }
+