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: 28288 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 35DF52100C for ; Fri, 11 Apr 2014 15:30:33 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rp16sf18418349pbb.9 for ; Fri, 11 Apr 2014 08:30:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:mailing-list :precedence:list-id:list-unsubscribe:list-subscribe:list-archive :list-post:list-help:sender:delivered-to:from:to:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results; bh=MaiptlS4f/7VKSwerzJYZCCmYwTZXGiMRW3riSjz0O8=; b=dIwchw1Ln98hsI6QCQJ3eAUGXzkKTb8n6Rr/uEBSfbLo9QRbGM0vVEuYVzSKPucRdq H4WIl6htoRqZLAzbLl3G8L3WCuaMp0lTHuO4+E4ENZu0qu4pKyQ1Z40N1U3+f6RnVkrG T9GEWnNI+0OXkn7jeilp7Uup/q6q81sG6G2eWL7LuwPAP1kuw82W0UdQKmO//kfJGDst Jm3VOYOSlME0UldLq6lzQGK6+B3hUyFvta3oSwFQikIRu5RZrLyKYq15TxMykSdWMJxK mw6TctqjmB9aAdHPURqPkwkVwkTjI0MX9Teh7agteVOrb8mi+Q/QiYP2K7Krm/MkSvFL xkWw== X-Gm-Message-State: ALoCoQnsvRx1WpXBGo5a2E+kkX3PNRuyNEldmH1PLp1oOUy+ejOhrVNyGtwvQ/Kkxkf04Ou/OS6k X-Received: by 10.68.197.73 with SMTP id is9mr11689980pbc.0.1397230232522; Fri, 11 Apr 2014 08:30:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.46.33 with SMTP id j30ls1713624qga.67.gmail; Fri, 11 Apr 2014 08:30:32 -0700 (PDT) X-Received: by 10.220.48.8 with SMTP id p8mr365502vcf.75.1397230232366; Fri, 11 Apr 2014 08:30:32 -0700 (PDT) Received: from mail-ve0-x235.google.com (mail-ve0-x235.google.com [2607:f8b0:400c:c01::235]) by mx.google.com with ESMTPS id h5si1386009vcz.214.2014.04.11.08.30.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Apr 2014 08:30:32 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::235 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::235; Received: by mail-ve0-f181.google.com with SMTP id oy12so4824339veb.26 for ; Fri, 11 Apr 2014 08:30:32 -0700 (PDT) X-Received: by 10.220.7.131 with SMTP id d3mr856645vcd.45.1397230232274; Fri, 11 Apr 2014 08:30:32 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp65476vcb; Fri, 11 Apr 2014 08:30:31 -0700 (PDT) X-Received: by 10.68.231.196 with SMTP id ti4mr28457870pbc.48.1397230231581; Fri, 11 Apr 2014 08:30:31 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id wt1si4460749pbc.290.2014.04.11.08.30.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Apr 2014 08:30:31 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-48976-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 2331 invoked by alias); 11 Apr 2014 15:30:02 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 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-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> X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::235 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 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; }