about summary refs log tree commit diff
path: root/elf/dl-sort-maps.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2023-11-16 19:55:35 +0100
committerFlorian Weimer <fweimer@redhat.com>2023-11-16 20:16:05 +0100
commit849274d48fc59bfa6db3c713c8ced8026b20f3b7 (patch)
tree2f92737d63b3b236acd167df35a6d2556bea4c07 /elf/dl-sort-maps.c
parenta8dcffb30680d6db5704f9ce2fc30621ceb454e7 (diff)
downloadglibc-849274d48fc59bfa6db3c713c8ced8026b20f3b7.tar.gz
glibc-849274d48fc59bfa6db3c713c8ced8026b20f3b7.tar.xz
glibc-849274d48fc59bfa6db3c713c8ced8026b20f3b7.zip
elf: Fix force_first handling in dlclose (bug 30981)
The force_first parameter was ineffective because the dlclose'd
object was not necessarily the first in the maps array.  Also
enable force_first handling unconditionally, regardless of namespace.
The initial object in a namespace should be destructed first, too.

The _dl_sort_maps_dfs function had early returns for relocation
dependency processing which broke force_first handling, too, and
this is fixed in this change as well.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'elf/dl-sort-maps.c')
-rw-r--r--elf/dl-sort-maps.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/elf/dl-sort-maps.c b/elf/dl-sort-maps.c
index 5616c8a6a3..5c846c7c6f 100644
--- a/elf/dl-sort-maps.c
+++ b/elf/dl-sort-maps.c
@@ -255,13 +255,12 @@ _dl_sort_maps_dfs (struct link_map **maps, unsigned int nmaps,
 	     The below memcpy is not needed in the do_reldeps case here,
 	     since we wrote back to maps[] during DFS traversal.  */
 	  if (maps_head == maps)
-	    return;
+	    break;
 	}
       assert (maps_head == maps);
-      return;
     }
-
-  memcpy (maps, rpo, sizeof (struct link_map *) * nmaps);
+  else
+    memcpy (maps, rpo, sizeof (struct link_map *) * nmaps);
 
   /* Skipping the first object at maps[0] is not valid in general,
      since traversing along object dependency-links may "find" that