make new TLS setup block even implementation-internals signals
[musl] / src / ldso / dynlink.c
index 21c3eba..93cfb42 100644 (file)
@@ -209,14 +209,20 @@ static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
                        if (!h) h = sysv_hash(s);
                        sym = sysv_lookup(s, h, dso);
                }
-               if (sym && (!need_def || sym->st_shndx) && sym->st_value
-                && (1<<(sym->st_info&0xf) & OK_TYPES)
-                && (1<<(sym->st_info>>4) & OK_BINDS)) {
-                       if (def.sym && sym->st_info>>4 == STB_WEAK) continue;
-                       def.sym = sym;
-                       def.dso = dso;
-                       if (sym->st_info>>4 == STB_GLOBAL) break;
-               }
+               if (!sym) continue;
+               if (!sym->st_shndx)
+                       if (need_def || (sym->st_info&0xf) == STT_TLS)
+                               continue;
+               if (!sym->st_value)
+                       if ((sym->st_info&0xf) != STT_TLS)
+                               continue;
+               if (!(1<<(sym->st_info&0xf) & OK_TYPES)) continue;
+               if (!(1<<(sym->st_info>>4) & OK_BINDS)) continue;
+
+               if (def.sym && sym->st_info>>4 == STB_WEAK) continue;
+               def.sym = sym;
+               def.dso = dso;
+               if (sym->st_info>>4 == STB_GLOBAL) break;
        }
        return def;
 }
@@ -527,6 +533,11 @@ static struct dso *load_library(const char *name)
        /* Add a shortname only if name arg was not an explicit pathname. */
        if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
        if (p->tls_image) {
+               if (!__pthread_self_init()) {
+                       free(p);
+                       munmap(map, map_len);
+                       return 0;
+               }
                p->tls_id = ++tls_cnt;
                tls_align = MAXP2(tls_align, p->tls_align);
                tls_offset += p->tls_size + p->tls_align - 1;
@@ -719,8 +730,7 @@ void *__tls_get_addr(size_t *v)
 
        /* Block signals to make accessing new TLS async-signal-safe */
        sigset_t set;
-       sigfillset(&set);
-       pthread_sigmask(SIG_BLOCK, &set, &set);
+       pthread_sigmask(SIG_BLOCK, SIGALL_SET, &set);
        if (self->dtv && v[0]<=(size_t)self->dtv[0] && self->dtv[v[0]]) {
                pthread_sigmask(SIG_SETMASK, &set, 0);
                return (char *)self->dtv[v[0]]+v[1];