#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
void *base;
};
+struct td_index {
+ size_t args[2];
+ struct td_index *next;
+};
+
struct dso {
unsigned char *base;
char *name;
void **new_dtv;
unsigned char *new_tls;
int new_dtv_idx, new_tls_idx;
+ struct td_index *td_index;
struct dso *fini_next;
char *shortname;
char buf[];
REL_DTPOFF,
REL_TPOFF,
REL_TPOFF_NEG,
+ REL_TLSDESC,
};
#include "reloc.h"
static pthread_rwlock_t lock;
static struct debug debug;
static size_t tls_cnt, tls_offset, tls_align = 4*sizeof(size_t);
+static size_t static_tls_cnt;
static pthread_mutex_t init_fini_lock = { ._m_type = PTHREAD_MUTEX_RECURSIVE };
static long long builtin_tls[(sizeof(struct pthread) + 64)/sizeof(long long)];
#define NO_INLINE_ADDEND (1<<REL_COPY | 1<<REL_GOT | 1<<REL_PLT)
+ptrdiff_t __tlsdesc_static(), __tlsdesc_dynamic();
+
static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride)
{
unsigned char *base = dso->base;
*reloc_addr = def.dso->tls_offset - tls_val + addend;
break;
#endif
+ case REL_TLSDESC:
+ if (stride<3) addend = reloc_addr[1];
+ if (runtime && def.dso->tls_id >= static_tls_cnt) {
+ struct td_index *new = malloc(sizeof *new);
+ if (!new) error(errbuf, sizeof errbuf,
+ "Error relocating %s: cannot allocate TLSDESC for %s",
+ dso->name, sym ? name : "(local)" );
+ new->next = dso->td_index;
+ dso->td_index = new;
+ new->args[0] = def.dso->tls_id;
+ new->args[1] = tls_val + addend;
+ reloc_addr[0] = (size_t)__tlsdesc_dynamic;
+ reloc_addr[1] = (size_t)new;
+ } else {
+ reloc_addr[0] = (size_t)__tlsdesc_static;
+#ifdef TLS_ABOVE_TP
+ reloc_addr[1] = tls_val + def.dso->tls_offset
+ + TPOFF_K + addend;
+#else
+ reloc_addr[1] = tls_val - def.dso->tls_offset
+ + addend;
+#endif
+ }
+ break;
}
}
}
dprintf(2, "%s: Thread-local storage not supported by kernel.\n", argv[0]);
_exit(127);
}
+ static_tls_cnt = tls_cnt;
if (ldso_fail) _exit(127);
if (ldd_mode) _exit(0);
for (p=orig_tail->next; p; p=next) {
next = p->next;
munmap(p->map, p->map_len);
+ while (p->td_index) {
+ void *tmp = p->td_index->next;
+ free(p->td_index);
+ p->td_index = tmp;
+ }
free(p->deps);
free(p);
}