From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=huawei.com 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 From: "Wangbing(wangbing,RTOS/Poincare Lab)" To: "libc-alpha@sourceware.org" CC: Nixiaoming 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] Content-Type: multipart/alternative; boundary="_000_efbc56f827194b87878392540b88fa12huaweicom_" 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 List-Id: --_000_efbc56f827194b87878392540b88fa12huaweicom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable dlsym with RTLD_DEFAULT add dependency for target symbol, if program use dl= sym 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 sy= mbol 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 =3D NULL; - if (handle =3D=3D RTLD_DEFAULT) + if (handle =3D=3D RTLD_DEFAULT || handle =3D=3D RTLD_PROBE) { match =3D _dl_sym_find_caller_link_map (caller); + int def_flags =3D flags; + if (handle =3D=3D RTLD_DEFAULT) + { + def_flags |=3D 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 =3D 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 =3D match; args.vers =3D vers; args.flags - =3D flags | DL_LOOKUP_ADD_DEPENDENCY | DL_LOOKUP_GSCOPE_LOCK; + =3D def_flags | DL_LOOKUP_GSCOPE_LOCK; args.refp =3D &ref; THREAD_GSCOPE_SET_FLAG (); --_000_efbc56f827194b87878392540b88fa12huaweicom_--