From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B43BD3858C53; Wed, 18 Oct 2023 14:38:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B43BD3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1697639891; bh=ETevVscmSjoq4fmcA8LcBMYopAt/OSxb9geghJmp9UY=; h=From:To:Subject:Date:From; b=nT7P3voVX3iGy7xF24TzveudMNo+2GYFR3GsbRjSnWiSEEvEd3hbK+eMnvgJ43HmC UPOXmQtpMrww5qYEA2HDjxM3IxkYBfu6Jtrr/DWc/NxRn8YXQc4+7HOiANH3CkaO4d 4xoGHJKQaznfvM2VS8xEF6I6EO6fXoUQDwSzGIvE= From: "fweimer at redhat dot com" To: glibc-bugs@sourceware.org Subject: [Bug dynamic-link/30981] New: dlclose does not properly implement force-first handling Date: Wed, 18 Oct 2023 14:38:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: dynamic-link X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fweimer at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30981 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, t= he 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=3D1): {+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[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[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[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[