From patchwork Tue Sep 27 09:21:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: develop--- via Libc-alpha X-Patchwork-Id: 58066 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 953983858280 for ; Tue, 27 Sep 2022 09:21:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 953983858280 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664270490; bh=sNBkU+t1l1blN/pBHZAqyBrtTpoLJe0CAFx0MSefkCs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DEV/vgRJtMdq7LG8lbjV7bVIRON/VusJV+deFRx9rSirO9dRaQHQMkqBX8R3rOKK2 NR9rRWPI7zAQNzo6NbxIVuHfyT/RKrtNYwcm9BmSCXFxF69XONOzHOU2xhV1Qn0oTq 3l/g2i3iavgNaNmzisO5jv8fMCY5MNKwiuqAWpMg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by sourceware.org (Postfix) with ESMTPS id 8A5BC3858D39 for ; Tue, 27 Sep 2022 09:21:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A5BC3858D39 Received: from canpemm100006.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4McDXL15hLzlWhC for ; Tue, 27 Sep 2022 17:16:50 +0800 (CST) Received: from kwepemi500012.china.huawei.com (7.221.188.12) by canpemm100006.china.huawei.com (7.192.104.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 27 Sep 2022 17:21:04 +0800 Received: from kwepemi500012.china.huawei.com ([7.221.188.12]) by kwepemi500012.china.huawei.com ([7.221.188.12]) with mapi id 15.01.2375.031; Tue, 27 Sep 2022 17:21:04 +0800 To: "libc-alpha@sourceware.org" Subject: [PATCH] dlsym: Add RTLD_PROBE for situation when dlsym only wants to probe a symbol but not use it Thread-Topic: [PATCH] dlsym: Add RTLD_PROBE for situation when dlsym only wants to probe a symbol but not use it Thread-Index: AdjSUldFVe8LqKScTBGD4gk6mdmo2A== Date: Tue, 27 Sep 2022 09:21:04 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.109.108] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HTML_MESSAGE, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: , From: "Wangbing\(wangbing, RTOS/Poincare Lab\) via Libc-alpha" Reply-To: "Wangbing\(wangbing,RTOS/Poincare Lab\)" Cc: Nixiaoming Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" dlsym with RTLD_DEFAULT add dependency for target symbol, if program use dlsym only to detect if a symbol exist, and will not use it. this operation will make unable to dlclose so file containing target symbol, add RTLD_PROBE to support symbol probe. commit f769328dba5351107097c3a3ad7e1192604318d0 Author: Wang Bing > Date: Tue Sep 27 14:58:43 2022 +0800 dlsym: Add RTLD_PROBE for situation when dlsym only wants to probe a symbol but not use it diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h index fe181085..7ac0d5f1 100644 --- a/dlfcn/dlfcn.h +++ b/dlfcn/dlfcn.h @@ -39,6 +39,9 @@ is returned. */ # define RTLD_DEFAULT ((void *) 0) +/* If only find sym in the global scope, but will not use it, do not + set sym dependency. */ +# define RTLD_PROBE ((void *) -2l) /* Type for namespace indices. */ typedef long int Lmid_t; diff --git a/elf/dl-sym.c b/elf/dl-sym.c index de5769f9..970f2028 100644 --- a/elf/dl-sym.c +++ b/elf/dl-sym.c @@ -92,10 +92,15 @@ do_sym (void *handle, const char *name, void *who, /* Link map of the caller if needed. */ struct link_map *match = NULL; - if (handle == RTLD_DEFAULT) + if (handle == RTLD_DEFAULT || handle == RTLD_PROBE) { match = _dl_sym_find_caller_link_map (caller); + int def_flags = flags; + if (handle == RTLD_DEFAULT) + { + def_flags |= DL_LOOKUP_ADD_DEPENDENCY; + } /* Search the global scope. We have the simple case where we look up in the scope of an object which was part of the initial binary. And then the more complex part @@ -104,7 +109,7 @@ do_sym (void *handle, const char *name, void *who, if (RTLD_SINGLE_THREAD_P) result = GLRO(dl_lookup_symbol_x) (name, match, &ref, match->l_scope, vers, 0, - flags | DL_LOOKUP_ADD_DEPENDENCY, + def_flags, NULL); else { @@ -113,7 +118,7 @@ do_sym (void *handle, const char *name, void *who, args.map = match; args.vers = vers; args.flags - = flags | DL_LOOKUP_ADD_DEPENDENCY | DL_LOOKUP_GSCOPE_LOCK; + = def_flags | DL_LOOKUP_GSCOPE_LOCK; args.refp = &ref; THREAD_GSCOPE_SET_FLAG ();