[Midnightbsd-cvs] src [7872] trunk/libexec/rtld-elf/rtld.c: Pospone the DF_1_NODELETE processing until object DAG is

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Sep 14 12:24:32 EDT 2016


Revision: 7872
          http://svnweb.midnightbsd.org/src/?rev=7872
Author:   laffer1
Date:     2016-09-14 12:24:32 -0400 (Wed, 14 Sep 2016)
Log Message:
-----------
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.

Obtained from: FreeBSD

Modified Paths:
--------------
    trunk/libexec/rtld-elf/rtld.c

Modified: trunk/libexec/rtld-elf/rtld.c
===================================================================
--- trunk/libexec/rtld-elf/rtld.c	2016-09-14 16:22:56 UTC (rev 7871)
+++ trunk/libexec/rtld-elf/rtld.c	2016-09-14 16:24:32 UTC (rev 7872)
@@ -25,7 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD: src/libexec/rtld-elf/rtld.c,v 1.9 2012/10/25 23:21:06 laffer1 Exp $
+ * $MidnightBSD$
  */
 
 /*
@@ -1589,6 +1589,26 @@
     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
@@ -1777,12 +1797,6 @@
 	  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);
 }
@@ -2678,8 +2692,14 @@
 		/* 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



More information about the Midnightbsd-cvs mailing list