From nobody Thu Apr 17 01:06:46 2025 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZdKVH0frsz5tW0c for ; Thu, 17 Apr 2025 01:06:47 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZdKVG5RJ1z3ZL8 for ; Thu, 17 Apr 2025 01:06:46 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744852006; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wzi8P5e/qufIoUphSOblPunN1TzhCIvqVjHJw+w1uEI=; b=PeGTAYYntf5+jgvMFv6/R73PjGYAEgu3hJd4j60Ama/nD8EhKCHJAnIpB/POwmuADEuKbf 9lUpVkbflKdFLc/GBH2wQP1Ny59YarC8YX928l5JJkOpnrsTbGqxTbF85UGX+CqHrG8HeR /ccbPWaeKS5Enf4I0aCrQA0EdAHT31f2LM4EEEAuPFGecijR/Umj9Gj+1LmWj/vR256Yme 24dnTvHDgbXJQ61jBmHMgVutAMPr9ORg+Pso05BtLj+1Aq5rNYVf1KIyJdfTJ5L0+n6193 j9Nv6Sd6sSYutFB+g+M3aQCq9vb4AoYjVgnU7GYJqzWpy+4FDbDH1xYQHwn4nw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744852006; a=rsa-sha256; cv=none; b=EgnW0I7L4TIQj+B0lg3qi3fj4BqiDOLP02ui+hzE1THEVHNDYR3jF2DrCacGyB6UtAU5A6 oIpG5THCEQfyNKEQ2QU6BrjUnXG8UbMB5tXBwh8uPwTqZoKiPK3pb1XKdU9SMjUq5Lw1mu CmrkPo8T28HAjeAPsnXpdRybzlu15hgH+1eZisIcQFez2XjdcjX70SRdNWK1+r9Ovg0wxo 9bV2hpxYV0U8U+IBHm7tWaqcFIQz5Glx0VM1kfve1UBZ1sC5Z6OSZyiJKSZJqPrhhhbcC8 Zk6VEqWIV8rYBGm4VtM9An3bys1uuFt5EJ46zdgKXQHkL+9JVvNZaW/6+J7F4A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744852006; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wzi8P5e/qufIoUphSOblPunN1TzhCIvqVjHJw+w1uEI=; b=XmA5zS3z3wznFv0K+qUyWt1d2w//LhXflv7nBD3wcDMH6cLqUHrrZmX+Y7I8xJDOUTIjrU kO5Go0ATpC1eXIIwbtsJJAX/EKOdJ5ouA9h4sNNGq0EcFQZS4RmXMDuVDz1ozv5zeJ1g1d R0pP/7uZce2VSub4x2kQhSLLv0+8PZMxGgpRINbLaYNS4/jrkWQllCCSiP4hJiAngRyi0E /Pzdl3lhOJtnTo6AQS7X3m0lPTo7ZuRL7hVl14NqT+Uw1Ql47cWgPIibopMxt/AWUiiwYG ozd3kJOAEygJ1pT5gd7V8jkinGQU8Xot3trzpfOKnPhomSR1tvjdNs77xFvZIA== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZdKVG4x8yzB7k for ; Thu, 17 Apr 2025 01:06:46 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 53H16k2I035068 for ; Thu, 17 Apr 2025 01:06:46 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from bugzilla@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 53H16knS035066 for bugs@FreeBSD.org; Thu, 17 Apr 2025 01:06:46 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: bugzilla set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 285870] Bug in atexit code in rare specific case + patch to correct it Date: Thu, 17 Apr 2025 01:06:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 14.2-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: commit-hook@FreeBSD.org X-Bugzilla-Status: In Progress X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: kevans@freebsd.org X-Bugzilla-Flags: mfc-stable14? mfc-stable13? X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D285870 --- Comment #8 from commit-hook@FreeBSD.org --- A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=3Dc43ae65b4b89be422cdcd399a7abc44f6= db4b298 commit c43ae65b4b89be422cdcd399a7abc44f6db4b298 Author: Aur=C3=A9lien Croc de Suray AuthorDate: 2025-04-05 00:47:53 +0000 Commit: Kyle Evans CommitDate: 2025-04-17 01:01:36 +0000 libc: allow __cxa_atexit handlers to be added during __cxa_finalize science/dlib-cpp reveals an interesting scenario that works fine on other platforms but not on FreeBSD; notably, it ends up creating a new global object from some destructor which is called during __cxa_finalize. This breaks when libdlib is dlopen()ed and then subsequently dlclose()ed, as we never end up invoking the created object's dtor until program exit when the shlib is already unmapped. Fix it by noting when we're in the middle of __cxa_finalize for a dso, and then restarting the search if __cxa_atexit() was called in the middle somewhere. We wait until we've processed the initial set before starting over and processing the newly added handlers as if it were a complete set of handlers added during runtime. The alternative is calling them as they're added to maintain a LIFO in terms of total ordering, but in theory a constructor could add another global object that also needs to be destroyed, and that object needs to be destroyed after the one that constructed it to avoid creating unexpected lifetime issues. This manifests in the pdlib PHP extension for dlib crashing, see [0]. [0] https://github.com/goodspb/pdlib/issues/39 PR: 285870 Reviewed by: kevans (also supplied commit message) (cherry picked from commit 23427c8e1fedb9fc68ad0bd27a59c7ffd2b3008c) lib/libc/stdlib/atexit.c | 61 ++++++++++++++++++++++++++++----------------= ---- 1 file changed, 36 insertions(+), 25 deletions(-) --=20 You are receiving this mail because: You are on the CC list for the bug.=