From owner-svn-src-all@FreeBSD.ORG Tue Aug 14 13:28:31 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2D2D3106566B; Tue, 14 Aug 2012 13:28:31 +0000 (UTC) (envelope-from kan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F2EEF8FC12; Tue, 14 Aug 2012 13:28:30 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q7EDSUF8001367; Tue, 14 Aug 2012 13:28:30 GMT (envelope-from kan@svn.freebsd.org) Received: (from kan@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q7EDSU0Y001365; Tue, 14 Aug 2012 13:28:30 GMT (envelope-from kan@svn.freebsd.org) Message-Id: <201208141328.q7EDSU0Y001365@svn.freebsd.org> From: Alexander Kabaev Date: Tue, 14 Aug 2012 13:28:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r239253 - head/libexec/rtld-elf X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Aug 2012 13:28:31 -0000 Author: kan Date: Tue Aug 14 13:28:30 2012 New Revision: 239253 URL: http://svn.freebsd.org/changeset/base/239253 Log: Pospone the DF_1_NODELETE processing until object DAG is fully loaded. Trying to up the reference from the load loop risks missing dependencies that have not been loaded yet. MFC afer: 1 week Reported by: nox Reviewd by: kib Modified: head/libexec/rtld-elf/rtld.c Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Tue Aug 14 12:15:01 2012 (r239252) +++ head/libexec/rtld-elf/rtld.c Tue Aug 14 13:28:30 2012 (r239253) @@ -1743,6 +1743,26 @@ init_dag(Obj_Entry *root) root->dag_inited = true; } +static void +process_nodelete(Obj_Entry *root) +{ + const Objlist_Entry *elm; + + /* + * Walk over object DAG and process every dependent object that + * is marked as DF_1_NODELETE. They need to grow their own DAG, + * which then should have its reference upped separately. + */ + STAILQ_FOREACH(elm, &root->dagmembers, link) { + if (elm->obj != NULL && elm->obj->z_nodelete && + !elm->obj->ref_nodel) { + dbg("obj %s nodelete", elm->obj->path); + init_dag(elm->obj); + ref_dag(elm->obj); + elm->obj->ref_nodel = true; + } + } +} /* * Initialize the dynamic linker. The argument is the address at which * the dynamic linker has been mapped into memory. The primary task of @@ -1932,12 +1952,6 @@ process_needed(Obj_Entry *obj, Needed_En flags & ~RTLD_LO_NOLOAD); if (obj1 == NULL && !ld_tracing && (flags & RTLD_LO_FILTEES) == 0) return (-1); - if (obj1 != NULL && obj1->z_nodelete && !obj1->ref_nodel) { - dbg("obj %s nodelete", obj1->path); - init_dag(obj1); - ref_dag(obj1); - obj1->ref_nodel = true; - } } return (0); } @@ -2833,8 +2847,14 @@ dlopen_object(const char *name, int fd, /* Make list of init functions to call. */ initlist_add_objects(obj, &obj->next, &initlist); } + /* + * Process all no_delete objects here, given them own + * DAGs to prevent their dependencies from being unloaded. + * This has to be done after we have loaded all of the + * dependencies, so that we do not miss any. + */ + process_nodelete(obj); } else { - /* * Bump the reference counts for objects on this DAG. If * this is the first dlopen() call for the object that was