From nobody Sun Jul 16 12:34:51 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R3l6350q1z4mZGM; Sun, 16 Jul 2023 12:34:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R3l632vN5z3LCm; Sun, 16 Jul 2023 12:34:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689510891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Mj+0OS9O9pHXMmgcnVnFzdD5DgSfUxgJCISMNk4aRAY=; b=XiDnTQ34frT04hJ8sXuT4SUN8OPjZPnQ+UvifNiQ5iznu/00n+vUlZ4FkooeQ6/UoyciwW F0RJgK/6FtRLl8VwWr+9y4sGnJzqTci4a9MmJsVqzRLsC7a05L2UifYklQGqYLEtVOIT4E YZ6XuUY8IJ4hJ911esqqQ91G41LRSPhigc3S2lP3KowyWyn2fHdfMm+nctL/8iEvvzHa8R 0y2ei/iK/+XSLKWnfat+7Y1jotx6zWd2Dspr8FDGHnMEt4tS/DXLeArLa9LX+n9QZYoYMG nislVo4p/jitIycVhEGlLOqaduT4C5b2hMKtKLseAka+vYLqmZu2D/4Mm9CUYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689510891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Mj+0OS9O9pHXMmgcnVnFzdD5DgSfUxgJCISMNk4aRAY=; b=uF9tPAxkz8U7y5DgwxkEE9dQ+GWF0fZSjNZHKZ4Fr24dxM70FKNVrZzaAwakPw/LjcV2wf O1umJ3CnUpAysCMRzoCrJ4p/uVTcT9rEV2Oaqf5rO4UL+W3zqxgY5AUWHEMmHWyfRtea7X YIT16/+WEjKgbcRiaV4sK1eIeej1gnS+I1KCtl9MFHnhMtNk5qqKoveSgOGrITmbxIJBOf xCCb1urqrEewR1mUv9e714+FmHz4A6A9uscYgyK1+6im1X+khmAilLPbSwdCmaqP2TXJO5 fZTmUPKC3XC+0Apb6fdSKXtl9gqeENNZu3GctYHmscIji4940+xhZfv25RrFog== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689510891; a=rsa-sha256; cv=none; b=JGGTp4uksQDEEf4tHf0S/50bt0Hkl2r+Gen7w3gdHU249Dql7hPO3OfRP1sPANkisrkmIf ZrsJKBbTjOCI8oZ8K7vZlz076X//gcUcavo8fB4m/Z2zJ5RR/g6Y+u32PV9MLFN8AerXya b2ABEeJVVuhHif+PVeMIUK/Vv5CR7U3Aysjy9upfXFpxFNOzBC64WbJUvGbFPZiokkS70v 4Erf+oUH8lnYdKPFK03mRYG5D/WHz+MdooeYYOsVhbZrU3fcJJpjCSkRbk9Vki+L55gDQB IoQW8NkOal7xJT0pfMh3AgX5cKXhuqokoEwtPcXcXtKb6uI2ChMjS0zT7/YdBg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4R3l631jySzjNd; Sun, 16 Jul 2023 12:34:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 36GCYpRu082297; Sun, 16 Jul 2023 12:34:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36GCYplB082296; Sun, 16 Jul 2023 12:34:51 GMT (envelope-from git) Date: Sun, 16 Jul 2023 12:34:51 GMT Message-Id: <202307161234.36GCYplB082296@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 1005d3d05362 - main - rtld: fix dlopen() for an object that is already mapped but not yet initialized List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1005d3d05362de368b1ea7aeb8eb20cee993e122 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1005d3d05362de368b1ea7aeb8eb20cee993e122 commit 1005d3d05362de368b1ea7aeb8eb20cee993e122 Author: Konstantin Belousov AuthorDate: 2023-07-14 13:38:03 +0000 Commit: Konstantin Belousov CommitDate: 2023-07-16 12:34:34 +0000 rtld: fix dlopen() for an object that is already mapped but not yet initialized For instance, dso might be mapped as needed but not yet initialized from the other subtree of needed objects, while current object' constructor does dlopen() for the dso. Right now rtld does relocations and other processing based on the arrival of new objects in the global list, which is not happens there. Directly check for the initialization state of the object, for which we would return the handle. One practical use case of this support is e.g. dlopen("libthr.so", RTLD_NOLOAD) by libraries that are threading-aware but happy to live with libc pthread shims if the program is not multithreaded. Reviewed by: tijl Sponsored by: The FreeBSD Foundation MFC after: 2 weeks --- libexec/rtld-elf/rtld.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 5c96405be62c..83315d5023ba 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -3714,7 +3714,6 @@ static Obj_Entry * dlopen_object(const char *name, int fd, Obj_Entry *refobj, int lo_flags, int mode, RtldLockState *lockstate) { - Obj_Entry *old_obj_tail; Obj_Entry *obj; Objlist initlist; RtldLockState mlockstate; @@ -3731,7 +3730,6 @@ dlopen_object(const char *name, int fd, Obj_Entry *refobj, int lo_flags, } GDB_STATE(RT_ADD,NULL); - old_obj_tail = globallist_curr(TAILQ_LAST(&obj_list, obj_entry_q)); obj = NULL; if (name == NULL && fd == -1) { obj = obj_main; @@ -3744,9 +3742,9 @@ dlopen_object(const char *name, int fd, Obj_Entry *refobj, int lo_flags, obj->dl_refcount++; if (mode & RTLD_GLOBAL && objlist_find(&list_global, obj) == NULL) objlist_push_tail(&list_global, obj); - if (globallist_next(old_obj_tail) != NULL) { - /* We loaded something new. */ - assert(globallist_next(old_obj_tail) == obj); + + if (!obj->init_done) { + /* We loaded something new and have to init something. */ if ((lo_flags & RTLD_LO_DEEPBIND) != 0) obj->symbolic = true; result = 0;