support looking up thread-local objects with dlsym

This commit is contained in:
Rich Felker 2012-10-19 21:57:56 -04:00
parent deb15b3cf2
commit 0a1c2c1c17
1 changed files with 6 additions and 0 deletions

View File

@ -1089,6 +1089,8 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra)
} }
struct symdef def = find_sym(p, s, 0); struct symdef def = find_sym(p, s, 0);
if (!def.sym) goto failed; if (!def.sym) goto failed;
if ((def.sym->st_info&0xf) == STT_TLS)
return __tls_get_addr((size_t []){def.dso->tls_id, def.sym->st_value});
return def.dso->base + def.sym->st_value; return def.dso->base + def.sym->st_value;
} }
if (p->ghashtab) { if (p->ghashtab) {
@ -1098,6 +1100,8 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra)
h = sysv_hash(s); h = sysv_hash(s);
sym = sysv_lookup(s, h, p); sym = sysv_lookup(s, h, p);
} }
if (sym && (sym->st_info&0xf) == STT_TLS)
return __tls_get_addr((size_t []){p->tls_id, sym->st_value});
if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES)) if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
return p->base + sym->st_value; return p->base + sym->st_value;
if (p->deps) for (i=0; p->deps[i]; i++) { if (p->deps) for (i=0; p->deps[i]; i++) {
@ -1108,6 +1112,8 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra)
if (!h) h = sysv_hash(s); if (!h) h = sysv_hash(s);
sym = sysv_lookup(s, h, p->deps[i]); sym = sysv_lookup(s, h, p->deps[i]);
} }
if (sym && (sym->st_info&0xf) == STT_TLS)
return __tls_get_addr((size_t []){p->deps[i]->tls_id, sym->st_value});
if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES)) if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
return p->deps[i]->base + sym->st_value; return p->deps[i]->base + sym->st_value;
} }