From patchwork Fri Apr 11 15:29:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 338550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7B45C14008F for ; Sat, 12 Apr 2014 01:30:27 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=E/tl5sGl59dBwg2s5P691KkFXoop6Td EeRXO2kxkJ25dxltujEzoFBat3cswUdx51YfBc/mxjjNIGx0w4AElK62e5GuXQFt Hoky7V0aTLX1EMHJ8QZAYZ8kY623JWUNQGNGHaSlr8gdS2ZEfPVMDkhuX/8jx7Yn 8JACdDdPn9Eo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=1QXSAt5K58fzhNzaOfaYpMfrCls=; b=Jt4zG d4kjA6erYQ3opgZI+DBw/xS/cI31VvC9tJVZGp+X3y7dljz0w7mp79ju9rDjHNtf TtEyF+/RjsnYNJw0B1VxNdg+K5uPKId4aIq+6C17vgI4MONeyx6N3pxT98trFwRt aDSGZHNNn/yCGxU6Tgp66KeLXQuaaaErFfbYjc= Received: (qmail 2331 invoked by alias); 11 Apr 2014 15:30:02 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 2121 invoked by uid 89); 11 Apr 2014 15:30:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-wi0-f174.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=MaiptlS4f/7VKSwerzJYZCCmYwTZXGiMRW3riSjz0O8=; b=CgMHH5V62g+Dmq8OXWVtMlrIqsVUbu5dRSlMHtlsA+DCTnmUY1mWckBzZ4vF5sSFgR PM91HENrwgKuuHufVAsDO4FuuKSzslvRgghWvFhSos+SW2ECCVY17VTfivB8lfPdkrRU X8wW7AzoKqjTQLmWKzOMLrALeEI+fAiM0MJ0q4Qu5wpv0+lGpQ7WoJ49ajXcdvAV7ePa EObBmF4JV93vV6FyPSCSqTbazp0PV8K+RLp70w/MdPNVrXjHCohG2m+I+SKODqnbl1z/ VpnOF3Y2EmobHYUNV+ob+LReYoqq+XKUm3eiawQ9OpYvcFa6Dq8469HkCn135lck5OuN 4IOw== X-Gm-Message-State: ALoCoQmzgTRSZNsLWq17+b/Dsi+to+bn+M747oR0+lBitZSBCn66aDUDwmA8HSh0ly+s4zLH+vTx X-Received: by 10.181.5.6 with SMTP id ci6mr3990958wid.39.1397230196251; Fri, 11 Apr 2014 08:29:56 -0700 (PDT) From: Will Newton To: libc-alpha@sourceware.org Subject: [PATCH 3/3] elf/dl-lookup.c: Use __glibc_likely and __glibc_unlikely Date: Fri, 11 Apr 2014 16:29:48 +0100 Message-Id: <1397230188-14581-3-git-send-email-will.newton@linaro.org> In-Reply-To: <1397230188-14581-1-git-send-email-will.newton@linaro.org> References: <1397230188-14581-1-git-send-email-will.newton@linaro.org> Convert all uses of __builtin_expect to __glibc_likely and __glibc_unlikely. Most of these are trivial boolean expressions but a few were not. In particular the use of __builtin_expect in the switch expression in do_lookup_x has been removed. Verified that there are no code changes on x86_64 and ARM aside from line numbers. ChangeLog: 2014-04-11 Will Newton * elf/dl-lookup.c: Use __glibc_unlikely and __glibc_likely rather than __builtin_expect. --- elf/dl-lookup.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c index 1c6ca89..7e7ab22 100644 --- a/elf/dl-lookup.c +++ b/elf/dl-lookup.c @@ -92,11 +92,10 @@ check_match (const char *const undef_name, { unsigned int stt = ELFW(ST_TYPE) (sym->st_info); assert (ELF_RTYPE_CLASS_PLT == 1); - if (__builtin_expect ((sym->st_value == 0 /* No value. */ - && stt != STT_TLS) - || ELF_MACHINE_SYM_NO_MATCH (sym) - || (type_class & (sym->st_shndx == SHN_UNDEF)), - 0)) + if (__glibc_unlikely((sym->st_value == 0 /* No value. */ + && stt != STT_TLS) + || ELF_MACHINE_SYM_NO_MATCH (sym) + || (type_class & (sym->st_shndx == SHN_UNDEF)))) return NULL; /* Ignore all but STT_NOTYPE, STT_OBJECT, STT_FUNC, @@ -405,8 +404,8 @@ do_lookup_x (const char *undef_name, uint_fast32_t new_hash, unsigned int hashbit2 = ((new_hash >> map->l_gnu_shift) & (__ELF_NATIVE_CLASS - 1)); - if (__builtin_expect ((bitmask_word >> hashbit1) - & (bitmask_word >> hashbit2) & 1, 0)) + if (__glibc_unlikely ((bitmask_word >> hashbit1) + & (bitmask_word >> hashbit2) & 1)) { Elf32_Word bucket = map->l_gnu_buckets[new_hash % map->l_nbuckets]; @@ -461,7 +460,7 @@ do_lookup_x (const char *undef_name, uint_fast32_t new_hash, if (sym != NULL) { found_it: - switch (__builtin_expect (ELFW(ST_BIND) (sym->st_info), STB_GLOBAL)) + switch (ELFW(ST_BIND) (sym->st_info)) { case STB_WEAK: /* Weak definition. Use this value if we don't find another. */ @@ -495,7 +494,7 @@ do_lookup_x (const char *undef_name, uint_fast32_t new_hash, /* If this current map is the one mentioned in the verneed entry and we have not found a weak entry, it is a bug. */ if (symidx == STN_UNDEF && version != NULL && version->filename != NULL - && __builtin_expect (_dl_name_match_p (version->filename, map), 0)) + && __glibc_unlikely (_dl_name_match_p (version->filename, map))) return -1; } while (++i < n); @@ -776,7 +775,7 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map, if (res > 0) break; - if (__builtin_expect (res, 0) < 0 && skip_map == NULL) + if (__glibc_unlikely (res < 0) && skip_map == NULL) { /* Oh, oh. The file named in the relocation entry does not contain the needed symbol. This code is never reached @@ -857,7 +856,7 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map, in the global scope which was dynamically loaded. In this case we have to prevent the latter from being unloaded unless the UNDEF_MAP object is also unloaded. */ - if (__builtin_expect (current_value.m->l_type == lt_loaded, 0) + if (__glibc_unlikely (current_value.m->l_type == lt_loaded) /* Don't do this for explicit lookups as opposed to implicit runtime lookups. */ && (flags & DL_LOOKUP_ADD_DEPENDENCY) != 0 @@ -874,8 +873,8 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map, if (__glibc_unlikely (current_value.m->l_used == 0)) current_value.m->l_used = 1; - if (__builtin_expect (GLRO(dl_debug_mask) - & (DL_DEBUG_BINDINGS|DL_DEBUG_PRELINK), 0)) + if (__glibc_unlikely (GLRO(dl_debug_mask) + & (DL_DEBUG_BINDINGS|DL_DEBUG_PRELINK))) _dl_debug_bindings (undef_name, undef_map, ref, ¤t_value, version, type_class, protected); @@ -892,9 +891,9 @@ _dl_setup_hash (struct link_map *map) { Elf_Symndx *hash; - if (__builtin_expect (map->l_info[DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + if (__glibc_likely (map->l_info[DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM - + DT_EXTRANUM + DT_VALNUM] != NULL, 1)) + + DT_EXTRANUM + DT_VALNUM] != NULL)) { Elf32_Word *hash32 = (void *) D_PTR (map, l_info[DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM @@ -973,10 +972,10 @@ _dl_debug_bindings (const char *undef_name, struct link_map *undef_map, type_class, undef_map); if (val.s != value->s || val.m != value->m) conflict = 1; - else if (__builtin_expect (undef_map->l_symbolic_in_local_scope, 0) + else if (__glibc_unlikely (undef_map->l_symbolic_in_local_scope) && val.s - && __builtin_expect (ELFW(ST_BIND) (val.s->st_info), - STB_GLOBAL) == STB_GNU_UNIQUE) + && __glibc_unlikely (ELFW(ST_BIND) (val.s->st_info) + == STB_GNU_UNIQUE)) { /* If it is STB_GNU_UNIQUE and undef_map's l_local_scope contains any DT_SYMBOLIC libraries, unfortunately there @@ -1010,11 +1009,11 @@ _dl_debug_bindings (const char *undef_name, struct link_map *undef_map, if (value->s) { - if (__builtin_expect (ELFW(ST_TYPE) (value->s->st_info) - == STT_TLS, 0)) + if (__glibc_unlikely (ELFW(ST_TYPE) (value->s->st_info) + == STT_TLS)) type_class = 4; - else if (__builtin_expect (ELFW(ST_TYPE) (value->s->st_info) - == STT_GNU_IFUNC, 0)) + else if (__glibc_unlikely (ELFW(ST_TYPE) (value->s->st_info) + == STT_GNU_IFUNC)) type_class |= 8; }