From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7999 Path: news.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 4/5] dynlink.c: pass gnu-hash table pointer to gnu_lookup Date: Wed, 24 Jun 2015 02:24:54 +0300 Message-ID: <1435101895-18240-5-git-send-email-amonakov@ispras.ru> References: <1435101895-18240-1-git-send-email-amonakov@ispras.ru> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1435107368 14358 80.91.229.3 (24 Jun 2015 00:56:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 24 Jun 2015 00:56:08 +0000 (UTC) Cc: Alexander Monakov To: musl@lists.openwall.com Original-X-From: musl-return-8012-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jun 24 02:56:07 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Z7Yyy-0004Mm-Px for gllmg-musl@m.gmane.org; Wed, 24 Jun 2015 02:56:04 +0200 Original-Received: (qmail 24390 invoked by uid 550); 24 Jun 2015 00:56:00 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 3939 invoked from network); 23 Jun 2015 23:25:39 -0000 X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435101895-18240-1-git-send-email-amonakov@ispras.ru> Xref: news.gmane.org gmane.linux.lib.musl.general:7999 Archived-At: The callers need to check the value of the pointer anyway, so make them pass the pointer to gnu_lookup instead of reloading it there. Reorder gnu_lookup arguments so that always-used ones are listed first. GCC can choose a calling convention with arguments in registers (e.g. up to 3 arguments in eax, ecx, edx on x86), but cannot reorder the arguments for static functions. --- src/ldso/dynlink.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c index 28812ef..99be7d0 100644 --- a/src/ldso/dynlink.c +++ b/src/ldso/dynlink.c @@ -235,9 +235,8 @@ static Sym *sysv_lookup(const char *s, uint32_t h, struct dso *dso) return 0; } -static Sym *gnu_lookup(const char *s, uint32_t h1, struct dso *dso) +static Sym *gnu_lookup(uint32_t h1, struct dso *dso, uint32_t *hashtab, const char *s) { - uint32_t *hashtab = dso->ghashtab; uint32_t nbuckets = hashtab[0]; uint32_t *buckets = hashtab + 4 + hashtab[2]*(sizeof(size_t)/4); uint32_t i = buckets[umod(h1, nbuckets, &dso->gudiv)]; @@ -257,9 +256,9 @@ static Sym *gnu_lookup(const char *s, uint32_t h1, struct dso *dso) return 0; } -static Sym *gnu_lookup_filtered(const char *s, uint32_t h1, struct dso *dso, uint32_t fofs, size_t fmask) +static Sym *gnu_lookup_filtered(uint32_t h1, struct dso *dso, uint32_t *hashtab, const char *s, + uint32_t fofs, size_t fmask) { - uint32_t *hashtab = dso->ghashtab; size_t *bloomwords = hashtab+4; size_t f = bloomwords[fofs & dso->ghashmask]; if (!(f & fmask)) return 0; @@ -267,7 +266,7 @@ static Sym *gnu_lookup_filtered(const char *s, uint32_t h1, struct dso *dso, uin f >>= (h1 >> hashtab[3]) % (8 * sizeof f); if (!(f & 1)) return 0; - return gnu_lookup(s, h1, dso); + return gnu_lookup(h1, dso, hashtab, s); } #define OK_TYPES (1<next) { Sym *sym; if (!dso->global) continue; - if (dso->ghashtab) { + if ((ght = dso->ghashtab)) { if (!ghm) { gh = gnu_hash(s); int maskbits = 8 * sizeof ghm; gho = gh / maskbits; ghm = 1ul << gh % maskbits; } - sym = gnu_lookup_filtered(s, gh, dso, gho, ghm); + sym = gnu_lookup_filtered(gh, dso, ght, s, gho, ghm); } else { if (!h) h = sysv_hash(s); sym = sysv_lookup(s, h, dso); @@ -1623,7 +1622,7 @@ void *__tls_get_addr(size_t *); static void *do_dlsym(struct dso *p, const char *s, void *ra) { size_t i; - uint32_t h = 0, gh = 0; + uint32_t h = 0, gh = 0, *ght; Sym *sym; if (p == head || p == RTLD_DEFAULT || p == RTLD_NEXT) { if (p == RTLD_DEFAULT) { @@ -1641,9 +1640,9 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra) } if (invalid_dso_handle(p)) return 0; - if (p->ghashtab) { + if ((ght = p->ghashtab)) { gh = gnu_hash(s); - sym = gnu_lookup(s, gh, p); + sym = gnu_lookup(gh, p, ght, s); } else { h = sysv_hash(s); sym = sysv_lookup(s, h, p); @@ -1653,9 +1652,9 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra) if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES)) return p->base + sym->st_value; if (p->deps) for (i=0; p->deps[i]; i++) { - if (p->deps[i]->ghashtab) { + if ((ght = p->deps[i]->ghashtab)) { if (!gh) gh = gnu_hash(s); - sym = gnu_lookup(s, gh, p->deps[i]); + sym = gnu_lookup(gh, p->deps[i], ght, s); } else { if (!h) h = sysv_hash(s); sym = sysv_lookup(s, h, p->deps[i]);