public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/30981] New: dlclose does not properly implement force-first handling
@ 2023-10-18 14:38 fweimer at redhat dot com
  2023-10-18 14:50 ` [Bug dynamic-link/30981] " sam at gentoo dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: fweimer at redhat dot com @ 2023-10-18 14:38 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30981

            Bug ID: 30981
           Summary: dlclose does not properly implement force-first
                    handling
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: fweimer at redhat dot com
  Target Milestone: ---

The ELF destructor for the dlclose'd object should run first, but that does not
happen due to two factors:

The array passed to _dl_sort_maps is gathered from the linked list of all
shared objects. In case of cycles and an unfortuate dlopen/dlclose order, the
first array element may not be the link map passed to dlclose, so the
force_first flag does not have the intended effect.

Inside _dl_sort_maps_dfs, the relocation dependency sorting (for_fini mode) has
early returns which bypass the force_first flag processing further down in the
function's source code. This means that force_first may not have any effect if
for_fini is active.

Fixing these two issues changes the results of the existing tst-bz15311 test
case:

-output(glibc.rtld.dynamic_sort=1):
{+a[d>c>b>a>];+e[e>];+f[f>];+g[g>];+d[];%d(b(e(a()))a()g(c(a()f(b(e(a()))))));-d[];-g[];-f[];-e[];-a[<a<c<d<g<f<b<e];}
-output(glibc.rtld.dynamic_sort=2):
{+a[d>c>b>a>];+e[e>];+f[f>];+g[g>];+d[];%d(b(e(a()))a()g(c(a()f(b(e(a()))))));-d[];-g[];-f[];-e[];-a[<g<f<a<b<c<d<e];}
+output(glibc.rtld.dynamic_sort=1):
{+a[d>c>b>a>];+e[e>];+f[f>];+g[g>];+d[];%d(b(e(a()))a()g(c(a()f(b(e(a()))))));-d[];-g[];-f[];-e[];-a[<a<b<c<d<g<f<e];}
+output(glibc.rtld.dynamic_sort=2):
{+a[d>c>b>a>];+e[e>];+f[f>];+g[g>];+d[];%d(b(e(a()))a()g(c(a()f(b(e(a()))))));-d[];-g[];-f[];-e[];-a[<a<g<f<b<c<d<e];}

In the glibc.rtld.dynamic_sort=1, the lack of nice abcd destructor ordering was
historically blamed on a sorting algorithm deficiency, while in reality it
seems to be a result of the incorrect way _dl_sort_maps was called by dlclose
(the first issue described above).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-20 12:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-18 14:38 [Bug dynamic-link/30981] New: dlclose does not properly implement force-first handling fweimer at redhat dot com
2023-10-18 14:50 ` [Bug dynamic-link/30981] " sam at gentoo dot org
2023-10-19  7:03 ` fweimer at redhat dot com
2023-11-16 18:57 ` fweimer at redhat dot com
2023-11-16 19:19 ` fweimer at redhat dot com
2023-11-20 12:11 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).