PATCH: Handle DF_1_INTERPOSE (take 2)

H. J. Lu hjl@lucon.org
Sun Jun 1 04:46:00 GMT 2003


I fixed a small bug. Here is the new one.

H.J.
-------------- next part --------------
2003-05-31  H.J. Lu <hongjiu.lu@intel.com>

	* elf/dl-deps.c (_dl_map_object_deps): Handle DF_1_INTERPOSE.

--- elf/dl-deps.c.interpose	2003-01-12 00:01:04.000000000 -0800
+++ elf/dl-deps.c	2003-05-31 19:32:25.000000000 -0700
@@ -145,7 +145,7 @@ _dl_map_object_deps (struct link_map *ma
 		     int trace_mode, int open_mode)
 {
   struct list known[1 + npreloads + 1];
-  struct list *runp, *tail;
+  struct list *runp, *tail, *interpose;
   unsigned int nlist, i;
   /* Object name.  */
   const char *name;
@@ -185,6 +185,9 @@ _dl_map_object_deps (struct link_map *ma
   /* Pointer to last unique object.  */
   tail = &known[nlist - 1];
 
+  /* Where we should start to put interposers.  */
+  interpose = tail;
+
   /* Process each element of the search list, loading each of its
      auxiliary objects and immediate dependencies.  Auxiliary objects
      will be added in the list before the object itself and
@@ -261,12 +264,45 @@ _dl_map_object_deps (struct link_map *ma
 
 		    newp = alloca (sizeof (struct list));
 
-		    /* Append DEP to the list.  */
-		    newp->map = dep;
-		    newp->done = 0;
-		    newp->next = NULL;
-		    tail->next = newp;
-		    tail = newp;
+		    if (__builtin_expect ((dep->l_flags_1
+					   & DF_1_INTERPOSE), 0))
+		      {
+			/* If DEP is an interposer, we put
+			   it right after INTERPOSE.  */
+			newp->map = dep;
+			newp->done = 0;
+			newp->next = interpose->next;
+			interpose->next = newp;
+
+			/* Update the double linked list of all
+			   objects.  */
+			if (dep->l_prev)
+			  dep->l_prev->l_next = dep->l_next;
+			if (dep->l_next)
+			  dep->l_next->l_prev = dep->l_prev;
+
+			dep->l_next = interpose->map->l_next;
+			dep->l_prev = interpose->map;
+			if (interpose->map->l_next)
+			  interpose->map->l_next->l_prev = dep;
+			interpose->map->l_next = dep;
+
+			/* If INTERPOSE is the same as TAIL,
+			   we need to move TAIL too.  */
+			if (interpose == tail)
+			  tail = newp;
+
+			/* Put the next interposer after this one.  */
+			interpose = newp;
+		      }
+		    else
+		      {
+			newp->map = dep;
+			newp->done = 0;
+			newp->next = NULL;
+			tail->next = newp;
+			tail = newp;
+		      }
 		    ++nlist;
 		    /* Set the mark bit that says it's already in the list.  */
 		    dep->l_reserved = 1;


More information about the Libc-alpha mailing list