From patchwork Sun May 1 02:06:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 53369 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 104093858D28 for ; Sun, 1 May 2022 02:07:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 104093858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651370845; bh=PJRw5bJRSwvP+RMYIczaBYB+Mv6k3C3P4GFSM8LoRt8=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tAMarYG9QES3uO9s+BAc/P9Os7NGE3plqElrp2ddSqx3JVW+b9oV+q+Z7hZcVUjDC ebzv52exPxJ8DbW1otCrTCbvem13oN2ZgMy8EHOyCd6gJbV9sRhVGOthaNkmqhY7cq dtj6FULPTzepUX3no022Qhjjq4I1Mw3khOmv9yGE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by sourceware.org (Postfix) with ESMTPS id 7A7CF3858D33 for ; Sun, 1 May 2022 02:06:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A7CF3858D33 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2f84aeb403fso101794857b3.22 for ; Sat, 30 Apr 2022 19:06:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=PJRw5bJRSwvP+RMYIczaBYB+Mv6k3C3P4GFSM8LoRt8=; b=0ZxaintpWJrB1yPq+04z3E7HkY/xzZbHrvof7Vwki7SNkMvMqMPLyF6ikb94/wcHQH d3hVXUIsHGAZo56sS7HoYK8S37yjF3ecWkj66DemXxWwpkiMDXMhzAziOLiAQs1TKkSO nj8uCJ4ihjqIIALeaW4oY8bpy20ieBHL7XEyjAIzLdzmgCf6SvGSOPWAgcKPM1hUb3CU Bawv02WveZlqxZqxY/N6fNc5kByfHvxYv59rl8/dYCnvTkjEBpXYDyJaAl+Ns5eP4EiO d3WKV4iVQxGTcytXdi5B/hJp+I56iGfiM5c1w8Wfk/vS48y4LFByFQjl7bZj5JH2g8WK hJ7A== X-Gm-Message-State: AOAM532e+vvpAHtoOvc5e1NKLWFUnbeDLmZwoxKrwCAGjI9Mj4wQ2BnW srXcFN5QRPTrcwPaSGaJrn49aM5hXITgZUPYU5XNT70r9GtWJaco9oI7bjwhxfdSeFhNSYU+UlB PBnFo1y6YVPblfnq96f168Iwdlk+TfUJsd7QXNikzqTwwsndLnJI9edLLODzR/FEXwh3b X-Google-Smtp-Source: ABdhPJxGHiXixflzsYDoc2Kty5Pf2EY+eu7yc83ljEKUJCznuJ2xYSivCTQ0hlGeKoQmir5V4Xr2b6iYzOyF X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:a6bd:e82a:7b1:cc1]) (user=maskray job=sendgmr) by 2002:a25:5cc:0:b0:648:5905:15e6 with SMTP id 195-20020a2505cc000000b00648590515e6mr5582866ybf.241.1651370810802; Sat, 30 Apr 2022 19:06:50 -0700 (PDT) Date: Sat, 30 Apr 2022 19:06:43 -0700 Message-Id: <20220501020643.1538749-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH] elf: Remove one-default-version check when searching an unversioned symbol To: libc-alpha@sourceware.org, Florian Weimer X-Spam-Status: No, score=-19.5 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Fangrui Song via Libc-alpha From: Fangrui Song Reply-To: Fangrui Song Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" When searching an unversioned symbol, a definition of version VER_NDX_GLOBAL is preferred while a default version symbol is a fallback. The linker ensures that two default versions cannot be attached to the same symbol (``multiple definition of `foo'``), so it is of very little value for the loader to check this corner case. Delete `num_versions` to simplify code. --- elf/dl-lookup.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c index 989b073e4f..5c6b2dc3df 100644 --- a/elf/dl-lookup.c +++ b/elf/dl-lookup.c @@ -65,8 +65,7 @@ check_match (const char *const undef_name, const Elf_Symndx symidx, const char *const strtab, const struct link_map *const map, - const ElfW(Sym) **const versioned_sym, - int *const num_versions) + const ElfW(Sym) **const versioned_sym) { unsigned int stt = ELFW(ST_TYPE) (sym->st_info); assert (ELF_RTYPE_CLASS_PLT == 1); @@ -147,9 +146,7 @@ check_match (const char *const undef_name, >= ((flags & DL_LOOKUP_RETURN_NEWEST) ? 2 : 3)) { /* Don't accept hidden symbols. */ - if ((verstab[symidx] & 0x8000) == 0 - && (*num_versions)++ == 0) - /* No version so far. */ + if ((verstab[symidx] & 0x8000) == 0) *versioned_sym = sym; return NULL; @@ -380,7 +377,6 @@ do_lookup_x (const char *undef_name, unsigned int new_hash, continue; Elf_Symndx symidx; - int num_versions = 0; const ElfW(Sym) *versioned_sym = NULL; /* The tables for this map. */ @@ -414,8 +410,7 @@ do_lookup_x (const char *undef_name, unsigned int new_hash, symidx = ELF_MACHINE_HASH_SYMIDX (map, hasharr); sym = check_match (undef_name, ref, version, flags, type_class, &symtab[symidx], symidx, - strtab, map, &versioned_sym, - &num_versions); + strtab, map, &versioned_sym); if (sym != NULL) goto found_it; } @@ -439,18 +434,17 @@ do_lookup_x (const char *undef_name, unsigned int new_hash, { sym = check_match (undef_name, ref, version, flags, type_class, &symtab[symidx], symidx, - strtab, map, &versioned_sym, - &num_versions); + strtab, map, &versioned_sym); if (sym != NULL) goto found_it; } } - /* If we have seen exactly one versioned symbol while we are - looking for an unversioned symbol and the version is not the - default version we still accept this symbol since there are - no possible ambiguities. */ - sym = num_versions == 1 ? versioned_sym : NULL; + /* When looking for an unversioned symbol, a default version is a fallback + when VER_NDX_GLOBAL is absent. We don't repeat the check ensured by + the linker: no two default version can be attached to the same symbol. + */ + sym = versioned_sym; if (sym != NULL) {